Changeset 8579

Show
Ignore:
Timestamp:
05/11/07 16:42:01 (19 months ago)
Author:
alex
Message:

client is working again. Needs advices (ticket 2520). Refs #2520

Files:
1 modified

Legend:

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

    r8548 r8579  
    7373                var bindArgs = { 
    7474                        url: this.url, 
    75                         handleAs: "text/json", 
     75                        handleAs: "json", 
    7676                        content: { "message": dojo.toJson([props]) }, 
    7777                        jsonpParam: "jsonp" // usually ignored 
     
    105105                } 
    106106                d.addCallback(dojo.hitch(this, "finishInit")); 
     107                d.addErrback(function(e){ console.debug("handshake error!:", e); }); 
    107108                return d; 
    108109        } 
    109110 
    110         this.finishInit = function(type, data, evt, request){ 
     111        this.finishInit = function(data){ 
    111112                data = data[0]; 
    112113                this.handshakeReturn = data; 
     
    150151        this._deliver = function(message){ 
    151152                // dipatch events along the specified path 
    152                 if(!message["channel"]){ 
    153                         console.debug("cometd error: no channel for message!"); 
    154                         return; 
    155                 } 
    156153                if(!this.currentTransport){ 
    157154                        this.backlog.push(["deliver", message]); 
    158155                        return; 
    159156                } 
     157                if(!message["channel"]){ 
     158                        if(message["success"] !== true){ 
     159                                console.debug("cometd error: no channel for message!", message); 
     160                                return; 
     161                        } 
     162                } 
    160163                this.lastMessage = message; 
    161164                // check to see if we got a /meta channel message that we care about 
    162                 if(     (message.channel.length > 5)&& 
     165                if(     (message["channel"]) && 
     166                        (message.channel.length > 5)&& 
    163167                        (message.channel.substr(0, 5) == "/meta")){ 
    164168                        // check for various meta topic actions that we need to respond to 
     
    186190                        // dispatch the message to any locally subscribed listeners 
    187191                        var tname = (this.globalTopicChannels[message.channel]) ? message.channel : "/cometd"+message.channel; 
    188                         dojo.publish(tname, message); 
     192                        dojo.publish(tname, [ message ]); 
    189193                } 
    190194        } 
     
    268272                                                                /*obj*/                                 message){ 
    269273                console.debug(channel); 
    270                 console.debugShallow(message); 
     274                console.debug(message); 
    271275        } 
    272276 
     
    301305                        // destroy the local topic? 
    302306                        var tname = (useLocalTopics) ? channel : "/cometd"+channel; 
    303                         dojo.event.topic.unsubscribe(tname, objOrFunc, funcName); 
     307                        dojo.unsubscribe(tname, objOrFunc, funcName); 
    304308                } 
    305309                return this.currentTransport.sendMessage({ 
     
    311315        this.unsubscribed = function(/*string*/                         channel,  
    312316                                                                /*obj*/                                 message){ 
    313                 console.debug(channel); 
    314                 console.debugShallow(message); 
     317                console.debug(channel, message); 
    315318        } 
    316319 
     
    455458                                case "/meta/connect": 
    456459                                        if(!message.successful){ 
    457                                                 dojo.debug("cometd connection error:", message.error); 
     460                                                console.debug("cometd connection error:", message.error); 
    458461                                                return; 
    459462                                        } 
     
    464467                                case "/meta/reconnect": 
    465468                                        if(!message.successful){ 
    466                                                 dojo.debug("cometd reconnection error:", message.error); 
     469                                                console.debug("cometd reconnection error:", message.error); 
    467470                                                return; 
    468471                                        } 
     
    471474                                case "/meta/subscribe": 
    472475                                        if(!message.successful){ 
    473                                                 dojo.debug("cometd subscription error for channel", message.channel, ":", message.error); 
     476                                                console.debug("cometd subscription error for channel", message.channel, ":", message.error); 
    474477                                                return; 
    475478                                        } 
    476479                                        // this.subscribed(message.channel); 
    477                                         dojo.debug(message.channel); 
     480                                        console.debug(message.channel); 
    478481                                        break; 
    479482                        } 
     
    482485 
    483486        this.openTunnelWith = function(content, url){ 
    484                 dojo.xhrPost({ 
     487                console.debug("openTunnelWith:", content, (url||cometd.url)); 
     488                var d = dojo.xhrPost({ 
    485489                        url: (url||cometd.url), 
    486490                        content: content, 
    487                         handleAs: "text/json", 
    488                 }).addCallback(dojo.hitch(this, function(data){ 
    489                                 // console.debug(evt.responseText); 
    490                                 cometd.deliver(data); 
    491                                 this.connected = false; 
    492                                 this.tunnelCollapse(); 
    493                 })).addErrback(function(){  
    494                         console.debug("tunnel opening failed");  
     491                        handleAs: "json", 
     492                }); 
     493                d.addCallback(dojo.hitch(this, function(data){ 
     494                        // console.debug(evt.responseText); 
     495                        console.debug(data); 
     496                        cometd.deliver(data); 
     497                        this.connected = false; 
     498                        this.tunnelCollapse(); 
     499                })); 
     500                d.addErrback(function(err){  
     501                        console.debug("tunnel opening failed:", err); 
    495502                }); 
    496503                this.connected = true; 
     
    545552                // FIXME: open up the connection here 
    546553                this.openTunnelWith({ 
    547                         message: dojo.json.serialize([ 
     554                        message: dojo.toJson([ 
    548555                                { 
    549556                                        channel:        "/meta/connect", 
     
    563570                        this.connected = false; 
    564571                        this.openTunnelWith({ 
    565                                 message: dojo.json.serialize([ 
     572                                message: dojo.toJson([ 
    566573                                        { 
    567574                                                channel:        "/meta/reconnect",