epicenter-libs 3.30.0 → 3.31.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/browser/cometd-acd4ed9d.js +4398 -0
  2. package/dist/browser/cometd-acd4ed9d.js.map +1 -0
  3. package/dist/browser/{epicenter-5cdf3000.js → epicenter-6dbc1da9.js} +682 -811
  4. package/dist/browser/epicenter-6dbc1da9.js.map +1 -0
  5. package/dist/browser/epicenter.js +1 -1
  6. package/dist/cjs/cometd-ebbe05cc.js +4416 -0
  7. package/dist/cjs/cometd-ebbe05cc.js.map +1 -0
  8. package/dist/cjs/{epicenter-87213a4f.js → epicenter-75cdb854.js} +683 -816
  9. package/dist/cjs/epicenter-75cdb854.js.map +1 -0
  10. package/dist/cjs/epicenter.js +1 -1
  11. package/dist/epicenter.js +4960 -4439
  12. package/dist/epicenter.js.map +1 -1
  13. package/dist/epicenter.min.js +1 -1
  14. package/dist/epicenter.min.js.map +1 -1
  15. package/dist/module/cometd-ff06a302.js +4403 -0
  16. package/dist/module/cometd-ff06a302.js.map +1 -0
  17. package/dist/module/{epicenter-9bcc042c.js → epicenter-ce6c721b.js} +683 -816
  18. package/dist/module/epicenter-ce6c721b.js.map +1 -0
  19. package/dist/module/epicenter.js +1 -1
  20. package/dist/types/adapters/account.d.ts +7 -8
  21. package/dist/types/adapters/admin.d.ts +1 -2
  22. package/dist/types/adapters/asset.d.ts +3 -4
  23. package/dist/types/adapters/authentication.d.ts +2 -3
  24. package/dist/types/adapters/channel.d.ts +6 -6
  25. package/dist/types/adapters/chat.d.ts +2 -3
  26. package/dist/types/adapters/cometd.d.ts +14 -7
  27. package/dist/types/adapters/consensus.d.ts +1 -2
  28. package/dist/types/adapters/episode.d.ts +1 -2
  29. package/dist/types/adapters/group.d.ts +5 -5
  30. package/dist/types/adapters/leaderboard.d.ts +3 -4
  31. package/dist/types/adapters/presence.d.ts +12 -3
  32. package/dist/types/adapters/project.d.ts +19 -1
  33. package/dist/types/adapters/run.d.ts +9 -10
  34. package/dist/types/adapters/user.d.ts +3 -4
  35. package/dist/types/adapters/vault.d.ts +28 -6
  36. package/dist/types/adapters/wallet.d.ts +2 -3
  37. package/dist/types/adapters/world.d.ts +7 -7
  38. package/dist/types/utils/fault.d.ts +2 -2
  39. package/package.json +7 -6
  40. package/src/adapters/account.ts +7 -7
  41. package/src/adapters/admin.ts +1 -1
  42. package/src/adapters/asset.ts +3 -3
  43. package/src/adapters/authentication.ts +2 -2
  44. package/src/adapters/channel.ts +54 -10
  45. package/src/adapters/chat.ts +2 -2
  46. package/src/adapters/cometd.ts +186 -76
  47. package/src/adapters/consensus.ts +1 -1
  48. package/src/adapters/episode.ts +1 -1
  49. package/src/adapters/group.ts +5 -5
  50. package/src/adapters/leaderboard.ts +3 -3
  51. package/src/adapters/presence.ts +27 -3
  52. package/src/adapters/project.ts +18 -0
  53. package/src/adapters/run.ts +12 -9
  54. package/src/adapters/user.ts +3 -3
  55. package/src/adapters/vault.ts +43 -5
  56. package/src/adapters/wallet.ts +2 -2
  57. package/src/adapters/world.ts +7 -7
  58. package/src/utils/fault.ts +2 -1
  59. package/dist/browser/AckExtension-f37f42e2.js +0 -129
  60. package/dist/browser/AckExtension-f37f42e2.js.map +0 -1
  61. package/dist/browser/ReloadExtension-8757fb10.js +0 -253
  62. package/dist/browser/ReloadExtension-8757fb10.js.map +0 -1
  63. package/dist/browser/cometd-a791c574.js +0 -3438
  64. package/dist/browser/cometd-a791c574.js.map +0 -1
  65. package/dist/browser/epicenter-5cdf3000.js.map +0 -1
  66. package/dist/cjs/AckExtension-c8934f63.js +0 -131
  67. package/dist/cjs/AckExtension-c8934f63.js.map +0 -1
  68. package/dist/cjs/ReloadExtension-c1e9a491.js +0 -255
  69. package/dist/cjs/ReloadExtension-c1e9a491.js.map +0 -1
  70. package/dist/cjs/cometd-a0313fb9.js +0 -3441
  71. package/dist/cjs/cometd-a0313fb9.js.map +0 -1
  72. package/dist/cjs/epicenter-87213a4f.js.map +0 -1
  73. package/dist/module/AckExtension-4b46f46c.js +0 -129
  74. package/dist/module/AckExtension-4b46f46c.js.map +0 -1
  75. package/dist/module/ReloadExtension-9d1a4aac.js +0 -253
  76. package/dist/module/ReloadExtension-9d1a4aac.js.map +0 -1
  77. package/dist/module/cometd-89bc0e26.js +0 -3438
  78. package/dist/module/cometd-89bc0e26.js.map +0 -1
  79. package/dist/module/epicenter-9bcc042c.js.map +0 -1
