Changeset 8811

Show
Ignore:
Timestamp:
05/29/07 15:47:29 (18 months ago)
Author:
alex
Message:

merging patches from Greg Wilkins (cometd committer) to add primordial advices support and use option JSON comment filtering for the return. Refs #2520

Files:
1 modified

Legend:

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

    r8806 r8811  
    3636        this.globalTopicChannels = {}; 
    3737        this.backlog = []; 
     38        this.handleAs="json-comment-optional"; 
     39        this.advice; 
    3840 
    3941        this.tunnelInit = function(childLocation, childDomain){ 
     
    5961                // local auth functions to ask for/get auth data? 
    6062 
     63        props.ext = { "json-comment-filtered": true }; 
     64 
    6165                // FIXME: what about ScriptSrcIO for x-domain comet? 
    6266                this.url = root||djConfig["cometdRoot"]; 
     
    7377                var bindArgs = { 
    7478                        url: this.url, 
    75                         handleAs: "json", 
     79                        handleAs: this.handleAs, 
    7680                        content: { "message": dojo.toJson([props]) }, 
    7781                        jsonpParam: "jsonp" // usually ignored 
     
    113117                this.handshakeReturn = data; 
    114118                // pick a transport 
    115                 if(data["authSuccessful"] == false){ 
    116                         console.debug("cometd authentication failed"); 
     119                if (data["advice"]){ 
     120                        this.advice = data.advice; 
     121                } 
     122                if((!data.successful)&&(!data.authSuccessful)){ 
     123                        console.debug("cometd init failed"); 
     124                        // TODO follow advice 
    117125                        return; 
    118126                } 
     
    130138                this.tunnelInit = dojo.hitch(this.currentTransport, "tunnelInit"); 
    131139                this.tunnelCollapse = dojo.hitch(this.currentTransport, "tunnelCollapse"); 
     140 
    132141                this.initialized = true; 
    133142                this.currentTransport.startup(data); 
     
    155164                        return; 
    156165                } 
     166 
    157167                if(!message["channel"]){ 
    158168                        if(message["success"] !== true){ 
     
    162172                } 
    163173                this.lastMessage = message; 
     174 
     175                if(message.advice){ 
     176                        this.advice = message.advice; // TODO maybe merge? 
     177                } 
     178 
    164179                // check to see if we got a /meta channel message that we care about 
    165180                if(     (message["channel"]) && 
     
    318333 
    319334        // FIXME: add an "addPublisher" function 
    320  
    321335} 
    322336 
     
    339353cometd.blahTransport = new function(){ 
    340354        this.connected = false; 
    341         this.connectionId = null; 
    342355        this.authToken = null; 
    343356        this.lastTimestamp = null; 
     
    391404dojox.cometd.longPollTransport = new function(){ 
    392405        this.connected = false; 
    393         this.connectionId = null; 
    394406 
    395407        this.authToken = null; 
     
    423435                        // try to restart the tunnel 
    424436                        this.connected = false; 
    425                         console.debug("clientId:", dojox.cometd.clientId); 
     437                        // console.debug("clientId:", dojox.cometd.clientId); 
     438                         
     439                        // TODO handle transport specific advice 
     440                         
     441                        if(dojox.cometd["advice"]){ 
     442                                if(dojox.cometd.advice["reconnect"]=="none"){ 
     443                                        return; 
     444                                } 
     445                         
     446                    if( (dojox.cometd.advice["interval"])&& 
     447                                        (dojox.cometd.advice.interval>0) ){ 
     448                                        setTimeout(function(){ 
     449                                                dojox.cometd.currentTransport._reconnect(); 
     450                                        }, dojox.cometd.advice.interval); 
     451                                }else{ 
     452                                        this._reconnect(); 
     453                                } 
     454                        }else{ 
     455                                this._reconnect(); 
     456                        } 
     457            } 
     458        }        
     459                         
     460        this._reconnect = function(){ 
     461                if(     (dojox.cometd["advice"])&& 
     462                        (dojox.cometd.advice["reconnect"]=="handshake") 
     463                ){ 
     464                        dojox.io.cometd.init(null,dojox.io.cometd.url); 
     465                }else{ 
    426466                        this.openTunnelWith({ 
    427467                                message: dojo.toJson([ 
     
    430470                                                connectionType: "long-polling", 
    431471                                                clientId:       dojox.cometd.clientId, 
    432                                                 connectionId:   this.connectionId, 
    433472                                                timestamp:      this.lastTimestamp, 
    434473                                                id:                     this.lastId 
     
    450489                        this.lastId = message.id; 
    451490                } 
     491 
    452492                // check to see if we got a /meta channel message that we care about 
    453493                if(     (message.channel.length > 5)&& 
     
    460500                                                return; 
    461501                                        } 
    462                                         this.connectionId = message.connectionId; 
    463502                                        this.connected = true; 
    464503                                        this.processBacklog(); 
     
    476515                                                return; 
    477516                                        } 
    478                                         // this.subscribed(message.channel); 
    479                                         console.debug(message.channel); 
     517                                        this.subscribed(message.channel); 
     518                                        // console.debug(message.channel); 
    480519                                        break; 
    481520                        } 
     
    488527                        url: (url||dojox.cometd.url), 
    489528                        content: content, 
    490                         handleAs: "json", 
     529                        // handleAs: "json", 
     530                        handleAs: dojox.cometd.handleAs, 
    491531                }); 
    492532                d.addCallback(dojo.hitch(this, function(data){ 
     
    499539                d.addErrback(function(err){  
    500540                        console.debug("tunnel opening failed:", err); 
     541 
     542                        // TODO - follow advice to reconnect or rehandshake? 
    501543                }); 
    502544                this.connected = true; 
     
    512554                // FIXME: what about auth fields? 
    513555                if((bypassBacklog)||(this.connected)){ 
    514                         message.connectionId = this.connectionId; 
    515556                        message.clientId = dojox.cometd.clientId; 
    516557 
    517558                        return dojo.xhrPost({ 
    518559                                url: dojox.cometd.url||djConfig["cometdRoot"], 
    519                                 handleAs: "json", 
     560                                handleAs: dojox.cometd.handleAs, 
    520561                                content: {  
    521562                                        message: dojo.toJson([ message ])  
     
    535576dojox.cometd.callbackPollTransport = new function(){ 
    536577        this.connected = false; 
    537         this.connectionId = null; 
    538578 
    539579        this.authToken = null; 
     
    574614                                                connectionType: "long-polling", 
    575615                                                clientId:       dojox.cometd.clientId, 
    576                                                 connectionId:   this.connectionId, 
    577616                                                timestamp:      this.lastTimestamp, 
    578617                                                id:                     this.lastId 
     
    592631                        url: (url||dojox.cometd.url), 
    593632                        content: content, 
    594                         handleAs: "json", 
     633                        handleAs: dojox.cometd.handleAs, 
    595634                        jsonpParam: "jsonp", 
    596635                }).addCallback(dojo.hitch(this, function(data){ 
     
    614653                // FIXME: what about auth fields? 
    615654                if((bypassBacklog)||(this.connected)){ 
    616                         message.connectionId = this.connectionId; 
    617655                        message.clientId = dojox.cometd.clientId; 
    618656                        var bindArgs = { 
    619657                                url: dojox.cometd.url||djConfig["cometdRoot"], 
    620                                 handleAs: "json", 
     658                                handleAs: dojox.io.cometd.handleAs, 
    621659                                jsonpParam: "jsonp", 
    622660                                content: { message: dojo.toJson([ message ]) }, 
     
    633671        } 
    634672} 
    635  
    636673dojox.cometd.connectionTypes.register("long-polling", dojox.cometd.longPollTransport.check, dojox.cometd.longPollTransport); 
    637674dojox.cometd.connectionTypes.register("callback-polling", dojox.cometd.callbackPollTransport.check, dojox.cometd.callbackPollTransport);