_base.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. // wrapped by build app
  2. define("dojox/cometd/_base", ["dijit","dojo","dojox","dojo/require!dojo/AdapterRegistry"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.cometd._base");
  4. dojo.require("dojo.AdapterRegistry");
  5. /*
  6. * this file defines Comet protocol client. Actual message transport is
  7. * deferred to one of several connection type implementations. The default is a
  8. * long-polling implementation. A single global object named "dojox.cometd" is
  9. * used to mediate for these connection types in order to provide a stable
  10. * interface.
  11. *
  12. * extensions modules may be loaded (eg "dojox.cometd.timestamp", that use
  13. * the cometd._extendInList and cometd._extendOutList fields to provide functions
  14. * that extend and handling incoming and outgoing messages.
  15. *
  16. * By default the long-polling and callback-polling transports will be required.
  17. * If specific or alternative transports are required, then they can be directly
  18. * loaded. For example dojo.require('dojox.cometd.longPollTransportJsonEncoded')
  19. * will load cometd with only the json encoded variant of the long polling transport.
  20. */
  21. dojox.cometd = {
  22. Connection: function(prefix){ // This constructor is stored as dojox.cometd.Connection
  23. // summary
  24. // This constructor is used to create new cometd connections. Generally, you should use
  25. // one cometd connection for each server you connect to. A default connection instance is
  26. // created at dojox.cometd.
  27. // To connect to a new server you can create an instance like:
  28. // var cometd = new dojox.cometd.Connection("/otherServer");
  29. // cometd.init("http://otherServer.com/cometd");
  30. //
  31. // prefix is the prefix for all the events that are published in the Dojo pub/sub system.
  32. // You must include this prefix, and it should start with a slash like "/myprefix".
  33. // cometd states:
  34. // unconnected, handshaking, connecting, connected, disconnected
  35. dojo.mixin(this, {
  36. prefix: prefix,
  37. _status: "unconnected",
  38. _handshook: false,
  39. _initialized: false,
  40. _polling: false,
  41. expectedNetworkDelay: 10000, // expected max network delay
  42. connectTimeout: 0, // If set, used as ms to wait for a connect response and sent as the advised timeout
  43. version: "1.0",
  44. minimumVersion: "0.9",
  45. clientId: null,
  46. messageId: 0,
  47. batch: 0,
  48. _isXD: false,
  49. handshakeReturn: null,
  50. currentTransport: null,
  51. url: null,
  52. lastMessage: null,
  53. _messageQ: [],
  54. handleAs: "json",
  55. _advice: {},
  56. _backoffInterval: 0,
  57. _backoffIncrement: 1000,
  58. _backoffMax: 60000,
  59. _deferredSubscribes: {},
  60. _deferredUnsubscribes: {},
  61. _subscriptions: [],
  62. _extendInList: [], // List of functions invoked before delivering messages
  63. _extendOutList: [] // List of functions invoked before sending messages
  64. });
  65. this.state = function() {
  66. return this._status;
  67. }
  68. this.init = function( /*String*/ root,
  69. /*Object?*/ props,
  70. /*Object?*/ bargs){ // return: dojo.Deferred
  71. // summary:
  72. // Initialize the cometd implementation of the Bayeux protocol
  73. // description:
  74. // Initialize the cometd implementation of the Bayeux protocol by
  75. // sending a handshake message. The cometd state will be changed to CONNECTING
  76. // until a handshake response is received and the first successful connect message
  77. // has returned.
  78. // The protocol state changes may be monitored
  79. // by subscribing to the dojo topic "/prefix/meta" (typically "/cometd/meta") where
  80. // events are published in the form
  81. // {cometd:this,action:"handshake",successful:true,state:this.state()}
  82. // root:
  83. // The URL of the cometd server. If the root is absolute, the host
  84. // is examined to determine if xd transport is needed. Otherwise the
  85. // same domain is assumed.
  86. // props:
  87. // An optional object that is used as the basis of the handshake message
  88. // bargs:
  89. // An optional object of bind args mixed in with the send of the handshake
  90. // example:
  91. // | dojox.cometd.init("/cometd");
  92. // | dojox.cometd.init("http://xdHost/cometd",{ext:{user:"fred",pwd:"secret"}});
  93. // FIXME: if the root isn't from the same host, we should automatically
  94. // try to select an XD-capable transport
  95. props = props || {};
  96. // go ask the short bus server what we can support
  97. props.version = this.version;
  98. props.minimumVersion = this.minimumVersion;
  99. props.channel = "/meta/handshake";
  100. props.id = "" + this.messageId++;
  101. this.url = root || dojo.config["cometdRoot"];
  102. if(!this.url){
  103. throw "no cometd root";
  104. return null;
  105. }
  106. // Are we x-domain? borrowed from dojo.uri.Uri in lieu of fixed host and port properties
  107. var regexp = "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?$";
  108. var parts = ("" + window.location).match(new RegExp(regexp));
  109. if(parts[4]){
  110. var tmp = parts[4].split(":");
  111. var thisHost = tmp[0];
  112. var thisPort = tmp[1]||"80"; // FIXME: match 443
  113. parts = this.url.match(new RegExp(regexp));
  114. if(parts[4]){
  115. tmp = parts[4].split(":");
  116. var urlHost = tmp[0];
  117. var urlPort = tmp[1]||"80";
  118. this._isXD = ((urlHost != thisHost)||(urlPort != thisPort));
  119. }
  120. }
  121. if(!this._isXD){
  122. props.supportedConnectionTypes = dojo.map(dojox.cometd.connectionTypes.pairs, "return item[0]");
  123. }
  124. props = this._extendOut(props);
  125. var bindArgs = {
  126. url: this.url,
  127. handleAs: this.handleAs,
  128. content: { "message": dojo.toJson([props]) },
  129. load: dojo.hitch(this,function(msg){
  130. this._backon();
  131. this._finishInit(msg);
  132. }),
  133. error: dojo.hitch(this,function(e){
  134. this._backoff();
  135. this._finishInit(e);
  136. }),
  137. timeout: this.expectedNetworkDelay
  138. };
  139. if(bargs){
  140. dojo.mixin(bindArgs, bargs);
  141. }
  142. this._props = props;
  143. for(var tname in this._subscriptions){
  144. for(var sub in this._subscriptions[tname]){
  145. if(this._subscriptions[tname][sub].topic){
  146. dojo.unsubscribe(this._subscriptions[tname][sub].topic);
  147. }
  148. }
  149. }
  150. this._messageQ = [];
  151. this._subscriptions = [];
  152. this._initialized = true;
  153. this._status = "handshaking";
  154. this.batch = 0;
  155. this.startBatch();
  156. var r;
  157. // if xdomain, then we assume jsonp for handshake
  158. if(this._isXD){
  159. bindArgs.callbackParamName = "jsonp";
  160. r = dojo.io.script.get(bindArgs);
  161. }else{
  162. r = dojo.xhrPost(bindArgs);
  163. }
  164. return r;
  165. }
  166. this.publish = function(/*String*/ channel, /*Object*/ data, /*Object?*/ props){
  167. // summary:
  168. // publishes the passed message to the cometd server for delivery
  169. // on the specified topic
  170. // channel:
  171. // the destination channel for the message
  172. // data:
  173. // a JSON object containing the message "payload"
  174. // properties:
  175. // Optional. Other meta-data to be mixed into the top-level of the
  176. // message
  177. var message = {
  178. data: data,
  179. channel: channel
  180. };
  181. if(props){
  182. dojo.mixin(message, props);
  183. }
  184. this._sendMessage(message);
  185. }
  186. this.subscribe = function( /*String */ channel,
  187. /*Object */ objOrFunc,
  188. /*String */ funcName,
  189. /*Object?*/ props){ // return: dojo.Deferred
  190. // summary:
  191. // inform the server of this client's interest in channel
  192. // description:
  193. // `dojox.cometd.subscribe()` handles all the hard work of telling
  194. // the server that we want to be notified when events are
  195. // published on a particular topic. `subscribe` accepts a function
  196. // to handle messages and returns a `dojo.Deferred` object which
  197. // has an extra property added to it which makes it suitable for
  198. // passing to `dojox.cometd.unsubscribe()` as a "subscription
  199. // handle" (much like the handle object that `dojo.connect()`
  200. // produces and which `dojo.disconnect()` expects).
  201. //
  202. // Note that of a subscription is registered before a connection
  203. // with the server is established, events sent before the
  204. // connection is established will not be delivered to this client.
  205. // The deferred object which `subscribe` returns will callback
  206. // when the server successfuly acknolwedges receipt of our
  207. // "subscribe" request.
  208. // channel:
  209. // name of the cometd channel to subscribe to
  210. // objOrFunc:
  211. // an object scope for funcName or the name or reference to a
  212. // function to be called when messages are delivered to the
  213. // channel
  214. // funcName:
  215. // the second half of the objOrFunc/funcName pair for identifying
  216. // a callback function to notifiy upon channel message delivery
  217. // example:
  218. // Simple subscribe use-case
  219. // | dojox.cometd.init("http://myserver.com:8080/cometd");
  220. // | // log out all incoming messages on /foo/bar
  221. // | dojox.cometd.subscribe("/foo/bar", console, "debug");
  222. // example:
  223. // Subscribe before connection is initialized
  224. // | dojox.cometd.subscribe("/foo/bar", console, "debug");
  225. // | dojox.cometd.init("http://myserver.com:8080/cometd");
  226. // example:
  227. // Subscribe an unsubscribe
  228. // | dojox.cometd.init("http://myserver.com:8080/cometd");
  229. // | var h = dojox.cometd.subscribe("/foo/bar", console, "debug");
  230. // | dojox.cometd.unsubscribe(h);
  231. // example:
  232. // Listen for successful subscription:
  233. // | dojox.cometd.init("http://myserver.com:8080/cometd");
  234. // | var h = dojox.cometd.subscribe("/foo/bar", console, "debug");
  235. // | h.addCallback(function(){
  236. // | console.debug("subscription to /foo/bar established");
  237. // | });
  238. props = props||{};
  239. if(objOrFunc){
  240. var tname = prefix + channel;
  241. var subs = this._subscriptions[tname];
  242. if(!subs || subs.length == 0){
  243. subs = [];
  244. props.channel = "/meta/subscribe";
  245. props.subscription = channel;
  246. this._sendMessage(props);
  247. var _ds = this._deferredSubscribes;
  248. if(_ds[channel]){
  249. _ds[channel].cancel();
  250. delete _ds[channel];
  251. }
  252. _ds[channel] = new dojo.Deferred();
  253. }
  254. for(var i in subs){
  255. if(subs[i].objOrFunc === objOrFunc && (!subs[i].funcName&&!funcName||subs[i].funcName==funcName) ){
  256. return null;
  257. }
  258. }
  259. var topic = dojo.subscribe(tname, objOrFunc, funcName);
  260. subs.push({
  261. topic: topic,
  262. objOrFunc: objOrFunc,
  263. funcName: funcName
  264. });
  265. this._subscriptions[tname] = subs;
  266. }
  267. var ret = this._deferredSubscribes[channel] || {};
  268. ret.args = dojo._toArray(arguments);
  269. return ret; // dojo.Deferred
  270. }
  271. this.unsubscribe = function( /*String*/ channel,
  272. /*Object?*/ objOrFunc,
  273. /*String?*/ funcName,
  274. /*Object?*/ props){
  275. // summary:
  276. // inform the server of this client's disinterest in channel
  277. // channel:
  278. // name of the cometd channel to unsubscribe from
  279. // objOrFunc:
  280. // an object scope for funcName or the name or reference to a
  281. // function to be called when messages are delivered to the
  282. // channel. If null then all subscribers to the channel are unsubscribed.
  283. // funcName:
  284. // the second half of the objOrFunc/funcName pair for identifying
  285. // a callback function to notifiy upon channel message delivery
  286. if(
  287. (arguments.length == 1) &&
  288. (!dojo.isString(channel)) &&
  289. (channel.args)
  290. ){
  291. // it's a subscription handle, unroll
  292. return this.unsubscribe.apply(this, channel.args);
  293. }
  294. var tname = prefix + channel;
  295. var subs = this._subscriptions[tname];
  296. if(!subs || subs.length==0){
  297. return null;
  298. }
  299. var s=0;
  300. for(var i in subs){
  301. var sb = subs[i];
  302. if((!objOrFunc) ||
  303. (
  304. sb.objOrFunc===objOrFunc &&
  305. (!sb.funcName && !funcName || sb.funcName==funcName)
  306. )
  307. ){
  308. dojo.unsubscribe(subs[i].topic);
  309. delete subs[i];
  310. }else{
  311. s++;
  312. }
  313. }
  314. if(s == 0){
  315. props = props || {};
  316. props.channel = "/meta/unsubscribe";
  317. props.subscription = channel;
  318. delete this._subscriptions[tname];
  319. this._sendMessage(props);
  320. this._deferredUnsubscribes[channel] = new dojo.Deferred();
  321. if(this._deferredSubscribes[channel]){
  322. this._deferredSubscribes[channel].cancel();
  323. delete this._deferredSubscribes[channel];
  324. }
  325. }
  326. return this._deferredUnsubscribes[channel]; // dojo.Deferred
  327. }
  328. this.disconnect = function(){
  329. // summary:
  330. // Disconnect from the server.
  331. // description:
  332. // Disconnect from the server by sending a disconnect message
  333. // example:
  334. // | dojox.cometd.disconnect();
  335. for(var tname in this._subscriptions){
  336. for(var sub in this._subscriptions[tname]){
  337. if(this._subscriptions[tname][sub].topic){
  338. dojo.unsubscribe(this._subscriptions[tname][sub].topic);
  339. }
  340. }
  341. }
  342. this._subscriptions = [];
  343. this._messageQ = [];
  344. if(this._initialized && this.currentTransport){
  345. this._initialized=false;
  346. this.currentTransport.disconnect();
  347. }
  348. if(!this._polling) {
  349. this._publishMeta("connect",false);
  350. }
  351. this._initialized=false;
  352. this._handshook=false;
  353. this._status = "disconnected"; //should be disconnecting, but we ignore the reply to this message
  354. this._publishMeta("disconnect",true);
  355. }
  356. // public extension points
  357. this.subscribed = function( /*String*/channel, /*Object*/message){ }
  358. this.unsubscribed = function(/*String*/channel, /*Object*/message){ }
  359. // private methods (TODO name all with leading _)
  360. this.tunnelInit = function(childLocation, childDomain){
  361. // placeholder - replaced by _finishInit
  362. }
  363. this.tunnelCollapse = function(){
  364. // placeholder - replaced by _finishInit
  365. }
  366. this._backoff = function(){
  367. if(!this._advice){
  368. this._advice={reconnect:"retry",interval:0};
  369. }else if(!this._advice.interval){
  370. this._advice.interval = 0;
  371. }
  372. if(this._backoffInterval < this._backoffMax){
  373. this._backoffInterval += this._backoffIncrement;
  374. }
  375. }
  376. this._backon = function(){
  377. this._backoffInterval=0;
  378. }
  379. this._interval = function(){
  380. var i = this._backoffInterval + (this._advice ? (this._advice.interval ? this._advice.interval : 0) : 0);
  381. if (i>0){
  382. console.log("Retry in interval+backoff=" + this._advice.interval + "+" + this._backoffInterval+"="+i+"ms");
  383. }
  384. return i;
  385. }
  386. this._publishMeta = function(action,successful,props){
  387. try {
  388. var meta = {cometd:this,action:action,successful:successful,state:this.state()};
  389. if (props){
  390. dojo.mixin(meta, props);
  391. }
  392. dojo.publish(this.prefix + "/meta", [meta]);
  393. } catch(e) {
  394. console.log(e);
  395. }
  396. }
  397. this._finishInit = function(data){
  398. // summary:
  399. // Handle the handshake return from the server and initialize
  400. // connection if all is OK
  401. if(this._status!="handshaking") {return;}
  402. var wasHandshook = this._handshook;
  403. var successful = false;
  404. var metaMsg = {};
  405. if (data instanceof Error) {
  406. dojo.mixin(metaMsg,{
  407. reestablish:false,
  408. failure: true,
  409. error: data,
  410. advice: this._advice
  411. });
  412. } else {
  413. data = data[0];
  414. data = this._extendIn(data);
  415. this.handshakeReturn = data;
  416. // remember any advice
  417. if(data["advice"]){
  418. this._advice = data.advice;
  419. }
  420. successful = data.successful ? data.successful : false;
  421. // check version
  422. if(data.version < this.minimumVersion){
  423. if (console.log)
  424. console.log("cometd protocol version mismatch. We wanted", this.minimumVersion, "but got", data.version);
  425. successful=false;
  426. this._advice.reconnect="none";
  427. }
  428. dojo.mixin(metaMsg,{reestablish: successful && wasHandshook, response:data});
  429. }
  430. this._publishMeta("handshake",successful,metaMsg);
  431. //in the meta listeners, disconnect() may have been called, so recheck it now to
  432. //prevent resends or continuing with initializing the protocol
  433. if(this._status!="handshaking") {return;}
  434. // If all OK
  435. if(successful){
  436. this._status = "connecting";
  437. this._handshook = true;
  438. // pick a transport
  439. this.currentTransport = dojox.cometd.connectionTypes.match(
  440. data.supportedConnectionTypes,
  441. data.version,
  442. this._isXD
  443. );
  444. var transport = this.currentTransport;
  445. // initialize the transport
  446. transport._cometd = this;
  447. transport.version = data.version;
  448. this.clientId = data.clientId;
  449. this.tunnelInit = transport.tunnelInit && dojo.hitch(transport, "tunnelInit");
  450. this.tunnelCollapse = transport.tunnelCollapse && dojo.hitch(transport, "tunnelCollapse");
  451. transport.startup(data);
  452. }else{
  453. // If there is a problem follow advice
  454. if(!this._advice || this._advice["reconnect"] != "none"){
  455. setTimeout(dojo.hitch(this, "init", this.url, this._props), this._interval());
  456. }
  457. }
  458. }
  459. // FIXME: lots of repeated code...why?
  460. this._extendIn = function(message){
  461. // summary: Handle extensions for inbound messages
  462. dojo.forEach(dojox.cometd._extendInList, function(f){
  463. message = f(message) || message;
  464. });
  465. return message;
  466. }
  467. this._extendOut = function(message){
  468. // summary: Handle extensions for inbound messages
  469. dojo.forEach(dojox.cometd._extendOutList, function(f){
  470. message = f(message) || message;
  471. });
  472. return message;
  473. }
  474. this.deliver = function(messages){
  475. dojo.forEach(messages, this._deliver, this);
  476. return messages;
  477. }
  478. this._deliver = function(message){
  479. // dipatch events along the specified path
  480. message = this._extendIn(message);
  481. if(!message["channel"]){
  482. if(message["success"] !== true){
  483. return;
  484. }
  485. }
  486. this.lastMessage = message;
  487. if(message.advice){
  488. this._advice = message.advice; // TODO maybe merge?
  489. }
  490. // check to see if we got a /meta channel message that we care about
  491. var deferred=null;
  492. if( (message["channel"]) &&
  493. (message.channel.length > 5) &&
  494. (message.channel.substr(0, 5) == "/meta")){
  495. // check for various meta topic actions that we need to respond to
  496. switch(message.channel){
  497. case "/meta/connect":
  498. var metaMsg = {response: message};
  499. if(message.successful) {
  500. if (this._status != "connected"){
  501. this._status = "connected";
  502. this.endBatch();
  503. }
  504. }
  505. if(this._initialized){
  506. this._publishMeta("connect",message.successful, metaMsg);
  507. }
  508. break;
  509. case "/meta/subscribe":
  510. deferred = this._deferredSubscribes[message.subscription];
  511. try
  512. {
  513. if(!message.successful){
  514. if(deferred){
  515. deferred.errback(new Error(message.error));
  516. }
  517. this.currentTransport.cancelConnect();
  518. return;
  519. }
  520. if(deferred){
  521. deferred.callback(true);
  522. }
  523. this.subscribed(message.subscription, message);
  524. } catch(e) {
  525. log.warn(e);
  526. }
  527. break;
  528. case "/meta/unsubscribe":
  529. deferred = this._deferredUnsubscribes[message.subscription];
  530. try
  531. {
  532. if(!message.successful){
  533. if(deferred){
  534. deferred.errback(new Error(message.error));
  535. }
  536. this.currentTransport.cancelConnect();
  537. return;
  538. }
  539. if(deferred){
  540. deferred.callback(true);
  541. }
  542. this.unsubscribed(message.subscription, message);
  543. } catch(e) {
  544. log.warn(e);
  545. }
  546. break;
  547. default:
  548. if(message.successful && !message.successful){
  549. this.currentTransport.cancelConnect();
  550. return;
  551. }
  552. }
  553. }
  554. // send the message down for processing by the transport
  555. this.currentTransport.deliver(message);
  556. if(message.data){
  557. // dispatch the message to any locally subscribed listeners
  558. try{
  559. var messages = [message];
  560. // Determine target topic
  561. var tname = prefix + message.channel;
  562. // Deliver to globs that apply to target topic
  563. var tnameParts = message.channel.split("/");
  564. var tnameGlob = prefix;
  565. for (var i = 1; i < tnameParts.length - 1; i++){
  566. dojo.publish(tnameGlob + "/**", messages);
  567. tnameGlob += "/" + tnameParts[i];
  568. }
  569. dojo.publish(tnameGlob + "/**", messages);
  570. dojo.publish(tnameGlob + "/*", messages);
  571. // deliver to target topic
  572. dojo.publish(tname,messages);
  573. }catch(e){
  574. console.log(e);
  575. }
  576. }
  577. }
  578. this._sendMessage = function(/* object */ message){
  579. if(this.currentTransport && !this.batch){
  580. return this.currentTransport.sendMessages([message]);
  581. }else{
  582. this._messageQ.push(message);
  583. return null;
  584. }
  585. }
  586. this.startBatch = function(){
  587. this.batch++;
  588. }
  589. this.endBatch = function(){
  590. if(--this.batch <= 0 && this.currentTransport && this._status == "connected"){
  591. this.batch = 0;
  592. var messages = this._messageQ;
  593. this._messageQ = [];
  594. if(messages.length > 0){
  595. this.currentTransport.sendMessages(messages);
  596. }
  597. }
  598. }
  599. this._onUnload = function(){
  600. // make this the last of the onUnload method
  601. dojo.addOnUnload(dojox.cometd, "disconnect");
  602. }
  603. this._connectTimeout = function(){
  604. // summary: Return the connect timeout in ms, calculated as the minimum of the advised timeout
  605. // and the configured timeout. Else 0 to indicate no client side timeout
  606. var advised=0;
  607. if(this._advice && this._advice.timeout && this.expectedNetworkDelay > 0){
  608. advised = this._advice.timeout + this.expectedNetworkDelay;
  609. }
  610. if(this.connectTimeout > 0 && this.connectTimeout < advised){
  611. return this.connectTimeout;
  612. }
  613. return advised;
  614. }
  615. },
  616. // connectionTypes are shared by all cometd Connection.
  617. connectionTypes : new dojo.AdapterRegistry(true)
  618. }
  619. // create the default instance
  620. dojox.cometd.Connection.call(dojox.cometd,"/cometd");
  621. /*
  622. FIXME: TODOC: this info should be part of the relevant functions and/or overview so
  623. the parser can find it.
  624. transport objects MUST expose the following methods:
  625. - check
  626. - startup
  627. - sendMessages
  628. - deliver
  629. - disconnect
  630. optional, standard but transport dependent methods are:
  631. - tunnelCollapse
  632. - tunnelInit
  633. Transports SHOULD be namespaced under the cometd object and transports MUST
  634. register themselves with cometd.connectionTypes
  635. here's a stub transport defintion:
  636. cometd.blahTransport = new function(){
  637. this._connectionType="my-polling";
  638. this._cometd=null;
  639. this.lastTimestamp = null;
  640. this.check = function(types, version, xdomain){
  641. // summary:
  642. // determines whether or not this transport is suitable given a
  643. // list of transport types that the server supports
  644. return dojo.inArray(types, "blah");
  645. }
  646. this.startup = function(){
  647. if(dojox.cometd._polling){ return; }
  648. // FIXME: fill in startup routine here
  649. dojox.cometd._polling = true;
  650. }
  651. this.sendMessages = function(message){
  652. // FIXME: fill in message array sending logic
  653. }
  654. this.deliver = function(message){
  655. }
  656. this.disconnect = function(){
  657. // send orderly disconnect message
  658. }
  659. this.cancelConnect = function(){
  660. // cancel the current connection
  661. }
  662. }
  663. cometd.connectionTypes.register("blah", cometd.blahTransport.check, cometd.blahTransport);
  664. */
  665. dojo.addOnUnload(dojox.cometd, "_onUnload");
  666. });