Changeset 13143

Show
Ignore:
Timestamp:
03/19/08 05:24:10 (8 months ago)
Author:
alex
Message:

Adds a subscribe/unsubscribe handle system (still needs docs). Formatting updates. Refs #4366

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dojox/trunk/cometd/_base.js

    r13107 r13143  
    1919         
    2020        // cometd states: 
    21         this.DISCONNECTED="DISCONNECTED";       // _initialized==false  && _connected==false 
    22         this.CONNECTING="CONNECTING";           // _initialized==true   && _connected==false (handshake sent) 
    23         this.CONNECTED="CONNECTED";             // _initialized==true   && _connected==true (first successful connect) 
    24         this.DISCONNECTING="DISCONNECING";      // _initialized==false  && _connected==true (disconnect sent) 
     21 
     22        // alex; OMG, these "constants" need to die. Java truly is a degenerative disease. 
     23        this.DISCONNECTED = "DISCONNECTED";             // _initialized==false  && _connected==false 
     24        this.CONNECTING = "CONNECTING";                 // _initialized==true   && _connected==false (handshake sent) 
     25        this.CONNECTED = "CONNECTED";                   // _initialized==true   && _connected==true (first successful connect) 
     26        this.DISCONNECTING = "DISCONNECING";    // _initialized==false  && _connected==true (disconnect sent) 
    2527         
    2628        this._initialized = false; 
     
    3032        this.connectionTypes = new dojo.AdapterRegistry(true); 
    3133 
    32         this.version="1.0"; 
    33         this.minimumVersion="0.9"; 
    34         this.clientId=null; 
    35         this.messageId=0; 
    36         this.batch=0; 
     34        this.version =  "1.0"; 
     35        this.minimumVersion = "0.9"; 
     36        this.clientId = null; 
     37        this.messageId = 0; 
     38        this.batch = 0; 
    3739 
    3840        this._isXD = false; 
    39         this.handshakeReturn=null; 
    40         this.currentTransport=null; 
     41        this.handshakeReturn = null; 
     42        this.currentTransport = null; 
    4143        this.url = null; 
    42         this.lastMessage=null; 
    43         this._messageQ=[]; 
    44         this.handleAs="json-comment-optional"; 
    45         this._advice={}; 
    46         this._backoffInterval=0; 
    47         this._backoffIncrement=1000; 
    48         this._backoffMax=60000; 
    49         this._deferredSubscribes={}; 
    50         this._deferredUnsubscribes={}; 
    51         this._subscriptions=[]; 
    52         this._extendInList=[];  // List of functions invoked before delivering messages 
    53         this._extendOutList=[]; // List of functions invoked before sending messages 
     44        this.lastMessage = null; 
     45        this._messageQ = []; 
     46        this.handleAs = "json-comment-optional"; 
     47        this._advice = {}; 
     48        this._backoffInterval = 0; 
     49        this._backoffIncrement = 1000; 
     50        this._backoffMax = 60000; 
     51        this._deferredSubscribes = {}; 
     52        this._deferredUnsubscribes = {}; 
     53        this._subscriptions = []; 
     54        this._extendInList = [];        // List of functions invoked before delivering messages 
     55        this._extendOutList = [];       // List of functions invoked before sending messages 
    5456 
    5557        this.state = function() { 
    56                 return this._initialized?(this._connected?this.CONNECTED:this.CONNECTING):(this._connected?this.DISCONNECTING:this.DISCONNECTED); 
     58                return this._initialized ?  
     59                        (this._connected ? "CONNECTED" : "CONNECTING") :  
     60                        ( this._connected ? "DISCONNECTING" : "DISCONNECTED"); 
    5761        } 
    5862 
     
    168172                        r = dojo.xhrPost(bindArgs); 
    169173                } 
    170                 dojo.publish("/cometd/meta", [{cometd:this,action:"handshake",successful:true,state:this.state()}]); 
     174                dojo.publish("/cometd/meta", [ 
     175                        { 
     176                                cometd: this, 
     177                                action: "handshake", 
     178                                successful: true, 
     179                                state: this.state() 
     180                        } 
     181                ]); 
    171182                return r; 
    172183        } 
     
    241252                                funcName: funcName 
    242253                        }); 
    243                         this._subscriptions[tname] =subs; 
    244                 } 
    245                 return this._deferredSubscribes[channel]; 
     254                        this._subscriptions[tname] = subs; 
     255                } 
     256                var ret = this._deferredSubscribes[channel]||{}; 
     257                ret.args = dojo._toArray(arguments); 
     258                return ret; 
    246259        } 
    247260 
     
    263276                //              the second half of the objOrFunc/funcName pair for identifying 
    264277                //              a callback function to notifiy upon channel message delivery 
     278 
     279                if( 
     280                        (arguments.length == 1) && 
     281                        (!dojo.isString(channel)) && 
     282                        (channel.args) 
     283                ){ 
     284                        // it's a subscription handle, unroll 
     285                        return this.unsubscribe.apply(this, channel.args); 
     286                } 
    265287                 
    266288                var tname = "/cometd"+channel;