@@ -0,0 +1,4398 @@
1
+ import { c as createCommonjsModule, g as getDefaultExportFromCjs } from './epicenter-6dbc1da9.js';
2
+
3
+ var classApplyDescriptorGet = createCommonjsModule(function (module) {
4
+ function _classApplyDescriptorGet(receiver, descriptor) {
5
+ if (descriptor.get) {
6
+ return descriptor.get.call(receiver);
7
+ }
8
+
9
+ return descriptor.value;
10
+ }
11
+
12
+ module.exports = _classApplyDescriptorGet;
13
+ module.exports["default"] = module.exports, module.exports.__esModule = true;
14
+ });
15
+
16
+ var classExtractFieldDescriptor = createCommonjsModule(function (module) {
17
+ function _classExtractFieldDescriptor(receiver, privateMap, action) {
18
+ if (!privateMap.has(receiver)) {
19
+ throw new TypeError("attempted to " + action + " private field on non-instance");
20
+ }
21
+
22
+ return privateMap.get(receiver);
23
+ }
24
+
25
+ module.exports = _classExtractFieldDescriptor;
26
+ module.exports["default"] = module.exports, module.exports.__esModule = true;
27
+ });
28
+
29
+ var classPrivateFieldGet = createCommonjsModule(function (module) {
30
+ function _classPrivateFieldGet(receiver, privateMap) {
31
+ var descriptor = classExtractFieldDescriptor(receiver, privateMap, "get");
32
+ return classApplyDescriptorGet(receiver, descriptor);
33
+ }
34
+
35
+ module.exports = _classPrivateFieldGet;
36
+ module.exports["default"] = module.exports, module.exports.__esModule = true;
37
+ });
38
+
39
+ var _classPrivateFieldGet = /*@__PURE__*/getDefaultExportFromCjs(classPrivateFieldGet);
40
+
41
+ var classApplyDescriptorSet = createCommonjsModule(function (module) {
42
+ function _classApplyDescriptorSet(receiver, descriptor, value) {
43
+ if (descriptor.set) {
44
+ descriptor.set.call(receiver, value);
45
+ } else {
46
+ if (!descriptor.writable) {
47
+ throw new TypeError("attempted to set read only private field");
48
+ }
49
+
50
+ descriptor.value = value;
51
+ }
52
+ }
53
+
54
+ module.exports = _classApplyDescriptorSet;
55
+ module.exports["default"] = module.exports, module.exports.__esModule = true;
56
+ });
57
+
58
+ var classPrivateFieldSet = createCommonjsModule(function (module) {
59
+ function _classPrivateFieldSet(receiver, privateMap, value) {
60
+ var descriptor = classExtractFieldDescriptor(receiver, privateMap, "set");
61
+ classApplyDescriptorSet(receiver, descriptor, value);
62
+ return value;
63
+ }
64
+
65
+ module.exports = _classPrivateFieldSet;
66
+ module.exports["default"] = module.exports, module.exports.__esModule = true;
67
+ });
68
+
69
+ var _classPrivateFieldSet = /*@__PURE__*/getDefaultExportFromCjs(classPrivateFieldSet);
70
+
71
+ function _classPrivateFieldInitSpec$a(obj, privateMap, value) { _checkPrivateRedeclaration$a(obj, privateMap); privateMap.set(obj, value); }
72
+ function _checkPrivateRedeclaration$a(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
73
+ var _types = /*#__PURE__*/new WeakMap();
74
+ var _transports$1 = /*#__PURE__*/new WeakMap();
75
+ /*
76
+ * Copyright (c) 2008 the original author or authors.
77
+ *
78
+ * Licensed under the Apache License, Version 2.0 (the "License");
79
+ * you may not use this file except in compliance with the License.
80
+ * You may obtain a copy of the License at
81
+ *
82
+ * http://www.apache.org/licenses/LICENSE-2.0
83
+ *
84
+ * Unless required by applicable law or agreed to in writing, software
85
+ * distributed under the License is distributed on an "AS IS" BASIS,
86
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
87
+ * See the License for the specific language governing permissions and
88
+ * limitations under the License.
89
+ */
90
+
91
+ /**
92
+ * A registry for transports used by the CometD object.
93
+ */
94
+ class TransportRegistry {
95
+ constructor() {
96
+ _classPrivateFieldInitSpec$a(this, _types, {
97
+ writable: true,
98
+ value: []
99
+ });
100
+ _classPrivateFieldInitSpec$a(this, _transports$1, {
101
+ writable: true,
102
+ value: {}
103
+ });
104
+ }
105
+ getTransportTypes() {
106
+ return _classPrivateFieldGet(this, _types).slice(0);
107
+ }
108
+ add(type, transport, index) {
109
+ let existing = false;
110
+ for (let i = 0; i < _classPrivateFieldGet(this, _types).length; ++i) {
111
+ if (_classPrivateFieldGet(this, _types)[i] === type) {
112
+ existing = true;
113
+ break;
114
+ }
115
+ }
116
+ if (!existing) {
117
+ if (typeof index !== "number") {
118
+ _classPrivateFieldGet(this, _types).push(type);
119
+ } else {
120
+ _classPrivateFieldGet(this, _types).splice(index, 0, type);
121
+ }
122
+ _classPrivateFieldGet(this, _transports$1)[type] = transport;
123
+ }
124
+ return !existing;
125
+ }
126
+ find(type) {
127
+ for (let i = 0; i < _classPrivateFieldGet(this, _types).length; ++i) {
128
+ if (_classPrivateFieldGet(this, _types)[i] === type) {
129
+ return _classPrivateFieldGet(this, _transports$1)[type];
130
+ }
131
+ }
132
+ return null;
133
+ }
134
+ negotiateTransport(types, version, crossDomain, url) {
135
+ for (let i = 0; i < _classPrivateFieldGet(this, _types).length; ++i) {
136
+ const type = _classPrivateFieldGet(this, _types)[i];
137
+ for (let j = 0; j < types.length; ++j) {
138
+ if (type === types[j]) {
139
+ const transport = _classPrivateFieldGet(this, _transports$1)[type];
140
+ if (transport.accept(version, crossDomain, url) === true) {
141
+ return transport;
142
+ }
143
+ }
144
+ }
145
+ }
146
+ return null;
147
+ }
148
+ clear() {
149
+ _classPrivateFieldSet(this, _types, []);
150
+ _classPrivateFieldSet(this, _transports$1, {});
151
+ }
152
+ reset(init) {
153
+ for (let i = 0; i < _classPrivateFieldGet(this, _types).length; ++i) {
154
+ _classPrivateFieldGet(this, _transports$1)[_classPrivateFieldGet(this, _types)[i]].reset(init);
155
+ }
156
+ }
157
+ findTransportTypes(version, crossDomain, url) {
158
+ const result = [];
159
+ for (let i = 0; i < _classPrivateFieldGet(this, _types).length; ++i) {
160
+ const type = _classPrivateFieldGet(this, _types)[i];
161
+ if (_classPrivateFieldGet(this, _transports$1)[type].accept(version, crossDomain, url) === true) {
162
+ result.push(type);
163
+ }
164
+ }
165
+ return result;
166
+ }
167
+ remove(type) {
168
+ for (let i = 0; i < _classPrivateFieldGet(this, _types).length; ++i) {
169
+ if (_classPrivateFieldGet(this, _types)[i] === type) {
170
+ _classPrivateFieldGet(this, _types).splice(i, 1);
171
+ const transport = _classPrivateFieldGet(this, _transports$1)[type];
172
+ delete _classPrivateFieldGet(this, _transports$1)[type];
173
+ return transport;
174
+ }
175
+ }
176
+ return null;
177
+ }
178
+ }
179
+
180
+ function _classPrivateFieldInitSpec$9(obj, privateMap, value) { _checkPrivateRedeclaration$9(obj, privateMap); privateMap.set(obj, value); }
181
+ function _checkPrivateRedeclaration$9(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
182
+ var _type = /*#__PURE__*/new WeakMap();
183
+ var _cometd$1 = /*#__PURE__*/new WeakMap();
184
+ var _url = /*#__PURE__*/new WeakMap();
185
+ /*
186
+ * Copyright (c) 2008 the original author or authors.
187
+ *
188
+ * Licensed under the Apache License, Version 2.0 (the "License");
189
+ * you may not use this file except in compliance with the License.
190
+ * You may obtain a copy of the License at
191
+ *
192
+ * http://www.apache.org/licenses/LICENSE-2.0
193
+ *
194
+ * Unless required by applicable law or agreed to in writing, software
195
+ * distributed under the License is distributed on an "AS IS" BASIS,
196
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
197
+ * See the License for the specific language governing permissions and
198
+ * limitations under the License.
199
+ */
200
+
201
+ /**
202
+ * Base class with the common functionality for transports.
203
+ */
204
+ class Transport {
205
+ constructor() {
206
+ _classPrivateFieldInitSpec$9(this, _type, {
207
+ writable: true,
208
+ value: void 0
209
+ });
210
+ _classPrivateFieldInitSpec$9(this, _cometd$1, {
211
+ writable: true,
212
+ value: void 0
213
+ });
214
+ _classPrivateFieldInitSpec$9(this, _url, {
215
+ writable: true,
216
+ value: void 0
217
+ });
218
+ }
219
+ /**
220
+ * Function invoked just after a transport has been successfully registered.
221
+ * @param type the type of transport (for example "long-polling")
222
+ * @param cometd the cometd object this transport has been registered to
223
+ * @see #unregistered()
224
+ */
225
+ registered(type, cometd) {
226
+ _classPrivateFieldSet(this, _type, type);
227
+ _classPrivateFieldSet(this, _cometd$1, cometd);
228
+ }
229
+ /**
230
+ * Function invoked just after a transport has been successfully unregistered.
231
+ * @see #registered(type, cometd)
232
+ */
233
+ unregistered() {
234
+ _classPrivateFieldSet(this, _type, null);
235
+ _classPrivateFieldSet(this, _cometd$1, null);
236
+ }
237
+ get cometd() {
238
+ return _classPrivateFieldGet(this, _cometd$1);
239
+ }
240
+ notifyTransportTimeout(messages) {
241
+ const callbacks = this.cometd._getTransportListeners("timeout");
242
+ if (callbacks) {
243
+ for (let i = 0; i < callbacks.length; ++i) {
244
+ const listener = callbacks[i];
245
+ try {
246
+ const result = listener.call(this, messages);
247
+ if (typeof result === "number" && result > 0) {
248
+ return result;
249
+ }
250
+ } catch (x) {
251
+ this.cometd._info("Exception during execution of transport listener", listener, x);
252
+ }
253
+ }
254
+ }
255
+ return 0;
256
+ }
257
+ debug() {
258
+ this.cometd._debug.apply(this.cometd, arguments);
259
+ }
260
+ get configuration() {
261
+ return this.cometd.getConfiguration();
262
+ }
263
+ get advice() {
264
+ return this.cometd.getAdvice();
265
+ }
266
+ setTimeout(funktion, delay) {
267
+ return this.cometd.setTimeout(funktion, delay);
268
+ }
269
+ clearTimeout(id) {
270
+ this.cometd.clearTimeout(id);
271
+ }
272
+ convertToJSON(messages) {
273
+ const maxSize = this.configuration.maxSendBayeuxMessageSize;
274
+ let result = "[";
275
+ for (let i = 0; i < messages.length; ++i) {
276
+ if (i > 0) {
277
+ result += ",";
278
+ }
279
+ const message = messages[i];
280
+ const json = JSON.stringify(message);
281
+ if (json.length > maxSize) {
282
+ throw new Error("maxSendBayeuxMessageSize " + maxSize + " exceeded");
283
+ }
284
+ result += json;
285
+ }
286
+ result += "]";
287
+ return result;
288
+ }
289
+ /**
290
+ * Converts the given response into an array of bayeux messages
291
+ * @param response the response to convert
292
+ * @return an array of bayeux messages obtained by converting the response
293
+ */
294
+ convertToMessages(response) {
295
+ if (response === undefined || response === null) {
296
+ return [];
297
+ }
298
+ if (typeof response === "string" || response instanceof String) {
299
+ try {
300
+ return JSON.parse(response);
301
+ } catch (x) {
302
+ this.debug("Could not convert to JSON the following string:", response);
303
+ throw x;
304
+ }
305
+ }
306
+ if (Array.isArray(response)) {
307
+ return response;
308
+ }
309
+ if (response instanceof Object) {
310
+ return [response];
311
+ }
312
+ throw new Error("Conversion Error " + response + ", typeof " + typeof response);
313
+ }
314
+ /**
315
+ * Returns whether this transport can work for the given version and cross domain communication case.
316
+ * @param version a string indicating the transport version
317
+ * @param crossDomain a boolean indicating whether the communication is cross domain
318
+ * @param url the URL to connect to
319
+ * @return true if this transport can work for the given version and cross domain communication case,
320
+ * false otherwise
321
+ */
322
+ accept(version, crossDomain, url) {
323
+ throw new Error("Abstract");
324
+ }
325
+ /**
326
+ * Returns the type of this transport.
327
+ * @see #registered(type, cometd)
328
+ */
329
+ get type() {
330
+ return _classPrivateFieldGet(this, _type);
331
+ }
332
+ get url() {
333
+ return _classPrivateFieldGet(this, _url);
334
+ }
335
+ set url(url) {
336
+ _classPrivateFieldSet(this, _url, url);
337
+ }
338
+ send(envelope, metaConnect) {
339
+ throw new Error("Abstract");
340
+ }
341
+ reset(init) {
342
+ this.debug("Transport", this.type, "reset", init ? "initial" : "retry");
343
+ }
344
+ abort() {
345
+ this.debug("Transport", this.type, "aborted");
346
+ }
347
+ toString() {
348
+ return this.type;
349
+ }
350
+ }
351
+
352
+ function _classPrivateMethodInitSpec$5(obj, privateSet) { _checkPrivateRedeclaration$8(obj, privateSet); privateSet.add(obj); }
353
+ function _classPrivateFieldInitSpec$8(obj, privateMap, value) { _checkPrivateRedeclaration$8(obj, privateMap); privateMap.set(obj, value); }
354
+ function _checkPrivateRedeclaration$8(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
355
+ function _classPrivateMethodGet$5(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
356
+
357
+ /**
358
+ * Base class with the common functionality for transports based on requests.
359
+ * The key responsibility is to allow at most 2 outstanding requests to the server,
360
+ * to avoid that requests are sent behind a long poll.
361
+ * To achieve this, we have one reserved request for the long poll, and all other
362
+ * requests are serialized one after the other.
363
+ */
364
+ var _requestIds = /*#__PURE__*/new WeakMap();
365
+ var _metaConnectRequest = /*#__PURE__*/new WeakMap();
366
+ var _requests = /*#__PURE__*/new WeakMap();
367
+ var _envelopes = /*#__PURE__*/new WeakMap();
368
+ var _coalesceEnvelopes = /*#__PURE__*/new WeakSet();
369
+ var _onTransportTimeout$1 = /*#__PURE__*/new WeakSet();
370
+ var _transportSend = /*#__PURE__*/new WeakSet();
371
+ var _queueSend$1 = /*#__PURE__*/new WeakSet();
372
+ var _metaConnectComplete = /*#__PURE__*/new WeakSet();
373
+ var _complete = /*#__PURE__*/new WeakSet();
374
+ var _metaConnectSend = /*#__PURE__*/new WeakSet();
375
+ class RequestTransport extends Transport {
376
+ constructor(...args) {
377
+ super(...args);
378
+ _classPrivateMethodInitSpec$5(this, _metaConnectSend);
379
+ _classPrivateMethodInitSpec$5(this, _complete);
380
+ _classPrivateMethodInitSpec$5(this, _metaConnectComplete);
381
+ _classPrivateMethodInitSpec$5(this, _queueSend$1);
382
+ _classPrivateMethodInitSpec$5(this, _transportSend);
383
+ _classPrivateMethodInitSpec$5(this, _onTransportTimeout$1);
384
+ _classPrivateMethodInitSpec$5(this, _coalesceEnvelopes);
385
+ _classPrivateFieldInitSpec$8(this, _requestIds, {
386
+ writable: true,
387
+ value: 0
388
+ });
389
+ _classPrivateFieldInitSpec$8(this, _metaConnectRequest, {
390
+ writable: true,
391
+ value: null
392
+ });
393
+ _classPrivateFieldInitSpec$8(this, _requests, {
394
+ writable: true,
395
+ value: []
396
+ });
397
+ _classPrivateFieldInitSpec$8(this, _envelopes, {
398
+ writable: true,
399
+ value: []
400
+ });
401
+ }
402
+ complete(request, success, metaConnect) {
403
+ if (metaConnect) {
404
+ _classPrivateMethodGet$5(this, _metaConnectComplete, _metaConnectComplete2).call(this, request);
405
+ } else {
406
+ _classPrivateMethodGet$5(this, _complete, _complete2).call(this, request, success);
407
+ }
408
+ }
409
+ /**
410
+ * Performs the actual send depending on the transport type details.
411
+ * @param envelope the envelope to send
412
+ * @param request the request information
413
+ * @return {boolean} whether the send succeeded
414
+ */
415
+ transportSend(envelope, request) {
416
+ throw new Error("Abstract");
417
+ }
418
+ transportSuccess(envelope, request, responses) {
419
+ if (!request.expired) {
420
+ this.clearTimeout(request.timeout);
421
+ this.debug("Transport", this.type, "cancelled waiting for message replies");
422
+ this.complete(request, true, request.metaConnect);
423
+ if (responses && responses.length > 0) {
424
+ envelope.onSuccess(responses);
425
+ } else {
426
+ envelope.onFailure(request.xhr, envelope.messages, {
427
+ httpCode: 204
428
+ });
429
+ }
430
+ }
431
+ }
432
+ transportFailure(envelope, request, failure) {
433
+ if (!request.expired) {
434
+ this.clearTimeout(request.timeout);
435
+ this.debug("Transport", this.type, "cancelled waiting for failed message replies");
436
+ this.complete(request, false, request.metaConnect);
437
+ envelope.onFailure(request.xhr, envelope.messages, failure);
438
+ }
439
+ }
440
+ send(envelope, metaConnect) {
441
+ if (metaConnect) {
442
+ _classPrivateMethodGet$5(this, _metaConnectSend, _metaConnectSend2).call(this, envelope);
443
+ } else {
444
+ _classPrivateMethodGet$5(this, _queueSend$1, _queueSend2$1).call(this, envelope);
445
+ }
446
+ }
447
+ abort() {
448
+ super.abort();
449
+ for (let i = 0; i < _classPrivateFieldGet(this, _requests).length; ++i) {
450
+ const request = _classPrivateFieldGet(this, _requests)[i];
451
+ if (request) {
452
+ this.debug("Aborting request", request);
453
+ if (!this.abortXHR(request.xhr)) {
454
+ this.transportFailure(request.envelope, request, {
455
+ reason: "abort"
456
+ });
457
+ }
458
+ }
459
+ }
460
+ const metaConnectRequest = _classPrivateFieldGet(this, _metaConnectRequest);
461
+ if (metaConnectRequest) {
462
+ this.debug("Aborting /meta/connect request", metaConnectRequest);
463
+ if (!this.abortXHR(metaConnectRequest.xhr)) {
464
+ this.transportFailure(metaConnectRequest.envelope, metaConnectRequest, {
465
+ reason: "abort"
466
+ });
467
+ }
468
+ }
469
+ this.reset(true);
470
+ }
471
+ reset(init) {
472
+ super.reset(init);
473
+ _classPrivateFieldSet(this, _metaConnectRequest, null);
474
+ _classPrivateFieldSet(this, _requests, []);
475
+ _classPrivateFieldSet(this, _envelopes, []);
476
+ }
477
+ abortXHR(xhr) {
478
+ if (xhr) {
479
+ try {
480
+ const state = xhr.readyState;
481
+ xhr.abort();
482
+ return state !== window.XMLHttpRequest.UNSENT;
483
+ } catch (x) {
484
+ this.debug(x);
485
+ }
486
+ }
487
+ return false;
488
+ }
489
+ xhrStatus(xhr) {
490
+ if (xhr) {
491
+ try {
492
+ return xhr.status;
493
+ } catch (x) {
494
+ this.debug(x);
495
+ }
496
+ }
497
+ return -1;
498
+ }
499
+ }
500
+ function _coalesceEnvelopes2(envelope) {
501
+ while (_classPrivateFieldGet(this, _envelopes).length > 0) {
502
+ const envelopeAndRequest = _classPrivateFieldGet(this, _envelopes)[0];
503
+ const newEnvelope = envelopeAndRequest[0];
504
+ const newRequest = envelopeAndRequest[1];
505
+ if (newEnvelope.url === envelope.url && newEnvelope.sync === envelope.sync) {
506
+ _classPrivateFieldGet(this, _envelopes).shift();
507
+ envelope.messages = envelope.messages.concat(newEnvelope.messages);
508
+ this.debug("Coalesced", newEnvelope.messages.length, "messages from request", newRequest.id);
509
+ continue;
510
+ }
511
+ break;
512
+ }
513
+ }
514
+ function _onTransportTimeout2$1(envelope, request, delay) {
515
+ const result = this.notifyTransportTimeout(envelope.messages);
516
+ if (result > 0) {
517
+ this.debug("Transport", this.type, "extended waiting for message replies of request", request.id, ":", result, "ms");
518
+ request.timeout = this.setTimeout(() => {
519
+ _classPrivateMethodGet$5(this, _onTransportTimeout$1, _onTransportTimeout2$1).call(this, envelope, request, delay + result);
520
+ }, result);
521
+ } else {
522
+ request.expired = true;
523
+ const errorMessage = "Transport " + this + " expired waiting for message replies of request " + request.id + ": " + delay + " ms";
524
+ const failure = {
525
+ reason: errorMessage
526
+ };
527
+ const xhr = request.xhr;
528
+ failure.httpCode = this.xhrStatus(xhr);
529
+ this.abortXHR(xhr);
530
+ this.debug(errorMessage);
531
+ this.complete(request, false, request.metaConnect);
532
+ envelope.onFailure(xhr, envelope.messages, failure);
533
+ }
534
+ }
535
+ function _transportSend2(envelope, request) {
536
+ if (this.transportSend(envelope, request)) {
537
+ request.expired = false;
538
+ if (!envelope.sync) {
539
+ let delay = this.configuration.maxNetworkDelay;
540
+ if (request.metaConnect === true) {
541
+ delay += this.advice.timeout;
542
+ }
543
+ this.debug("Transport", this.type, "started waiting for message replies of request", request.id, ":", delay, "ms");
544
+ request.timeout = this.setTimeout(() => {
545
+ _classPrivateMethodGet$5(this, _onTransportTimeout$1, _onTransportTimeout2$1).call(this, envelope, request, delay);
546
+ }, delay);
547
+ }
548
+ }
549
+ }
550
+ function _queueSend2$1(envelope) {
551
+ var _this$requestIds;
552
+ const requestId = _classPrivateFieldSet(this, _requestIds, (_this$requestIds = _classPrivateFieldGet(this, _requestIds), ++_this$requestIds));
553
+ const request = {
554
+ id: requestId,
555
+ metaConnect: false,
556
+ envelope: envelope
557
+ };
558
+
559
+ // Consider the /meta/connect requests which should always be present.
560
+ if (_classPrivateFieldGet(this, _requests).length < this.configuration.maxConnections - 1) {
561
+ _classPrivateFieldGet(this, _requests).push(request);
562
+ _classPrivateMethodGet$5(this, _transportSend, _transportSend2).call(this, envelope, request);
563
+ } else {
564
+ this.debug("Transport", this.type, "queueing request", requestId, "envelope", envelope);
565
+ _classPrivateFieldGet(this, _envelopes).push([envelope, request]);
566
+ }
567
+ }
568
+ function _metaConnectComplete2(request) {
569
+ const requestId = request.id;
570
+ this.debug("Transport", this.type, "/meta/connect complete, request", requestId);
571
+ if (_classPrivateFieldGet(this, _metaConnectRequest) !== null && _classPrivateFieldGet(this, _metaConnectRequest).id !== requestId) {
572
+ throw new Error("/meta/connect request mismatch, completing request " + requestId);
573
+ }
574
+ _classPrivateFieldSet(this, _metaConnectRequest, null);
575
+ }
576
+ function _complete2(request, success) {
577
+ const index = _classPrivateFieldGet(this, _requests).indexOf(request);
578
+ // The index can be negative if the request has been aborted
579
+ if (index >= 0) {
580
+ _classPrivateFieldGet(this, _requests).splice(index, 1);
581
+ }
582
+ if (_classPrivateFieldGet(this, _envelopes).length > 0) {
583
+ const envelopeAndRequest = _classPrivateFieldGet(this, _envelopes).shift();
584
+ const nextEnvelope = envelopeAndRequest[0];
585
+ const nextRequest = envelopeAndRequest[1];
586
+ this.debug("Transport dequeued request", nextRequest.id);
587
+ if (success) {
588
+ if (this.configuration.autoBatch) {
589
+ _classPrivateMethodGet$5(this, _coalesceEnvelopes, _coalesceEnvelopes2).call(this, nextEnvelope);
590
+ }
591
+ _classPrivateMethodGet$5(this, _queueSend$1, _queueSend2$1).call(this, nextEnvelope);
592
+ this.debug("Transport", this.type, "completed request", request.id, nextEnvelope);
593
+ } else {
594
+ // Keep the semantic of calling callbacks asynchronously.
595
+ this.setTimeout(() => {
596
+ this.complete(nextRequest, false, nextRequest.metaConnect);
597
+ const failure = {
598
+ reason: "Previous request failed"
599
+ };
600
+ const xhr = nextRequest.xhr;
601
+ failure.httpCode = this.xhrStatus(xhr);
602
+ nextEnvelope.onFailure(xhr, nextEnvelope.messages, failure);
603
+ }, 0);
604
+ }
605
+ }
606
+ }
607
+ function _metaConnectSend2(envelope) {
608
+ var _this$requestIds2;
609
+ if (_classPrivateFieldGet(this, _metaConnectRequest) !== null) {
610
+ throw new Error("Concurrent /meta/connect requests not allowed, request id=" + _classPrivateFieldGet(this, _metaConnectRequest).id + " not yet completed");
611
+ }
612
+ const requestId = _classPrivateFieldSet(this, _requestIds, (_this$requestIds2 = _classPrivateFieldGet(this, _requestIds), ++_this$requestIds2));
613
+ this.debug("Transport", this.type, "/meta/connect send, request", requestId, "envelope", envelope);
614
+ const request = {
615
+ id: requestId,
616
+ metaConnect: true,
617
+ envelope: envelope
618
+ };
619
+ _classPrivateMethodGet$5(this, _transportSend, _transportSend2).call(this, envelope, request);
620
+ _classPrivateFieldSet(this, _metaConnectRequest, request);
621
+ }
622
+
623
+ function _classPrivateFieldInitSpec$7(obj, privateMap, value) { _checkPrivateRedeclaration$7(obj, privateMap); privateMap.set(obj, value); }
624
+ function _checkPrivateRedeclaration$7(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
625
+ var _jsonp = /*#__PURE__*/new WeakMap();
626
+ class CallbackPollingTransport extends RequestTransport {
627
+ constructor(...args) {
628
+ super(...args);
629
+ _classPrivateFieldInitSpec$7(this, _jsonp, {
630
+ writable: true,
631
+ value: 0
632
+ });
633
+ }
634
+ accept(version, crossDomain, url) {
635
+ return true;
636
+ }
637
+ jsonpSend(packet) {
638
+ var _this$jsonp, _this$jsonp2;
639
+ const head = window.document.getElementsByTagName("head")[0];
640
+ const script = window.document.createElement("script");
641
+ const callbackName = "_cometd_jsonp_" + (_classPrivateFieldSet(this, _jsonp, (_this$jsonp = _classPrivateFieldGet(this, _jsonp), _this$jsonp2 = _this$jsonp++, _this$jsonp)), _this$jsonp2);
642
+ window[callbackName] = responseText => {
643
+ head.removeChild(script);
644
+ delete window[callbackName];
645
+ packet.onSuccess(responseText);
646
+ };
647
+ let url = packet.url;
648
+ url += url.indexOf("?") < 0 ? "?" : "&";
649
+ url += "jsonp=" + callbackName;
650
+ url += "&message=" + encodeURIComponent(packet.body);
651
+ script.src = url;
652
+ script.async = packet.sync !== true;
653
+ script.type = "text/javascript";
654
+ script.onerror = e => {
655
+ packet.onError("jsonp " + e.type);
656
+ };
657
+ head.appendChild(script);
658
+ }
659
+ transportSend(envelope, request) {
660
+ // Microsoft Internet Explorer has a 2083 URL max length
661
+ // We must ensure that we stay within that length.
662
+ let start = 0;
663
+ let length = envelope.messages.length;
664
+ const lengths = [];
665
+ while (length > 0) {
666
+ // Encode the messages because all brackets, quotes, commas, colons, etc.
667
+ // present in the JSON will be URL encoded, taking many more characters.
668
+ const json = JSON.stringify(envelope.messages.slice(start, start + length));
669
+ const urlLength = envelope.url.length + encodeURI(json).length;
670
+ const maxLength = this.configuration.maxURILength;
671
+ if (urlLength > maxLength) {
672
+ if (length === 1) {
673
+ const x = "Bayeux message too big (" + urlLength + " bytes, max is " + maxLength + ") " + "for transport " + this;
674
+ // Keep the semantic of calling callbacks asynchronously.
675
+ this.setTimeout(() => this.transportFailure(envelope, request, {
676
+ exception: x
677
+ }), 0);
678
+ return false;
679
+ }
680
+ --length;
681
+ continue;
682
+ }
683
+ lengths.push(length);
684
+ start += length;
685
+ length = envelope.messages.length - start;
686
+ }
687
+
688
+ // Here we are sure that the messages can be sent within the URL limit
689
+
690
+ let envelopeToSend = envelope;
691
+ if (lengths.length > 1) {
692
+ let begin = 0;
693
+ let end = lengths[0];
694
+ this.debug("Transport", this.type, "split", envelope.messages.length, "messages into", lengths.join(" + "));
695
+ envelopeToSend = this.cometd._mixin(false, {}, envelope);
696
+ envelopeToSend.messages = envelope.messages.slice(begin, end);
697
+ envelopeToSend.onSuccess = envelope.onSuccess;
698
+ envelopeToSend.onFailure = envelope.onFailure;
699
+ for (let i = 1; i < lengths.length; ++i) {
700
+ const nextEnvelope = this.cometd._mixin(false, {}, envelope);
701
+ begin = end;
702
+ end += lengths[i];
703
+ nextEnvelope.messages = envelope.messages.slice(begin, end);
704
+ nextEnvelope.onSuccess = envelope.onSuccess;
705
+ nextEnvelope.onFailure = envelope.onFailure;
706
+ this.send(nextEnvelope, request.metaConnect);
707
+ }
708
+ }
709
+ this.debug("Transport", this.type, "sending request", request.id, "envelope", envelopeToSend);
710
+ try {
711
+ let sameStack = true;
712
+ this.jsonpSend({
713
+ transport: this,
714
+ url: envelopeToSend.url,
715
+ sync: envelopeToSend.sync,
716
+ headers: this.configuration.requestHeaders,
717
+ body: JSON.stringify(envelopeToSend.messages),
718
+ onSuccess: responses => {
719
+ let success = false;
720
+ try {
721
+ const received = this.convertToMessages(responses);
722
+ if (received.length === 0) {
723
+ this.transportFailure(envelopeToSend, request, {
724
+ httpCode: 204
725
+ });
726
+ } else {
727
+ success = true;
728
+ this.transportSuccess(envelopeToSend, request, received);
729
+ }
730
+ } catch (x) {
731
+ this.debug(x);
732
+ if (!success) {
733
+ this.transportFailure(envelopeToSend, request, {
734
+ exception: x
735
+ });
736
+ }
737
+ }
738
+ },
739
+ onError: (reason, exception) => {
740
+ const failure = {
741
+ reason: reason,
742
+ exception: exception
743
+ };
744
+ if (sameStack) {
745
+ // Keep the semantic of calling callbacks asynchronously.
746
+ this.setTimeout(() => {
747
+ this.transportFailure(envelopeToSend, request, failure);
748
+ }, 0);
749
+ } else {
750
+ this.transportFailure(envelopeToSend, request, failure);
751
+ }
752
+ }
753
+ });
754
+ sameStack = false;
755
+ return true;
756
+ } catch (xx) {
757
+ // Keep the semantic of calling callbacks asynchronously.
758
+ this.setTimeout(() => {
759
+ this.transportFailure(envelopeToSend, request, {
760
+ exception: xx
761
+ });
762
+ }, 0);
763
+ return false;
764
+ }
765
+ }
766
+ }
767
+
768
+ function _classPrivateMethodInitSpec$4(obj, privateSet) { _checkPrivateRedeclaration$6(obj, privateSet); privateSet.add(obj); }
769
+ function _classPrivateFieldInitSpec$6(obj, privateMap, value) { _checkPrivateRedeclaration$6(obj, privateMap); privateMap.set(obj, value); }
770
+ function _checkPrivateRedeclaration$6(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
771
+ function _classPrivateMethodGet$4(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
772
+ var _supportsCrossDomain = /*#__PURE__*/new WeakMap();
773
+ var _newXMLHttpRequest = /*#__PURE__*/new WeakSet();
774
+ var _copyContext = /*#__PURE__*/new WeakSet();
775
+ class LongPollingTransport extends RequestTransport {
776
+ constructor(...args) {
777
+ super(...args);
778
+ _classPrivateMethodInitSpec$4(this, _copyContext);
779
+ _classPrivateMethodInitSpec$4(this, _newXMLHttpRequest);
780
+ // By default, support cross domain.
781
+ _classPrivateFieldInitSpec$6(this, _supportsCrossDomain, {
782
+ writable: true,
783
+ value: true
784
+ });
785
+ }
786
+ accept(version, crossDomain, url) {
787
+ return _classPrivateFieldGet(this, _supportsCrossDomain) || !crossDomain;
788
+ }
789
+ xhrSend(packet) {
790
+ const xhr = _classPrivateMethodGet$4(this, _newXMLHttpRequest, _newXMLHttpRequest2).call(this);
791
+ _classPrivateMethodGet$4(this, _copyContext, _copyContext2).call(this, xhr);
792
+ xhr.withCredentials = true;
793
+ xhr.open("POST", packet.url, packet.sync !== true);
794
+ const headers = packet.headers;
795
+ if (headers) {
796
+ for (let headerName in headers) {
797
+ if (headers.hasOwnProperty(headerName)) {
798
+ xhr.setRequestHeader(headerName, headers[headerName]);
799
+ }
800
+ }
801
+ }
802
+ xhr.setRequestHeader("Content-Type", "application/json");
803
+ xhr.onload = () => {
804
+ if (xhr.status === 200) {
805
+ packet.onSuccess(xhr.responseText);
806
+ } else {
807
+ packet.onError(xhr.statusText);
808
+ }
809
+ };
810
+ xhr.onabort = xhr.onerror = () => {
811
+ packet.onError(xhr.statusText);
812
+ };
813
+ xhr.send(packet.body);
814
+ return xhr;
815
+ }
816
+ transportSend(envelope, request) {
817
+ this.debug("Transport", this.type, "sending request", request.id, "envelope", envelope);
818
+ try {
819
+ let sameStack = true;
820
+ request.xhr = this.xhrSend({
821
+ transport: this,
822
+ url: envelope.url,
823
+ sync: envelope.sync,
824
+ headers: this.configuration.requestHeaders,
825
+ body: this.convertToJSON(envelope.messages),
826
+ onSuccess: response => {
827
+ this.debug("Transport", this.type, "received response", response);
828
+ let success = false;
829
+ try {
830
+ const received = this.convertToMessages(response);
831
+ if (received.length === 0) {
832
+ _classPrivateFieldSet(this, _supportsCrossDomain, false);
833
+ this.transportFailure(envelope, request, {
834
+ httpCode: 204
835
+ });
836
+ } else {
837
+ success = true;
838
+ this.transportSuccess(envelope, request, received);
839
+ }
840
+ } catch (x) {
841
+ this.debug(x);
842
+ if (!success) {
843
+ _classPrivateFieldSet(this, _supportsCrossDomain, false);
844
+ const failure = {
845
+ exception: x
846
+ };
847
+ failure.httpCode = this.xhrStatus(request.xhr);
848
+ this.transportFailure(envelope, request, failure);
849
+ }
850
+ }
851
+ },
852
+ onError: (reason, exception) => {
853
+ this.debug("Transport", this.type, "received error", reason, exception);
854
+ _classPrivateFieldSet(this, _supportsCrossDomain, false);
855
+ const failure = {
856
+ reason: reason,
857
+ exception: exception
858
+ };
859
+ failure.httpCode = this.xhrStatus(request.xhr);
860
+ if (sameStack) {
861
+ // Keep the semantic of calling callbacks asynchronously.
862
+ this.setTimeout(() => {
863
+ this.transportFailure(envelope, request, failure);
864
+ }, 0);
865
+ } else {
866
+ this.transportFailure(envelope, request, failure);
867
+ }
868
+ }
869
+ });
870
+ sameStack = false;
871
+ return true;
872
+ } catch (x) {
873
+ this.debug("Transport", this.type, "exception:", x);
874
+ _classPrivateFieldSet(this, _supportsCrossDomain, false);
875
+ // Keep the semantic of calling callbacks asynchronously.
876
+ this.setTimeout(() => {
877
+ this.transportFailure(envelope, request, {
878
+ exception: x
879
+ });
880
+ }, 0);
881
+ return false;
882
+ }
883
+ }
884
+ reset(init) {
885
+ super.reset(init);
886
+ _classPrivateFieldSet(this, _supportsCrossDomain, true);
887
+ }
888
+ }
889
+ function _newXMLHttpRequest2() {
890
+ return new window.XMLHttpRequest();
891
+ }
892
+ function _copyContext2(xhr) {
893
+ try {
894
+ // Copy external context, to be used in other environments.
895
+ xhr.context = this.context;
896
+ } catch (e) {
897
+ // May happen if XHR is wrapped by Object.seal(),
898
+ // Object.freeze(), or Object.preventExtensions().
899
+ this.debug("Could not copy transport context into XHR", e);
900
+ }
901
+ }
902
+
903
+ function _classPrivateMethodInitSpec$3(obj, privateSet) { _checkPrivateRedeclaration$5(obj, privateSet); privateSet.add(obj); }
904
+ function _classPrivateFieldInitSpec$5(obj, privateMap, value) { _checkPrivateRedeclaration$5(obj, privateMap); privateMap.set(obj, value); }
905
+ function _checkPrivateRedeclaration$5(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
906
+ function _classPrivateMethodGet$3(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
907
+ var _webSocketSupported = /*#__PURE__*/new WeakMap();
908
+ var _webSocketConnected = /*#__PURE__*/new WeakMap();
909
+ var _stickyReconnect = /*#__PURE__*/new WeakMap();
910
+ var _context = /*#__PURE__*/new WeakMap();
911
+ var _connecting = /*#__PURE__*/new WeakMap();
912
+ var _connected$1 = /*#__PURE__*/new WeakMap();
913
+ var _successCallback = /*#__PURE__*/new WeakMap();
914
+ var _forceClose = /*#__PURE__*/new WeakSet();
915
+ var _sameContext = /*#__PURE__*/new WeakSet();
916
+ var _storeEnvelope = /*#__PURE__*/new WeakSet();
917
+ var _removeEnvelope = /*#__PURE__*/new WeakSet();
918
+ var _websocketConnect = /*#__PURE__*/new WeakSet();
919
+ var _onTransportTimeout = /*#__PURE__*/new WeakSet();
920
+ var _webSocketSend = /*#__PURE__*/new WeakSet();
921
+ var _send$1 = /*#__PURE__*/new WeakSet();
922
+ var _onOpen = /*#__PURE__*/new WeakSet();
923
+ var _onMessage = /*#__PURE__*/new WeakSet();
924
+ var _onClose = /*#__PURE__*/new WeakSet();
925
+ var _webSocketClose = /*#__PURE__*/new WeakSet();
926
+ class WebSocketTransport extends Transport {
927
+ constructor(...args) {
928
+ super(...args);
929
+ _classPrivateMethodInitSpec$3(this, _webSocketClose);
930
+ _classPrivateMethodInitSpec$3(this, _onClose);
931
+ _classPrivateMethodInitSpec$3(this, _onMessage);
932
+ _classPrivateMethodInitSpec$3(this, _onOpen);
933
+ _classPrivateMethodInitSpec$3(this, _send$1);
934
+ _classPrivateMethodInitSpec$3(this, _webSocketSend);
935
+ _classPrivateMethodInitSpec$3(this, _onTransportTimeout);
936
+ _classPrivateMethodInitSpec$3(this, _websocketConnect);
937
+ _classPrivateMethodInitSpec$3(this, _removeEnvelope);
938
+ _classPrivateMethodInitSpec$3(this, _storeEnvelope);
939
+ _classPrivateMethodInitSpec$3(this, _sameContext);
940
+ _classPrivateMethodInitSpec$3(this, _forceClose);
941
+ // By default, WebSocket is supported.
942
+ _classPrivateFieldInitSpec$5(this, _webSocketSupported, {
943
+ writable: true,
944
+ value: true
945
+ });
946
+ // Whether we were able to establish a WebSocket connection.
947
+ _classPrivateFieldInitSpec$5(this, _webSocketConnected, {
948
+ writable: true,
949
+ value: false
950
+ });
951
+ _classPrivateFieldInitSpec$5(this, _stickyReconnect, {
952
+ writable: true,
953
+ value: true
954
+ });
955
+ // The context contains the envelopes that have been sent
956
+ // and the timeouts for the messages that have been sent.
957
+ _classPrivateFieldInitSpec$5(this, _context, {
958
+ writable: true,
959
+ value: null
960
+ });
961
+ _classPrivateFieldInitSpec$5(this, _connecting, {
962
+ writable: true,
963
+ value: null
964
+ });
965
+ _classPrivateFieldInitSpec$5(this, _connected$1, {
966
+ writable: true,
967
+ value: false
968
+ });
969
+ _classPrivateFieldInitSpec$5(this, _successCallback, {
970
+ writable: true,
971
+ value: null
972
+ });
973
+ }
974
+ reset(init) {
975
+ super.reset(init);
976
+ _classPrivateFieldSet(this, _webSocketSupported, true);
977
+ if (init) {
978
+ _classPrivateFieldSet(this, _webSocketConnected, false);
979
+ }
980
+ _classPrivateFieldSet(this, _stickyReconnect, true);
981
+ if (init) {
982
+ _classPrivateFieldSet(this, _context, null);
983
+ }
984
+ _classPrivateFieldSet(this, _connecting, null);
985
+ _classPrivateFieldSet(this, _connected$1, false);
986
+ }
987
+ _notifySuccess(fn, messages) {
988
+ fn.call(this, messages);
989
+ }
990
+ _notifyFailure(fn, context, messages, failure) {
991
+ fn.call(this, context, messages, failure);
992
+ }
993
+ accept(version, crossDomain, url) {
994
+ this.debug("Transport", this.type, "accept, supported:", _classPrivateFieldGet(this, _webSocketSupported));
995
+ // Using !! to return a boolean (and not the WebSocket object).
996
+ return _classPrivateFieldGet(this, _webSocketSupported) && !!window.WebSocket && this.cometd.websocketEnabled !== false;
997
+ }
998
+ send(envelope, metaConnect) {
999
+ this.debug("Transport", this.type, "sending", envelope, "/meta/connect =", metaConnect);
1000
+ _classPrivateMethodGet$3(this, _send$1, _send2$1).call(this, _classPrivateFieldGet(this, _context), envelope, metaConnect);
1001
+ }
1002
+ abort() {
1003
+ super.abort();
1004
+ _classPrivateMethodGet$3(this, _forceClose, _forceClose2).call(this, _classPrivateFieldGet(this, _context), {
1005
+ code: 1000,
1006
+ reason: "Abort"
1007
+ });
1008
+ this.reset(true);
1009
+ }
1010
+ }
1011
+ function _forceClose2(context, event) {
1012
+ if (context) {
1013
+ _classPrivateMethodGet$3(this, _webSocketClose, _webSocketClose2).call(this, context, event.code, event.reason);
1014
+ // Force immediate failure of pending messages to trigger reconnect.
1015
+ // This is needed because the server may not reply to our close()
1016
+ // and therefore the onclose function is never called.
1017
+ _classPrivateMethodGet$3(this, _onClose, _onClose2).call(this, context, event);
1018
+ }
1019
+ }
1020
+ function _sameContext2(context) {
1021
+ return context === _classPrivateFieldGet(this, _connecting) || context === _classPrivateFieldGet(this, _context);
1022
+ }
1023
+ function _storeEnvelope2(context, envelope, metaConnect) {
1024
+ const messageIds = [];
1025
+ for (let i = 0; i < envelope.messages.length; ++i) {
1026
+ const message = envelope.messages[i];
1027
+ if (message.id) {
1028
+ messageIds.push(message.id);
1029
+ }
1030
+ }
1031
+ context.envelopes[messageIds.join(",")] = [envelope, metaConnect];
1032
+ this.debug("Transport", this.type, "stored envelope, envelopes", context.envelopes);
1033
+ }
1034
+ function _removeEnvelope2(context, messageIds) {
1035
+ let removed = false;
1036
+ const envelopes = context.envelopes;
1037
+ for (let j = 0; j < messageIds.length; ++j) {
1038
+ const id = messageIds[j];
1039
+ for (let key in envelopes) {
1040
+ if (envelopes.hasOwnProperty(key)) {
1041
+ const ids = key.split(",");
1042
+ const index = ids.indexOf(id);
1043
+ if (index >= 0) {
1044
+ removed = true;
1045
+ ids.splice(index, 1);
1046
+ const envelope = envelopes[key][0];
1047
+ const metaConnect = envelopes[key][1];
1048
+ delete envelopes[key];
1049
+ if (ids.length > 0) {
1050
+ envelopes[ids.join(",")] = [envelope, metaConnect];
1051
+ }
1052
+ break;
1053
+ }
1054
+ }
1055
+ }
1056
+ }
1057
+ if (removed) {
1058
+ this.debug("Transport", this.type, "removed envelope, envelopes", envelopes);
1059
+ }
1060
+ }
1061
+ function _websocketConnect2(context) {
1062
+ // We may have multiple attempts to open a WebSocket
1063
+ // connection, for example a /meta/connect request that
1064
+ // may take time, along with a user-triggered publish.
1065
+ // Early return if we are already connecting.
1066
+ if (_classPrivateFieldGet(this, _connecting)) {
1067
+ return;
1068
+ }
1069
+
1070
+ // Mangle the URL, changing the scheme from "http" to "ws".
1071
+ const url = this.cometd.getURL().replace(/^http/, "ws");
1072
+ this.debug("Transport", this.type, "connecting to URL", url);
1073
+ try {
1074
+ const protocol = this.configuration.protocol;
1075
+ context.webSocket = protocol ? new window.WebSocket(url, protocol) : new window.WebSocket(url);
1076
+ _classPrivateFieldSet(this, _connecting, context);
1077
+ } catch (x) {
1078
+ _classPrivateFieldSet(this, _webSocketSupported, false);
1079
+ this.debug("Exception while creating WebSocket object", x);
1080
+ throw x;
1081
+ }
1082
+
1083
+ // By default use sticky reconnects.
1084
+ _classPrivateFieldSet(this, _stickyReconnect, this.configuration.stickyReconnect !== false);
1085
+ const connectTimeout = this.configuration.connectTimeout;
1086
+ if (connectTimeout > 0) {
1087
+ context.connectTimer = this.setTimeout(() => {
1088
+ this.debug("Transport", this.type, "timed out while connecting to URL", url, ":", connectTimeout, "ms");
1089
+ // The connection was not opened, close anyway.
1090
+ _classPrivateMethodGet$3(this, _forceClose, _forceClose2).call(this, context, {
1091
+ code: 1000,
1092
+ reason: "Connect Timeout"
1093
+ });
1094
+ }, connectTimeout);
1095
+ }
1096
+ const onopen = () => {
1097
+ this.debug("Transport", this.type, "onopen", context);
1098
+ if (context.connectTimer) {
1099
+ this.clearTimeout(context.connectTimer);
1100
+ }
1101
+ if (_classPrivateMethodGet$3(this, _sameContext, _sameContext2).call(this, context)) {
1102
+ _classPrivateFieldSet(this, _connecting, null);
1103
+ _classPrivateFieldSet(this, _context, context);
1104
+ _classPrivateFieldSet(this, _webSocketConnected, true);
1105
+ _classPrivateMethodGet$3(this, _onOpen, _onOpen2).call(this, context);
1106
+ } else {
1107
+ // We have a valid connection already, close this one.
1108
+ this.cometd._warn("Closing extra WebSocket connection", this, "active connection", _classPrivateFieldGet(this, _context));
1109
+ _classPrivateMethodGet$3(this, _forceClose, _forceClose2).call(this, context, {
1110
+ code: 1000,
1111
+ reason: "Extra Connection"
1112
+ });
1113
+ }
1114
+ };
1115
+
1116
+ // This callback is invoked when the server sends the close frame.
1117
+ // The close frame for a connection may arrive *after* another
1118
+ // connection has been opened, so we must make sure that actions
1119
+ // are performed only if it's the same connection.
1120
+ const onclose = event => {
1121
+ event = event || {
1122
+ code: 1000
1123
+ };
1124
+ this.debug("Transport", this.type, "onclose", context, event, "connecting", _classPrivateFieldGet(this, _connecting), "current", _classPrivateFieldGet(this, _context));
1125
+ if (context.connectTimer) {
1126
+ this.clearTimeout(context.connectTimer);
1127
+ }
1128
+ _classPrivateMethodGet$3(this, _onClose, _onClose2).call(this, context, event);
1129
+ };
1130
+ const onmessage = wsMessage => {
1131
+ this.debug("Transport", this.type, "onmessage", wsMessage, context);
1132
+ _classPrivateMethodGet$3(this, _onMessage, _onMessage2).call(this, context, wsMessage);
1133
+ };
1134
+ context.webSocket.onopen = onopen;
1135
+ context.webSocket.onclose = onclose;
1136
+ context.webSocket.onerror = () => {
1137
+ // Clients should call onclose(), but if they do not we do it here for safety.
1138
+ onclose({
1139
+ code: 1000,
1140
+ reason: "Error"
1141
+ });
1142
+ };
1143
+ context.webSocket.onmessage = onmessage;
1144
+ this.debug("Transport", this.type, "configured callbacks on", context);
1145
+ }
1146
+ function _onTransportTimeout2(context, message, delay) {
1147
+ const result = this.notifyTransportTimeout([message]);
1148
+ if (result > 0) {
1149
+ this.debug("Transport", this.type, "extended waiting for message replies:", result, "ms");
1150
+ context.timeouts[message.id] = this.setTimeout(() => {
1151
+ _classPrivateMethodGet$3(this, _onTransportTimeout, _onTransportTimeout2).call(this, context, message, delay + result);
1152
+ }, result);
1153
+ } else {
1154
+ this.debug("Transport", this.type, "expired waiting for message reply", message.id, ":", delay, "ms");
1155
+ _classPrivateMethodGet$3(this, _forceClose, _forceClose2).call(this, context, {
1156
+ code: 1000,
1157
+ reason: "Message Timeout"
1158
+ });
1159
+ }
1160
+ }
1161
+ function _webSocketSend2(context, envelope, metaConnect) {
1162
+ let json;
1163
+ try {
1164
+ json = this.convertToJSON(envelope.messages);
1165
+ } catch (x) {
1166
+ this.debug("Transport", this.type, "exception:", x);
1167
+ const mIds = [];
1168
+ for (let j = 0; j < envelope.messages.length; ++j) {
1169
+ const m = envelope.messages[j];
1170
+ mIds.push(m.id);
1171
+ }
1172
+ _classPrivateMethodGet$3(this, _removeEnvelope, _removeEnvelope2).call(this, context, mIds);
1173
+ // Keep the semantic of calling callbacks asynchronously.
1174
+ this.setTimeout(() => {
1175
+ this._notifyFailure(envelope.onFailure, context, envelope.messages, {
1176
+ exception: x
1177
+ });
1178
+ }, 0);
1179
+ return;
1180
+ }
1181
+ context.webSocket.send(json);
1182
+ this.debug("Transport", this.type, "sent", envelope, "/meta/connect =", metaConnect);
1183
+
1184
+ // Manage the timeout waiting for the response.
1185
+ let delay = this.configuration.maxNetworkDelay;
1186
+ if (metaConnect) {
1187
+ delay += this.advice.timeout;
1188
+ _classPrivateFieldSet(this, _connected$1, true);
1189
+ }
1190
+ const messageIds = [];
1191
+ for (let i = 0; i < envelope.messages.length; ++i) {
1192
+ const message = envelope.messages[i];
1193
+ if (message.id) {
1194
+ messageIds.push(message.id);
1195
+ context.timeouts[message.id] = this.setTimeout(() => {
1196
+ _classPrivateMethodGet$3(this, _onTransportTimeout, _onTransportTimeout2).call(this, context, message, delay);
1197
+ }, delay);
1198
+ }
1199
+ }
1200
+ this.debug("Transport", this.type, "started waiting for message replies", delay, "ms, messageIds:", messageIds, ", timeouts:", context.timeouts);
1201
+ }
1202
+ function _send2$1(context, envelope, metaConnect) {
1203
+ try {
1204
+ if (context === null) {
1205
+ context = _classPrivateFieldGet(this, _connecting) || {
1206
+ envelopes: {},
1207
+ timeouts: {}
1208
+ };
1209
+ _classPrivateMethodGet$3(this, _storeEnvelope, _storeEnvelope2).call(this, context, envelope, metaConnect);
1210
+ _classPrivateMethodGet$3(this, _websocketConnect, _websocketConnect2).call(this, context);
1211
+ } else {
1212
+ _classPrivateMethodGet$3(this, _storeEnvelope, _storeEnvelope2).call(this, context, envelope, metaConnect);
1213
+ _classPrivateMethodGet$3(this, _webSocketSend, _webSocketSend2).call(this, context, envelope, metaConnect);
1214
+ }
1215
+ } catch (x) {
1216
+ // Keep the semantic of calling callbacks asynchronously.
1217
+ this.setTimeout(() => {
1218
+ _classPrivateMethodGet$3(this, _forceClose, _forceClose2).call(this, context, {
1219
+ code: 1000,
1220
+ reason: "Exception",
1221
+ exception: x
1222
+ });
1223
+ }, 0);
1224
+ }
1225
+ }
1226
+ function _onOpen2(context) {
1227
+ const envelopes = context.envelopes;
1228
+ this.debug("Transport", this.type, "opened", context, "pending messages", envelopes);
1229
+ for (let key in envelopes) {
1230
+ if (envelopes.hasOwnProperty(key)) {
1231
+ const element = envelopes[key];
1232
+ const envelope = element[0];
1233
+ const metaConnect = element[1];
1234
+ // Store the success callback, which is independent of the envelope,
1235
+ // so that it can be used to notify arrival of messages.
1236
+ _classPrivateFieldSet(this, _successCallback, envelope.onSuccess);
1237
+ _classPrivateMethodGet$3(this, _webSocketSend, _webSocketSend2).call(this, context, envelope, metaConnect);
1238
+ }
1239
+ }
1240
+ }
1241
+ function _onMessage2(context, wsMessage) {
1242
+ this.debug("Transport", this.type, "received websocket message", wsMessage, context);
1243
+ let close = false;
1244
+ const messages = this.convertToMessages(wsMessage.data);
1245
+ const messageIds = [];
1246
+ for (let i = 0; i < messages.length; ++i) {
1247
+ const message = messages[i];
1248
+
1249
+ // Detect if the message is a response to a request we made.
1250
+ // If it's a meta message, for sure it's a response; otherwise it's
1251
+ // a publish message and publish responses don't have the data field.
1252
+ if (/^\/meta\//.test(message.channel) || message.data === undefined) {
1253
+ if (message.id) {
1254
+ messageIds.push(message.id);
1255
+ const timeout = context.timeouts[message.id];
1256
+ if (timeout) {
1257
+ this.clearTimeout(timeout);
1258
+ delete context.timeouts[message.id];
1259
+ this.debug("Transport", this.type, "removed timeout for message", message.id, ", timeouts", context.timeouts);
1260
+ }
1261
+ }
1262
+ }
1263
+ if ("/meta/connect" === message.channel) {
1264
+ _classPrivateFieldSet(this, _connected$1, false);
1265
+ }
1266
+ if ("/meta/disconnect" === message.channel && !_classPrivateFieldGet(this, _connected$1)) {
1267
+ close = true;
1268
+ }
1269
+ }
1270
+
1271
+ // Remove the envelope corresponding to the messages.
1272
+ _classPrivateMethodGet$3(this, _removeEnvelope, _removeEnvelope2).call(this, context, messageIds);
1273
+ this._notifySuccess(_classPrivateFieldGet(this, _successCallback), messages);
1274
+ if (close) {
1275
+ _classPrivateMethodGet$3(this, _webSocketClose, _webSocketClose2).call(this, context, 1000, "Disconnect");
1276
+ }
1277
+ }
1278
+ function _onClose2(context, event) {
1279
+ this.debug("Transport", this.type, "closed", context, event);
1280
+ if (_classPrivateMethodGet$3(this, _sameContext, _sameContext2).call(this, context)) {
1281
+ // Remember if we were able to connect.
1282
+ // This close event could be due to server shutdown,
1283
+ // and if it restarts we want to try websocket again.
1284
+ _classPrivateFieldSet(this, _webSocketSupported, _classPrivateFieldGet(this, _stickyReconnect) && _classPrivateFieldGet(this, _webSocketConnected));
1285
+ _classPrivateFieldSet(this, _connecting, null);
1286
+ _classPrivateFieldSet(this, _context, null);
1287
+ }
1288
+ const timeouts = context.timeouts;
1289
+ context.timeouts = {};
1290
+ for (let id in timeouts) {
1291
+ if (timeouts.hasOwnProperty(id)) {
1292
+ this.clearTimeout(timeouts[id]);
1293
+ }
1294
+ }
1295
+ const envelopes = context.envelopes;
1296
+ context.envelopes = {};
1297
+ for (let key in envelopes) {
1298
+ if (envelopes.hasOwnProperty(key)) {
1299
+ const envelope = envelopes[key][0];
1300
+ const metaConnect = envelopes[key][1];
1301
+ if (metaConnect) {
1302
+ _classPrivateFieldSet(this, _connected$1, false);
1303
+ }
1304
+ const failure = {
1305
+ websocketCode: event.code,
1306
+ reason: event.reason
1307
+ };
1308
+ if (event.exception) {
1309
+ failure.exception = event.exception;
1310
+ }
1311
+ this._notifyFailure(envelope.onFailure, context, envelope.messages, failure);
1312
+ }
1313
+ }
1314
+ }
1315
+ function _webSocketClose2(context, code, reason) {
1316
+ try {
1317
+ if (context.webSocket) {
1318
+ context.webSocket.close(code, reason);
1319
+ }
1320
+ } catch (x) {
1321
+ this.debug(x);
1322
+ }
1323
+ }
1324
+
1325
+ var _CometD;
1326
+ function _classPrivateMethodInitSpec$2(obj, privateSet) { _checkPrivateRedeclaration$4(obj, privateSet); privateSet.add(obj); }
1327
+ function _classPrivateFieldInitSpec$4(obj, privateMap, value) { _checkPrivateRedeclaration$4(obj, privateMap); privateMap.set(obj, value); }
1328
+ function _checkPrivateRedeclaration$4(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
1329
+ function _classPrivateMethodGet$2(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
1330
+ function _classStaticPrivateMethodGet(receiver, classConstructor, method) { _classCheckPrivateStaticAccess$1(receiver, classConstructor); return method; }
1331
+ function _classCheckPrivateStaticAccess$1(receiver, classConstructor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } }
1332
+
1333
+ /**
1334
+ * Browsers may throttle the Window scheduler,
1335
+ * so we may replace it with a Worker scheduler.
1336
+ */
1337
+ function Scheduler() {
1338
+ let _ids = 0;
1339
+ const _tasks = {};
1340
+ this.register = funktion => {
1341
+ const id = ++_ids;
1342
+ _tasks[id] = funktion;
1343
+ return id;
1344
+ };
1345
+ this.unregister = id => {
1346
+ const funktion = _tasks[id];
1347
+ delete _tasks[id];
1348
+ return funktion;
1349
+ };
1350
+ this.setTimeout = (funktion, delay) => window.setTimeout(funktion, delay);
1351
+ this.clearTimeout = id => {
1352
+ window.clearTimeout(id);
1353
+ };
1354
+ }
1355
+
1356
+ /**
1357
+ * The scheduler code that will run in the Worker.
1358
+ * Workers have a built-in `self` variable similar to `window`.
1359
+ */
1360
+ function WorkerScheduler() {
1361
+ const _tasks = {};
1362
+ self.onmessage = e => {
1363
+ const cmd = e.data;
1364
+ const id = _tasks[cmd.id];
1365
+ switch (cmd.type) {
1366
+ case "setTimeout":
1367
+ _tasks[cmd.id] = self.setTimeout(() => {
1368
+ delete _tasks[cmd.id];
1369
+ self.postMessage({
1370
+ id: cmd.id
1371
+ });
1372
+ }, cmd.delay);
1373
+ break;
1374
+ case "clearTimeout":
1375
+ delete _tasks[cmd.id];
1376
+ if (id) {
1377
+ self.clearTimeout(id);
1378
+ }
1379
+ break;
1380
+ default:
1381
+ throw new Error("Unknown command " + cmd.type);
1382
+ }
1383
+ };
1384
+ }
1385
+
1386
+ /**
1387
+ * The constructor for a CometD object, identified by an optional name.
1388
+ * The default name is the string "default".
1389
+ * @param name the optional name of this cometd object
1390
+ */
1391
+ var _scheduler = /*#__PURE__*/new WeakMap();
1392
+ var _name$1 = /*#__PURE__*/new WeakMap();
1393
+ var _crossDomain = /*#__PURE__*/new WeakMap();
1394
+ var _transports = /*#__PURE__*/new WeakMap();
1395
+ var _transport = /*#__PURE__*/new WeakMap();
1396
+ var _status = /*#__PURE__*/new WeakMap();
1397
+ var _messageId = /*#__PURE__*/new WeakMap();
1398
+ var _clientId = /*#__PURE__*/new WeakMap();
1399
+ var _batch$2 = /*#__PURE__*/new WeakMap();
1400
+ var _messageQueue = /*#__PURE__*/new WeakMap();
1401
+ var _internalBatch = /*#__PURE__*/new WeakMap();
1402
+ var _listenerId = /*#__PURE__*/new WeakMap();
1403
+ var _listeners = /*#__PURE__*/new WeakMap();
1404
+ var _transportListeners = /*#__PURE__*/new WeakMap();
1405
+ var _backoff = /*#__PURE__*/new WeakMap();
1406
+ var _scheduledSend = /*#__PURE__*/new WeakMap();
1407
+ var _extensions = /*#__PURE__*/new WeakMap();
1408
+ var _advice = /*#__PURE__*/new WeakMap();
1409
+ var _handshakeProps = /*#__PURE__*/new WeakMap();
1410
+ var _handshakeCallback = /*#__PURE__*/new WeakMap();
1411
+ var _callbacks = /*#__PURE__*/new WeakMap();
1412
+ var _remoteCalls = /*#__PURE__*/new WeakMap();
1413
+ var _reestablish = /*#__PURE__*/new WeakMap();
1414
+ var _connected = /*#__PURE__*/new WeakMap();
1415
+ var _unconnectTime = /*#__PURE__*/new WeakMap();
1416
+ var _handshakeMessages = /*#__PURE__*/new WeakMap();
1417
+ var _metaConnect = /*#__PURE__*/new WeakMap();
1418
+ var _config = /*#__PURE__*/new WeakMap();
1419
+ var _log = /*#__PURE__*/new WeakSet();
1420
+ var _isCrossDomain = /*#__PURE__*/new WeakSet();
1421
+ var _configure = /*#__PURE__*/new WeakSet();
1422
+ var _removeListener = /*#__PURE__*/new WeakSet();
1423
+ var _removeSubscription = /*#__PURE__*/new WeakSet();
1424
+ var _clearSubscriptions = /*#__PURE__*/new WeakSet();
1425
+ var _setStatus = /*#__PURE__*/new WeakSet();
1426
+ var _isDisconnected = /*#__PURE__*/new WeakSet();
1427
+ var _nextMessageId = /*#__PURE__*/new WeakSet();
1428
+ var _applyExtension = /*#__PURE__*/new WeakSet();
1429
+ var _applyIncomingExtensions = /*#__PURE__*/new WeakSet();
1430
+ var _applyOutgoingExtensions = /*#__PURE__*/new WeakSet();
1431
+ var _notify = /*#__PURE__*/new WeakSet();
1432
+ var _notifyListeners = /*#__PURE__*/new WeakSet();
1433
+ var _cancelDelayedSend = /*#__PURE__*/new WeakSet();
1434
+ var _delayedSend = /*#__PURE__*/new WeakSet();
1435
+ var _send = /*#__PURE__*/new WeakSet();
1436
+ var _queueSend = /*#__PURE__*/new WeakSet();
1437
+ var _resetBackoff = /*#__PURE__*/new WeakSet();
1438
+ var _increaseBackoff = /*#__PURE__*/new WeakSet();
1439
+ var _startBatch = /*#__PURE__*/new WeakSet();
1440
+ var _flushBatch = /*#__PURE__*/new WeakSet();
1441
+ var _endBatch = /*#__PURE__*/new WeakSet();
1442
+ var _connect = /*#__PURE__*/new WeakSet();
1443
+ var _delayedConnect = /*#__PURE__*/new WeakSet();
1444
+ var _updateAdvice = /*#__PURE__*/new WeakSet();
1445
+ var _disconnect = /*#__PURE__*/new WeakSet();
1446
+ var _notifyTransportException = /*#__PURE__*/new WeakSet();
1447
+ var _handshake = /*#__PURE__*/new WeakSet();
1448
+ var _delayedHandshake = /*#__PURE__*/new WeakSet();
1449
+ var _notifyCallback = /*#__PURE__*/new WeakSet();
1450
+ var _handleCallback = /*#__PURE__*/new WeakSet();
1451
+ var _handleRemoteCall = /*#__PURE__*/new WeakSet();
1452
+ var _handleTransportFailure = /*#__PURE__*/new WeakSet();
1453
+ var _failHandshake = /*#__PURE__*/new WeakSet();
1454
+ var _handshakeResponse = /*#__PURE__*/new WeakSet();
1455
+ var _handshakeFailure = /*#__PURE__*/new WeakSet();
1456
+ var _matchMetaConnect = /*#__PURE__*/new WeakSet();
1457
+ var _failConnect = /*#__PURE__*/new WeakSet();
1458
+ var _connectResponse = /*#__PURE__*/new WeakSet();
1459
+ var _connectFailure = /*#__PURE__*/new WeakSet();
1460
+ var _failDisconnect = /*#__PURE__*/new WeakSet();
1461
+ var _disconnectResponse = /*#__PURE__*/new WeakSet();
1462
+ var _disconnectFailure = /*#__PURE__*/new WeakSet();
1463
+ var _failSubscribe = /*#__PURE__*/new WeakSet();
1464
+ var _subscribeResponse = /*#__PURE__*/new WeakSet();
1465
+ var _subscribeFailure = /*#__PURE__*/new WeakSet();
1466
+ var _failUnsubscribe = /*#__PURE__*/new WeakSet();
1467
+ var _unsubscribeResponse = /*#__PURE__*/new WeakSet();
1468
+ var _unsubscribeFailure = /*#__PURE__*/new WeakSet();
1469
+ var _failMessage = /*#__PURE__*/new WeakSet();
1470
+ var _messageResponse = /*#__PURE__*/new WeakSet();
1471
+ var _messageFailure = /*#__PURE__*/new WeakSet();
1472
+ var _receive = /*#__PURE__*/new WeakSet();
1473
+ var _handleMessages = /*#__PURE__*/new WeakSet();
1474
+ var _handleFailure = /*#__PURE__*/new WeakSet();
1475
+ var _hasSubscriptions = /*#__PURE__*/new WeakSet();
1476
+ var _resolveScopedCallback = /*#__PURE__*/new WeakSet();
1477
+ var _addListener = /*#__PURE__*/new WeakSet();
1478
+ class CometD {
1479
+ constructor(_name2) {
1480
+ _classPrivateMethodInitSpec$2(this, _addListener);
1481
+ _classPrivateMethodInitSpec$2(this, _resolveScopedCallback);
1482
+ _classPrivateMethodInitSpec$2(this, _hasSubscriptions);
1483
+ _classPrivateMethodInitSpec$2(this, _handleFailure);
1484
+ _classPrivateMethodInitSpec$2(this, _handleMessages);
1485
+ _classPrivateMethodInitSpec$2(this, _receive);
1486
+ _classPrivateMethodInitSpec$2(this, _messageFailure);
1487
+ _classPrivateMethodInitSpec$2(this, _messageResponse);
1488
+ _classPrivateMethodInitSpec$2(this, _failMessage);
1489
+ _classPrivateMethodInitSpec$2(this, _unsubscribeFailure);
1490
+ _classPrivateMethodInitSpec$2(this, _unsubscribeResponse);
1491
+ _classPrivateMethodInitSpec$2(this, _failUnsubscribe);
1492
+ _classPrivateMethodInitSpec$2(this, _subscribeFailure);
1493
+ _classPrivateMethodInitSpec$2(this, _subscribeResponse);
1494
+ _classPrivateMethodInitSpec$2(this, _failSubscribe);
1495
+ _classPrivateMethodInitSpec$2(this, _disconnectFailure);
1496
+ _classPrivateMethodInitSpec$2(this, _disconnectResponse);
1497
+ _classPrivateMethodInitSpec$2(this, _failDisconnect);
1498
+ _classPrivateMethodInitSpec$2(this, _connectFailure);
1499
+ _classPrivateMethodInitSpec$2(this, _connectResponse);
1500
+ _classPrivateMethodInitSpec$2(this, _failConnect);
1501
+ _classPrivateMethodInitSpec$2(this, _matchMetaConnect);
1502
+ _classPrivateMethodInitSpec$2(this, _handshakeFailure);
1503
+ _classPrivateMethodInitSpec$2(this, _handshakeResponse);
1504
+ _classPrivateMethodInitSpec$2(this, _failHandshake);
1505
+ _classPrivateMethodInitSpec$2(this, _handleTransportFailure);
1506
+ _classPrivateMethodInitSpec$2(this, _handleRemoteCall);
1507
+ _classPrivateMethodInitSpec$2(this, _handleCallback);
1508
+ _classPrivateMethodInitSpec$2(this, _notifyCallback);
1509
+ _classPrivateMethodInitSpec$2(this, _delayedHandshake);
1510
+ /**
1511
+ * Sends the initial handshake message
1512
+ */
1513
+ _classPrivateMethodInitSpec$2(this, _handshake);
1514
+ _classPrivateMethodInitSpec$2(this, _notifyTransportException);
1515
+ _classPrivateMethodInitSpec$2(this, _disconnect);
1516
+ _classPrivateMethodInitSpec$2(this, _updateAdvice);
1517
+ _classPrivateMethodInitSpec$2(this, _delayedConnect);
1518
+ /**
1519
+ * Sends the connect message
1520
+ */
1521
+ _classPrivateMethodInitSpec$2(this, _connect);
1522
+ /**
1523
+ * Ends the batch of messages to be sent in a single request,
1524
+ * optionally sending messages present in the message queue depending
1525
+ * on the given argument.
1526
+ */
1527
+ _classPrivateMethodInitSpec$2(this, _endBatch);
1528
+ _classPrivateMethodInitSpec$2(this, _flushBatch);
1529
+ /**
1530
+ * Starts the batch of messages to be sent in a single request.
1531
+ */
1532
+ _classPrivateMethodInitSpec$2(this, _startBatch);
1533
+ _classPrivateMethodInitSpec$2(this, _increaseBackoff);
1534
+ _classPrivateMethodInitSpec$2(this, _resetBackoff);
1535
+ _classPrivateMethodInitSpec$2(this, _queueSend);
1536
+ /**
1537
+ * Delivers the messages to the CometD server
1538
+ * @param messages the array of messages to send
1539
+ * @param metaConnect true if this send is on /meta/connect
1540
+ * @param extraPath an extra path to append to the Bayeux server URL
1541
+ */
1542
+ _classPrivateMethodInitSpec$2(this, _send);
1543
+ _classPrivateMethodInitSpec$2(this, _delayedSend);
1544
+ _classPrivateMethodInitSpec$2(this, _cancelDelayedSend);
1545
+ _classPrivateMethodInitSpec$2(this, _notifyListeners);
1546
+ _classPrivateMethodInitSpec$2(this, _notify);
1547
+ _classPrivateMethodInitSpec$2(this, _applyOutgoingExtensions);
1548
+ _classPrivateMethodInitSpec$2(this, _applyIncomingExtensions);
1549
+ _classPrivateMethodInitSpec$2(this, _applyExtension);
1550
+ _classPrivateMethodInitSpec$2(this, _nextMessageId);
1551
+ _classPrivateMethodInitSpec$2(this, _isDisconnected);
1552
+ _classPrivateMethodInitSpec$2(this, _setStatus);
1553
+ _classPrivateMethodInitSpec$2(this, _clearSubscriptions);
1554
+ _classPrivateMethodInitSpec$2(this, _removeSubscription);
1555
+ _classPrivateMethodInitSpec$2(this, _removeListener);
1556
+ _classPrivateMethodInitSpec$2(this, _configure);
1557
+ /**
1558
+ * Returns whether the given hostAndPort is cross domain.
1559
+ * The default implementation checks against window.location.host
1560
+ * but this function can be overridden to make it work in non-browser
1561
+ * environments.
1562
+ *
1563
+ * @param hostAndPort the host and port in format host:port
1564
+ * @return whether the given hostAndPort is cross domain
1565
+ */
1566
+ _classPrivateMethodInitSpec$2(this, _isCrossDomain);
1567
+ _classPrivateMethodInitSpec$2(this, _log);
1568
+ _classPrivateFieldInitSpec$4(this, _scheduler, {
1569
+ writable: true,
1570
+ value: new Scheduler()
1571
+ });
1572
+ _classPrivateFieldInitSpec$4(this, _name$1, {
1573
+ writable: true,
1574
+ value: void 0
1575
+ });
1576
+ _classPrivateFieldInitSpec$4(this, _crossDomain, {
1577
+ writable: true,
1578
+ value: false
1579
+ });
1580
+ _classPrivateFieldInitSpec$4(this, _transports, {
1581
+ writable: true,
1582
+ value: new TransportRegistry()
1583
+ });
1584
+ _classPrivateFieldInitSpec$4(this, _transport, {
1585
+ writable: true,
1586
+ value: void 0
1587
+ });
1588
+ _classPrivateFieldInitSpec$4(this, _status, {
1589
+ writable: true,
1590
+ value: "disconnected"
1591
+ });
1592
+ _classPrivateFieldInitSpec$4(this, _messageId, {
1593
+ writable: true,
1594
+ value: 0
1595
+ });
1596
+ _classPrivateFieldInitSpec$4(this, _clientId, {
1597
+ writable: true,
1598
+ value: null
1599
+ });
1600
+ _classPrivateFieldInitSpec$4(this, _batch$2, {
1601
+ writable: true,
1602
+ value: 0
1603
+ });
1604
+ _classPrivateFieldInitSpec$4(this, _messageQueue, {
1605
+ writable: true,
1606
+ value: []
1607
+ });
1608
+ _classPrivateFieldInitSpec$4(this, _internalBatch, {
1609
+ writable: true,
1610
+ value: false
1611
+ });
1612
+ _classPrivateFieldInitSpec$4(this, _listenerId, {
1613
+ writable: true,
1614
+ value: 0
1615
+ });
1616
+ _classPrivateFieldInitSpec$4(this, _listeners, {
1617
+ writable: true,
1618
+ value: {}
1619
+ });
1620
+ _classPrivateFieldInitSpec$4(this, _transportListeners, {
1621
+ writable: true,
1622
+ value: {}
1623
+ });
1624
+ _classPrivateFieldInitSpec$4(this, _backoff, {
1625
+ writable: true,
1626
+ value: 0
1627
+ });
1628
+ _classPrivateFieldInitSpec$4(this, _scheduledSend, {
1629
+ writable: true,
1630
+ value: null
1631
+ });
1632
+ _classPrivateFieldInitSpec$4(this, _extensions, {
1633
+ writable: true,
1634
+ value: []
1635
+ });
1636
+ _classPrivateFieldInitSpec$4(this, _advice, {
1637
+ writable: true,
1638
+ value: {}
1639
+ });
1640
+ _classPrivateFieldInitSpec$4(this, _handshakeProps, {
1641
+ writable: true,
1642
+ value: void 0
1643
+ });
1644
+ _classPrivateFieldInitSpec$4(this, _handshakeCallback, {
1645
+ writable: true,
1646
+ value: void 0
1647
+ });
1648
+ _classPrivateFieldInitSpec$4(this, _callbacks, {
1649
+ writable: true,
1650
+ value: {}
1651
+ });
1652
+ _classPrivateFieldInitSpec$4(this, _remoteCalls, {
1653
+ writable: true,
1654
+ value: {}
1655
+ });
1656
+ _classPrivateFieldInitSpec$4(this, _reestablish, {
1657
+ writable: true,
1658
+ value: false
1659
+ });
1660
+ _classPrivateFieldInitSpec$4(this, _connected, {
1661
+ writable: true,
1662
+ value: false
1663
+ });
1664
+ _classPrivateFieldInitSpec$4(this, _unconnectTime, {
1665
+ writable: true,
1666
+ value: 0
1667
+ });
1668
+ _classPrivateFieldInitSpec$4(this, _handshakeMessages, {
1669
+ writable: true,
1670
+ value: 0
1671
+ });
1672
+ _classPrivateFieldInitSpec$4(this, _metaConnect, {
1673
+ writable: true,
1674
+ value: null
1675
+ });
1676
+ _classPrivateFieldInitSpec$4(this, _config, {
1677
+ writable: true,
1678
+ value: {
1679
+ useWorkerScheduler: true,
1680
+ protocol: null,
1681
+ stickyReconnect: true,
1682
+ connectTimeout: 0,
1683
+ maxConnections: 2,
1684
+ backoffIncrement: 1000,
1685
+ maxBackoff: 60000,
1686
+ logLevel: "info",
1687
+ maxNetworkDelay: 10000,
1688
+ requestHeaders: {},
1689
+ appendMessageTypeToURL: true,
1690
+ autoBatch: false,
1691
+ urls: {},
1692
+ maxURILength: 2000,
1693
+ maxSendBayeuxMessageSize: 8192,
1694
+ advice: {
1695
+ timeout: 60000,
1696
+ interval: 0,
1697
+ reconnect: undefined,
1698
+ maxInterval: 0
1699
+ }
1700
+ }
1701
+ });
1702
+ _classPrivateFieldSet(this, _name$1, _name2 || "default");
1703
+ // Initialize transports.
1704
+ if (window.WebSocket) {
1705
+ this.registerTransport("websocket", new WebSocketTransport());
1706
+ }
1707
+ this.registerTransport("long-polling", new LongPollingTransport());
1708
+ this.registerTransport("callback-polling", new CallbackPollingTransport());
1709
+ }
1710
+ /**
1711
+ * Mixes in the given objects into the target object by copying the properties.
1712
+ * @param deep if the copy must be deep
1713
+ * @param target the target object
1714
+ * @param objects the objects whose properties are copied into the target
1715
+ */
1716
+ _mixin(deep, target, objects) {
1717
+ const result = target || {};
1718
+
1719
+ // Skip first 2 parameters (deep and target), and loop over the others.
1720
+ for (let i = 2; i < arguments.length; ++i) {
1721
+ const object = arguments[i];
1722
+ if (object === undefined || object === null) {
1723
+ continue;
1724
+ }
1725
+ for (let propName in object) {
1726
+ if (object.hasOwnProperty(propName)) {
1727
+ const prop = _classStaticPrivateMethodGet(CometD, CometD, _fieldValue).call(CometD, object, propName);
1728
+ const targ = _classStaticPrivateMethodGet(CometD, CometD, _fieldValue).call(CometD, result, propName);
1729
+
1730
+ // Avoid infinite loops.
1731
+ if (prop === target) {
1732
+ continue;
1733
+ }
1734
+ // Do not mixin undefined values.
1735
+ if (prop === undefined) {
1736
+ continue;
1737
+ }
1738
+ if (deep && typeof prop === "object" && prop !== null) {
1739
+ if (prop instanceof Array) {
1740
+ result[propName] = this._mixin(deep, targ instanceof Array ? targ : [], prop);
1741
+ } else {
1742
+ const source = typeof targ === "object" && !(targ instanceof Array) ? targ : {};
1743
+ result[propName] = this._mixin(deep, source, prop);
1744
+ }
1745
+ } else {
1746
+ result[propName] = prop;
1747
+ }
1748
+ }
1749
+ }
1750
+ }
1751
+ return result;
1752
+ }
1753
+ _warn() {
1754
+ _classPrivateMethodGet$2(this, _log, _log2).call(this, "warn", arguments);
1755
+ }
1756
+ _info() {
1757
+ if (_classPrivateFieldGet(this, _config).logLevel !== "warn") {
1758
+ _classPrivateMethodGet$2(this, _log, _log2).call(this, "info", arguments);
1759
+ }
1760
+ }
1761
+ _debug() {
1762
+ if (_classPrivateFieldGet(this, _config).logLevel === "debug") {
1763
+ _classPrivateMethodGet$2(this, _log, _log2).call(this, "debug", arguments);
1764
+ }
1765
+ }
1766
+ /**
1767
+ * Sends a complete bayeux message.
1768
+ * This method is exposed as a public so that extensions may use it
1769
+ * to send bayeux message directly, for example in case of re-sending
1770
+ * messages that have already been sent but that for some reason must
1771
+ * be resent.
1772
+ */
1773
+ send(message) {
1774
+ _classPrivateMethodGet$2(this, _queueSend, _queueSend2).call(this, message);
1775
+ }
1776
+ _getCallback(messageId) {
1777
+ return _classPrivateFieldGet(this, _callbacks)[messageId];
1778
+ }
1779
+ _putCallback(messageId, callback) {
1780
+ const result = this._getCallback(messageId);
1781
+ if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, callback)) {
1782
+ _classPrivateFieldGet(this, _callbacks)[messageId] = callback;
1783
+ }
1784
+ return result;
1785
+ }
1786
+ onTransportFailure(message, failureInfo, failureHandler) {
1787
+ this._debug("Transport failure", failureInfo, "for", message);
1788
+ const transports = this.getTransportRegistry();
1789
+ const url = this.getURL();
1790
+ const crossDomain = _classPrivateMethodGet$2(this, _isCrossDomain, _isCrossDomain2).call(this, _classStaticPrivateMethodGet(CometD, CometD, _splitURL).call(CometD, url)[2]);
1791
+ const version = "1.0";
1792
+ const transportTypes = transports.findTransportTypes(version, crossDomain, url);
1793
+ if (failureInfo.action === "none") {
1794
+ if (message.channel === "/meta/handshake") {
1795
+ if (!failureInfo.transport) {
1796
+ const failure = "Could not negotiate transport, client=[" + transportTypes + "], server=[" + message.supportedConnectionTypes + "]";
1797
+ this._warn(failure);
1798
+ const transport = this.getTransport();
1799
+ if (transport) {
1800
+ const transportType = transport.type;
1801
+ _classPrivateMethodGet$2(this, _notifyTransportException, _notifyTransportException2).call(this, transportType, null, {
1802
+ reason: failure,
1803
+ connectionType: transportType,
1804
+ transport: transport
1805
+ });
1806
+ }
1807
+ }
1808
+ }
1809
+ } else {
1810
+ failureInfo.delay = this.getBackoffPeriod();
1811
+ // Different logic depending on whether we are handshaking or connecting.
1812
+ if (message.channel === "/meta/handshake") {
1813
+ if (!failureInfo.transport) {
1814
+ // The transport is invalid, try to negotiate again.
1815
+ const oldTransportType = _classPrivateFieldGet(this, _transport) ? _classPrivateFieldGet(this, _transport).type : null;
1816
+ const newTransport = transports.negotiateTransport(transportTypes, version, crossDomain, url);
1817
+ if (!newTransport) {
1818
+ this._warn("Could not negotiate transport, client=[" + transportTypes + "]");
1819
+ _classPrivateMethodGet$2(this, _notifyTransportException, _notifyTransportException2).call(this, oldTransportType, null, message.failure);
1820
+ failureInfo.action = "none";
1821
+ } else {
1822
+ const newTransportType = newTransport.type;
1823
+ this._debug("Transport", oldTransportType, "->", newTransportType);
1824
+ _classPrivateMethodGet$2(this, _notifyTransportException, _notifyTransportException2).call(this, oldTransportType, newTransportType, message.failure);
1825
+ failureInfo.action = "handshake";
1826
+ failureInfo.transport = newTransport;
1827
+ }
1828
+ }
1829
+ if (failureInfo.action !== "none") {
1830
+ this.increaseBackoffPeriod();
1831
+ }
1832
+ } else {
1833
+ const now = new Date().getTime();
1834
+ if (_classPrivateFieldGet(this, _unconnectTime) === 0) {
1835
+ _classPrivateFieldSet(this, _unconnectTime, now);
1836
+ }
1837
+ if (failureInfo.action === "retry") {
1838
+ failureInfo.delay = this.increaseBackoffPeriod();
1839
+ // Check whether we may switch to handshaking.
1840
+ const maxInterval = _classPrivateFieldGet(this, _advice).maxInterval;
1841
+ if (maxInterval > 0) {
1842
+ const expiration = _classPrivateFieldGet(this, _advice).timeout + _classPrivateFieldGet(this, _advice).interval + maxInterval;
1843
+ const unconnected = now - _classPrivateFieldGet(this, _unconnectTime);
1844
+ if (unconnected + _classPrivateFieldGet(this, _backoff) > expiration) {
1845
+ failureInfo.action = "handshake";
1846
+ }
1847
+ }
1848
+ }
1849
+ if (failureInfo.action === "handshake") {
1850
+ failureInfo.delay = 0;
1851
+ transports.reset(false);
1852
+ this.resetBackoffPeriod();
1853
+ }
1854
+ }
1855
+ }
1856
+ failureHandler.call(this, failureInfo);
1857
+ }
1858
+ /**
1859
+ * Receives a message.
1860
+ * This method is exposed as a public so that extensions may inject
1861
+ * messages simulating that they had been received.
1862
+ */
1863
+ receive(message) {
1864
+ _classPrivateMethodGet$2(this, _receive, _receive2).call(this, message);
1865
+ }
1866
+ //
1867
+ // PUBLIC API
1868
+ //
1869
+
1870
+ /**
1871
+ * Registers the given transport under the given transport type.
1872
+ * The optional index parameter specifies the "priority" at which the
1873
+ * transport is registered (where 0 is the max priority).
1874
+ * If a transport with the same type is already registered, this function
1875
+ * does nothing and returns false.
1876
+ * @param type the transport type
1877
+ * @param transport the transport object
1878
+ * @param index the index at which this transport is to be registered
1879
+ * @return true if the transport has been registered, false otherwise
1880
+ */
1881
+ registerTransport(type, transport, index) {
1882
+ const result = _classPrivateFieldGet(this, _transports).add(type, transport, index);
1883
+ if (result) {
1884
+ this._debug("Registered transport", type);
1885
+ if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, transport.registered)) {
1886
+ transport.registered(type, this);
1887
+ }
1888
+ }
1889
+ return result;
1890
+ }
1891
+ /**
1892
+ * Unregisters the transport with the given transport type.
1893
+ * @param type the transport type to unregister
1894
+ * @return the transport that has been unregistered,
1895
+ * or null if no transport was previously registered under the given transport type
1896
+ */
1897
+ unregisterTransport(type) {
1898
+ const transport = _classPrivateFieldGet(this, _transports).remove(type);
1899
+ if (transport !== null) {
1900
+ this._debug("Unregistered transport", type);
1901
+ if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, transport.unregistered)) {
1902
+ transport.unregistered();
1903
+ }
1904
+ }
1905
+ return transport;
1906
+ }
1907
+ unregisterTransports() {
1908
+ _classPrivateFieldGet(this, _transports).clear();
1909
+ }
1910
+ /**
1911
+ * @return an array of all registered transport types
1912
+ */
1913
+ getTransportTypes() {
1914
+ return _classPrivateFieldGet(this, _transports).getTransportTypes();
1915
+ }
1916
+ findTransport(name) {
1917
+ return _classPrivateFieldGet(this, _transports).find(name);
1918
+ }
1919
+
1920
+ /**
1921
+ * @returns the TransportRegistry object
1922
+ */
1923
+ getTransportRegistry() {
1924
+ return _classPrivateFieldGet(this, _transports);
1925
+ }
1926
+
1927
+ /**
1928
+ * Configures the initial Bayeux communication with the Bayeux server.
1929
+ * Configuration is passed via an object that must contain a mandatory field <code>url</code>
1930
+ * of type string containing the URL of the Bayeux server.
1931
+ * @param configuration the configuration object
1932
+ */
1933
+ configure(configuration) {
1934
+ _classPrivateMethodGet$2(this, _configure, _configure2).call(this, configuration);
1935
+ }
1936
+ /**
1937
+ * Configures and establishes the Bayeux communication with the Bayeux server
1938
+ * via a handshake and a subsequent connect.
1939
+ * @param configuration the configuration object
1940
+ * @param handshakeProps an object to be merged with the handshake message
1941
+ */
1942
+ init(configuration, handshakeProps) {
1943
+ this.configure(configuration);
1944
+ this.handshake(handshakeProps);
1945
+ }
1946
+ /**
1947
+ * Establishes the Bayeux communication with the Bayeux server
1948
+ * via a handshake and a subsequent connect.
1949
+ * @param handshakeProps an object to be merged with the handshake message
1950
+ * @param handshakeCallback a function to be invoked when the handshake is acknowledged
1951
+ */
1952
+ handshake(handshakeProps, handshakeCallback) {
1953
+ const status = this.getStatus();
1954
+ if (status !== "disconnected") {
1955
+ throw new Error("Illegal state: " + status);
1956
+ }
1957
+ _classPrivateMethodGet$2(this, _handshake, _handshake2).call(this, handshakeProps, handshakeCallback);
1958
+ }
1959
+ /**
1960
+ * Disconnects from the Bayeux server.
1961
+ * @param disconnectProps an object to be merged with the disconnect message
1962
+ * @param disconnectCallback a function to be invoked when the disconnect is acknowledged
1963
+ */
1964
+ disconnect(disconnectProps, disconnectCallback) {
1965
+ if (this.isDisconnected()) {
1966
+ return;
1967
+ }
1968
+ if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, disconnectProps)) {
1969
+ disconnectCallback = disconnectProps;
1970
+ disconnectProps = undefined;
1971
+ }
1972
+ const bayeuxMessage = {
1973
+ id: _classPrivateMethodGet$2(this, _nextMessageId, _nextMessageId2).call(this),
1974
+ channel: "/meta/disconnect"
1975
+ };
1976
+ // Do not allow the user to override important fields.
1977
+ const message = this._mixin(false, {}, disconnectProps, bayeuxMessage);
1978
+
1979
+ // Save the callback.
1980
+ this._putCallback(message.id, disconnectCallback);
1981
+ _classPrivateMethodGet$2(this, _setStatus, _setStatus2).call(this, "disconnecting");
1982
+ _classPrivateMethodGet$2(this, _send, _send2).call(this, [message], false, "disconnect");
1983
+ }
1984
+ /**
1985
+ * Marks the start of a batch of application messages to be sent to the server
1986
+ * in a single request, obtaining a single response containing (possibly) many
1987
+ * application reply messages.
1988
+ * Messages are held in a queue and not sent until {@link #endBatch()} is called.
1989
+ * If startBatch() is called multiple times, then an equal number of endBatch()
1990
+ * calls must be made to close and send the batch of messages.
1991
+ */
1992
+ startBatch() {
1993
+ _classPrivateMethodGet$2(this, _startBatch, _startBatch2).call(this);
1994
+ }
1995
+ /**
1996
+ * Marks the end of a batch of application messages to be sent to the server
1997
+ * in a single request.
1998
+ */
1999
+ endBatch() {
2000
+ _classPrivateMethodGet$2(this, _endBatch, _endBatch2).call(this);
2001
+ }
2002
+ /**
2003
+ * Executes the given callback in the given scope, surrounded by a {@link #startBatch()}
2004
+ * and {@link #endBatch()} calls.
2005
+ * @param scope the scope of the callback, may be omitted
2006
+ * @param callback the callback to be executed within {@link #startBatch()} and {@link #endBatch()} calls
2007
+ */
2008
+ batch(scope, callback) {
2009
+ const delegate = _classPrivateMethodGet$2(this, _resolveScopedCallback, _resolveScopedCallback2).call(this, scope, callback);
2010
+ this.startBatch();
2011
+ try {
2012
+ delegate.method.call(delegate.scope);
2013
+ this.endBatch();
2014
+ } catch (x) {
2015
+ this._info("Exception during execution of batch", x);
2016
+ this.endBatch();
2017
+ throw x;
2018
+ }
2019
+ }
2020
+ /**
2021
+ * Adds a transport listener for the specified transport event,
2022
+ * executing the given callback when the event happens.
2023
+ *
2024
+ * The currently supported event is "timeout".
2025
+ *
2026
+ * The callback function takes an array of messages for which
2027
+ * the event happened.
2028
+ *
2029
+ * For the "timeout" event, the callback function may return a
2030
+ * positive value that extends the wait for message replies by
2031
+ * the returned amount, in milliseconds.
2032
+ *
2033
+ * @param {String} event the type of transport event
2034
+ * @param {Function} callback the function associate to the given transport event
2035
+ */
2036
+ addTransportListener(event, callback) {
2037
+ if (event !== "timeout") {
2038
+ throw new Error("Unsupported event " + event);
2039
+ }
2040
+ let callbacks = _classPrivateFieldGet(this, _transportListeners)[event];
2041
+ if (!callbacks) {
2042
+ _classPrivateFieldGet(this, _transportListeners)[event] = callbacks = [];
2043
+ }
2044
+ callbacks.push(callback);
2045
+ }
2046
+ /**
2047
+ * Removes the transport listener for the specified transport event.
2048
+ * @param {String} event the type of transport event
2049
+ * @param {Function} callback the function disassociate from the given transport event
2050
+ * @return {boolean} whether the disassociation was successful
2051
+ */
2052
+ removeTransportListener(event, callback) {
2053
+ const callbacks = _classPrivateFieldGet(this, _transportListeners)[event];
2054
+ if (callbacks) {
2055
+ const index = callbacks.indexOf(callback);
2056
+ if (index >= 0) {
2057
+ callbacks.splice(index, 1);
2058
+ return true;
2059
+ }
2060
+ }
2061
+ return false;
2062
+ }
2063
+ _getTransportListeners(event) {
2064
+ return _classPrivateFieldGet(this, _transportListeners)[event];
2065
+ }
2066
+
2067
+ /**
2068
+ * Adds a listener for bayeux messages, performing the given callback in the given scope
2069
+ * when a message for the given channel arrives.
2070
+ * @param channel the channel the listener is interested to
2071
+ * @param scope the scope of the callback, may be omitted
2072
+ * @param callback the callback to call when a message is sent to the channel
2073
+ * @returns the subscription handle to be passed to {@link #removeListener(object)}
2074
+ */
2075
+ addListener(channel, scope, callback) {
2076
+ if (arguments.length < 2) {
2077
+ throw new Error("Illegal arguments number: required 2, got " + arguments.length);
2078
+ }
2079
+ if (!_classStaticPrivateMethodGet(CometD, CometD, _isString).call(CometD, channel)) {
2080
+ throw new Error("Illegal argument type: channel must be a string");
2081
+ }
2082
+ return _classPrivateMethodGet$2(this, _addListener, _addListener2).call(this, channel, scope, callback, true);
2083
+ }
2084
+ /**
2085
+ * Removes the subscription obtained with a call to {@link #addListener(string, object, function)}.
2086
+ * @param subscription the subscription to unsubscribe.
2087
+ */
2088
+ removeListener(subscription) {
2089
+ // Beware of subscription.id == 0, which is falsy => cannot use !subscription.id
2090
+ if (!subscription || !subscription.channel || !("id" in subscription)) {
2091
+ throw new Error("Invalid argument: expected subscription, not " + subscription);
2092
+ }
2093
+ _classPrivateMethodGet$2(this, _removeListener, _removeListener2).call(this, subscription);
2094
+ }
2095
+ /**
2096
+ * Removes all listeners registered with {@link #addListener(channel, scope, callback)} or
2097
+ * {@link #subscribe(channel, scope, callback)}.
2098
+ */
2099
+ clearListeners() {
2100
+ _classPrivateFieldSet(this, _listeners, {});
2101
+ }
2102
+ /**
2103
+ * Subscribes to the given channel, performing the given callback in the given scope
2104
+ * when a message for the channel arrives.
2105
+ * @param channel the channel to subscribe to
2106
+ * @param scope the scope of the callback, may be omitted
2107
+ * @param callback the callback to call when a message is sent to the channel
2108
+ * @param subscribeProps an object to be merged with the subscribe message
2109
+ * @param subscribeCallback a function to be invoked when the subscription is acknowledged
2110
+ * @return the subscription handle to be passed to {@link #unsubscribe(object)}
2111
+ */
2112
+ subscribe(channel, scope, callback, subscribeProps, subscribeCallback) {
2113
+ if (arguments.length < 2) {
2114
+ throw new Error("Illegal arguments number: required 2, got " + arguments.length);
2115
+ }
2116
+ if (!_classStaticPrivateMethodGet(CometD, CometD, _isValidChannel).call(CometD, channel)) {
2117
+ throw new Error("Illegal argument: invalid channel " + channel);
2118
+ }
2119
+ if (this.isDisconnected()) {
2120
+ throw new Error("Illegal state: disconnected");
2121
+ }
2122
+
2123
+ // Normalize arguments
2124
+ if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, scope)) {
2125
+ subscribeCallback = subscribeProps;
2126
+ subscribeProps = callback;
2127
+ callback = scope;
2128
+ scope = undefined;
2129
+ }
2130
+ if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, subscribeProps)) {
2131
+ subscribeCallback = subscribeProps;
2132
+ subscribeProps = undefined;
2133
+ }
2134
+
2135
+ // Only send the message to the server if this client has not yet subscribed to the channel
2136
+ const send = !_classPrivateMethodGet$2(this, _hasSubscriptions, _hasSubscriptions2).call(this, channel);
2137
+ const subscription = _classPrivateMethodGet$2(this, _addListener, _addListener2).call(this, channel, scope, callback, false);
2138
+ if (send) {
2139
+ // Send the subscription message after the subscription registration to avoid
2140
+ // races where the server would send a message to the subscribers, but here
2141
+ // on the client the subscription has not been added yet to the data structures
2142
+ const bayeuxMessage = {
2143
+ id: _classPrivateMethodGet$2(this, _nextMessageId, _nextMessageId2).call(this),
2144
+ channel: "/meta/subscribe",
2145
+ subscription: channel
2146
+ };
2147
+ // Do not allow the user to override important fields.
2148
+ const message = this._mixin(false, {}, subscribeProps, bayeuxMessage);
2149
+
2150
+ // Save the callback.
2151
+ this._putCallback(message.id, subscribeCallback);
2152
+ _classPrivateMethodGet$2(this, _queueSend, _queueSend2).call(this, message);
2153
+ } else {
2154
+ if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, subscribeCallback)) {
2155
+ // Keep the semantic of calling callbacks asynchronously.
2156
+ this.setTimeout(() => {
2157
+ _classPrivateMethodGet$2(this, _notifyCallback, _notifyCallback2).call(this, subscribeCallback, {
2158
+ id: _classPrivateMethodGet$2(this, _nextMessageId, _nextMessageId2).call(this),
2159
+ successful: true,
2160
+ channel: "/meta/subscribe",
2161
+ subscription: channel
2162
+ });
2163
+ }, 0);
2164
+ }
2165
+ }
2166
+ return subscription;
2167
+ }
2168
+ /**
2169
+ * Unsubscribes the subscription obtained with a call to {@link #subscribe(string, object, function)}.
2170
+ * @param subscription the subscription to unsubscribe.
2171
+ * @param unsubscribeProps an object to be merged with the unsubscribe message
2172
+ * @param unsubscribeCallback a function to be invoked when the unsubscription is acknowledged
2173
+ */
2174
+ unsubscribe(subscription, unsubscribeProps, unsubscribeCallback) {
2175
+ if (arguments.length < 1) {
2176
+ throw new Error("Illegal arguments number: required 1, got " + arguments.length);
2177
+ }
2178
+ if (this.isDisconnected()) {
2179
+ throw new Error("Illegal state: disconnected");
2180
+ }
2181
+ if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, unsubscribeProps)) {
2182
+ unsubscribeCallback = unsubscribeProps;
2183
+ unsubscribeProps = undefined;
2184
+ }
2185
+
2186
+ // Remove the local listener before sending the message
2187
+ // This ensures that if the server fails, this client does not get notifications
2188
+ this.removeListener(subscription);
2189
+ const channel = subscription.channel;
2190
+ // Only send the message to the server if this client unsubscribes the last subscription
2191
+ if (!_classPrivateMethodGet$2(this, _hasSubscriptions, _hasSubscriptions2).call(this, channel)) {
2192
+ const bayeuxMessage = {
2193
+ id: _classPrivateMethodGet$2(this, _nextMessageId, _nextMessageId2).call(this),
2194
+ channel: "/meta/unsubscribe",
2195
+ subscription: channel
2196
+ };
2197
+ // Do not allow the user to override important fields.
2198
+ const message = this._mixin(false, {}, unsubscribeProps, bayeuxMessage);
2199
+
2200
+ // Save the callback.
2201
+ this._putCallback(message.id, unsubscribeCallback);
2202
+ _classPrivateMethodGet$2(this, _queueSend, _queueSend2).call(this, message);
2203
+ } else {
2204
+ if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, unsubscribeCallback)) {
2205
+ // Keep the semantic of calling callbacks asynchronously.
2206
+ this.setTimeout(() => {
2207
+ _classPrivateMethodGet$2(this, _notifyCallback, _notifyCallback2).call(this, unsubscribeCallback, {
2208
+ id: _classPrivateMethodGet$2(this, _nextMessageId, _nextMessageId2).call(this),
2209
+ successful: true,
2210
+ channel: "/meta/unsubscribe",
2211
+ subscription: channel
2212
+ });
2213
+ }, 0);
2214
+ }
2215
+ }
2216
+ }
2217
+ resubscribe(subscription, subscribeProps) {
2218
+ _classPrivateMethodGet$2(this, _removeSubscription, _removeSubscription2).call(this, subscription);
2219
+ if (subscription) {
2220
+ return this.subscribe(subscription.channel, subscription.scope, subscription.callback, subscribeProps);
2221
+ }
2222
+ return undefined;
2223
+ }
2224
+ /**
2225
+ * Removes all subscriptions added via {@link #subscribe(channel, scope, callback, subscribeProps)},
2226
+ * but does not remove the listeners added via {@link addListener(channel, scope, callback)}.
2227
+ */
2228
+ clearSubscriptions() {
2229
+ _classPrivateMethodGet$2(this, _clearSubscriptions, _clearSubscriptions2).call(this);
2230
+ }
2231
+ /**
2232
+ * Publishes a message on the given channel, containing the given content.
2233
+ * @param channel the channel to publish the message to
2234
+ * @param content the content of the message
2235
+ * @param publishProps an object to be merged with the publish message
2236
+ * @param publishCallback a function to be invoked when the publish is acknowledged by the server
2237
+ */
2238
+ publish(channel, content, publishProps, publishCallback) {
2239
+ if (arguments.length < 1) {
2240
+ throw new Error("Illegal arguments number: required 1, got " + arguments.length);
2241
+ }
2242
+ if (!_classStaticPrivateMethodGet(CometD, CometD, _isValidChannel).call(CometD, channel)) {
2243
+ throw new Error("Illegal argument: invalid channel " + channel);
2244
+ }
2245
+ if (/^\/meta\//.test(channel)) {
2246
+ throw new Error("Illegal argument: cannot publish to meta channels");
2247
+ }
2248
+ if (this.isDisconnected()) {
2249
+ throw new Error("Illegal state: disconnected");
2250
+ }
2251
+ if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, content)) {
2252
+ publishCallback = content;
2253
+ content = {};
2254
+ publishProps = undefined;
2255
+ } else if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, publishProps)) {
2256
+ publishCallback = publishProps;
2257
+ publishProps = undefined;
2258
+ }
2259
+ const bayeuxMessage = {
2260
+ id: _classPrivateMethodGet$2(this, _nextMessageId, _nextMessageId2).call(this),
2261
+ channel: channel,
2262
+ data: content
2263
+ };
2264
+ // Do not allow the user to override important fields.
2265
+ const message = this._mixin(false, {}, publishProps, bayeuxMessage);
2266
+
2267
+ // Save the callback.
2268
+ this._putCallback(message.id, publishCallback);
2269
+ _classPrivateMethodGet$2(this, _queueSend, _queueSend2).call(this, message);
2270
+ }
2271
+ /**
2272
+ * Publishes a message with binary data on the given channel.
2273
+ * The binary data chunk may be an ArrayBuffer, a DataView, a TypedArray
2274
+ * (such as Uint8Array) or a plain integer array.
2275
+ * The metadata object may contain additional application data such as
2276
+ * a file name, a mime type, etc.
2277
+ * @param channel the channel to publish the message to
2278
+ * @param data the binary data to publish
2279
+ * @param last whether the binary data chunk is the last
2280
+ * @param meta an object containing metadata associated to the binary chunk
2281
+ * @param publishProps an object to be merged with the publish message
2282
+ * @param publishCallback a function to be invoked when the publish is acknowledged by the server
2283
+ */
2284
+ publishBinary(channel, data, last, meta, publishProps, publishCallback) {
2285
+ if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, data)) {
2286
+ publishCallback = data;
2287
+ data = new ArrayBuffer(0);
2288
+ last = true;
2289
+ meta = undefined;
2290
+ publishProps = undefined;
2291
+ } else if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, last)) {
2292
+ publishCallback = last;
2293
+ last = true;
2294
+ meta = undefined;
2295
+ publishProps = undefined;
2296
+ } else if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, meta)) {
2297
+ publishCallback = meta;
2298
+ meta = undefined;
2299
+ publishProps = undefined;
2300
+ } else if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, publishProps)) {
2301
+ publishCallback = publishProps;
2302
+ publishProps = undefined;
2303
+ }
2304
+ const content = {
2305
+ meta: meta,
2306
+ data: data,
2307
+ last: last
2308
+ };
2309
+ const ext = this._mixin(false, publishProps, {
2310
+ ext: {
2311
+ binary: {}
2312
+ }
2313
+ });
2314
+ this.publish(channel, content, ext, publishCallback);
2315
+ }
2316
+ /**
2317
+ * Performs a remote call, a request with a response, to the given target with the given data.
2318
+ * The response returned by the server is notified the given callback function.
2319
+ * The invocation may specify a timeout in milliseconds, after which the call is aborted on
2320
+ * the client-side, causing a failed response to be passed to the given callback function.
2321
+ * @param target the remote call target
2322
+ * @param content the remote call content
2323
+ * @param timeout the remote call timeout, or 0 for no timeout
2324
+ * @param callProps an object to be merged with the remote call message
2325
+ * @param callback the function to be invoked with the response
2326
+ */
2327
+ remoteCall(target, content, timeout, callProps, callback) {
2328
+ if (arguments.length < 1) {
2329
+ throw new Error("Illegal arguments number: required 1, got " + arguments.length);
2330
+ }
2331
+ if (!_classStaticPrivateMethodGet(CometD, CometD, _isString).call(CometD, target)) {
2332
+ throw new Error("Illegal argument type: target must be a string");
2333
+ }
2334
+ if (this.isDisconnected()) {
2335
+ throw new Error("Illegal state: disconnected");
2336
+ }
2337
+ if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, content)) {
2338
+ callback = content;
2339
+ content = {};
2340
+ timeout = _classPrivateFieldGet(this, _config).maxNetworkDelay;
2341
+ callProps = undefined;
2342
+ } else if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, timeout)) {
2343
+ callback = timeout;
2344
+ timeout = _classPrivateFieldGet(this, _config).maxNetworkDelay;
2345
+ callProps = undefined;
2346
+ } else if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, callProps)) {
2347
+ callback = callProps;
2348
+ callProps = undefined;
2349
+ }
2350
+ if (typeof timeout !== "number") {
2351
+ throw new Error("Illegal argument type: timeout must be a number");
2352
+ }
2353
+ if (!target.match(/^\//)) {
2354
+ target = "/" + target;
2355
+ }
2356
+ const channel = "/service" + target;
2357
+ if (!_classStaticPrivateMethodGet(CometD, CometD, _isValidChannel).call(CometD, channel)) {
2358
+ throw new Error("Illegal argument: invalid target " + target);
2359
+ }
2360
+ const bayeuxMessage = {
2361
+ id: _classPrivateMethodGet$2(this, _nextMessageId, _nextMessageId2).call(this),
2362
+ channel: channel,
2363
+ data: content
2364
+ };
2365
+ const message = this._mixin(false, {}, callProps, bayeuxMessage);
2366
+ const context = {
2367
+ callback: callback
2368
+ };
2369
+ if (timeout > 0) {
2370
+ context.timeout = this.setTimeout(() => {
2371
+ this._debug("Timing out remote call", message, "after", timeout, "ms");
2372
+ _classPrivateMethodGet$2(this, _failMessage, _failMessage2).call(this, {
2373
+ id: message.id,
2374
+ error: "406::timeout",
2375
+ successful: false,
2376
+ failure: {
2377
+ message: message,
2378
+ reason: "Remote Call Timeout"
2379
+ }
2380
+ });
2381
+ }, timeout);
2382
+ this._debug("Scheduled remote call timeout", message, "in", timeout, "ms");
2383
+ }
2384
+ _classPrivateFieldGet(this, _remoteCalls)[message.id] = context;
2385
+ _classPrivateMethodGet$2(this, _queueSend, _queueSend2).call(this, message);
2386
+ }
2387
+ /**
2388
+ * Performs a remote call with binary data.
2389
+ * @param target the remote call target
2390
+ * @param data the remote call binary data
2391
+ * @param last whether the binary data chunk is the last
2392
+ * @param meta an object containing meta data associated to the binary chunk
2393
+ * @param timeout the remote call timeout, or 0 for no timeout
2394
+ * @param callProps an object to be merged with the remote call message
2395
+ * @param callback the function to be invoked with the response
2396
+ */
2397
+ remoteCallBinary(target, data, last, meta, timeout, callProps, callback) {
2398
+ if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, data)) {
2399
+ callback = data;
2400
+ data = new ArrayBuffer(0);
2401
+ last = true;
2402
+ meta = undefined;
2403
+ timeout = _classPrivateFieldGet(this, _config).maxNetworkDelay;
2404
+ callProps = undefined;
2405
+ } else if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, last)) {
2406
+ callback = last;
2407
+ last = true;
2408
+ meta = undefined;
2409
+ timeout = _classPrivateFieldGet(this, _config).maxNetworkDelay;
2410
+ callProps = undefined;
2411
+ } else if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, meta)) {
2412
+ callback = meta;
2413
+ meta = undefined;
2414
+ timeout = _classPrivateFieldGet(this, _config).maxNetworkDelay;
2415
+ callProps = undefined;
2416
+ } else if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, timeout)) {
2417
+ callback = timeout;
2418
+ timeout = _classPrivateFieldGet(this, _config).maxNetworkDelay;
2419
+ callProps = undefined;
2420
+ } else if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, callProps)) {
2421
+ callback = callProps;
2422
+ callProps = undefined;
2423
+ }
2424
+ const content = {
2425
+ meta: meta,
2426
+ data: data,
2427
+ last: last
2428
+ };
2429
+ const ext = this._mixin(false, callProps, {
2430
+ ext: {
2431
+ binary: {}
2432
+ }
2433
+ });
2434
+ this.remoteCall(target, content, timeout, ext, callback);
2435
+ }
2436
+ /**
2437
+ * Returns a string representing the status of the bayeux communication with the Bayeux server.
2438
+ */
2439
+ getStatus() {
2440
+ return _classPrivateFieldGet(this, _status);
2441
+ }
2442
+
2443
+ /**
2444
+ * Returns whether this instance has been disconnected.
2445
+ */
2446
+ isDisconnected() {
2447
+ return _classPrivateMethodGet$2(this, _isDisconnected, _isDisconnected2).call(this);
2448
+ }
2449
+
2450
+ /**
2451
+ * Sets the backoff period used to increase the backoff time when retrying an unsuccessful or failed message.
2452
+ * Default value is 1 second, which means if there is a persistent failure the retries will happen
2453
+ * after 1 second, then after 2 seconds, then after 3 seconds, etc. So for example with 15 seconds of
2454
+ * elapsed time, there will be 5 retries (at 1, 3, 6, 10 and 15 seconds elapsed).
2455
+ * @param period the backoff period to set
2456
+ */
2457
+ setBackoffIncrement(period) {
2458
+ _classPrivateFieldGet(this, _config).backoffIncrement = period;
2459
+ }
2460
+ /**
2461
+ * Returns the backoff period used to increase the backoff time when retrying an unsuccessful or failed message.
2462
+ */
2463
+ getBackoffIncrement() {
2464
+ return _classPrivateFieldGet(this, _config).backoffIncrement;
2465
+ }
2466
+
2467
+ /**
2468
+ * Returns the backoff period to wait before retrying an unsuccessful or failed message.
2469
+ */
2470
+ getBackoffPeriod() {
2471
+ return _classPrivateFieldGet(this, _backoff);
2472
+ }
2473
+
2474
+ /**
2475
+ * Increases the backoff period up to the maximum value configured.
2476
+ * @returns the backoff period after increment
2477
+ */
2478
+ increaseBackoffPeriod() {
2479
+ return _classPrivateMethodGet$2(this, _increaseBackoff, _increaseBackoff2).call(this);
2480
+ }
2481
+
2482
+ /**
2483
+ * Resets the backoff period to zero.
2484
+ */
2485
+ resetBackoffPeriod() {
2486
+ _classPrivateMethodGet$2(this, _resetBackoff, _resetBackoff2).call(this);
2487
+ }
2488
+ /**
2489
+ * Sets the log level for console logging.
2490
+ * Valid values are the strings "error", "warn", "info" and "debug", from
2491
+ * less verbose to more verbose.
2492
+ * @param level the log level string
2493
+ */
2494
+ setLogLevel(level) {
2495
+ _classPrivateFieldGet(this, _config).logLevel = level;
2496
+ }
2497
+ /**
2498
+ * Registers an extension whose callbacks are called for every incoming message
2499
+ * (that comes from the server to this client implementation) and for every
2500
+ * outgoing message (that originates from this client implementation for the
2501
+ * server).
2502
+ * The format of the extension object is the following:
2503
+ * <pre>
2504
+ * {
2505
+ * incoming: message => { ... },
2506
+ * outgoing: message => { ... }
2507
+ * }
2508
+ * </pre>
2509
+ * Both properties are optional, but if they are present they will be called
2510
+ * respectively for each incoming message and for each outgoing message.
2511
+ * @param name the name of the extension
2512
+ * @param extension the extension to register
2513
+ * @return true if the extension was registered, false otherwise
2514
+ */
2515
+ registerExtension(name, extension) {
2516
+ if (arguments.length < 2) {
2517
+ throw new Error("Illegal arguments number: required 2, got " + arguments.length);
2518
+ }
2519
+ if (!_classStaticPrivateMethodGet(CometD, CometD, _isString).call(CometD, name)) {
2520
+ throw new Error("Illegal argument type: extension name must be a string");
2521
+ }
2522
+ let existing = false;
2523
+ for (let i = 0; i < _classPrivateFieldGet(this, _extensions).length; ++i) {
2524
+ const existingExtension = _classPrivateFieldGet(this, _extensions)[i];
2525
+ if (existingExtension.name === name) {
2526
+ existing = true;
2527
+ break;
2528
+ }
2529
+ }
2530
+ if (!existing) {
2531
+ _classPrivateFieldGet(this, _extensions).push({
2532
+ name: name,
2533
+ extension: extension
2534
+ });
2535
+ this._debug("Registered extension", name);
2536
+
2537
+ // Callback for extensions
2538
+ if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, extension.registered)) {
2539
+ extension.registered(name, this);
2540
+ }
2541
+ return true;
2542
+ } else {
2543
+ this._info("Could not register extension with name", name, "since another extension with the same name already exists");
2544
+ return false;
2545
+ }
2546
+ }
2547
+ /**
2548
+ * Unregister an extension previously registered with
2549
+ * {@link #registerExtension(name, extension)}.
2550
+ * @param name the name of the extension to unregister.
2551
+ * @return true if the extension was unregistered, false otherwise
2552
+ */
2553
+ unregisterExtension(name) {
2554
+ if (!_classStaticPrivateMethodGet(CometD, CometD, _isString).call(CometD, name)) {
2555
+ throw new Error("Illegal argument type: extension name must be a string");
2556
+ }
2557
+ let unregistered = false;
2558
+ for (let i = 0; i < _classPrivateFieldGet(this, _extensions).length; ++i) {
2559
+ const extension = _classPrivateFieldGet(this, _extensions)[i];
2560
+ if (extension.name === name) {
2561
+ _classPrivateFieldGet(this, _extensions).splice(i, 1);
2562
+ unregistered = true;
2563
+ this._debug("Unregistered extension", name);
2564
+
2565
+ // Callback for extensions
2566
+ const ext = extension.extension;
2567
+ if (_classStaticPrivateMethodGet(CometD, CometD, _isFunction).call(CometD, ext.unregistered)) {
2568
+ ext.unregistered();
2569
+ }
2570
+ break;
2571
+ }
2572
+ }
2573
+ return unregistered;
2574
+ }
2575
+ /**
2576
+ * Find the extension registered with the given name.
2577
+ * @param name the name of the extension to find
2578
+ * @return the extension found or null if no extension with the given name has been registered
2579
+ */
2580
+ getExtension(name) {
2581
+ for (let i = 0; i < _classPrivateFieldGet(this, _extensions).length; ++i) {
2582
+ const extension = _classPrivateFieldGet(this, _extensions)[i];
2583
+ if (extension.name === name) {
2584
+ return extension.extension;
2585
+ }
2586
+ }
2587
+ return null;
2588
+ }
2589
+ /**
2590
+ * Returns the name assigned to this CometD object, or the string "default"
2591
+ * if no name has been explicitly passed as parameter to the constructor.
2592
+ */
2593
+ getName() {
2594
+ return _classPrivateFieldGet(this, _name$1);
2595
+ }
2596
+
2597
+ /**
2598
+ * Returns the clientId assigned by the Bayeux server during handshake.
2599
+ */
2600
+ getClientId() {
2601
+ return _classPrivateFieldGet(this, _clientId);
2602
+ }
2603
+
2604
+ /**
2605
+ * Returns the URL of the Bayeux server.
2606
+ */
2607
+ getURL() {
2608
+ const transport = this.getTransport();
2609
+ if (transport) {
2610
+ let url = transport.url;
2611
+ if (url) {
2612
+ return url;
2613
+ }
2614
+ url = _classPrivateFieldGet(this, _config).urls[transport.type];
2615
+ if (url) {
2616
+ return url;
2617
+ }
2618
+ }
2619
+ return _classPrivateFieldGet(this, _config).url;
2620
+ }
2621
+ getTransport() {
2622
+ return _classPrivateFieldGet(this, _transport);
2623
+ }
2624
+ getConfiguration() {
2625
+ return this._mixin(true, {}, _classPrivateFieldGet(this, _config));
2626
+ }
2627
+ getAdvice() {
2628
+ return this._mixin(true, {}, _classPrivateFieldGet(this, _advice));
2629
+ }
2630
+ setTimeout(funktion, delay) {
2631
+ return _classPrivateFieldGet(this, _scheduler).setTimeout(() => {
2632
+ try {
2633
+ this._debug("Invoking timed function", funktion);
2634
+ funktion();
2635
+ } catch (x) {
2636
+ this._debug("Exception invoking timed function", funktion, x);
2637
+ }
2638
+ }, delay);
2639
+ }
2640
+ clearTimeout(id) {
2641
+ _classPrivateFieldGet(this, _scheduler).clearTimeout(id);
2642
+ }
2643
+ }
2644
+ _CometD = CometD;
2645
+ function _fieldValue(object, name) {
2646
+ try {
2647
+ return object[name];
2648
+ } catch (x) {
2649
+ return undefined;
2650
+ }
2651
+ }
2652
+ function _isString(value) {
2653
+ if (value === undefined || value === null) {
2654
+ return false;
2655
+ }
2656
+ return typeof value === "string" || value instanceof String;
2657
+ }
2658
+ function _isAlpha(char) {
2659
+ if (char >= "A" && char <= "Z") {
2660
+ return true;
2661
+ }
2662
+ return char >= "a" && char <= "z";
2663
+ }
2664
+ function _isNumeric(char) {
2665
+ return char >= "0" && char <= "9";
2666
+ }
2667
+ function _isAllowed(char) {
2668
+ switch (char) {
2669
+ case " ":
2670
+ case "!":
2671
+ case "#":
2672
+ case "$":
2673
+ case "(":
2674
+ case ")":
2675
+ case "*":
2676
+ case "+":
2677
+ case "-":
2678
+ case ".":
2679
+ case "/":
2680
+ case "@":
2681
+ case "_":
2682
+ case "{":
2683
+ case "~":
2684
+ case "}":
2685
+ return true;
2686
+ default:
2687
+ return false;
2688
+ }
2689
+ }
2690
+ function _isValidChannel(value) {
2691
+ if (!_classStaticPrivateMethodGet(_CometD, _CometD, _isString).call(_CometD, value)) {
2692
+ return false;
2693
+ }
2694
+ if (value.length < 2) {
2695
+ return false;
2696
+ }
2697
+ if (value.charAt(0) !== "/") {
2698
+ return false;
2699
+ }
2700
+ for (let i = 1; i < value.length; ++i) {
2701
+ const char = value.charAt(i);
2702
+ if (_classStaticPrivateMethodGet(_CometD, _CometD, _isAlpha).call(_CometD, char) || _classStaticPrivateMethodGet(_CometD, _CometD, _isNumeric).call(_CometD, char) || _classStaticPrivateMethodGet(_CometD, _CometD, _isAllowed).call(_CometD, char)) {
2703
+ continue;
2704
+ }
2705
+ return false;
2706
+ }
2707
+ return true;
2708
+ }
2709
+ function _isFunction(value) {
2710
+ if (value === undefined || value === null) {
2711
+ return false;
2712
+ }
2713
+ return typeof value === "function";
2714
+ }
2715
+ function _zeroPad(value, length) {
2716
+ let result = "";
2717
+ while (--length > 0) {
2718
+ if (value >= Math.pow(10, length)) {
2719
+ break;
2720
+ }
2721
+ result += "0";
2722
+ }
2723
+ result += value;
2724
+ return result;
2725
+ }
2726
+ function _log2(level, args) {
2727
+ if (window.console) {
2728
+ const logger = window.console[level];
2729
+ if (_classStaticPrivateMethodGet(_CometD, _CometD, _isFunction).call(_CometD, logger)) {
2730
+ const now = new Date();
2731
+ [].splice.call(args, 0, 0, _classStaticPrivateMethodGet(_CometD, _CometD, _zeroPad).call(_CometD, now.getHours(), 2) + ":" + _classStaticPrivateMethodGet(_CometD, _CometD, _zeroPad).call(_CometD, now.getMinutes(), 2) + ":" + _classStaticPrivateMethodGet(_CometD, _CometD, _zeroPad).call(_CometD, now.getSeconds(), 2) + "." + _classStaticPrivateMethodGet(_CometD, _CometD, _zeroPad).call(_CometD, now.getMilliseconds(), 3));
2732
+ logger.apply(window.console, args);
2733
+ }
2734
+ }
2735
+ }
2736
+ function _splitURL(url) {
2737
+ // [1] = protocol://,
2738
+ // [2] = host:port,
2739
+ // [3] = host,
2740
+ // [4] = IPv6_host,
2741
+ // [5] = IPv4_host,
2742
+ // [6] = :port,
2743
+ // [7] = port,
2744
+ // [8] = uri,
2745
+ // [9] = rest (query / fragment)
2746
+ return new RegExp("(^https?://)?(((\\[[^\\]]+])|([^:/?#]+))(:(\\d+))?)?([^?#]*)(.*)?").exec(url);
2747
+ }
2748
+ function _isCrossDomain2(hostAndPort) {
2749
+ if (window.location && window.location.host) {
2750
+ if (hostAndPort) {
2751
+ return hostAndPort !== window.location.host;
2752
+ }
2753
+ }
2754
+ return false;
2755
+ }
2756
+ function _configure2(configuration) {
2757
+ this._debug("Configuring cometd object with", configuration);
2758
+ // Support old style param, where only the Bayeux server URL was passed.
2759
+ if (_classStaticPrivateMethodGet(_CometD, _CometD, _isString).call(_CometD, configuration)) {
2760
+ configuration = {
2761
+ url: configuration
2762
+ };
2763
+ }
2764
+ if (!configuration) {
2765
+ configuration = {};
2766
+ }
2767
+ _classPrivateFieldSet(this, _config, this._mixin(false, _classPrivateFieldGet(this, _config), configuration));
2768
+ const url = this.getURL();
2769
+ if (!url) {
2770
+ throw new Error("Missing required configuration parameter 'url' specifying the Bayeux server URL");
2771
+ }
2772
+
2773
+ // Check if we're cross domain.
2774
+ const urlParts = _classStaticPrivateMethodGet(_CometD, _CometD, _splitURL).call(_CometD, url);
2775
+ const hostAndPort = urlParts[2];
2776
+ const uri = urlParts[8];
2777
+ const afterURI = urlParts[9];
2778
+ _classPrivateFieldSet(this, _crossDomain, _classPrivateMethodGet$2(this, _isCrossDomain, _isCrossDomain2).call(this, hostAndPort));
2779
+
2780
+ // Check if appending extra path is supported.
2781
+ if (_classPrivateFieldGet(this, _config).appendMessageTypeToURL) {
2782
+ if (afterURI !== undefined && afterURI.length > 0) {
2783
+ this._info("Appending message type to URI", uri, afterURI, "is not supported, disabling 'appendMessageTypeToURL' configuration");
2784
+ _classPrivateFieldGet(this, _config).appendMessageTypeToURL = false;
2785
+ } else {
2786
+ const uriSegments = uri.split("/");
2787
+ let lastSegmentIndex = uriSegments.length - 1;
2788
+ if (uri.match(/\/$/)) {
2789
+ lastSegmentIndex -= 1;
2790
+ }
2791
+ if (uriSegments[lastSegmentIndex].indexOf(".") >= 0) {
2792
+ // Very likely the CometD servlet's URL pattern is mapped to an extension,
2793
+ // such as *.cometd, so cannot add the extra path in this case.
2794
+ this._info("Appending message type to URI", uri, "is not supported, disabling 'appendMessageTypeToURL' configuration");
2795
+ _classPrivateFieldGet(this, _config).appendMessageTypeToURL = false;
2796
+ }
2797
+ }
2798
+ }
2799
+ if (window.Worker && window.Blob && window.URL && _classPrivateFieldGet(this, _config).useWorkerScheduler) {
2800
+ let code = WorkerScheduler.toString();
2801
+ // Remove the function declaration, the opening brace and the closing brace.
2802
+ code = code.substring(code.indexOf("{") + 1, code.lastIndexOf("}"));
2803
+ const blob = new window.Blob([code], {
2804
+ type: "application/json"
2805
+ });
2806
+ const blobURL = window.URL.createObjectURL(blob);
2807
+ const worker = new window.Worker(blobURL);
2808
+ // Replace setTimeout() and clearTimeout() with the worker implementation.
2809
+ _classPrivateFieldGet(this, _scheduler).setTimeout = (funktion, delay) => {
2810
+ const id = _classPrivateFieldGet(this, _scheduler).register(funktion);
2811
+ worker.postMessage({
2812
+ id: id,
2813
+ type: "setTimeout",
2814
+ delay: delay
2815
+ });
2816
+ return id;
2817
+ };
2818
+ _classPrivateFieldGet(this, _scheduler).clearTimeout = id => {
2819
+ _classPrivateFieldGet(this, _scheduler).unregister(id);
2820
+ worker.postMessage({
2821
+ id: id,
2822
+ type: "clearTimeout"
2823
+ });
2824
+ };
2825
+ worker.onmessage = e => {
2826
+ const id = e.data.id;
2827
+ const funktion = _classPrivateFieldGet(this, _scheduler).unregister(id);
2828
+ if (funktion) {
2829
+ funktion();
2830
+ }
2831
+ };
2832
+ }
2833
+ }
2834
+ function _removeListener2(subscription) {
2835
+ if (subscription) {
2836
+ const subscriptions = _classPrivateFieldGet(this, _listeners)[subscription.channel];
2837
+ if (subscriptions && subscriptions[subscription.id]) {
2838
+ delete subscriptions[subscription.id];
2839
+ this._debug("Removed", subscription.listener ? "listener" : "subscription", subscription);
2840
+ }
2841
+ }
2842
+ }
2843
+ function _removeSubscription2(subscription) {
2844
+ if (subscription && !subscription.listener) {
2845
+ _classPrivateMethodGet$2(this, _removeListener, _removeListener2).call(this, subscription);
2846
+ }
2847
+ }
2848
+ function _clearSubscriptions2() {
2849
+ for (let channel in _classPrivateFieldGet(this, _listeners)) {
2850
+ if (_classPrivateFieldGet(this, _listeners).hasOwnProperty(channel)) {
2851
+ const subscriptions = _classPrivateFieldGet(this, _listeners)[channel];
2852
+ if (subscriptions) {
2853
+ for (let id in subscriptions) {
2854
+ if (subscriptions.hasOwnProperty(id)) {
2855
+ _classPrivateMethodGet$2(this, _removeSubscription, _removeSubscription2).call(this, subscriptions[id]);
2856
+ }
2857
+ }
2858
+ }
2859
+ }
2860
+ }
2861
+ }
2862
+ function _setStatus2(newStatus) {
2863
+ const oldStatus = this.getStatus();
2864
+ if (oldStatus !== newStatus) {
2865
+ this._debug("Status", oldStatus, "->", newStatus);
2866
+ _classPrivateFieldSet(this, _status, newStatus);
2867
+ }
2868
+ }
2869
+ function _isDisconnected2() {
2870
+ const status = _classPrivateFieldGet(this, _status);
2871
+ return status === "disconnecting" || status === "disconnected";
2872
+ }
2873
+ function _nextMessageId2() {
2874
+ var _this$messageId;
2875
+ const result = _classPrivateFieldSet(this, _messageId, (_this$messageId = _classPrivateFieldGet(this, _messageId), ++_this$messageId));
2876
+ return "" + result;
2877
+ }
2878
+ function _applyExtension2(scope, callback, name, message, outgoing) {
2879
+ try {
2880
+ return callback.call(scope, message);
2881
+ } catch (x) {
2882
+ const handler = this.onExtensionException;
2883
+ if (_classStaticPrivateMethodGet(_CometD, _CometD, _isFunction).call(_CometD, handler)) {
2884
+ this._debug("Invoking extension exception handler", name, x);
2885
+ try {
2886
+ handler.call(this, x, name, outgoing, message);
2887
+ } catch (xx) {
2888
+ this._info("Exception during execution of extension exception handler", name, xx);
2889
+ }
2890
+ } else {
2891
+ this._info("Exception during execution of extension", name, x);
2892
+ }
2893
+ return message;
2894
+ }
2895
+ }
2896
+ function _applyIncomingExtensions2(message) {
2897
+ for (let i = 0; i < _classPrivateFieldGet(this, _extensions).length; ++i) {
2898
+ if (message === undefined || message === null) {
2899
+ break;
2900
+ }
2901
+ const extension = _classPrivateFieldGet(this, _extensions)[i];
2902
+ const callback = extension.extension.incoming;
2903
+ if (_classStaticPrivateMethodGet(_CometD, _CometD, _isFunction).call(_CometD, callback)) {
2904
+ const result = _classPrivateMethodGet$2(this, _applyExtension, _applyExtension2).call(this, extension.extension, callback, extension.name, message, false);
2905
+ message = result === undefined ? message : result;
2906
+ }
2907
+ }
2908
+ return message;
2909
+ }
2910
+ function _applyOutgoingExtensions2(message) {
2911
+ for (let i = _classPrivateFieldGet(this, _extensions).length - 1; i >= 0; --i) {
2912
+ if (message === undefined || message === null) {
2913
+ break;
2914
+ }
2915
+ const extension = _classPrivateFieldGet(this, _extensions)[i];
2916
+ const callback = extension.extension.outgoing;
2917
+ if (_classStaticPrivateMethodGet(_CometD, _CometD, _isFunction).call(_CometD, callback)) {
2918
+ const result = _classPrivateMethodGet$2(this, _applyExtension, _applyExtension2).call(this, extension.extension, callback, extension.name, message, true);
2919
+ message = result === undefined ? message : result;
2920
+ }
2921
+ }
2922
+ return message;
2923
+ }
2924
+ function _notify2(channel, message) {
2925
+ const subscriptions = _classPrivateFieldGet(this, _listeners)[channel];
2926
+ if (subscriptions) {
2927
+ for (let id in subscriptions) {
2928
+ if (subscriptions.hasOwnProperty(id)) {
2929
+ const subscription = subscriptions[id];
2930
+ // Subscriptions may come and go, so the array may have holes.
2931
+ if (subscription) {
2932
+ try {
2933
+ subscription.callback.call(subscription.scope, message);
2934
+ } catch (x) {
2935
+ const handler = this.onListenerException;
2936
+ if (_classStaticPrivateMethodGet(_CometD, _CometD, _isFunction).call(_CometD, handler)) {
2937
+ this._debug("Invoking listener exception handler", subscription, x);
2938
+ try {
2939
+ handler.call(this, x, subscription, subscription.listener, message);
2940
+ } catch (xx) {
2941
+ this._info("Exception during execution of listener exception handler", subscription, xx);
2942
+ }
2943
+ } else {
2944
+ this._info("Exception during execution of listener", subscription, message, x);
2945
+ }
2946
+ }
2947
+ }
2948
+ }
2949
+ }
2950
+ }
2951
+ }
2952
+ function _notifyListeners2(channel, message) {
2953
+ // Notify direct listeners
2954
+ _classPrivateMethodGet$2(this, _notify, _notify2).call(this, channel, message);
2955
+
2956
+ // Notify the globbing listeners
2957
+ const channelParts = channel.split("/");
2958
+ const last = channelParts.length - 1;
2959
+ for (let i = last; i > 0; --i) {
2960
+ let channelPart = channelParts.slice(0, i).join("/") + "/*";
2961
+ // We don't want to notify /foo/* if the channel is /foo/bar/baz,
2962
+ // so we stop at the first non-recursive globbing.
2963
+ if (i === last) {
2964
+ _classPrivateMethodGet$2(this, _notify, _notify2).call(this, channelPart, message);
2965
+ }
2966
+ // Add the recursive globber and notify.
2967
+ channelPart += "*";
2968
+ _classPrivateMethodGet$2(this, _notify, _notify2).call(this, channelPart, message);
2969
+ }
2970
+ }
2971
+ function _cancelDelayedSend2() {
2972
+ if (_classPrivateFieldGet(this, _scheduledSend) !== null) {
2973
+ this.clearTimeout(_classPrivateFieldGet(this, _scheduledSend));
2974
+ }
2975
+ _classPrivateFieldSet(this, _scheduledSend, null);
2976
+ }
2977
+ function _delayedSend2(operation, delay) {
2978
+ _classPrivateMethodGet$2(this, _cancelDelayedSend, _cancelDelayedSend2).call(this);
2979
+ const time = _classPrivateFieldGet(this, _advice).interval + delay;
2980
+ this._debug("Function scheduled in", time, "ms, interval =", _classPrivateFieldGet(this, _advice).interval, "backoff =", _classPrivateFieldGet(this, _backoff), operation);
2981
+ _classPrivateFieldSet(this, _scheduledSend, this.setTimeout(operation, time));
2982
+ }
2983
+ function _send2(messages, metaConnect, extraPath) {
2984
+ // We must be sure that the messages have a clientId.
2985
+ // This is not guaranteed since the handshake may take time to return
2986
+ // (and hence the clientId is not known yet) and the application
2987
+ // may create other messages.
2988
+ for (let i = 0; i < messages.length; ++i) {
2989
+ let message = messages[i];
2990
+ const messageId = message.id;
2991
+ const clientId = this.getClientId();
2992
+ if (clientId) {
2993
+ message.clientId = clientId;
2994
+ }
2995
+ message = _classPrivateMethodGet$2(this, _applyOutgoingExtensions, _applyOutgoingExtensions2).call(this, message);
2996
+ if (message !== undefined && message !== null) {
2997
+ // Extensions may have modified the message id, but we need to own it.
2998
+ message.id = messageId;
2999
+ messages[i] = message;
3000
+ } else {
3001
+ delete _classPrivateFieldGet(this, _callbacks)[messageId];
3002
+ messages.splice(i--, 1);
3003
+ }
3004
+ }
3005
+ if (messages.length === 0) {
3006
+ return;
3007
+ }
3008
+ if (metaConnect) {
3009
+ _classPrivateFieldSet(this, _metaConnect, messages[0]);
3010
+ }
3011
+ let url = this.getURL();
3012
+ if (_classPrivateFieldGet(this, _config).appendMessageTypeToURL) {
3013
+ // If url does not end with "/", then append it
3014
+ if (!url.match(/\/$/)) {
3015
+ url = url + "/";
3016
+ }
3017
+ if (extraPath) {
3018
+ url = url + extraPath;
3019
+ }
3020
+ }
3021
+ const envelope = {
3022
+ url: url,
3023
+ sync: false,
3024
+ messages: messages,
3025
+ onSuccess: rcvdMessages => {
3026
+ try {
3027
+ _classPrivateMethodGet$2(this, _handleMessages, _handleMessages2).call(this, rcvdMessages);
3028
+ } catch (x) {
3029
+ this._info("Exception during handling of messages", x);
3030
+ }
3031
+ },
3032
+ onFailure: (conduit, messages, failure) => {
3033
+ try {
3034
+ const transport = this.getTransport();
3035
+ failure.connectionType = transport ? transport.type : "unknown";
3036
+ _classPrivateMethodGet$2(this, _handleFailure, _handleFailure2).call(this, conduit, messages, failure);
3037
+ } catch (x) {
3038
+ this._info("Exception during handling of failure", x);
3039
+ }
3040
+ }
3041
+ };
3042
+ this._debug("Send", envelope);
3043
+ this.getTransport().send(envelope, metaConnect);
3044
+ }
3045
+ function _queueSend2(message) {
3046
+ if (_classPrivateFieldGet(this, _batch$2) > 0 || _classPrivateFieldGet(this, _internalBatch) === true) {
3047
+ _classPrivateFieldGet(this, _messageQueue).push(message);
3048
+ } else {
3049
+ _classPrivateMethodGet$2(this, _send, _send2).call(this, [message], false);
3050
+ }
3051
+ }
3052
+ function _resetBackoff2() {
3053
+ _classPrivateFieldSet(this, _backoff, 0);
3054
+ }
3055
+ function _increaseBackoff2() {
3056
+ if (_classPrivateFieldGet(this, _backoff) < _classPrivateFieldGet(this, _config).maxBackoff) {
3057
+ _classPrivateFieldSet(this, _backoff, _classPrivateFieldGet(this, _backoff) + this.getBackoffIncrement());
3058
+ }
3059
+ return _classPrivateFieldGet(this, _backoff);
3060
+ }
3061
+ function _startBatch2() {
3062
+ var _this$batch;
3063
+ _classPrivateFieldSet(this, _batch$2, (_this$batch = _classPrivateFieldGet(this, _batch$2), ++_this$batch));
3064
+ this._debug("Starting batch, depth", _classPrivateFieldGet(this, _batch$2));
3065
+ }
3066
+ function _flushBatch2() {
3067
+ const messages = _classPrivateFieldGet(this, _messageQueue);
3068
+ _classPrivateFieldSet(this, _messageQueue, []);
3069
+ if (messages.length > 0) {
3070
+ _classPrivateMethodGet$2(this, _send, _send2).call(this, messages, false);
3071
+ }
3072
+ }
3073
+ function _endBatch2() {
3074
+ var _this$batch2;
3075
+ _classPrivateFieldSet(this, _batch$2, (_this$batch2 = _classPrivateFieldGet(this, _batch$2), --_this$batch2));
3076
+ this._debug("Ending batch, depth", _classPrivateFieldGet(this, _batch$2));
3077
+ if (_classPrivateFieldGet(this, _batch$2) < 0) {
3078
+ throw new Error("Calls to startBatch() and endBatch() are not paired");
3079
+ }
3080
+ if (_classPrivateFieldGet(this, _batch$2) === 0 && !this.isDisconnected() && !_classPrivateFieldGet(this, _internalBatch)) {
3081
+ _classPrivateMethodGet$2(this, _flushBatch, _flushBatch2).call(this);
3082
+ }
3083
+ }
3084
+ function _connect2() {
3085
+ if (!this.isDisconnected()) {
3086
+ const bayeuxMessage = {
3087
+ id: _classPrivateMethodGet$2(this, _nextMessageId, _nextMessageId2).call(this),
3088
+ channel: "/meta/connect",
3089
+ connectionType: this.getTransport().type
3090
+ };
3091
+
3092
+ // In case of reload or temporary loss of connection
3093
+ // we want the next successful connect to return immediately
3094
+ // instead of being held by the server, so that connect listeners
3095
+ // can be notified that the connection has been re-established
3096
+ if (!_classPrivateFieldGet(this, _connected)) {
3097
+ bayeuxMessage.advice = {
3098
+ timeout: 0
3099
+ };
3100
+ }
3101
+ _classPrivateMethodGet$2(this, _setStatus, _setStatus2).call(this, "connecting");
3102
+ this._debug("Connect sent", bayeuxMessage);
3103
+ _classPrivateMethodGet$2(this, _send, _send2).call(this, [bayeuxMessage], true, "connect");
3104
+ _classPrivateMethodGet$2(this, _setStatus, _setStatus2).call(this, "connected");
3105
+ }
3106
+ }
3107
+ function _delayedConnect2(delay) {
3108
+ _classPrivateMethodGet$2(this, _setStatus, _setStatus2).call(this, "connecting");
3109
+ _classPrivateMethodGet$2(this, _delayedSend, _delayedSend2).call(this, () => {
3110
+ _classPrivateMethodGet$2(this, _connect, _connect2).call(this);
3111
+ }, delay);
3112
+ }
3113
+ function _updateAdvice2(newAdvice) {
3114
+ if (newAdvice) {
3115
+ _classPrivateFieldSet(this, _advice, this._mixin(false, {}, _classPrivateFieldGet(this, _config).advice, newAdvice));
3116
+ this._debug("New advice", _classPrivateFieldGet(this, _advice));
3117
+ }
3118
+ }
3119
+ function _disconnect2(abort) {
3120
+ _classPrivateMethodGet$2(this, _cancelDelayedSend, _cancelDelayedSend2).call(this);
3121
+ const transport = this.getTransport();
3122
+ if (abort && transport) {
3123
+ transport.abort();
3124
+ }
3125
+ _classPrivateFieldSet(this, _crossDomain, false);
3126
+ _classPrivateFieldSet(this, _transport, null);
3127
+ _classPrivateMethodGet$2(this, _setStatus, _setStatus2).call(this, "disconnected");
3128
+ _classPrivateFieldSet(this, _clientId, null);
3129
+ _classPrivateFieldSet(this, _batch$2, 0);
3130
+ _classPrivateMethodGet$2(this, _resetBackoff, _resetBackoff2).call(this);
3131
+ _classPrivateFieldSet(this, _reestablish, false);
3132
+ _classPrivateFieldSet(this, _connected, false);
3133
+ _classPrivateFieldSet(this, _unconnectTime, 0);
3134
+ _classPrivateFieldSet(this, _metaConnect, null);
3135
+
3136
+ // Fail any existing queued message
3137
+ if (_classPrivateFieldGet(this, _messageQueue).length > 0) {
3138
+ const messages = _classPrivateFieldGet(this, _messageQueue);
3139
+ _classPrivateFieldSet(this, _messageQueue, []);
3140
+ _classPrivateMethodGet$2(this, _handleFailure, _handleFailure2).call(this, undefined, messages, {
3141
+ reason: "Disconnected"
3142
+ });
3143
+ }
3144
+ }
3145
+ function _notifyTransportException2(oldTransport, newTransport, failure) {
3146
+ const handler = this.onTransportException;
3147
+ if (_classStaticPrivateMethodGet(_CometD, _CometD, _isFunction).call(_CometD, handler)) {
3148
+ this._debug("Invoking transport exception handler", oldTransport, newTransport, failure);
3149
+ try {
3150
+ handler.call(this, failure, oldTransport, newTransport);
3151
+ } catch (x) {
3152
+ this._info("Exception during execution of transport exception handler", x);
3153
+ }
3154
+ }
3155
+ }
3156
+ function _handshake2(handshakeProps, handshakeCallback) {
3157
+ if (_classStaticPrivateMethodGet(_CometD, _CometD, _isFunction).call(_CometD, handshakeProps)) {
3158
+ handshakeCallback = handshakeProps;
3159
+ handshakeProps = undefined;
3160
+ }
3161
+ _classPrivateFieldSet(this, _clientId, null);
3162
+ this.clearSubscriptions();
3163
+
3164
+ // Reset the transports if we're not retrying the handshake
3165
+ if (this.isDisconnected()) {
3166
+ _classPrivateFieldGet(this, _transports).reset(true);
3167
+ }
3168
+
3169
+ // Reset the advice.
3170
+ _classPrivateMethodGet$2(this, _updateAdvice, _updateAdvice2).call(this, {});
3171
+ _classPrivateFieldSet(this, _batch$2, 0);
3172
+
3173
+ // Mark the start of an internal batch.
3174
+ // This is needed because handshake and connect are async.
3175
+ // It may happen that the application calls init() then subscribe()
3176
+ // and the subscribe message is sent before the connect message, if
3177
+ // the subscribe message is not held until the connect message is sent.
3178
+ // So here we start a batch to hold temporarily any message until
3179
+ // the connection is fully established.
3180
+ _classPrivateFieldSet(this, _internalBatch, true);
3181
+
3182
+ // Save the properties provided by the user, so that
3183
+ // we can reuse them during automatic re-handshake
3184
+ _classPrivateFieldSet(this, _handshakeProps, handshakeProps);
3185
+ _classPrivateFieldSet(this, _handshakeCallback, handshakeCallback);
3186
+ const version = "1.0";
3187
+
3188
+ // Figure out the transports to send to the server
3189
+ const url = this.getURL();
3190
+ const transportTypes = _classPrivateFieldGet(this, _transports).findTransportTypes(version, _classPrivateFieldGet(this, _crossDomain), url);
3191
+ const bayeuxMessage = {
3192
+ id: _classPrivateMethodGet$2(this, _nextMessageId, _nextMessageId2).call(this),
3193
+ version: version,
3194
+ minimumVersion: version,
3195
+ channel: "/meta/handshake",
3196
+ supportedConnectionTypes: transportTypes,
3197
+ advice: {
3198
+ timeout: _classPrivateFieldGet(this, _advice).timeout,
3199
+ interval: _classPrivateFieldGet(this, _advice).interval
3200
+ }
3201
+ };
3202
+ // Do not allow the user to override important fields.
3203
+ const message = this._mixin(false, {}, _classPrivateFieldGet(this, _handshakeProps), bayeuxMessage);
3204
+
3205
+ // Save the callback.
3206
+ this._putCallback(message.id, handshakeCallback);
3207
+
3208
+ // Pick up the first available transport as initial transport
3209
+ // since we don't know if the server supports it
3210
+ if (!_classPrivateFieldGet(this, _transport)) {
3211
+ _classPrivateFieldSet(this, _transport, _classPrivateFieldGet(this, _transports).negotiateTransport(transportTypes, version, _classPrivateFieldGet(this, _crossDomain), url));
3212
+ if (!_classPrivateFieldGet(this, _transport)) {
3213
+ const failure = "Could not find initial transport among: " + this.getTransportTypes();
3214
+ this._warn(failure);
3215
+ throw new Error(failure);
3216
+ }
3217
+ }
3218
+ this._debug("Initial transport is", _classPrivateFieldGet(this, _transport).type);
3219
+
3220
+ // We started a batch to hold the application messages,
3221
+ // so here we must bypass it and send immediately.
3222
+ _classPrivateMethodGet$2(this, _setStatus, _setStatus2).call(this, "handshaking");
3223
+ this._debug("Handshake sent", message);
3224
+ _classPrivateMethodGet$2(this, _send, _send2).call(this, [message], false, "handshake");
3225
+ }
3226
+ function _delayedHandshake2(delay) {
3227
+ _classPrivateMethodGet$2(this, _setStatus, _setStatus2).call(this, "handshaking");
3228
+
3229
+ // We will call #handshake() which will reset #clientId, but we want to avoid
3230
+ // that between the end of this method and the call to #handshake() someone may
3231
+ // call publish() (or other methods that call #queueSend()).
3232
+ _classPrivateFieldSet(this, _internalBatch, true);
3233
+ _classPrivateMethodGet$2(this, _delayedSend, _delayedSend2).call(this, () => {
3234
+ _classPrivateMethodGet$2(this, _handshake, _handshake2).call(this, _classPrivateFieldGet(this, _handshakeProps), _classPrivateFieldGet(this, _handshakeCallback));
3235
+ }, delay);
3236
+ }
3237
+ function _notifyCallback2(callback, message) {
3238
+ try {
3239
+ callback.call(this, message);
3240
+ } catch (x) {
3241
+ const handler = this.onCallbackException;
3242
+ if (_classStaticPrivateMethodGet(_CometD, _CometD, _isFunction).call(_CometD, handler)) {
3243
+ this._debug("Invoking callback exception handler", x);
3244
+ try {
3245
+ handler.call(this, x, message);
3246
+ } catch (xx) {
3247
+ this._info("Exception during execution of callback exception handler", xx);
3248
+ }
3249
+ } else {
3250
+ this._info("Exception during execution of message callback", x);
3251
+ }
3252
+ }
3253
+ }
3254
+ function _handleCallback2(message) {
3255
+ const callback = this._getCallback([message.id]);
3256
+ if (_classStaticPrivateMethodGet(_CometD, _CometD, _isFunction).call(_CometD, callback)) {
3257
+ delete _classPrivateFieldGet(this, _callbacks)[message.id];
3258
+ _classPrivateMethodGet$2(this, _notifyCallback, _notifyCallback2).call(this, callback, message);
3259
+ }
3260
+ }
3261
+ function _handleRemoteCall2(message) {
3262
+ const context = _classPrivateFieldGet(this, _remoteCalls)[message.id];
3263
+ delete _classPrivateFieldGet(this, _remoteCalls)[message.id];
3264
+ if (context) {
3265
+ this._debug("Handling remote call response for", message, "with context", context);
3266
+
3267
+ // Clear the timeout, if present.
3268
+ const timeout = context.timeout;
3269
+ if (timeout) {
3270
+ this.clearTimeout(timeout);
3271
+ }
3272
+ const callback = context.callback;
3273
+ if (_classStaticPrivateMethodGet(_CometD, _CometD, _isFunction).call(_CometD, callback)) {
3274
+ _classPrivateMethodGet$2(this, _notifyCallback, _notifyCallback2).call(this, callback, message);
3275
+ return true;
3276
+ }
3277
+ }
3278
+ return false;
3279
+ }
3280
+ function _handleTransportFailure2(failureInfo) {
3281
+ this._debug("Transport failure handling", failureInfo);
3282
+ if (failureInfo.transport) {
3283
+ _classPrivateFieldSet(this, _transport, failureInfo.transport);
3284
+ }
3285
+ if (failureInfo.url) {
3286
+ _classPrivateFieldGet(this, _transport).url = failureInfo.url;
3287
+ }
3288
+ const action = failureInfo.action;
3289
+ const delay = failureInfo.delay || 0;
3290
+ switch (action) {
3291
+ case "handshake":
3292
+ _classPrivateMethodGet$2(this, _delayedHandshake, _delayedHandshake2).call(this, delay);
3293
+ break;
3294
+ case "retry":
3295
+ _classPrivateMethodGet$2(this, _delayedConnect, _delayedConnect2).call(this, delay);
3296
+ break;
3297
+ case "none":
3298
+ _classPrivateMethodGet$2(this, _disconnect, _disconnect2).call(this, true);
3299
+ break;
3300
+ default:
3301
+ throw new Error("Unknown action " + action);
3302
+ }
3303
+ }
3304
+ function _failHandshake2(message, failureInfo) {
3305
+ _classPrivateMethodGet$2(this, _handleCallback, _handleCallback2).call(this, message);
3306
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/handshake", message);
3307
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/unsuccessful", message);
3308
+
3309
+ // The listeners may have disconnected.
3310
+ if (this.isDisconnected()) {
3311
+ failureInfo.action = "none";
3312
+ }
3313
+ this.onTransportFailure(message, failureInfo, failureInfo => _classPrivateMethodGet$2(this, _handleTransportFailure, _handleTransportFailure2).call(this, failureInfo));
3314
+ }
3315
+ function _handshakeResponse2(message) {
3316
+ const url = this.getURL();
3317
+ if (message.successful) {
3318
+ const crossDomain = _classPrivateMethodGet$2(this, _isCrossDomain, _isCrossDomain2).call(this, _classStaticPrivateMethodGet(_CometD, _CometD, _splitURL).call(_CometD, url)[2]);
3319
+ const newTransport = _classPrivateFieldGet(this, _transports).negotiateTransport(message.supportedConnectionTypes, message.version, crossDomain, url);
3320
+ if (newTransport === null) {
3321
+ message.successful = false;
3322
+ _classPrivateMethodGet$2(this, _failHandshake, _failHandshake2).call(this, message, {
3323
+ cause: "negotiation",
3324
+ action: "none",
3325
+ transport: null
3326
+ });
3327
+ return;
3328
+ } else {
3329
+ const oldTransport = _classPrivateFieldGet(this, _transport);
3330
+ if (oldTransport !== newTransport) {
3331
+ this._debug("Transport", oldTransport && oldTransport.type, "->", newTransport.type);
3332
+ _classPrivateFieldSet(this, _transport, newTransport);
3333
+ }
3334
+ }
3335
+ _classPrivateFieldSet(this, _clientId, message.clientId);
3336
+
3337
+ // End the internal batch and allow held messages from the application
3338
+ // to go to the server (see #handshake() where we start the internal batch).
3339
+ _classPrivateFieldSet(this, _internalBatch, false);
3340
+ _classPrivateMethodGet$2(this, _flushBatch, _flushBatch2).call(this);
3341
+
3342
+ // Here the new transport is in place, as well as the clientId, so
3343
+ // the listeners can perform a publish() if they want.
3344
+ // Notify the listeners before the connect below.
3345
+ message.reestablish = _classPrivateFieldGet(this, _reestablish);
3346
+ _classPrivateFieldSet(this, _reestablish, true);
3347
+ _classPrivateMethodGet$2(this, _handleCallback, _handleCallback2).call(this, message);
3348
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/handshake", message);
3349
+ _classPrivateFieldSet(this, _handshakeMessages, message["x-messages"] || 0);
3350
+ const action = this.isDisconnected() ? "none" : _classPrivateFieldGet(this, _advice).reconnect || "retry";
3351
+ switch (action) {
3352
+ case "retry":
3353
+ _classPrivateMethodGet$2(this, _resetBackoff, _resetBackoff2).call(this);
3354
+ if (_classPrivateFieldGet(this, _handshakeMessages) === 0) {
3355
+ _classPrivateMethodGet$2(this, _delayedConnect, _delayedConnect2).call(this, 0);
3356
+ } else {
3357
+ this._debug("Processing", _classPrivateFieldGet(this, _handshakeMessages), "handshake-delivered messages");
3358
+ }
3359
+ break;
3360
+ case "none":
3361
+ _classPrivateMethodGet$2(this, _disconnect, _disconnect2).call(this, true);
3362
+ break;
3363
+ default:
3364
+ throw new Error("Unrecognized advice action " + action);
3365
+ }
3366
+ } else {
3367
+ _classPrivateMethodGet$2(this, _failHandshake, _failHandshake2).call(this, message, {
3368
+ cause: "unsuccessful",
3369
+ action: _classPrivateFieldGet(this, _advice).reconnect || "handshake",
3370
+ transport: this.getTransport()
3371
+ });
3372
+ }
3373
+ }
3374
+ function _handshakeFailure2(message) {
3375
+ _classPrivateMethodGet$2(this, _failHandshake, _failHandshake2).call(this, message, {
3376
+ cause: "failure",
3377
+ action: "handshake",
3378
+ transport: null
3379
+ });
3380
+ }
3381
+ function _matchMetaConnect2(connect) {
3382
+ if (this.getStatus() === "disconnected") {
3383
+ return true;
3384
+ }
3385
+ if (_classPrivateFieldGet(this, _metaConnect) && _classPrivateFieldGet(this, _metaConnect).id === connect.id) {
3386
+ _classPrivateFieldSet(this, _metaConnect, null);
3387
+ return true;
3388
+ }
3389
+ return false;
3390
+ }
3391
+ function _failConnect2(message, failureInfo) {
3392
+ // Notify the listeners after the status change but before the next action.
3393
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/connect", message);
3394
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/unsuccessful", message);
3395
+
3396
+ // The listeners may have disconnected.
3397
+ if (this.isDisconnected()) {
3398
+ failureInfo.action = "none";
3399
+ }
3400
+ this.onTransportFailure(message, failureInfo, failureInfo => _classPrivateMethodGet$2(this, _handleTransportFailure, _handleTransportFailure2).call(this, failureInfo));
3401
+ }
3402
+ function _connectResponse2(message) {
3403
+ if (_classPrivateMethodGet$2(this, _matchMetaConnect, _matchMetaConnect2).call(this, message)) {
3404
+ _classPrivateFieldSet(this, _connected, message.successful);
3405
+ if (_classPrivateFieldGet(this, _connected)) {
3406
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/connect", message);
3407
+
3408
+ // Normally, the advice will say "reconnect: "retry", interval: 0"
3409
+ // and the server will hold the request, so when a response returns
3410
+ // we immediately call the server again (long polling).
3411
+ // Listeners can call disconnect(), so check the state after they run.
3412
+ const action = this.isDisconnected() ? "none" : _classPrivateFieldGet(this, _advice).reconnect || "retry";
3413
+ switch (action) {
3414
+ case "retry":
3415
+ _classPrivateMethodGet$2(this, _resetBackoff, _resetBackoff2).call(this);
3416
+ _classPrivateMethodGet$2(this, _delayedConnect, _delayedConnect2).call(this, _classPrivateFieldGet(this, _backoff));
3417
+ break;
3418
+ case "none":
3419
+ _classPrivateMethodGet$2(this, _disconnect, _disconnect2).call(this, false);
3420
+ break;
3421
+ default:
3422
+ throw new Error("Unrecognized advice action " + action);
3423
+ }
3424
+ } else {
3425
+ _classPrivateMethodGet$2(this, _failConnect, _failConnect2).call(this, message, {
3426
+ cause: "unsuccessful",
3427
+ action: _classPrivateFieldGet(this, _advice).reconnect || "retry",
3428
+ transport: this.getTransport()
3429
+ });
3430
+ }
3431
+ } else {
3432
+ this._debug("Mismatched /meta/connect reply", message);
3433
+ }
3434
+ }
3435
+ function _connectFailure2(message) {
3436
+ if (_classPrivateMethodGet$2(this, _matchMetaConnect, _matchMetaConnect2).call(this, message)) {
3437
+ _classPrivateFieldSet(this, _connected, false);
3438
+ _classPrivateMethodGet$2(this, _failConnect, _failConnect2).call(this, message, {
3439
+ cause: "failure",
3440
+ action: "retry",
3441
+ transport: null
3442
+ });
3443
+ } else {
3444
+ this._debug("Mismatched /meta/connect failure", message);
3445
+ }
3446
+ }
3447
+ function _failDisconnect2(message) {
3448
+ _classPrivateMethodGet$2(this, _disconnect, _disconnect2).call(this, true);
3449
+ _classPrivateMethodGet$2(this, _handleCallback, _handleCallback2).call(this, message);
3450
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/disconnect", message);
3451
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/unsuccessful", message);
3452
+ }
3453
+ function _disconnectResponse2(message) {
3454
+ if (message.successful) {
3455
+ // Wait for the /meta/connect to arrive.
3456
+ _classPrivateMethodGet$2(this, _disconnect, _disconnect2).call(this, false);
3457
+ _classPrivateMethodGet$2(this, _handleCallback, _handleCallback2).call(this, message);
3458
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/disconnect", message);
3459
+ } else {
3460
+ _classPrivateMethodGet$2(this, _failDisconnect, _failDisconnect2).call(this, message);
3461
+ }
3462
+ }
3463
+ function _disconnectFailure2(message) {
3464
+ _classPrivateMethodGet$2(this, _failDisconnect, _failDisconnect2).call(this, message);
3465
+ }
3466
+ function _failSubscribe2(message) {
3467
+ const subscriptions = _classPrivateFieldGet(this, _listeners)[message.subscription];
3468
+ if (subscriptions) {
3469
+ for (let id in subscriptions) {
3470
+ if (subscriptions.hasOwnProperty(id)) {
3471
+ const subscription = subscriptions[id];
3472
+ if (subscription && !subscription.listener) {
3473
+ delete subscriptions[id];
3474
+ this._debug("Removed failed subscription", subscription);
3475
+ }
3476
+ }
3477
+ }
3478
+ }
3479
+ _classPrivateMethodGet$2(this, _handleCallback, _handleCallback2).call(this, message);
3480
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/subscribe", message);
3481
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/unsuccessful", message);
3482
+ }
3483
+ function _subscribeResponse2(message) {
3484
+ if (message.successful) {
3485
+ _classPrivateMethodGet$2(this, _handleCallback, _handleCallback2).call(this, message);
3486
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/subscribe", message);
3487
+ } else {
3488
+ _classPrivateMethodGet$2(this, _failSubscribe, _failSubscribe2).call(this, message);
3489
+ }
3490
+ }
3491
+ function _subscribeFailure2(message) {
3492
+ _classPrivateMethodGet$2(this, _failSubscribe, _failSubscribe2).call(this, message);
3493
+ }
3494
+ function _failUnsubscribe2(message) {
3495
+ _classPrivateMethodGet$2(this, _handleCallback, _handleCallback2).call(this, message);
3496
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/unsubscribe", message);
3497
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/unsuccessful", message);
3498
+ }
3499
+ function _unsubscribeResponse2(message) {
3500
+ if (message.successful) {
3501
+ _classPrivateMethodGet$2(this, _handleCallback, _handleCallback2).call(this, message);
3502
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/unsubscribe", message);
3503
+ } else {
3504
+ _classPrivateMethodGet$2(this, _failUnsubscribe, _failUnsubscribe2).call(this, message);
3505
+ }
3506
+ }
3507
+ function _unsubscribeFailure2(message) {
3508
+ _classPrivateMethodGet$2(this, _failUnsubscribe, _failUnsubscribe2).call(this, message);
3509
+ }
3510
+ function _failMessage2(message) {
3511
+ if (!_classPrivateMethodGet$2(this, _handleRemoteCall, _handleRemoteCall2).call(this, message)) {
3512
+ _classPrivateMethodGet$2(this, _handleCallback, _handleCallback2).call(this, message);
3513
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/publish", message);
3514
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/unsuccessful", message);
3515
+ }
3516
+ }
3517
+ function _messageResponse2(message) {
3518
+ if (message.data !== undefined) {
3519
+ if (!_classPrivateMethodGet$2(this, _handleRemoteCall, _handleRemoteCall2).call(this, message)) {
3520
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, message.channel, message);
3521
+ if (_classPrivateFieldGet(this, _handshakeMessages) > 0) {
3522
+ var _this$handshakeMessag;
3523
+ _classPrivateFieldSet(this, _handshakeMessages, (_this$handshakeMessag = _classPrivateFieldGet(this, _handshakeMessages), --_this$handshakeMessag));
3524
+ if (_classPrivateFieldGet(this, _handshakeMessages) === 0) {
3525
+ this._debug("Processed last handshake-delivered message");
3526
+ _classPrivateMethodGet$2(this, _delayedConnect, _delayedConnect2).call(this, 0);
3527
+ }
3528
+ }
3529
+ }
3530
+ } else {
3531
+ if (message.successful === undefined) {
3532
+ this._warn("Unknown Bayeux Message", message);
3533
+ } else {
3534
+ if (message.successful) {
3535
+ _classPrivateMethodGet$2(this, _handleCallback, _handleCallback2).call(this, message);
3536
+ _classPrivateMethodGet$2(this, _notifyListeners, _notifyListeners2).call(this, "/meta/publish", message);
3537
+ } else {
3538
+ _classPrivateMethodGet$2(this, _failMessage, _failMessage2).call(this, message);
3539
+ }
3540
+ }
3541
+ }
3542
+ }
3543
+ function _messageFailure2(failure) {
3544
+ _classPrivateMethodGet$2(this, _failMessage, _failMessage2).call(this, failure);
3545
+ }
3546
+ function _receive2(message) {
3547
+ _classPrivateFieldSet(this, _unconnectTime, 0);
3548
+ message = _classPrivateMethodGet$2(this, _applyIncomingExtensions, _applyIncomingExtensions2).call(this, message);
3549
+ if (message === undefined || message === null) {
3550
+ return;
3551
+ }
3552
+ _classPrivateMethodGet$2(this, _updateAdvice, _updateAdvice2).call(this, message.advice);
3553
+ const channel = message.channel;
3554
+ switch (channel) {
3555
+ case "/meta/handshake":
3556
+ _classPrivateMethodGet$2(this, _handshakeResponse, _handshakeResponse2).call(this, message);
3557
+ break;
3558
+ case "/meta/connect":
3559
+ _classPrivateMethodGet$2(this, _connectResponse, _connectResponse2).call(this, message);
3560
+ break;
3561
+ case "/meta/disconnect":
3562
+ _classPrivateMethodGet$2(this, _disconnectResponse, _disconnectResponse2).call(this, message);
3563
+ break;
3564
+ case "/meta/subscribe":
3565
+ _classPrivateMethodGet$2(this, _subscribeResponse, _subscribeResponse2).call(this, message);
3566
+ break;
3567
+ case "/meta/unsubscribe":
3568
+ _classPrivateMethodGet$2(this, _unsubscribeResponse, _unsubscribeResponse2).call(this, message);
3569
+ break;
3570
+ default:
3571
+ _classPrivateMethodGet$2(this, _messageResponse, _messageResponse2).call(this, message);
3572
+ break;
3573
+ }
3574
+ }
3575
+ function _handleMessages2(rcvdMessages) {
3576
+ this._debug("Received", rcvdMessages);
3577
+ for (let i = 0; i < rcvdMessages.length; ++i) {
3578
+ const message = rcvdMessages[i];
3579
+ this.receive(message);
3580
+ }
3581
+ }
3582
+ function _handleFailure2(conduit, messages, failure) {
3583
+ this._debug("handleFailure", conduit, messages, failure);
3584
+ failure.transport = conduit;
3585
+ for (let i = 0; i < messages.length; ++i) {
3586
+ const message = messages[i];
3587
+ const failureMessage = {
3588
+ id: message.id,
3589
+ successful: false,
3590
+ channel: message.channel,
3591
+ failure: failure
3592
+ };
3593
+ failure.message = message;
3594
+ switch (message.channel) {
3595
+ case "/meta/handshake":
3596
+ _classPrivateMethodGet$2(this, _handshakeFailure, _handshakeFailure2).call(this, failureMessage);
3597
+ break;
3598
+ case "/meta/connect":
3599
+ _classPrivateMethodGet$2(this, _connectFailure, _connectFailure2).call(this, failureMessage);
3600
+ break;
3601
+ case "/meta/disconnect":
3602
+ _classPrivateMethodGet$2(this, _disconnectFailure, _disconnectFailure2).call(this, failureMessage);
3603
+ break;
3604
+ case "/meta/subscribe":
3605
+ failureMessage.subscription = message.subscription;
3606
+ _classPrivateMethodGet$2(this, _subscribeFailure, _subscribeFailure2).call(this, failureMessage);
3607
+ break;
3608
+ case "/meta/unsubscribe":
3609
+ failureMessage.subscription = message.subscription;
3610
+ _classPrivateMethodGet$2(this, _unsubscribeFailure, _unsubscribeFailure2).call(this, failureMessage);
3611
+ break;
3612
+ default:
3613
+ _classPrivateMethodGet$2(this, _messageFailure, _messageFailure2).call(this, failureMessage);
3614
+ break;
3615
+ }
3616
+ }
3617
+ }
3618
+ function _hasSubscriptions2(channel) {
3619
+ const subscriptions = _classPrivateFieldGet(this, _listeners)[channel];
3620
+ if (subscriptions) {
3621
+ for (let id in subscriptions) {
3622
+ if (subscriptions.hasOwnProperty(id)) {
3623
+ if (subscriptions[id]) {
3624
+ return true;
3625
+ }
3626
+ }
3627
+ }
3628
+ }
3629
+ return false;
3630
+ }
3631
+ function _resolveScopedCallback2(scope, callback) {
3632
+ const delegate = {
3633
+ scope: scope,
3634
+ method: callback
3635
+ };
3636
+ if (_classStaticPrivateMethodGet(_CometD, _CometD, _isFunction).call(_CometD, scope)) {
3637
+ delegate.scope = undefined;
3638
+ delegate.method = scope;
3639
+ } else {
3640
+ if (_classStaticPrivateMethodGet(_CometD, _CometD, _isString).call(_CometD, callback)) {
3641
+ if (!scope) {
3642
+ throw new Error("Invalid scope " + scope);
3643
+ }
3644
+ delegate.method = scope[callback];
3645
+ if (!_classStaticPrivateMethodGet(_CometD, _CometD, _isFunction).call(_CometD, delegate.method)) {
3646
+ throw new Error("Invalid callback " + callback + " for scope " + scope);
3647
+ }
3648
+ } else if (!_classStaticPrivateMethodGet(_CometD, _CometD, _isFunction).call(_CometD, callback)) {
3649
+ throw new Error("Invalid callback " + callback);
3650
+ }
3651
+ }
3652
+ return delegate;
3653
+ }
3654
+ function _addListener2(channel, scope, callback, isListener) {
3655
+ var _this$listenerId;
3656
+ // The data structure is a map<channel, subscription[]>, where each subscription
3657
+ // holds the callback to be called and its scope.
3658
+
3659
+ const delegate = _classPrivateMethodGet$2(this, _resolveScopedCallback, _resolveScopedCallback2).call(this, scope, callback);
3660
+ this._debug("Adding", isListener ? "listener" : "subscription", "on", channel, "with scope", delegate.scope, "and callback", delegate.method);
3661
+ const id = _classPrivateFieldSet(this, _listenerId, (_this$listenerId = _classPrivateFieldGet(this, _listenerId), ++_this$listenerId));
3662
+ const subscription = {
3663
+ id: id,
3664
+ channel: channel,
3665
+ scope: delegate.scope,
3666
+ callback: delegate.method,
3667
+ listener: isListener
3668
+ };
3669
+ let subscriptions = _classPrivateFieldGet(this, _listeners)[channel];
3670
+ if (!subscriptions) {
3671
+ subscriptions = {};
3672
+ _classPrivateFieldGet(this, _listeners)[channel] = subscriptions;
3673
+ }
3674
+ subscriptions[id] = subscription;
3675
+ this._debug("Added", isListener ? "listener" : "subscription", subscription);
3676
+ return subscription;
3677
+ }
3678
+
3679
+ function _classPrivateFieldInitSpec$3(obj, privateMap, value) { _checkPrivateRedeclaration$3(obj, privateMap); privateMap.set(obj, value); }
3680
+ function _checkPrivateRedeclaration$3(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
3681
+ var _cometd = /*#__PURE__*/new WeakMap();
3682
+ /*
3683
+ * Copyright (c) 2008 the original author or authors.
3684
+ *
3685
+ * Licensed under the Apache License, Version 2.0 (the "License");
3686
+ * you may not use this file except in compliance with the License.
3687
+ * You may obtain a copy of the License at
3688
+ *
3689
+ * http://www.apache.org/licenses/LICENSE-2.0
3690
+ *
3691
+ * Unless required by applicable law or agreed to in writing, software
3692
+ * distributed under the License is distributed on an "AS IS" BASIS,
3693
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3694
+ * See the License for the specific language governing permissions and
3695
+ * limitations under the License.
3696
+ */
3697
+
3698
+ /**
3699
+ * Base class for CometD extensions.
3700
+ */
3701
+ class Extension {
3702
+ constructor() {
3703
+ _classPrivateFieldInitSpec$3(this, _cometd, {
3704
+ writable: true,
3705
+ value: void 0
3706
+ });
3707
+ }
3708
+ registered(name, cometd) {
3709
+ _classPrivateFieldSet(this, _cometd, cometd);
3710
+ }
3711
+ unregistered() {
3712
+ _classPrivateFieldSet(this, _cometd, null);
3713
+ }
3714
+ get cometd() {
3715
+ return _classPrivateFieldGet(this, _cometd);
3716
+ }
3717
+ incoming(message) {
3718
+ return message;
3719
+ }
3720
+ outgoing(message) {
3721
+ return message;
3722
+ }
3723
+ }
3724
+
3725
+ function _classPrivateMethodInitSpec$1(obj, privateSet) { _checkPrivateRedeclaration$2(obj, privateSet); privateSet.add(obj); }
3726
+ function _classPrivateFieldInitSpec$2(obj, privateMap, value) { _checkPrivateRedeclaration$2(obj, privateMap); privateMap.set(obj, value); }
3727
+ function _checkPrivateRedeclaration$2(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
3728
+ function _classPrivateMethodGet$1(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
3729
+
3730
+ /**
3731
+ * This client-side extension enables the client to acknowledge to the server
3732
+ * the messages that the client has received.
3733
+ * For the acknowledgement to work, the server must be configured with the
3734
+ * correspondent server-side ack extension. If both client and server support
3735
+ * the ack extension, then the ack functionality will take place automatically.
3736
+ * By enabling this extension, all messages arriving from the server will arrive
3737
+ * via /meta/connect, so the comet communication will be slightly chattier.
3738
+ * The fact that all messages will return via /meta/connect means also that the
3739
+ * messages will arrive with total order, which is not guaranteed if messages
3740
+ * can arrive via both /meta/connect and normal response.
3741
+ * Messages are not acknowledged one by one, but instead a batch of messages is
3742
+ * acknowledged when the /meta/connect returns.
3743
+ */
3744
+ var _serverSupportsAcks = /*#__PURE__*/new WeakMap();
3745
+ var _batch$1 = /*#__PURE__*/new WeakMap();
3746
+ var _debug = /*#__PURE__*/new WeakSet();
3747
+ class AckExtension extends Extension {
3748
+ constructor(..._args) {
3749
+ super(..._args);
3750
+ _classPrivateMethodInitSpec$1(this, _debug);
3751
+ _classPrivateFieldInitSpec$2(this, _serverSupportsAcks, {
3752
+ writable: true,
3753
+ value: false
3754
+ });
3755
+ _classPrivateFieldInitSpec$2(this, _batch$1, {
3756
+ writable: true,
3757
+ value: 0
3758
+ });
3759
+ }
3760
+ registered(name, cometd) {
3761
+ super.registered(name, cometd);
3762
+ _classPrivateMethodGet$1(this, _debug, _debug2).call(this, "AckExtension: executing registration callback");
3763
+ }
3764
+ unregistered() {
3765
+ _classPrivateMethodGet$1(this, _debug, _debug2).call(this, "AckExtension: executing unregistration callback");
3766
+ super.unregistered();
3767
+ }
3768
+ incoming(message) {
3769
+ const channel = message.channel;
3770
+ const ext = message.ext;
3771
+ if (channel === "/meta/handshake") {
3772
+ if (ext) {
3773
+ const ackField = ext.ack;
3774
+ if (typeof ackField === "object") {
3775
+ // New format.
3776
+ _classPrivateFieldSet(this, _serverSupportsAcks, ackField.enabled === true);
3777
+ const batch = ackField.batch;
3778
+ if (typeof batch === "number") {
3779
+ _classPrivateFieldSet(this, _batch$1, batch);
3780
+ }
3781
+ } else {
3782
+ // Old format.
3783
+ _classPrivateFieldSet(this, _serverSupportsAcks, ackField === true);
3784
+ }
3785
+ }
3786
+ _classPrivateMethodGet$1(this, _debug, _debug2).call(this, "AckExtension: server supports acknowledgements", _classPrivateFieldGet(this, _serverSupportsAcks));
3787
+ } else if (channel === "/meta/connect" && message.successful && _classPrivateFieldGet(this, _serverSupportsAcks)) {
3788
+ if (ext && typeof ext.ack === "number") {
3789
+ _classPrivateFieldSet(this, _batch$1, ext.ack);
3790
+ _classPrivateMethodGet$1(this, _debug, _debug2).call(this, "AckExtension: server sent batch", _classPrivateFieldGet(this, _batch$1));
3791
+ }
3792
+ }
3793
+ return message;
3794
+ }
3795
+ outgoing(message) {
3796
+ const channel = message.channel;
3797
+ if (!message.ext) {
3798
+ message.ext = {};
3799
+ }
3800
+ if (channel === "/meta/handshake") {
3801
+ message.ext.ack = this.cometd && this.cometd.ackEnabled !== false;
3802
+ _classPrivateFieldSet(this, _serverSupportsAcks, false);
3803
+ _classPrivateFieldSet(this, _batch$1, 0);
3804
+ } else if (channel === "/meta/connect") {
3805
+ if (_classPrivateFieldGet(this, _serverSupportsAcks)) {
3806
+ message.ext.ack = _classPrivateFieldGet(this, _batch$1);
3807
+ _classPrivateMethodGet$1(this, _debug, _debug2).call(this, "AckExtension: client sending batch", _classPrivateFieldGet(this, _batch$1));
3808
+ }
3809
+ }
3810
+ return message;
3811
+ }
3812
+ }
3813
+ function _debug2(text, args) {
3814
+ this.cometd._debug(text, args);
3815
+ }
3816
+
3817
+ function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { _classCheckPrivateStaticAccess(receiver, classConstructor); _classCheckPrivateStaticFieldDescriptor(descriptor, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
3818
+ function _classCheckPrivateStaticFieldDescriptor(descriptor, action) { if (descriptor === undefined) { throw new TypeError("attempted to " + action + " private static field before its declaration"); } }
3819
+ function _classCheckPrivateStaticAccess(receiver, classConstructor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } }
3820
+ function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
3821
+ /*
3822
+ * Copyright (c) 2008 the original author or authors.
3823
+ *
3824
+ * Licensed under the Apache License, Version 2.0 (the "License");
3825
+ * you may not use this file except in compliance with the License.
3826
+ * You may obtain a copy of the License at
3827
+ *
3828
+ * http://www.apache.org/licenses/LICENSE-2.0
3829
+ *
3830
+ * Unless required by applicable law or agreed to in writing, software
3831
+ * distributed under the License is distributed on an "AS IS" BASIS,
3832
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3833
+ * See the License for the specific language governing permissions and
3834
+ * limitations under the License.
3835
+ */
3836
+
3837
+ /**
3838
+ * Z85 encoding/decoding as specified by https://rfc.zeromq.org/spec/32/.
3839
+ * Z85 encodes binary data to a string that may be sent as JSON payload,
3840
+ * and decodes strings to binary data.
3841
+ */
3842
+ class Z85 {
3843
+ /**
3844
+ * Encodes the given bytes to a string.
3845
+ * @param bytes the bytes to encode, either a number[], or an ArrayBuffer, or a TypedArray.
3846
+ * @return {string} the bytes encoded as a string
3847
+ */
3848
+ static encode(bytes) {
3849
+ let buffer = null;
3850
+ if (bytes instanceof ArrayBuffer) {
3851
+ buffer = bytes;
3852
+ } else if (bytes.buffer instanceof ArrayBuffer) {
3853
+ buffer = bytes.buffer;
3854
+ } else if (Array.isArray(bytes)) {
3855
+ buffer = new Uint8Array(bytes).buffer;
3856
+ }
3857
+ if (buffer == null) {
3858
+ throw new Error("Cannot Z85 encode " + bytes);
3859
+ }
3860
+ const length = buffer.byteLength;
3861
+ const remainder = length % 4;
3862
+ const padding = 4 - (remainder === 0 ? 4 : remainder);
3863
+ const view = new DataView(buffer);
3864
+ let result = "";
3865
+ let value = 0;
3866
+ for (let i = 0; i < length + padding; ++i) {
3867
+ const isPadding = i >= length;
3868
+ value = value * 256 + (isPadding ? 0 : view.getUint8(i));
3869
+ if ((i + 1) % 4 === 0) {
3870
+ let divisor = 85 * 85 * 85 * 85;
3871
+ for (let j = 5; j > 0; --j) {
3872
+ if (!isPadding || j > padding) {
3873
+ const code = Math.floor(value / divisor) % 85;
3874
+ result += _classStaticPrivateFieldSpecGet(Z85, Z85, _z85EncodeTable)[code];
3875
+ }
3876
+ divisor /= 85;
3877
+ }
3878
+ value = 0;
3879
+ }
3880
+ }
3881
+ return result;
3882
+ }
3883
+
3884
+ /**
3885
+ * Decodes the given string into an ArrayBuffer.
3886
+ * @param string the string to decode
3887
+ * @return {ArrayBuffer} the decoded bytes
3888
+ */
3889
+ static decode(string) {
3890
+ const remainder = string.length % 5;
3891
+ const padding = 5 - (remainder === 0 ? 5 : remainder);
3892
+ for (let p = 0; p < padding; ++p) {
3893
+ string += _classStaticPrivateFieldSpecGet(Z85, Z85, _z85EncodeTable)[_classStaticPrivateFieldSpecGet(Z85, Z85, _z85EncodeTable).length - 1];
3894
+ }
3895
+ const length = string.length;
3896
+ const buffer = new ArrayBuffer(length * 4 / 5 - padding);
3897
+ const view = new DataView(buffer);
3898
+ let value = 0;
3899
+ let charIdx = 0;
3900
+ let byteIdx = 0;
3901
+ for (let i = 0; i < length; ++i) {
3902
+ const code = string.charCodeAt(charIdx++) - 32;
3903
+ value = value * 85 + _classStaticPrivateFieldSpecGet(Z85, Z85, _z85DecodeTable)[code];
3904
+ if (charIdx % 5 === 0) {
3905
+ let divisor = 256 * 256 * 256;
3906
+ while (divisor >= 1) {
3907
+ if (byteIdx < view.byteLength) {
3908
+ view.setUint8(byteIdx++, Math.floor(value / divisor) % 256);
3909
+ }
3910
+ divisor /= 256;
3911
+ }
3912
+ value = 0;
3913
+ }
3914
+ }
3915
+ return buffer;
3916
+ }
3917
+ }
3918
+ var _z85EncodeTable = {
3919
+ writable: true,
3920
+ value: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", ".", "-", ":", "+", "=", "^", "!", "/", "*", "?", "&", "<", ">", "(", ")", "[", "]", "{", "}", "@", "%", "$", "#"]
3921
+ };
3922
+ var _z85DecodeTable = {
3923
+ writable: true,
3924
+ value: [0x00, 0x44, 0x00, 0x54, 0x53, 0x52, 0x48, 0x00, 0x4B, 0x4C, 0x46, 0x41, 0x00, 0x3F, 0x3E, 0x45, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x40, 0x00, 0x49, 0x42, 0x4A, 0x47, 0x51, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x4D, 0x00, 0x4E, 0x43, 0x00, 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x4F, 0x00, 0x50, 0x00, 0x00]
3925
+ };
3926
+
3927
+ /*
3928
+ * Copyright (c) 2008 the original author or authors.
3929
+ *
3930
+ * Licensed under the Apache License, Version 2.0 (the "License");
3931
+ * you may not use this file except in compliance with the License.
3932
+ * You may obtain a copy of the License at
3933
+ *
3934
+ * http://www.apache.org/licenses/LICENSE-2.0
3935
+ *
3936
+ * Unless required by applicable law or agreed to in writing, software
3937
+ * distributed under the License is distributed on an "AS IS" BASIS,
3938
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3939
+ * See the License for the specific language governing permissions and
3940
+ * limitations under the License.
3941
+ */
3942
+
3943
+ /**
3944
+ * Client-side extension that converts binary JavaScript objects
3945
+ * (ArrayBuffer, DataView and TypedArrays) into a textual
3946
+ * representation suitable for JSON, using the Z85 algorithm.
3947
+ */
3948
+ class BinaryExtension extends Extension {
3949
+ incoming(message) {
3950
+ if (!/^\/meta\//.test(message.channel)) {
3951
+ const ext = message.ext;
3952
+ if (ext) {
3953
+ const binaryExt = ext.binary;
3954
+ if (binaryExt) {
3955
+ message.data.data = Z85.decode(message.data.data);
3956
+ }
3957
+ }
3958
+ }
3959
+ return message;
3960
+ }
3961
+ outgoing(message) {
3962
+ if (!/^\/meta\//.test(message.channel)) {
3963
+ const ext = message.ext;
3964
+ if (ext) {
3965
+ const binaryExt = ext.binary;
3966
+ if (binaryExt) {
3967
+ message.data.data = Z85.encode(message.data.data);
3968
+ }
3969
+ }
3970
+ }
3971
+ return message;
3972
+ }
3973
+ }
3974
+
3975
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration$1(obj, privateSet); privateSet.add(obj); }
3976
+ function _classPrivateFieldInitSpec$1(obj, privateMap, value) { _checkPrivateRedeclaration$1(obj, privateMap); privateMap.set(obj, value); }
3977
+ function _checkPrivateRedeclaration$1(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
3978
+ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
3979
+
3980
+ /**
3981
+ * The reload extension allows a page to be loaded (or reloaded)
3982
+ * without having to re-handshake in the new (or reloaded) page,
3983
+ * therefore resuming the existing CometD connection.
3984
+ *
3985
+ * When the reload() method is called, the state of the CometD
3986
+ * connection is stored in the window.sessionStorage object.
3987
+ * The reload() method must therefore be called by page unload
3988
+ * handlers, often provided by JavaScript toolkits.
3989
+ *
3990
+ * When the page is (re)loaded, this extension checks the
3991
+ * window.sessionStorage and restores the CometD connection,
3992
+ * maintaining the same CometD clientId.
3993
+ */
3994
+ var _state = /*#__PURE__*/new WeakMap();
3995
+ var _name = /*#__PURE__*/new WeakMap();
3996
+ var _batch = /*#__PURE__*/new WeakMap();
3997
+ var _reloading = /*#__PURE__*/new WeakMap();
3998
+ var _reload = /*#__PURE__*/new WeakSet();
3999
+ var _similarState = /*#__PURE__*/new WeakSet();
4000
+ var _onHandshakeReply = /*#__PURE__*/new WeakSet();
4001
+ class ReloadExtension extends Extension {
4002
+ constructor(configuration) {
4003
+ super();
4004
+ _classPrivateMethodInitSpec(this, _onHandshakeReply);
4005
+ _classPrivateMethodInitSpec(this, _similarState);
4006
+ _classPrivateMethodInitSpec(this, _reload);
4007
+ _classPrivateFieldInitSpec$1(this, _state, {
4008
+ writable: true,
4009
+ value: {}
4010
+ });
4011
+ _classPrivateFieldInitSpec$1(this, _name, {
4012
+ writable: true,
4013
+ value: "org.cometd.reload"
4014
+ });
4015
+ _classPrivateFieldInitSpec$1(this, _batch, {
4016
+ writable: true,
4017
+ value: false
4018
+ });
4019
+ _classPrivateFieldInitSpec$1(this, _reloading, {
4020
+ writable: true,
4021
+ value: false
4022
+ });
4023
+ this.configure(configuration);
4024
+ }
4025
+ configure(config) {
4026
+ if (config) {
4027
+ if (typeof config.name === "string") {
4028
+ _classPrivateFieldSet(this, _name, config.name);
4029
+ }
4030
+ }
4031
+ }
4032
+ _receive(response) {
4033
+ this.cometd.receive(response);
4034
+ }
4035
+ registered(name, cometd) {
4036
+ super.registered(name, cometd);
4037
+ this.cometd.reload = config => _classPrivateMethodGet(this, _reload, _reload2).call(this, config);
4038
+ this.cometd.addListener("/meta/handshake", m => _classPrivateMethodGet(this, _onHandshakeReply, _onHandshakeReply2).call(this, m));
4039
+ }
4040
+ unregistered() {
4041
+ delete this.cometd.reload;
4042
+ super.unregistered();
4043
+ }
4044
+ outgoing(message) {
4045
+ switch (message.channel) {
4046
+ case "/meta/handshake":
4047
+ {
4048
+ _classPrivateFieldSet(this, _state, {
4049
+ url: this.cometd.getURL()
4050
+ });
4051
+ const state = window.sessionStorage.getItem(_classPrivateFieldGet(this, _name));
4052
+ this.cometd._debug("Reload extension found state", state);
4053
+ // Is there a saved handshake response from a prior load?
4054
+ if (state) {
4055
+ try {
4056
+ const oldState = JSON.parse(state);
4057
+
4058
+ // Remove the state, not needed anymore.
4059
+ window.sessionStorage.removeItem(_classPrivateFieldGet(this, _name));
4060
+ if (oldState.handshakeResponse && _classPrivateMethodGet(this, _similarState, _similarState2).call(this, oldState)) {
4061
+ this.cometd._debug("Reload extension restoring state", oldState);
4062
+
4063
+ // Since we are going to abort this message,
4064
+ // we must save an eventual callback to restore
4065
+ // it when we replay the handshake response.
4066
+ const callback = this.cometd._getCallback(message.id);
4067
+ this.cometd.setTimeout(() => {
4068
+ this.cometd._debug("Reload extension replaying handshake response", oldState.handshakeResponse);
4069
+ _classPrivateFieldGet(this, _state).handshakeResponse = oldState.handshakeResponse;
4070
+ _classPrivateFieldGet(this, _state).transportType = oldState.transportType;
4071
+
4072
+ // Restore the callback.
4073
+ this.cometd._putCallback(message.id, callback);
4074
+ const response = this.cometd._mixin(true, {}, _classPrivateFieldGet(this, _state).handshakeResponse, {
4075
+ // Keep the response message id the same as the request.
4076
+ id: message.id,
4077
+ // Tells applications this is a handshake replayed by the reload extension.
4078
+ ext: {
4079
+ reload: true
4080
+ }
4081
+ });
4082
+ // Use the same transport as before.
4083
+ response.supportedConnectionTypes = [_classPrivateFieldGet(this, _state).transportType];
4084
+ this._receive(response);
4085
+ this.cometd._debug("Reload extension replayed handshake response", response);
4086
+ }, 0);
4087
+
4088
+ // Delay any sends until first connect is complete.
4089
+ // This avoids that there is an old /meta/connect pending on server
4090
+ // that will be resumed to send messages to the client, when the
4091
+ // client has already closed the connection, thereby losing the messages.
4092
+ if (!_classPrivateFieldGet(this, _batch)) {
4093
+ _classPrivateFieldSet(this, _batch, true);
4094
+ this.cometd.startBatch();
4095
+ }
4096
+
4097
+ // This handshake is aborted, as we will replay the prior handshake response.
4098
+ return null;
4099
+ } else {
4100
+ this.cometd._debug("Reload extension could not restore state", oldState);
4101
+ }
4102
+ } catch (x) {
4103
+ this.cometd._debug("Reload extension error while trying to restore state", x);
4104
+ }
4105
+ }
4106
+ break;
4107
+ }
4108
+ case "/meta/connect":
4109
+ {
4110
+ if (_classPrivateFieldGet(this, _reloading) === true) {
4111
+ // The reload causes the failure of the outstanding /meta/connect,
4112
+ // which CometD will react to by sending another. Here we avoid
4113
+ // that /meta/connect messages are sent between the reload and
4114
+ // the destruction of the JavaScript context, so that we are sure
4115
+ // that the first /meta/connect is the one triggered after the
4116
+ // replay of the /meta/handshake by this extension.
4117
+ this.cometd._debug("Reload extension aborting /meta/connect during reload");
4118
+ return null;
4119
+ }
4120
+ if (!_classPrivateFieldGet(this, _state).transportType) {
4121
+ _classPrivateFieldGet(this, _state).transportType = message.connectionType;
4122
+ this.cometd._debug("Reload extension tracked transport type", _classPrivateFieldGet(this, _state).transportType);
4123
+ }
4124
+ break;
4125
+ }
4126
+ case "/meta/disconnect":
4127
+ {
4128
+ _classPrivateFieldSet(this, _state, {});
4129
+ break;
4130
+ }
4131
+ }
4132
+ return message;
4133
+ }
4134
+ incoming(message) {
4135
+ switch (message.channel) {
4136
+ case "/meta/handshake":
4137
+ {
4138
+ // Only record the handshake response if it's successful.
4139
+ if (message.successful) {
4140
+ // If the handshake response is already present, then we're replaying it.
4141
+ // Since the replay may have modified the handshake response, do not record it again.
4142
+ if (!_classPrivateFieldGet(this, _state).handshakeResponse) {
4143
+ // Save successful handshake response
4144
+ _classPrivateFieldGet(this, _state).handshakeResponse = message;
4145
+ this.cometd._debug("Reload extension tracked handshake response", message);
4146
+ }
4147
+ }
4148
+ break;
4149
+ }
4150
+ case "/meta/connect":
4151
+ {
4152
+ if (_classPrivateFieldGet(this, _batch)) {
4153
+ _classPrivateFieldSet(this, _batch, false);
4154
+ this.cometd.endBatch();
4155
+ }
4156
+ break;
4157
+ }
4158
+ case "/meta/disconnect":
4159
+ {
4160
+ if (_classPrivateFieldGet(this, _batch)) {
4161
+ _classPrivateFieldSet(this, _batch, false);
4162
+ this.cometd.endBatch();
4163
+ }
4164
+ _classPrivateFieldSet(this, _state, {});
4165
+ break;
4166
+ }
4167
+ }
4168
+ return message;
4169
+ }
4170
+ }
4171
+ function _reload2(config) {
4172
+ if (_classPrivateFieldGet(this, _state).handshakeResponse) {
4173
+ _classPrivateFieldSet(this, _reloading, true);
4174
+ const transport = this.cometd.getTransport();
4175
+ if (transport) {
4176
+ transport.abort();
4177
+ }
4178
+ this.configure(config);
4179
+ const state = JSON.stringify(_classPrivateFieldGet(this, _state));
4180
+ this.cometd._debug("Reload extension saving state", state);
4181
+ window.sessionStorage.setItem(_classPrivateFieldGet(this, _name), state);
4182
+ }
4183
+ }
4184
+ function _similarState2(oldState) {
4185
+ // We want to check here that the CometD object
4186
+ // did not change much between reloads.
4187
+ // We just check the URL for now, but in future
4188
+ // further checks may involve the transport type
4189
+ // and other configuration parameters.
4190
+ return _classPrivateFieldGet(this, _state).url === oldState.url;
4191
+ }
4192
+ function _onHandshakeReply2(message) {
4193
+ // Unsuccessful handshakes should
4194
+ // not be saved in case of reloads.
4195
+ if (message.successful !== true) {
4196
+ _classPrivateFieldSet(this, _state, {});
4197
+ }
4198
+ }
4199
+
4200
+ /*
4201
+ * Copyright (c) 2008 the original author or authors.
4202
+ *
4203
+ * Licensed under the Apache License, Version 2.0 (the "License");
4204
+ * you may not use this file except in compliance with the License.
4205
+ * You may obtain a copy of the License at
4206
+ *
4207
+ * http://www.apache.org/licenses/LICENSE-2.0
4208
+ *
4209
+ * Unless required by applicable law or agreed to in writing, software
4210
+ * distributed under the License is distributed on an "AS IS" BASIS,
4211
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4212
+ * See the License for the specific language governing permissions and
4213
+ * limitations under the License.
4214
+ */
4215
+
4216
+ /**
4217
+ * The timestamp extension adds the optional timestamp field to all outgoing messages.
4218
+ */
4219
+ class TimeStampExtension extends Extension {
4220
+ outgoing(message) {
4221
+ message.timestamp = new Date().toUTCString();
4222
+ return message;
4223
+ }
4224
+ }
4225
+
4226
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
4227
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
4228
+
4229
+ /**
4230
+ * With each handshake or connect, the extension sends timestamps within the
4231
+ * ext field like: <code>{ext:{timesync:{tc:12345567890,l:23,o:4567},...},...}</code>
4232
+ * where:<ul>
4233
+ * <li>tc is the client timestamp in ms since 1970 of when the message was sent.
4234
+ * <li>l is the network lag that the client has calculated.
4235
+ * <li>o is the clock offset that the client has calculated.
4236
+ * </ul>
4237
+ *
4238
+ * <p>
4239
+ * A CometD server that supports timesync, can respond with an ext
4240
+ * field like: <code>{ext:{timesync:{tc:12345567890,ts:1234567900,p:123,a:3},...},...}</code>
4241
+ * where:<ul>
4242
+ * <li>tc is the client timestamp of when the message was sent,
4243
+ * <li>ts is the server timestamp of when the message was received
4244
+ * <li>p is the poll duration in ms - ie the time the server took before sending the response.
4245
+ * <li>a is the measured accuracy of the calculated offset and lag sent by the client
4246
+ * </ul>
4247
+ *
4248
+ * <p>
4249
+ * The relationship between tc, ts & l is given by <code>ts=tc+o+l</code> (the
4250
+ * time the server received the message is the client time plus the offset plus the
4251
+ * network lag). Thus the accuracy of the o and l settings can be determined with
4252
+ * <code>a=(tc+o+l)-ts</code>.
4253
+ * </p>
4254
+ * <p>
4255
+ * When the client has received the response, it can make a more accurate estimate
4256
+ * of the lag as <code>l2=(now-tc-p)/2</code> (assuming symmetric lag).
4257
+ * A new offset can then be calculated with the relationship on the client
4258
+ * that <code>ts=tc+o2+l2</code>, thus <code>o2=ts-tc-l2</code>.
4259
+ * </p>
4260
+ * <p>
4261
+ * Since the client also receives the a value calculated on the server, it
4262
+ * should be possible to analyse this and compensate for some asymmetry
4263
+ * in the lag. But the current client does not do this.
4264
+ * </p>
4265
+ */
4266
+ var _maxSamples = /*#__PURE__*/new WeakMap();
4267
+ var _lags = /*#__PURE__*/new WeakMap();
4268
+ var _offsets = /*#__PURE__*/new WeakMap();
4269
+ var _lag = /*#__PURE__*/new WeakMap();
4270
+ var _offset = /*#__PURE__*/new WeakMap();
4271
+ class TimeSyncExtension extends Extension {
4272
+ constructor(configuration) {
4273
+ super();
4274
+ _classPrivateFieldInitSpec(this, _maxSamples, {
4275
+ writable: true,
4276
+ value: void 0
4277
+ });
4278
+ _classPrivateFieldInitSpec(this, _lags, {
4279
+ writable: true,
4280
+ value: []
4281
+ });
4282
+ _classPrivateFieldInitSpec(this, _offsets, {
4283
+ writable: true,
4284
+ value: []
4285
+ });
4286
+ _classPrivateFieldInitSpec(this, _lag, {
4287
+ writable: true,
4288
+ value: 0
4289
+ });
4290
+ _classPrivateFieldInitSpec(this, _offset, {
4291
+ writable: true,
4292
+ value: 0
4293
+ });
4294
+ _classPrivateFieldSet(this, _maxSamples, configuration && configuration.maxSamples || 10);
4295
+ }
4296
+ registered(name, cometd) {
4297
+ super.registered(name, cometd);
4298
+ this.cometd._debug("TimeSyncExtension: executing registration callback");
4299
+ }
4300
+ unregistered() {
4301
+ this.cometd._debug("TimeSyncExtension: executing unregistration callback");
4302
+ super.unregistered();
4303
+ _classPrivateFieldSet(this, _lags, []);
4304
+ _classPrivateFieldSet(this, _offsets, []);
4305
+ _classPrivateFieldSet(this, _lag, 0);
4306
+ _classPrivateFieldSet(this, _offset, 0);
4307
+ }
4308
+ incoming(message) {
4309
+ const channel = message.channel;
4310
+ if (channel && channel.indexOf("/meta/") === 0) {
4311
+ if (message.ext && message.ext.timesync) {
4312
+ const timesync = message.ext.timesync;
4313
+ this.cometd._debug("TimeSyncExtension: server sent timesync", timesync);
4314
+ const now = new Date().getTime();
4315
+ const l2 = (now - timesync.tc - timesync.p) / 2;
4316
+ const o2 = timesync.ts - timesync.tc - l2;
4317
+ _classPrivateFieldGet(this, _lags).push(l2);
4318
+ _classPrivateFieldGet(this, _offsets).push(o2);
4319
+ if (_classPrivateFieldGet(this, _offsets).length > _classPrivateFieldGet(this, _maxSamples)) {
4320
+ _classPrivateFieldGet(this, _offsets).shift();
4321
+ _classPrivateFieldGet(this, _lags).shift();
4322
+ }
4323
+ const samples = _classPrivateFieldGet(this, _offsets).length;
4324
+ let lagsSum = 0;
4325
+ let offsetsSum = 0;
4326
+ for (let i = 0; i < samples; ++i) {
4327
+ lagsSum += _classPrivateFieldGet(this, _lags)[i];
4328
+ offsetsSum += _classPrivateFieldGet(this, _offsets)[i];
4329
+ }
4330
+ _classPrivateFieldSet(this, _lag, parseInt((lagsSum / samples).toFixed()));
4331
+ _classPrivateFieldSet(this, _offset, parseInt((offsetsSum / samples).toFixed()));
4332
+ this.cometd._debug("TimeSyncExtension: network lag", _classPrivateFieldGet(this, _lag), "ms, time offset with server", _classPrivateFieldGet(this, _offset), "ms");
4333
+ }
4334
+ }
4335
+ return message;
4336
+ }
4337
+ outgoing(message) {
4338
+ const channel = message.channel;
4339
+ if (channel && channel.indexOf("/meta/") === 0) {
4340
+ if (!message.ext) {
4341
+ message.ext = {};
4342
+ }
4343
+ message.ext.timesync = {
4344
+ tc: new Date().getTime(),
4345
+ l: this.getNetworkLag(),
4346
+ o: this.getTimeOffset()
4347
+ };
4348
+ this.cometd._debug("TimeSyncExtension: client sending timesync", message.ext.timesync);
4349
+ }
4350
+ return message;
4351
+ }
4352
+ /**
4353
+ * Get the estimated offset in ms from the clients clock to the
4354
+ * servers clock. The server time is the client time plus the offset.
4355
+ */
4356
+ getTimeOffset() {
4357
+ return _classPrivateFieldGet(this, _offset);
4358
+ }
4359
+
4360
+ /**
4361
+ * Get the estimated network lag in ms from the client to the server.
4362
+ */
4363
+ getNetworkLag() {
4364
+ return _classPrivateFieldGet(this, _lag);
4365
+ }
4366
+
4367
+ /**
4368
+ * Get the estimated server time in ms since the epoch.
4369
+ */
4370
+ getServerTime() {
4371
+ return new Date().getTime() + this.getTimeOffset();
4372
+ }
4373
+
4374
+ /**
4375
+ * Get the estimated server time as a Date object
4376
+ */
4377
+ getServerDate() {
4378
+ return new Date(this.getServerTime());
4379
+ }
4380
+ /**
4381
+ * Set a timeout to expire at given time on the server.
4382
+ * @param callback The function to call when the timer expires
4383
+ * @param atServerTimeOrDate a js Time or Date object representing the
4384
+ * server time at which the timeout should expire
4385
+ */
4386
+ setTimeout(callback, atServerTimeOrDate) {
4387
+ const ts = atServerTimeOrDate instanceof Date ? atServerTimeOrDate.getTime() : 0 + atServerTimeOrDate;
4388
+ const tc = ts - this.getTimeOffset();
4389
+ let interval = tc - new Date().getTime();
4390
+ if (interval < 0) {
4391
+ interval = 0;
4392
+ }
4393
+ return this.cometd.setTimeout(callback, interval);
4394
+ }
4395
+ }
4396
+
4397
+ export { AckExtension, BinaryExtension, CallbackPollingTransport, CometD, Extension, LongPollingTransport, ReloadExtension, RequestTransport, TimeStampExtension, TimeSyncExtension, Transport, WebSocketTransport };
4398
+ //# sourceMappingURL=cometd-acd4ed9d.js.map