summaryrefslogtreecommitdiff
path: root/js/dojo/dojox/cometd/ack.js
blob: 95e7617ee42e109fe9a8de918c87c7a8b6456dc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//>>built
// wrapped by build app
define("dojox/cometd/ack", ["dijit","dojo","dojox","dojo/require!dojox/cometd/_base"], function(dijit,dojo,dojox){
dojo.provide("dojox.cometd.ack");
dojo.require("dojox.cometd._base");

/*
 * This file provides the dojox cometd ack extension which
 * acknowledges the messages received in /meta/connect responses.
 * Each meta/connect is sent with the id of the last successful meta/connect
 * received.  The server uses this information to manage a queue of unacknowleged
 * messages.
 *
 * To use, add dojo.require("dojox.cometd.ack"); and if the handshake will be sent
 * with ext:{ack:true}.  If the server supports the same extension, then the
 * mechanism will be initialized.  The dojox.cometd.ackEnabled field may also be
 * used to optionally enable/disable the extension before init of cometd.
 *
 */
dojox.cometd._ack = new function(){
	var supportAcks = false;
	var lastAck = -1;
	
	this._in = function(msg){
		if (msg.channel == "/meta/handshake") {
			supportAcks = msg.ext && msg.ext.ack;
		} else if (supportAcks && msg.channel == "/meta/connect" && msg.ext && msg.ext.ack && msg.successful) {
			var ackId = parseInt(msg.ext.ack);
			lastAck = ackId;
		}
		return msg;
	}
	
	this._out = function(msg){
	
		if (msg.channel == "/meta/handshake") {
			if (!msg.ext)
				msg.ext = {};
			msg.ext.ack = dojox.cometd.ackEnabled;
			lastAck = -1;
		}
		if (supportAcks && msg.channel == "/meta/connect") {
			if (!msg.ext)
				msg.ext = {};
			msg.ext.ack = lastAck;
		}
		return msg;
	}
};

dojox.cometd._extendInList.push(dojo.hitch(dojox.cometd._ack, "_in"));
dojox.cometd._extendOutList.push(dojo.hitch(dojox.cometd._ack, "_out"));
dojox.cometd.ackEnabled = true;

});