ack.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // wrapped by build app
  2. define("dojox/cometd/ack", ["dijit","dojo","dojox","dojo/require!dojox/cometd/_base"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.cometd.ack");
  4. dojo.require("dojox.cometd._base");
  5. /*
  6. * This file provides the dojox cometd ack extension which
  7. * acknowledges the messages received in /meta/connect responses.
  8. * Each meta/connect is sent with the id of the last successful meta/connect
  9. * received. The server uses this information to manage a queue of unacknowleged
  10. * messages.
  11. *
  12. * To use, add dojo.require("dojox.cometd.ack"); and if the handshake will be sent
  13. * with ext:{ack:true}. If the server supports the same extension, then the
  14. * mechanism will be initialized. The dojox.cometd.ackEnabled field may also be
  15. * used to optionally enable/disable the extension before init of cometd.
  16. *
  17. */
  18. dojox.cometd._ack = new function(){
  19. var supportAcks = false;
  20. var lastAck = -1;
  21. this._in = function(msg){
  22. if (msg.channel == "/meta/handshake") {
  23. supportAcks = msg.ext && msg.ext.ack;
  24. } else if (supportAcks && msg.channel == "/meta/connect" && msg.ext && msg.ext.ack && msg.successful) {
  25. var ackId = parseInt(msg.ext.ack);
  26. lastAck = ackId;
  27. }
  28. return msg;
  29. }
  30. this._out = function(msg){
  31. if (msg.channel == "/meta/handshake") {
  32. if (!msg.ext)
  33. msg.ext = {};
  34. msg.ext.ack = dojox.cometd.ackEnabled;
  35. lastAck = -1;
  36. }
  37. if (supportAcks && msg.channel == "/meta/connect") {
  38. if (!msg.ext)
  39. msg.ext = {};
  40. msg.ext.ack = lastAck;
  41. }
  42. return msg;
  43. }
  44. };
  45. dojox.cometd._extendInList.push(dojo.hitch(dojox.cometd._ack, "_in"));
  46. dojox.cometd._extendOutList.push(dojo.hitch(dojox.cometd._ack, "_out"));
  47. dojox.cometd.ackEnabled = true;
  48. });