2 * Copyright (c) 2010 the original author or authors.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
19 function bind(org_cometd)
\r
22 * This client-side extension enables the client to acknowledge to the server
\r
23 * the messages that the client has received.
\r
24 * For the acknowledgement to work, the server must be configured with the
\r
25 * correspondent server-side ack extension. If both client and server support
\r
26 * the ack extension, then the ack functionality will take place automatically.
\r
27 * By enabling this extension, all messages arriving from the server will arrive
\r
28 * via the long poll, so the comet communication will be slightly chattier.
\r
29 * The fact that all messages will return via long poll means also that the
\r
30 * messages will arrive with total order, which is not guaranteed if messages
\r
31 * can arrive via both long poll and normal response.
\r
32 * Messages are not acknowledged one by one, but instead a group of messages is
\r
33 * acknowledged when long poll returns.
\r
35 return org_cometd.AckExtension = function()
\r
38 var _serverSupportsAcks = false;
\r
41 function _debug(text, args)
\r
43 _cometd._debug(text, args);
\r
46 this.registered = function(name, cometd)
\r
49 _debug('AckExtension: executing registration callback');
\r
52 this.unregistered = function()
\r
54 _debug('AckExtension: executing unregistration callback');
\r
58 this.incoming = function(message)
\r
60 var channel = message.channel;
\r
61 if (channel == '/meta/handshake')
\r
63 _serverSupportsAcks = message.ext && message.ext.ack;
\r
64 _debug('AckExtension: server supports acks', _serverSupportsAcks);
\r
66 else if (_serverSupportsAcks && channel == '/meta/connect' && message.successful)
\r
68 var ext = message.ext;
\r
69 if (ext && typeof ext.ack === 'number')
\r
72 _debug('AckExtension: server sent ack id', _ackId);
\r
78 this.outgoing = function(message)
\r
80 var channel = message.channel;
\r
81 if (channel == '/meta/handshake')
\r
87 message.ext.ack = _cometd && _cometd.ackEnabled !== false;
\r
90 else if (_serverSupportsAcks && channel == '/meta/connect')
\r
96 message.ext.ack = _ackId;
\r
97 _debug('AckExtension: client sending ack id', _ackId);
\r
104 if (typeof define === 'function' && define.amd)
\r
106 define(['org/cometd'], bind);
\r