Changeset 8811
- Timestamp:
- 05/29/07 15:47:29 (18 months ago)
- Files:
-
- 1 modified
-
dojox/trunk/_cometd/cometd.js (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dojox/trunk/_cometd/cometd.js
r8806 r8811 36 36 this.globalTopicChannels = {}; 37 37 this.backlog = []; 38 this.handleAs="json-comment-optional"; 39 this.advice; 38 40 39 41 this.tunnelInit = function(childLocation, childDomain){ … … 59 61 // local auth functions to ask for/get auth data? 60 62 63 props.ext = { "json-comment-filtered": true }; 64 61 65 // FIXME: what about ScriptSrcIO for x-domain comet? 62 66 this.url = root||djConfig["cometdRoot"]; … … 73 77 var bindArgs = { 74 78 url: this.url, 75 handleAs: "json",79 handleAs: this.handleAs, 76 80 content: { "message": dojo.toJson([props]) }, 77 81 jsonpParam: "jsonp" // usually ignored … … 113 117 this.handshakeReturn = data; 114 118 // 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 117 125 return; 118 126 } … … 130 138 this.tunnelInit = dojo.hitch(this.currentTransport, "tunnelInit"); 131 139 this.tunnelCollapse = dojo.hitch(this.currentTransport, "tunnelCollapse"); 140 132 141 this.initialized = true; 133 142 this.currentTransport.startup(data); … … 155 164 return; 156 165 } 166 157 167 if(!message["channel"]){ 158 168 if(message["success"] !== true){ … … 162 172 } 163 173 this.lastMessage = message; 174 175 if(message.advice){ 176 this.advice = message.advice; // TODO maybe merge? 177 } 178 164 179 // check to see if we got a /meta channel message that we care about 165 180 if( (message["channel"]) && … … 318 333 319 334 // FIXME: add an "addPublisher" function 320 321 335 } 322 336 … … 339 353 cometd.blahTransport = new function(){ 340 354 this.connected = false; 341 this.connectionId = null;342 355 this.authToken = null; 343 356 this.lastTimestamp = null; … … 391 404 dojox.cometd.longPollTransport = new function(){ 392 405 this.connected = false; 393 this.connectionId = null;394 406 395 407 this.authToken = null; … … 423 435 // try to restart the tunnel 424 436 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{ 426 466 this.openTunnelWith({ 427 467 message: dojo.toJson([ … … 430 470 connectionType: "long-polling", 431 471 clientId: dojox.cometd.clientId, 432 connectionId: this.connectionId,433 472 timestamp: this.lastTimestamp, 434 473 id: this.lastId … … 450 489 this.lastId = message.id; 451 490 } 491 452 492 // check to see if we got a /meta channel message that we care about 453 493 if( (message.channel.length > 5)&& … … 460 500 return; 461 501 } 462 this.connectionId = message.connectionId;463 502 this.connected = true; 464 503 this.processBacklog(); … … 476 515 return; 477 516 } 478 //this.subscribed(message.channel);479 console.debug(message.channel);517 this.subscribed(message.channel); 518 // console.debug(message.channel); 480 519 break; 481 520 } … … 488 527 url: (url||dojox.cometd.url), 489 528 content: content, 490 handleAs: "json", 529 // handleAs: "json", 530 handleAs: dojox.cometd.handleAs, 491 531 }); 492 532 d.addCallback(dojo.hitch(this, function(data){ … … 499 539 d.addErrback(function(err){ 500 540 console.debug("tunnel opening failed:", err); 541 542 // TODO - follow advice to reconnect or rehandshake? 501 543 }); 502 544 this.connected = true; … … 512 554 // FIXME: what about auth fields? 513 555 if((bypassBacklog)||(this.connected)){ 514 message.connectionId = this.connectionId;515 556 message.clientId = dojox.cometd.clientId; 516 557 517 558 return dojo.xhrPost({ 518 559 url: dojox.cometd.url||djConfig["cometdRoot"], 519 handleAs: "json",560 handleAs: dojox.cometd.handleAs, 520 561 content: { 521 562 message: dojo.toJson([ message ]) … … 535 576 dojox.cometd.callbackPollTransport = new function(){ 536 577 this.connected = false; 537 this.connectionId = null;538 578 539 579 this.authToken = null; … … 574 614 connectionType: "long-polling", 575 615 clientId: dojox.cometd.clientId, 576 connectionId: this.connectionId,577 616 timestamp: this.lastTimestamp, 578 617 id: this.lastId … … 592 631 url: (url||dojox.cometd.url), 593 632 content: content, 594 handleAs: "json",633 handleAs: dojox.cometd.handleAs, 595 634 jsonpParam: "jsonp", 596 635 }).addCallback(dojo.hitch(this, function(data){ … … 614 653 // FIXME: what about auth fields? 615 654 if((bypassBacklog)||(this.connected)){ 616 message.connectionId = this.connectionId;617 655 message.clientId = dojox.cometd.clientId; 618 656 var bindArgs = { 619 657 url: dojox.cometd.url||djConfig["cometdRoot"], 620 handleAs: "json",658 handleAs: dojox.io.cometd.handleAs, 621 659 jsonpParam: "jsonp", 622 660 content: { message: dojo.toJson([ message ]) }, … … 633 671 } 634 672 } 635 636 673 dojox.cometd.connectionTypes.register("long-polling", dojox.cometd.longPollTransport.check, dojox.cometd.longPollTransport); 637 674 dojox.cometd.connectionTypes.register("callback-polling", dojox.cometd.callbackPollTransport.check, dojox.cometd.callbackPollTransport);