PageSourceSearch

https://www.ing.com.tr/assets/scripts/AckExtension.js

js ing.com.tr collected 2026-09-24 09:15:10 UTC 4,355 bytes, 105 lines download raw bytes

1/*
2 * Copyright (c) 2008-2018 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17(function(root, factory){
18    if (typeof exports === 'object') {
19        module.exports = factory(require('./cometd'));
20    } else if (typeof define === 'function' && define.amd) {
21        define(['./cometd'], factory);
22    } else {
23        factory(root.org.cometd);
24    }
25}(this, function(cometdModule) {
26    /**
27     * This client-side extension enables the client to acknowledge to the server
28     * the messages that the client has received.
29     * For the acknowledgement to work, the server must be configured with the
30     * correspondent server-side ack extension. If both client and server support
31     * the ack extension, then the ack functionality will take place automatically.
32     * By enabling this extension, all messages arriving from the server will arrive
33     * via /meta/connect, so the comet communication will be slightly chattier.
34     * The fact that all messages will return via /meta/connect means also that the
35     * messages will arrive with total order, which is not guaranteed if messages
36     * can arrive via both /meta/connect and normal response.
37     * Messages are not acknowledged one by one, but instead a batch of messages is
38     * acknowledged when the /meta/connect returns.
39     */
40    return cometdModule.AckExtension = function() {
41        var _cometd;
42        var _serverSupportsAcks = false;
43        var _batch;
44
45        function _debug(text, args) {
46            _cometd._debug(text, args);
47        }
48
49        this.registered = function(name, cometd) {
50            _cometd = cometd;
51            _debug('AckExtension: executing registration callback');
52        };
53
54        this.unregistered = function() {
55            _debug('AckExtension: executing unregistration callback');
56            _cometd = null;
57        };
58
59        this.incoming = function(message) {
60            var channel = message.channel;
61            var ext = message.ext;
62            if (channel === '/meta/handshake') {
63                if (ext) {
64                    var ackField = ext.ack;
65                    if (typeof ackField === 'object') {
66                        // New format.
67                        _serverSupportsAcks = ackField.enabled === true;
68                        var batch = ackField.batch;
69                        if (typeof batch === 'number') {
70                            _batch = batch;
71                        }
72                    } else {
73                        // Old format.
74                        _serverSupportsAcks = ackField === true;
75                    }
76                }
77                _debug('AckExtension: server supports acknowledgements', _serverSupportsAcks);
78            } else if (channel === '/meta/connect' && message.successful && _serverSupportsAcks) {
79                if (ext && typeof ext.ack === 'number') {
80                    _batch = ext.ack;
81                    _debug('AckExtension: server sent batch', _batch);
82                }
83            }
84            return message;
85        };
86
87        this.outgoing = function(message) {
88            var channel = message.channel;
89            if (!message.ext) {
90                message.ext = {};
91            }
92            if (channel === '/meta/handshake') {
93                message.ext.ack = _cometd && _cometd.ackEnabled !== false;
94                _serverSupportsAcks = false;
95                _batch = 0;
96            } else if (channel === '/meta/connect') {
97                if (_serverSupportsAcks) {
98                    message.ext.ack = _batch;
99                    _debug('AckExtension: client sending batch', _batch);
100                }
101            }
102            return message;
103        };
104    };
105}));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.