epicenter-libs 3.33.0 → 3.34.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.
- package/CHANGELOG.md +17 -0
- package/dist/browser/epicenter.js +105 -2
- package/dist/browser/epicenter.js.map +1 -1
- package/dist/cjs/epicenter.js +105 -2
- package/dist/cjs/epicenter.js.map +1 -1
- package/dist/epicenter.js +105 -2
- package/dist/epicenter.js.map +1 -1
- package/dist/epicenter.min.js +1 -1
- package/dist/epicenter.min.js.map +1 -1
- package/dist/module/epicenter.js +105 -2
- package/dist/module/epicenter.js.map +1 -1
- package/dist/types/adapters/chat.d.ts +63 -0
- package/package.json +1 -1
- package/src/adapters/chat.ts +95 -0
- package/src/utils/identification.ts +4 -0
- package/dist/test/_virtual/runtime.js +0 -3
- package/dist/test/_virtual/runtime2.js +0 -3
- package/dist/test/adapters/account.js +0 -169
- package/dist/test/adapters/admin.js +0 -53
- package/dist/test/adapters/asset.js +0 -425
- package/dist/test/adapters/authentication.js +0 -349
- package/dist/test/adapters/channel.js +0 -201
- package/dist/test/adapters/chat.js +0 -199
- package/dist/test/adapters/cometd.js +0 -514
- package/dist/test/adapters/consensus.js +0 -484
- package/dist/test/adapters/daily.js +0 -244
- package/dist/test/adapters/email.js +0 -179
- package/dist/test/adapters/episode.js +0 -175
- package/dist/test/adapters/group.js +0 -655
- package/dist/test/adapters/leaderboard.js +0 -162
- package/dist/test/adapters/matchmaker.js +0 -159
- package/dist/test/adapters/presence.js +0 -85
- package/dist/test/adapters/project.js +0 -94
- package/dist/test/adapters/recaptcha.js +0 -24
- package/dist/test/adapters/run.js +0 -1008
- package/dist/test/adapters/somebody.js +0 -154
- package/dist/test/adapters/task.js +0 -192
- package/dist/test/adapters/time.js +0 -28
- package/dist/test/adapters/user.js +0 -105
- package/dist/test/adapters/vault.js +0 -403
- package/dist/test/adapters/video.js +0 -249
- package/dist/test/adapters/vonage.js +0 -130
- package/dist/test/adapters/wallet.js +0 -130
- package/dist/test/adapters/world.js +0 -507
- package/dist/test/apis/video.js +0 -294
- package/dist/test/apis/vonage.js +0 -121
- package/dist/test/epicenter.js +0 -121
- package/dist/test/node_modules/@babel/runtime/helpers/esm/defineProperty.js +0 -12
- package/dist/test/node_modules/@babel/runtime/helpers/esm/toPrimitive.js +0 -14
- package/dist/test/node_modules/@babel/runtime/helpers/esm/toPropertyKey.js +0 -9
- package/dist/test/node_modules/@babel/runtime/helpers/esm/typeof.js +0 -11
- package/dist/test/node_modules/cometd/AckExtension.js +0 -91
- package/dist/test/node_modules/cometd/CallbackPollingTransport.js +0 -148
- package/dist/test/node_modules/cometd/Client.js +0 -2160
- package/dist/test/node_modules/cometd/Extension.js +0 -47
- package/dist/test/node_modules/cometd/LongPollingTransport.js +0 -135
- package/dist/test/node_modules/cometd/ReloadExtension.js +0 -214
- package/dist/test/node_modules/cometd/RequestTransport.js +0 -252
- package/dist/test/node_modules/cometd/Transport.js +0 -167
- package/dist/test/node_modules/cometd/TransportRegistry.js +0 -107
- package/dist/test/node_modules/cometd/WebSocketTransport.js +0 -384
- package/dist/test/node_modules/cometd/cometd.js +0 -9
- package/dist/test/node_modules/regenerator-runtime/runtime.js +0 -773
- package/dist/test/utilities.js +0 -17
- package/dist/test/utils/config.js +0 -189
- package/dist/test/utils/constants.js +0 -293
- package/dist/test/utils/cookies.js +0 -75
- package/dist/test/utils/error-manager.js +0 -57
- package/dist/test/utils/error.js +0 -12
- package/dist/test/utils/fault.js +0 -34
- package/dist/test/utils/filter-parser.js +0 -68
- package/dist/test/utils/helpers.js +0 -9
- package/dist/test/utils/identification.js +0 -161
- package/dist/test/utils/result.js +0 -20
- package/dist/test/utils/router.js +0 -551
- package/dist/test/utils/store.js +0 -79
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
2
|
-
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
3
|
-
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
4
|
-
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
5
|
-
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
6
|
-
var _type = /*#__PURE__*/new WeakMap();
|
|
7
|
-
var _cometd = /*#__PURE__*/new WeakMap();
|
|
8
|
-
var _url = /*#__PURE__*/new WeakMap();
|
|
9
|
-
/*
|
|
10
|
-
* Copyright (c) 2008 the original author or authors.
|
|
11
|
-
*
|
|
12
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
-
* you may not use this file except in compliance with the License.
|
|
14
|
-
* You may obtain a copy of the License at
|
|
15
|
-
*
|
|
16
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
-
*
|
|
18
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
-
* See the License for the specific language governing permissions and
|
|
22
|
-
* limitations under the License.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Base class with the common functionality for transports.
|
|
27
|
-
*/
|
|
28
|
-
class Transport {
|
|
29
|
-
constructor() {
|
|
30
|
-
_classPrivateFieldInitSpec(this, _type, void 0);
|
|
31
|
-
_classPrivateFieldInitSpec(this, _cometd, void 0);
|
|
32
|
-
_classPrivateFieldInitSpec(this, _url, void 0);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Function invoked just after a transport has been successfully registered.
|
|
36
|
-
* @param type the type of transport (for example "long-polling")
|
|
37
|
-
* @param cometd the cometd object this transport has been registered to
|
|
38
|
-
* @see #unregistered()
|
|
39
|
-
*/
|
|
40
|
-
registered(type, cometd) {
|
|
41
|
-
_classPrivateFieldSet(_type, this, type);
|
|
42
|
-
_classPrivateFieldSet(_cometd, this, cometd);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Function invoked just after a transport has been successfully unregistered.
|
|
46
|
-
* @see #registered(type, cometd)
|
|
47
|
-
*/
|
|
48
|
-
unregistered() {
|
|
49
|
-
_classPrivateFieldSet(_type, this, null);
|
|
50
|
-
_classPrivateFieldSet(_cometd, this, null);
|
|
51
|
-
}
|
|
52
|
-
get cometd() {
|
|
53
|
-
return _classPrivateFieldGet(_cometd, this);
|
|
54
|
-
}
|
|
55
|
-
notifyTransportTimeout(messages) {
|
|
56
|
-
const callbacks = this.cometd._getTransportListeners("timeout");
|
|
57
|
-
if (callbacks) {
|
|
58
|
-
for (let i = 0; i < callbacks.length; ++i) {
|
|
59
|
-
const listener = callbacks[i];
|
|
60
|
-
try {
|
|
61
|
-
const result = listener.call(this, messages);
|
|
62
|
-
if (typeof result === "number" && result > 0) {
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
} catch (x) {
|
|
66
|
-
this.cometd._info("Exception during execution of transport listener", listener, x);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return 0;
|
|
71
|
-
}
|
|
72
|
-
debug() {
|
|
73
|
-
this.cometd._debug.apply(this.cometd, arguments);
|
|
74
|
-
}
|
|
75
|
-
get configuration() {
|
|
76
|
-
return this.cometd.getConfiguration();
|
|
77
|
-
}
|
|
78
|
-
get advice() {
|
|
79
|
-
return this.cometd.getAdvice();
|
|
80
|
-
}
|
|
81
|
-
setTimeout(funktion, delay) {
|
|
82
|
-
return this.cometd.setTimeout(funktion, delay);
|
|
83
|
-
}
|
|
84
|
-
clearTimeout(id) {
|
|
85
|
-
this.cometd.clearTimeout(id);
|
|
86
|
-
}
|
|
87
|
-
convertToJSON(messages) {
|
|
88
|
-
const maxSize = this.configuration.maxSendBayeuxMessageSize;
|
|
89
|
-
let result = "[";
|
|
90
|
-
for (let i = 0; i < messages.length; ++i) {
|
|
91
|
-
if (i > 0) {
|
|
92
|
-
result += ",";
|
|
93
|
-
}
|
|
94
|
-
const message = messages[i];
|
|
95
|
-
const json = JSON.stringify(message);
|
|
96
|
-
if (json.length > maxSize) {
|
|
97
|
-
throw new Error("maxSendBayeuxMessageSize " + maxSize + " exceeded");
|
|
98
|
-
}
|
|
99
|
-
result += json;
|
|
100
|
-
}
|
|
101
|
-
result += "]";
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Converts the given response into an array of bayeux messages
|
|
106
|
-
* @param response the response to convert
|
|
107
|
-
* @return an array of bayeux messages obtained by converting the response
|
|
108
|
-
*/
|
|
109
|
-
convertToMessages(response) {
|
|
110
|
-
if (response === undefined || response === null) {
|
|
111
|
-
return [];
|
|
112
|
-
}
|
|
113
|
-
if (typeof response === "string" || response instanceof String) {
|
|
114
|
-
try {
|
|
115
|
-
return JSON.parse(response);
|
|
116
|
-
} catch (x) {
|
|
117
|
-
this.debug("Could not convert to JSON the following string:", response);
|
|
118
|
-
throw x;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (Array.isArray(response)) {
|
|
122
|
-
return response;
|
|
123
|
-
}
|
|
124
|
-
if (response instanceof Object) {
|
|
125
|
-
return [response];
|
|
126
|
-
}
|
|
127
|
-
throw new Error("Conversion Error " + response + ", typeof " + typeof response);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Returns whether this transport can work for the given version and cross domain communication case.
|
|
131
|
-
* @param version a string indicating the transport version
|
|
132
|
-
* @param crossDomain a boolean indicating whether the communication is cross domain
|
|
133
|
-
* @param url the URL to connect to
|
|
134
|
-
* @return true if this transport can work for the given version and cross domain communication case,
|
|
135
|
-
* false otherwise
|
|
136
|
-
*/
|
|
137
|
-
accept(version, crossDomain, url) {
|
|
138
|
-
throw new Error("Abstract");
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Returns the type of this transport.
|
|
142
|
-
* @see #registered(type, cometd)
|
|
143
|
-
*/
|
|
144
|
-
get type() {
|
|
145
|
-
return _classPrivateFieldGet(_type, this);
|
|
146
|
-
}
|
|
147
|
-
get url() {
|
|
148
|
-
return _classPrivateFieldGet(_url, this);
|
|
149
|
-
}
|
|
150
|
-
set url(url) {
|
|
151
|
-
_classPrivateFieldSet(_url, this, url);
|
|
152
|
-
}
|
|
153
|
-
send(envelope, metaConnect) {
|
|
154
|
-
throw new Error("Abstract");
|
|
155
|
-
}
|
|
156
|
-
reset(init) {
|
|
157
|
-
this.debug("Transport", this.type, "reset", init ? "initial" : "retry");
|
|
158
|
-
}
|
|
159
|
-
abort() {
|
|
160
|
-
this.debug("Transport", this.type, "aborted");
|
|
161
|
-
}
|
|
162
|
-
toString() {
|
|
163
|
-
return this.type;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export { Transport };
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
2
|
-
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
3
|
-
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
4
|
-
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
5
|
-
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
6
|
-
var _types = /*#__PURE__*/new WeakMap();
|
|
7
|
-
var _transports = /*#__PURE__*/new WeakMap();
|
|
8
|
-
/*
|
|
9
|
-
* Copyright (c) 2008 the original author or authors.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A registry for transports used by the CometD object.
|
|
26
|
-
*/
|
|
27
|
-
class TransportRegistry {
|
|
28
|
-
constructor() {
|
|
29
|
-
_classPrivateFieldInitSpec(this, _types, []);
|
|
30
|
-
_classPrivateFieldInitSpec(this, _transports, {});
|
|
31
|
-
}
|
|
32
|
-
getTransportTypes() {
|
|
33
|
-
return _classPrivateFieldGet(_types, this).slice(0);
|
|
34
|
-
}
|
|
35
|
-
add(type, transport, index) {
|
|
36
|
-
let existing = false;
|
|
37
|
-
for (let i = 0; i < _classPrivateFieldGet(_types, this).length; ++i) {
|
|
38
|
-
if (_classPrivateFieldGet(_types, this)[i] === type) {
|
|
39
|
-
existing = true;
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (!existing) {
|
|
44
|
-
if (typeof index !== "number") {
|
|
45
|
-
_classPrivateFieldGet(_types, this).push(type);
|
|
46
|
-
} else {
|
|
47
|
-
_classPrivateFieldGet(_types, this).splice(index, 0, type);
|
|
48
|
-
}
|
|
49
|
-
_classPrivateFieldGet(_transports, this)[type] = transport;
|
|
50
|
-
}
|
|
51
|
-
return !existing;
|
|
52
|
-
}
|
|
53
|
-
find(type) {
|
|
54
|
-
for (let i = 0; i < _classPrivateFieldGet(_types, this).length; ++i) {
|
|
55
|
-
if (_classPrivateFieldGet(_types, this)[i] === type) {
|
|
56
|
-
return _classPrivateFieldGet(_transports, this)[type];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
negotiateTransport(types, version, crossDomain, url) {
|
|
62
|
-
for (let i = 0; i < _classPrivateFieldGet(_types, this).length; ++i) {
|
|
63
|
-
const type = _classPrivateFieldGet(_types, this)[i];
|
|
64
|
-
for (let j = 0; j < types.length; ++j) {
|
|
65
|
-
if (type === types[j]) {
|
|
66
|
-
const transport = _classPrivateFieldGet(_transports, this)[type];
|
|
67
|
-
if (transport.accept(version, crossDomain, url) === true) {
|
|
68
|
-
return transport;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
clear() {
|
|
76
|
-
_classPrivateFieldSet(_types, this, []);
|
|
77
|
-
_classPrivateFieldSet(_transports, this, {});
|
|
78
|
-
}
|
|
79
|
-
reset(init) {
|
|
80
|
-
for (let i = 0; i < _classPrivateFieldGet(_types, this).length; ++i) {
|
|
81
|
-
_classPrivateFieldGet(_transports, this)[_classPrivateFieldGet(_types, this)[i]].reset(init);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
findTransportTypes(version, crossDomain, url) {
|
|
85
|
-
const result = [];
|
|
86
|
-
for (let i = 0; i < _classPrivateFieldGet(_types, this).length; ++i) {
|
|
87
|
-
const type = _classPrivateFieldGet(_types, this)[i];
|
|
88
|
-
if (_classPrivateFieldGet(_transports, this)[type].accept(version, crossDomain, url) === true) {
|
|
89
|
-
result.push(type);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return result;
|
|
93
|
-
}
|
|
94
|
-
remove(type) {
|
|
95
|
-
for (let i = 0; i < _classPrivateFieldGet(_types, this).length; ++i) {
|
|
96
|
-
if (_classPrivateFieldGet(_types, this)[i] === type) {
|
|
97
|
-
_classPrivateFieldGet(_types, this).splice(i, 1);
|
|
98
|
-
const transport = _classPrivateFieldGet(_transports, this)[type];
|
|
99
|
-
delete _classPrivateFieldGet(_transports, this)[type];
|
|
100
|
-
return transport;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export { TransportRegistry };
|
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
import { Transport } from './Transport.js';
|
|
2
|
-
|
|
3
|
-
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
|
|
4
|
-
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
5
|
-
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
6
|
-
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
7
|
-
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
8
|
-
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
9
|
-
var _webSocketSupported = /*#__PURE__*/new WeakMap();
|
|
10
|
-
var _webSocketConnected = /*#__PURE__*/new WeakMap();
|
|
11
|
-
var _stickyReconnect = /*#__PURE__*/new WeakMap();
|
|
12
|
-
var _context = /*#__PURE__*/new WeakMap();
|
|
13
|
-
var _connecting = /*#__PURE__*/new WeakMap();
|
|
14
|
-
var _connected = /*#__PURE__*/new WeakMap();
|
|
15
|
-
var _successCallback = /*#__PURE__*/new WeakMap();
|
|
16
|
-
var _WebSocketTransport_brand = /*#__PURE__*/new WeakSet();
|
|
17
|
-
class WebSocketTransport extends Transport {
|
|
18
|
-
constructor(...args) {
|
|
19
|
-
super(...args);
|
|
20
|
-
_classPrivateMethodInitSpec(this, _WebSocketTransport_brand);
|
|
21
|
-
// By default, WebSocket is supported.
|
|
22
|
-
_classPrivateFieldInitSpec(this, _webSocketSupported, true);
|
|
23
|
-
// Whether we were able to establish a WebSocket connection.
|
|
24
|
-
_classPrivateFieldInitSpec(this, _webSocketConnected, false);
|
|
25
|
-
_classPrivateFieldInitSpec(this, _stickyReconnect, true);
|
|
26
|
-
// The context contains the envelopes that have been sent
|
|
27
|
-
// and the timeouts for the messages that have been sent.
|
|
28
|
-
_classPrivateFieldInitSpec(this, _context, null);
|
|
29
|
-
_classPrivateFieldInitSpec(this, _connecting, null);
|
|
30
|
-
_classPrivateFieldInitSpec(this, _connected, false);
|
|
31
|
-
_classPrivateFieldInitSpec(this, _successCallback, null);
|
|
32
|
-
}
|
|
33
|
-
reset(init) {
|
|
34
|
-
super.reset(init);
|
|
35
|
-
_classPrivateFieldSet(_webSocketSupported, this, true);
|
|
36
|
-
if (init) {
|
|
37
|
-
_classPrivateFieldSet(_webSocketConnected, this, false);
|
|
38
|
-
}
|
|
39
|
-
_classPrivateFieldSet(_stickyReconnect, this, true);
|
|
40
|
-
if (init) {
|
|
41
|
-
_classPrivateFieldSet(_context, this, null);
|
|
42
|
-
}
|
|
43
|
-
_classPrivateFieldSet(_connecting, this, null);
|
|
44
|
-
_classPrivateFieldSet(_connected, this, false);
|
|
45
|
-
}
|
|
46
|
-
_notifySuccess(fn, messages) {
|
|
47
|
-
fn.call(this, messages);
|
|
48
|
-
}
|
|
49
|
-
_notifyFailure(fn, context, messages, failure) {
|
|
50
|
-
fn.call(this, context, messages, failure);
|
|
51
|
-
}
|
|
52
|
-
accept(version, crossDomain, url) {
|
|
53
|
-
this.debug("Transport", this.type, "accept, supported:", _classPrivateFieldGet(_webSocketSupported, this));
|
|
54
|
-
// Using !! to return a boolean (and not the WebSocket object).
|
|
55
|
-
return _classPrivateFieldGet(_webSocketSupported, this) && !!window.WebSocket && this.cometd.websocketEnabled !== false;
|
|
56
|
-
}
|
|
57
|
-
send(envelope, metaConnect) {
|
|
58
|
-
this.debug("Transport", this.type, "sending", envelope, "/meta/connect =", metaConnect);
|
|
59
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _send).call(this, _classPrivateFieldGet(_context, this), envelope, metaConnect);
|
|
60
|
-
}
|
|
61
|
-
abort() {
|
|
62
|
-
super.abort();
|
|
63
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _forceClose).call(this, _classPrivateFieldGet(_context, this), {
|
|
64
|
-
code: 1000,
|
|
65
|
-
reason: "Abort"
|
|
66
|
-
});
|
|
67
|
-
this.reset(true);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function _forceClose(context, event) {
|
|
71
|
-
if (context) {
|
|
72
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _webSocketClose).call(this, context, event.code, event.reason);
|
|
73
|
-
// Force immediate failure of pending messages to trigger reconnect.
|
|
74
|
-
// This is needed because the server may not reply to our close()
|
|
75
|
-
// and therefore the onclose function is never called.
|
|
76
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _onClose).call(this, context, event);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function _sameContext(context) {
|
|
80
|
-
return context === _classPrivateFieldGet(_connecting, this) || context === _classPrivateFieldGet(_context, this);
|
|
81
|
-
}
|
|
82
|
-
function _storeEnvelope(context, envelope, metaConnect) {
|
|
83
|
-
const messageIds = [];
|
|
84
|
-
for (let i = 0; i < envelope.messages.length; ++i) {
|
|
85
|
-
const message = envelope.messages[i];
|
|
86
|
-
if (message.id) {
|
|
87
|
-
messageIds.push(message.id);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
context.envelopes[messageIds.join(",")] = [envelope, metaConnect];
|
|
91
|
-
this.debug("Transport", this.type, "stored envelope, envelopes", context.envelopes);
|
|
92
|
-
}
|
|
93
|
-
function _removeEnvelope(context, messageIds) {
|
|
94
|
-
let removed = false;
|
|
95
|
-
const envelopes = context.envelopes;
|
|
96
|
-
for (let j = 0; j < messageIds.length; ++j) {
|
|
97
|
-
const id = messageIds[j];
|
|
98
|
-
for (let key in envelopes) {
|
|
99
|
-
if (envelopes.hasOwnProperty(key)) {
|
|
100
|
-
const ids = key.split(",");
|
|
101
|
-
const index = ids.indexOf(id);
|
|
102
|
-
if (index >= 0) {
|
|
103
|
-
removed = true;
|
|
104
|
-
ids.splice(index, 1);
|
|
105
|
-
const envelope = envelopes[key][0];
|
|
106
|
-
const metaConnect = envelopes[key][1];
|
|
107
|
-
delete envelopes[key];
|
|
108
|
-
if (ids.length > 0) {
|
|
109
|
-
envelopes[ids.join(",")] = [envelope, metaConnect];
|
|
110
|
-
}
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (removed) {
|
|
117
|
-
this.debug("Transport", this.type, "removed envelope, envelopes", envelopes);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function _websocketConnect(context) {
|
|
121
|
-
// We may have multiple attempts to open a WebSocket
|
|
122
|
-
// connection, for example a /meta/connect request that
|
|
123
|
-
// may take time, along with a user-triggered publish.
|
|
124
|
-
// Early return if we are already connecting.
|
|
125
|
-
if (_classPrivateFieldGet(_connecting, this)) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Mangle the URL, changing the scheme from "http" to "ws".
|
|
130
|
-
const url = this.cometd.getURL().replace(/^http/, "ws");
|
|
131
|
-
this.debug("Transport", this.type, "connecting to URL", url);
|
|
132
|
-
try {
|
|
133
|
-
const protocol = this.configuration.protocol;
|
|
134
|
-
context.webSocket = protocol ? new window.WebSocket(url, protocol) : new window.WebSocket(url);
|
|
135
|
-
_classPrivateFieldSet(_connecting, this, context);
|
|
136
|
-
} catch (x) {
|
|
137
|
-
_classPrivateFieldSet(_webSocketSupported, this, false);
|
|
138
|
-
this.debug("Exception while creating WebSocket object", x);
|
|
139
|
-
throw x;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// By default use sticky reconnects.
|
|
143
|
-
_classPrivateFieldSet(_stickyReconnect, this, this.configuration.stickyReconnect !== false);
|
|
144
|
-
const connectTimeout = this.configuration.connectTimeout;
|
|
145
|
-
if (connectTimeout > 0) {
|
|
146
|
-
context.connectTimer = this.setTimeout(() => {
|
|
147
|
-
this.debug("Transport", this.type, "timed out while connecting to URL", url, ":", connectTimeout, "ms");
|
|
148
|
-
// The connection was not opened, close anyway.
|
|
149
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _forceClose).call(this, context, {
|
|
150
|
-
code: 1000,
|
|
151
|
-
reason: "Connect Timeout"
|
|
152
|
-
});
|
|
153
|
-
}, connectTimeout);
|
|
154
|
-
}
|
|
155
|
-
const onopen = () => {
|
|
156
|
-
this.debug("Transport", this.type, "onopen", context);
|
|
157
|
-
if (context.connectTimer) {
|
|
158
|
-
this.clearTimeout(context.connectTimer);
|
|
159
|
-
}
|
|
160
|
-
if (_assertClassBrand(_WebSocketTransport_brand, this, _sameContext).call(this, context)) {
|
|
161
|
-
_classPrivateFieldSet(_connecting, this, null);
|
|
162
|
-
_classPrivateFieldSet(_context, this, context);
|
|
163
|
-
_classPrivateFieldSet(_webSocketConnected, this, true);
|
|
164
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _onOpen).call(this, context);
|
|
165
|
-
} else {
|
|
166
|
-
// We have a valid connection already, close this one.
|
|
167
|
-
this.cometd._warn("Closing extra WebSocket connection", this, "active connection", _classPrivateFieldGet(_context, this));
|
|
168
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _forceClose).call(this, context, {
|
|
169
|
-
code: 1000,
|
|
170
|
-
reason: "Extra Connection"
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// This callback is invoked when the server sends the close frame.
|
|
176
|
-
// The close frame for a connection may arrive *after* another
|
|
177
|
-
// connection has been opened, so we must make sure that actions
|
|
178
|
-
// are performed only if it's the same connection.
|
|
179
|
-
const onclose = event => {
|
|
180
|
-
event = event || {
|
|
181
|
-
code: 1000
|
|
182
|
-
};
|
|
183
|
-
this.debug("Transport", this.type, "onclose", context, event, "connecting", _classPrivateFieldGet(_connecting, this), "current", _classPrivateFieldGet(_context, this));
|
|
184
|
-
if (context.connectTimer) {
|
|
185
|
-
this.clearTimeout(context.connectTimer);
|
|
186
|
-
}
|
|
187
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _onClose).call(this, context, event);
|
|
188
|
-
};
|
|
189
|
-
const onmessage = wsMessage => {
|
|
190
|
-
this.debug("Transport", this.type, "onmessage", wsMessage, context);
|
|
191
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _onMessage).call(this, context, wsMessage);
|
|
192
|
-
};
|
|
193
|
-
context.webSocket.onopen = onopen;
|
|
194
|
-
context.webSocket.onclose = onclose;
|
|
195
|
-
context.webSocket.onerror = () => {
|
|
196
|
-
// Clients should call onclose(), but if they do not we do it here for safety.
|
|
197
|
-
onclose({
|
|
198
|
-
code: 1000,
|
|
199
|
-
reason: "Error"
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
context.webSocket.onmessage = onmessage;
|
|
203
|
-
this.debug("Transport", this.type, "configured callbacks on", context);
|
|
204
|
-
}
|
|
205
|
-
function _onTransportTimeout(context, message, delay) {
|
|
206
|
-
const result = this.notifyTransportTimeout([message]);
|
|
207
|
-
if (result > 0) {
|
|
208
|
-
this.debug("Transport", this.type, "extended waiting for message replies:", result, "ms");
|
|
209
|
-
context.timeouts[message.id] = this.setTimeout(() => {
|
|
210
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _onTransportTimeout).call(this, context, message, delay + result);
|
|
211
|
-
}, result);
|
|
212
|
-
} else {
|
|
213
|
-
this.debug("Transport", this.type, "expired waiting for message reply", message.id, ":", delay, "ms");
|
|
214
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _forceClose).call(this, context, {
|
|
215
|
-
code: 1000,
|
|
216
|
-
reason: "Message Timeout"
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
function _webSocketSend(context, envelope, metaConnect) {
|
|
221
|
-
let json;
|
|
222
|
-
try {
|
|
223
|
-
json = this.convertToJSON(envelope.messages);
|
|
224
|
-
} catch (x) {
|
|
225
|
-
this.debug("Transport", this.type, "exception:", x);
|
|
226
|
-
const mIds = [];
|
|
227
|
-
for (let j = 0; j < envelope.messages.length; ++j) {
|
|
228
|
-
const m = envelope.messages[j];
|
|
229
|
-
mIds.push(m.id);
|
|
230
|
-
}
|
|
231
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _removeEnvelope).call(this, context, mIds);
|
|
232
|
-
// Keep the semantic of calling callbacks asynchronously.
|
|
233
|
-
this.setTimeout(() => {
|
|
234
|
-
this._notifyFailure(envelope.onFailure, context, envelope.messages, {
|
|
235
|
-
exception: x
|
|
236
|
-
});
|
|
237
|
-
}, 0);
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
context.webSocket.send(json);
|
|
241
|
-
this.debug("Transport", this.type, "sent", envelope, "/meta/connect =", metaConnect);
|
|
242
|
-
|
|
243
|
-
// Manage the timeout waiting for the response.
|
|
244
|
-
let delay = this.configuration.maxNetworkDelay;
|
|
245
|
-
if (metaConnect) {
|
|
246
|
-
delay += this.advice.timeout;
|
|
247
|
-
_classPrivateFieldSet(_connected, this, true);
|
|
248
|
-
}
|
|
249
|
-
const messageIds = [];
|
|
250
|
-
for (let i = 0; i < envelope.messages.length; ++i) {
|
|
251
|
-
const message = envelope.messages[i];
|
|
252
|
-
if (message.id) {
|
|
253
|
-
messageIds.push(message.id);
|
|
254
|
-
context.timeouts[message.id] = this.setTimeout(() => {
|
|
255
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _onTransportTimeout).call(this, context, message, delay);
|
|
256
|
-
}, delay);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
this.debug("Transport", this.type, "started waiting for message replies", delay, "ms, messageIds:", messageIds, ", timeouts:", context.timeouts);
|
|
260
|
-
}
|
|
261
|
-
function _send(context, envelope, metaConnect) {
|
|
262
|
-
try {
|
|
263
|
-
if (context === null) {
|
|
264
|
-
context = _classPrivateFieldGet(_connecting, this) || {
|
|
265
|
-
envelopes: {},
|
|
266
|
-
timeouts: {}
|
|
267
|
-
};
|
|
268
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _storeEnvelope).call(this, context, envelope, metaConnect);
|
|
269
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _websocketConnect).call(this, context);
|
|
270
|
-
} else {
|
|
271
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _storeEnvelope).call(this, context, envelope, metaConnect);
|
|
272
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _webSocketSend).call(this, context, envelope, metaConnect);
|
|
273
|
-
}
|
|
274
|
-
} catch (x) {
|
|
275
|
-
// Keep the semantic of calling callbacks asynchronously.
|
|
276
|
-
this.setTimeout(() => {
|
|
277
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _forceClose).call(this, context, {
|
|
278
|
-
code: 1000,
|
|
279
|
-
reason: "Exception",
|
|
280
|
-
exception: x
|
|
281
|
-
});
|
|
282
|
-
}, 0);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
function _onOpen(context) {
|
|
286
|
-
const envelopes = context.envelopes;
|
|
287
|
-
this.debug("Transport", this.type, "opened", context, "pending messages", envelopes);
|
|
288
|
-
for (let key in envelopes) {
|
|
289
|
-
if (envelopes.hasOwnProperty(key)) {
|
|
290
|
-
const element = envelopes[key];
|
|
291
|
-
const envelope = element[0];
|
|
292
|
-
const metaConnect = element[1];
|
|
293
|
-
// Store the success callback, which is independent of the envelope,
|
|
294
|
-
// so that it can be used to notify arrival of messages.
|
|
295
|
-
_classPrivateFieldSet(_successCallback, this, envelope.onSuccess);
|
|
296
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _webSocketSend).call(this, context, envelope, metaConnect);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
function _onMessage(context, wsMessage) {
|
|
301
|
-
this.debug("Transport", this.type, "received websocket message", wsMessage, context);
|
|
302
|
-
let close = false;
|
|
303
|
-
const messages = this.convertToMessages(wsMessage.data);
|
|
304
|
-
const messageIds = [];
|
|
305
|
-
for (let i = 0; i < messages.length; ++i) {
|
|
306
|
-
const message = messages[i];
|
|
307
|
-
|
|
308
|
-
// Detect if the message is a response to a request we made.
|
|
309
|
-
// If it's a meta message, for sure it's a response; otherwise it's
|
|
310
|
-
// a publish message and publish responses don't have the data field.
|
|
311
|
-
if (/^\/meta\//.test(message.channel) || message.data === undefined) {
|
|
312
|
-
if (message.id) {
|
|
313
|
-
messageIds.push(message.id);
|
|
314
|
-
const timeout = context.timeouts[message.id];
|
|
315
|
-
if (timeout) {
|
|
316
|
-
this.clearTimeout(timeout);
|
|
317
|
-
delete context.timeouts[message.id];
|
|
318
|
-
this.debug("Transport", this.type, "removed timeout for message", message.id, ", timeouts", context.timeouts);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
if ("/meta/connect" === message.channel) {
|
|
323
|
-
_classPrivateFieldSet(_connected, this, false);
|
|
324
|
-
}
|
|
325
|
-
if ("/meta/disconnect" === message.channel && !_classPrivateFieldGet(_connected, this)) {
|
|
326
|
-
close = true;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
// Remove the envelope corresponding to the messages.
|
|
331
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _removeEnvelope).call(this, context, messageIds);
|
|
332
|
-
this._notifySuccess(_classPrivateFieldGet(_successCallback, this), messages);
|
|
333
|
-
if (close) {
|
|
334
|
-
_assertClassBrand(_WebSocketTransport_brand, this, _webSocketClose).call(this, context, 1000, "Disconnect");
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
function _onClose(context, event) {
|
|
338
|
-
this.debug("Transport", this.type, "closed", context, event);
|
|
339
|
-
if (_assertClassBrand(_WebSocketTransport_brand, this, _sameContext).call(this, context)) {
|
|
340
|
-
// Remember if we were able to connect.
|
|
341
|
-
// This close event could be due to server shutdown,
|
|
342
|
-
// and if it restarts we want to try websocket again.
|
|
343
|
-
_classPrivateFieldSet(_webSocketSupported, this, _classPrivateFieldGet(_stickyReconnect, this) && _classPrivateFieldGet(_webSocketConnected, this));
|
|
344
|
-
_classPrivateFieldSet(_connecting, this, null);
|
|
345
|
-
_classPrivateFieldSet(_context, this, null);
|
|
346
|
-
}
|
|
347
|
-
const timeouts = context.timeouts;
|
|
348
|
-
context.timeouts = {};
|
|
349
|
-
for (let id in timeouts) {
|
|
350
|
-
if (timeouts.hasOwnProperty(id)) {
|
|
351
|
-
this.clearTimeout(timeouts[id]);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
const envelopes = context.envelopes;
|
|
355
|
-
context.envelopes = {};
|
|
356
|
-
for (let key in envelopes) {
|
|
357
|
-
if (envelopes.hasOwnProperty(key)) {
|
|
358
|
-
const envelope = envelopes[key][0];
|
|
359
|
-
const metaConnect = envelopes[key][1];
|
|
360
|
-
if (metaConnect) {
|
|
361
|
-
_classPrivateFieldSet(_connected, this, false);
|
|
362
|
-
}
|
|
363
|
-
const failure = {
|
|
364
|
-
websocketCode: event.code,
|
|
365
|
-
reason: event.reason
|
|
366
|
-
};
|
|
367
|
-
if (event.exception) {
|
|
368
|
-
failure.exception = event.exception;
|
|
369
|
-
}
|
|
370
|
-
this._notifyFailure(envelope.onFailure, context, envelope.messages, failure);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
function _webSocketClose(context, code, reason) {
|
|
375
|
-
try {
|
|
376
|
-
if (context.webSocket) {
|
|
377
|
-
context.webSocket.close(code, reason);
|
|
378
|
-
}
|
|
379
|
-
} catch (x) {
|
|
380
|
-
this.debug(x);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
export { WebSocketTransport };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { CometD } from './Client.js';
|
|
2
|
-
export { Extension } from './Extension.js';
|
|
3
|
-
export { AckExtension } from './AckExtension.js';
|
|
4
|
-
export { ReloadExtension } from './ReloadExtension.js';
|
|
5
|
-
export { Transport } from './Transport.js';
|
|
6
|
-
export { RequestTransport } from './RequestTransport.js';
|
|
7
|
-
export { CallbackPollingTransport } from './CallbackPollingTransport.js';
|
|
8
|
-
export { LongPollingTransport } from './LongPollingTransport.js';
|
|
9
|
-
export { WebSocketTransport } from './WebSocketTransport.js';
|