source: Dev/branches/rest-dojo-ui/client/dojox/cometd/ack.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.5 KB
Line 
1dojo.provide("dojox.cometd.ack");
2dojo.require("dojox.cometd._base");
3
4/*
5 * This file provides the dojox cometd ack extension which
6 * acknowledges the messages received in /meta/connect responses.
7 * Each meta/connect is sent with the id of the last successful meta/connect
8 * received.  The server uses this information to manage a queue of unacknowleged
9 * messages.
10 *
11 * To use, add dojo.require("dojox.cometd.ack"); and if the handshake will be sent
12 * with ext:{ack:true}.  If the server supports the same extension, then the
13 * mechanism will be initialized.  The dojox.cometd.ackEnabled field may also be
14 * used to optionally enable/disable the extension before init of cometd.
15 *
16 */
17dojox.cometd._ack = new function(){
18        var supportAcks = false;
19        var lastAck = -1;
20       
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       
31        this._out = function(msg){
32       
33                if (msg.channel == "/meta/handshake") {
34                        if (!msg.ext)
35                                msg.ext = {};
36                        msg.ext.ack = dojox.cometd.ackEnabled;
37                        lastAck = -1;
38                }
39                if (supportAcks && msg.channel == "/meta/connect") {
40                        if (!msg.ext)
41                                msg.ext = {};
42                        msg.ext.ack = lastAck;
43                }
44                return msg;
45        }
46};
47
48dojox.cometd._extendInList.push(dojo.hitch(dojox.cometd._ack, "_in"));
49dojox.cometd._extendOutList.push(dojo.hitch(dojox.cometd._ack, "_out"));
50dojox.cometd.ackEnabled = true;
Note: See TracBrowser for help on using the repository browser.