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,47 +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 _cometd = /*#__PURE__*/new WeakMap();
|
|
7
|
-
/*
|
|
8
|
-
* Copyright (c) 2008 the original author or authors.
|
|
9
|
-
*
|
|
10
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
-
* you may not use this file except in compliance with the License.
|
|
12
|
-
* You may obtain a copy of the License at
|
|
13
|
-
*
|
|
14
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
-
*
|
|
16
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
-
* See the License for the specific language governing permissions and
|
|
20
|
-
* limitations under the License.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Base class for CometD extensions.
|
|
25
|
-
*/
|
|
26
|
-
class Extension {
|
|
27
|
-
constructor() {
|
|
28
|
-
_classPrivateFieldInitSpec(this, _cometd, void 0);
|
|
29
|
-
}
|
|
30
|
-
registered(name, cometd) {
|
|
31
|
-
_classPrivateFieldSet(_cometd, this, cometd);
|
|
32
|
-
}
|
|
33
|
-
unregistered() {
|
|
34
|
-
_classPrivateFieldSet(_cometd, this, null);
|
|
35
|
-
}
|
|
36
|
-
get cometd() {
|
|
37
|
-
return _classPrivateFieldGet(_cometd, this);
|
|
38
|
-
}
|
|
39
|
-
incoming(message) {
|
|
40
|
-
return message;
|
|
41
|
-
}
|
|
42
|
-
outgoing(message) {
|
|
43
|
-
return message;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export { Extension };
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { RequestTransport } from './RequestTransport.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 _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
7
|
-
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
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 _supportsCrossDomain = /*#__PURE__*/new WeakMap();
|
|
10
|
-
var _LongPollingTransport_brand = /*#__PURE__*/new WeakSet();
|
|
11
|
-
class LongPollingTransport extends RequestTransport {
|
|
12
|
-
constructor(...args) {
|
|
13
|
-
super(...args);
|
|
14
|
-
_classPrivateMethodInitSpec(this, _LongPollingTransport_brand);
|
|
15
|
-
// By default, support cross domain.
|
|
16
|
-
_classPrivateFieldInitSpec(this, _supportsCrossDomain, true);
|
|
17
|
-
}
|
|
18
|
-
accept(version, crossDomain, url) {
|
|
19
|
-
return _classPrivateFieldGet(_supportsCrossDomain, this) || !crossDomain;
|
|
20
|
-
}
|
|
21
|
-
xhrSend(packet) {
|
|
22
|
-
const xhr = _assertClassBrand(_LongPollingTransport_brand, this, _newXMLHttpRequest).call(this);
|
|
23
|
-
_assertClassBrand(_LongPollingTransport_brand, this, _copyContext).call(this, xhr);
|
|
24
|
-
xhr.withCredentials = true;
|
|
25
|
-
xhr.open("POST", packet.url, packet.sync !== true);
|
|
26
|
-
const headers = packet.headers;
|
|
27
|
-
if (headers) {
|
|
28
|
-
for (let headerName in headers) {
|
|
29
|
-
if (headers.hasOwnProperty(headerName)) {
|
|
30
|
-
xhr.setRequestHeader(headerName, headers[headerName]);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
xhr.setRequestHeader("Content-Type", "application/json");
|
|
35
|
-
xhr.onload = () => {
|
|
36
|
-
if (xhr.status === 200) {
|
|
37
|
-
packet.onSuccess(xhr.responseText);
|
|
38
|
-
} else {
|
|
39
|
-
packet.onError(xhr.statusText);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
xhr.onabort = xhr.onerror = () => {
|
|
43
|
-
packet.onError(xhr.statusText);
|
|
44
|
-
};
|
|
45
|
-
xhr.send(packet.body);
|
|
46
|
-
return xhr;
|
|
47
|
-
}
|
|
48
|
-
transportSend(envelope, request) {
|
|
49
|
-
this.debug("Transport", this.type, "sending request", request.id, "envelope", envelope);
|
|
50
|
-
try {
|
|
51
|
-
let sameStack = true;
|
|
52
|
-
request.xhr = this.xhrSend({
|
|
53
|
-
transport: this,
|
|
54
|
-
url: envelope.url,
|
|
55
|
-
sync: envelope.sync,
|
|
56
|
-
headers: this.configuration.requestHeaders,
|
|
57
|
-
body: this.convertToJSON(envelope.messages),
|
|
58
|
-
onSuccess: response => {
|
|
59
|
-
this.debug("Transport", this.type, "received response", response);
|
|
60
|
-
let success = false;
|
|
61
|
-
try {
|
|
62
|
-
const received = this.convertToMessages(response);
|
|
63
|
-
if (received.length === 0) {
|
|
64
|
-
_classPrivateFieldSet(_supportsCrossDomain, this, false);
|
|
65
|
-
this.transportFailure(envelope, request, {
|
|
66
|
-
httpCode: 204
|
|
67
|
-
});
|
|
68
|
-
} else {
|
|
69
|
-
success = true;
|
|
70
|
-
this.transportSuccess(envelope, request, received);
|
|
71
|
-
}
|
|
72
|
-
} catch (x) {
|
|
73
|
-
this.debug(x);
|
|
74
|
-
if (!success) {
|
|
75
|
-
_classPrivateFieldSet(_supportsCrossDomain, this, false);
|
|
76
|
-
const failure = {
|
|
77
|
-
exception: x
|
|
78
|
-
};
|
|
79
|
-
failure.httpCode = this.xhrStatus(request.xhr);
|
|
80
|
-
this.transportFailure(envelope, request, failure);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
onError: (reason, exception) => {
|
|
85
|
-
this.debug("Transport", this.type, "received error", reason, exception);
|
|
86
|
-
_classPrivateFieldSet(_supportsCrossDomain, this, false);
|
|
87
|
-
const failure = {
|
|
88
|
-
reason: reason,
|
|
89
|
-
exception: exception
|
|
90
|
-
};
|
|
91
|
-
failure.httpCode = this.xhrStatus(request.xhr);
|
|
92
|
-
if (sameStack) {
|
|
93
|
-
// Keep the semantic of calling callbacks asynchronously.
|
|
94
|
-
this.setTimeout(() => {
|
|
95
|
-
this.transportFailure(envelope, request, failure);
|
|
96
|
-
}, 0);
|
|
97
|
-
} else {
|
|
98
|
-
this.transportFailure(envelope, request, failure);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
sameStack = false;
|
|
103
|
-
return true;
|
|
104
|
-
} catch (x) {
|
|
105
|
-
this.debug("Transport", this.type, "exception:", x);
|
|
106
|
-
_classPrivateFieldSet(_supportsCrossDomain, this, false);
|
|
107
|
-
// Keep the semantic of calling callbacks asynchronously.
|
|
108
|
-
this.setTimeout(() => {
|
|
109
|
-
this.transportFailure(envelope, request, {
|
|
110
|
-
exception: x
|
|
111
|
-
});
|
|
112
|
-
}, 0);
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
reset(init) {
|
|
117
|
-
super.reset(init);
|
|
118
|
-
_classPrivateFieldSet(_supportsCrossDomain, this, true);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function _newXMLHttpRequest() {
|
|
122
|
-
return new window.XMLHttpRequest();
|
|
123
|
-
}
|
|
124
|
-
function _copyContext(xhr) {
|
|
125
|
-
try {
|
|
126
|
-
// Copy external context, to be used in other environments.
|
|
127
|
-
xhr.context = this.context;
|
|
128
|
-
} catch (e) {
|
|
129
|
-
// May happen if XHR is wrapped by Object.seal(),
|
|
130
|
-
// Object.freeze(), or Object.preventExtensions().
|
|
131
|
-
this.debug("Could not copy transport context into XHR", e);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export { LongPollingTransport };
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import { Extension } from './Extension.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 _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
7
|
-
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
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
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The reload extension allows a page to be loaded (or reloaded)
|
|
12
|
-
* without having to re-handshake in the new (or reloaded) page,
|
|
13
|
-
* therefore resuming the existing CometD connection.
|
|
14
|
-
*
|
|
15
|
-
* When the reload() method is called, the state of the CometD
|
|
16
|
-
* connection is stored in the window.sessionStorage object.
|
|
17
|
-
* The reload() method must therefore be called by page unload
|
|
18
|
-
* handlers, often provided by JavaScript toolkits.
|
|
19
|
-
*
|
|
20
|
-
* When the page is (re)loaded, this extension checks the
|
|
21
|
-
* window.sessionStorage and restores the CometD connection,
|
|
22
|
-
* maintaining the same CometD clientId.
|
|
23
|
-
*/
|
|
24
|
-
var _state = /*#__PURE__*/new WeakMap();
|
|
25
|
-
var _name = /*#__PURE__*/new WeakMap();
|
|
26
|
-
var _batch = /*#__PURE__*/new WeakMap();
|
|
27
|
-
var _reloading = /*#__PURE__*/new WeakMap();
|
|
28
|
-
var _ReloadExtension_brand = /*#__PURE__*/new WeakSet();
|
|
29
|
-
class ReloadExtension extends Extension {
|
|
30
|
-
constructor(configuration) {
|
|
31
|
-
super();
|
|
32
|
-
_classPrivateMethodInitSpec(this, _ReloadExtension_brand);
|
|
33
|
-
_classPrivateFieldInitSpec(this, _state, {});
|
|
34
|
-
_classPrivateFieldInitSpec(this, _name, "org.cometd.reload");
|
|
35
|
-
_classPrivateFieldInitSpec(this, _batch, false);
|
|
36
|
-
_classPrivateFieldInitSpec(this, _reloading, false);
|
|
37
|
-
this.configure(configuration);
|
|
38
|
-
}
|
|
39
|
-
configure(config) {
|
|
40
|
-
if (config) {
|
|
41
|
-
if (typeof config.name === "string") {
|
|
42
|
-
_classPrivateFieldSet(_name, this, config.name);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
_receive(response) {
|
|
47
|
-
this.cometd.receive(response);
|
|
48
|
-
}
|
|
49
|
-
registered(name, cometd) {
|
|
50
|
-
super.registered(name, cometd);
|
|
51
|
-
this.cometd.reload = config => _assertClassBrand(_ReloadExtension_brand, this, _reload).call(this, config);
|
|
52
|
-
this.cometd.addListener("/meta/handshake", m => _assertClassBrand(_ReloadExtension_brand, this, _onHandshakeReply).call(this, m));
|
|
53
|
-
}
|
|
54
|
-
unregistered() {
|
|
55
|
-
delete this.cometd.reload;
|
|
56
|
-
super.unregistered();
|
|
57
|
-
}
|
|
58
|
-
outgoing(message) {
|
|
59
|
-
switch (message.channel) {
|
|
60
|
-
case "/meta/handshake":
|
|
61
|
-
{
|
|
62
|
-
_classPrivateFieldSet(_state, this, {
|
|
63
|
-
url: this.cometd.getURL()
|
|
64
|
-
});
|
|
65
|
-
const state = window.sessionStorage.getItem(_classPrivateFieldGet(_name, this));
|
|
66
|
-
this.cometd._debug("Reload extension found state", state);
|
|
67
|
-
// Is there a saved handshake response from a prior load?
|
|
68
|
-
if (state) {
|
|
69
|
-
try {
|
|
70
|
-
const oldState = JSON.parse(state);
|
|
71
|
-
|
|
72
|
-
// Remove the state, not needed anymore.
|
|
73
|
-
window.sessionStorage.removeItem(_classPrivateFieldGet(_name, this));
|
|
74
|
-
if (oldState.handshakeResponse && _assertClassBrand(_ReloadExtension_brand, this, _similarState).call(this, oldState)) {
|
|
75
|
-
this.cometd._debug("Reload extension restoring state", oldState);
|
|
76
|
-
|
|
77
|
-
// Since we are going to abort this message,
|
|
78
|
-
// we must save an eventual callback to restore
|
|
79
|
-
// it when we replay the handshake response.
|
|
80
|
-
const callback = this.cometd._getCallback(message.id);
|
|
81
|
-
this.cometd.setTimeout(() => {
|
|
82
|
-
this.cometd._debug("Reload extension replaying handshake response", oldState.handshakeResponse);
|
|
83
|
-
_classPrivateFieldGet(_state, this).handshakeResponse = oldState.handshakeResponse;
|
|
84
|
-
_classPrivateFieldGet(_state, this).transportType = oldState.transportType;
|
|
85
|
-
|
|
86
|
-
// Restore the callback.
|
|
87
|
-
this.cometd._putCallback(message.id, callback);
|
|
88
|
-
const response = this.cometd._mixin(true, {}, _classPrivateFieldGet(_state, this).handshakeResponse, {
|
|
89
|
-
// Keep the response message id the same as the request.
|
|
90
|
-
id: message.id,
|
|
91
|
-
// Tells applications this is a handshake replayed by the reload extension.
|
|
92
|
-
ext: {
|
|
93
|
-
reload: true
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
// Use the same transport as before.
|
|
97
|
-
response.supportedConnectionTypes = [_classPrivateFieldGet(_state, this).transportType];
|
|
98
|
-
this._receive(response);
|
|
99
|
-
this.cometd._debug("Reload extension replayed handshake response", response);
|
|
100
|
-
}, 0);
|
|
101
|
-
|
|
102
|
-
// Delay any sends until first connect is complete.
|
|
103
|
-
// This avoids that there is an old /meta/connect pending on server
|
|
104
|
-
// that will be resumed to send messages to the client, when the
|
|
105
|
-
// client has already closed the connection, thereby losing the messages.
|
|
106
|
-
if (!_classPrivateFieldGet(_batch, this)) {
|
|
107
|
-
_classPrivateFieldSet(_batch, this, true);
|
|
108
|
-
this.cometd.startBatch();
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// This handshake is aborted, as we will replay the prior handshake response.
|
|
112
|
-
return null;
|
|
113
|
-
} else {
|
|
114
|
-
this.cometd._debug("Reload extension could not restore state", oldState);
|
|
115
|
-
}
|
|
116
|
-
} catch (x) {
|
|
117
|
-
this.cometd._debug("Reload extension error while trying to restore state", x);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
case "/meta/connect":
|
|
123
|
-
{
|
|
124
|
-
if (_classPrivateFieldGet(_reloading, this) === true) {
|
|
125
|
-
// The reload causes the failure of the outstanding /meta/connect,
|
|
126
|
-
// which CometD will react to by sending another. Here we avoid
|
|
127
|
-
// that /meta/connect messages are sent between the reload and
|
|
128
|
-
// the destruction of the JavaScript context, so that we are sure
|
|
129
|
-
// that the first /meta/connect is the one triggered after the
|
|
130
|
-
// replay of the /meta/handshake by this extension.
|
|
131
|
-
this.cometd._debug("Reload extension aborting /meta/connect during reload");
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
if (!_classPrivateFieldGet(_state, this).transportType) {
|
|
135
|
-
_classPrivateFieldGet(_state, this).transportType = message.connectionType;
|
|
136
|
-
this.cometd._debug("Reload extension tracked transport type", _classPrivateFieldGet(_state, this).transportType);
|
|
137
|
-
}
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
case "/meta/disconnect":
|
|
141
|
-
{
|
|
142
|
-
_classPrivateFieldSet(_state, this, {});
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return message;
|
|
147
|
-
}
|
|
148
|
-
incoming(message) {
|
|
149
|
-
switch (message.channel) {
|
|
150
|
-
case "/meta/handshake":
|
|
151
|
-
{
|
|
152
|
-
// Only record the handshake response if it's successful.
|
|
153
|
-
if (message.successful) {
|
|
154
|
-
// If the handshake response is already present, then we're replaying it.
|
|
155
|
-
// Since the replay may have modified the handshake response, do not record it again.
|
|
156
|
-
if (!_classPrivateFieldGet(_state, this).handshakeResponse) {
|
|
157
|
-
// Save successful handshake response
|
|
158
|
-
_classPrivateFieldGet(_state, this).handshakeResponse = message;
|
|
159
|
-
this.cometd._debug("Reload extension tracked handshake response", message);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
case "/meta/connect":
|
|
165
|
-
{
|
|
166
|
-
if (_classPrivateFieldGet(_batch, this)) {
|
|
167
|
-
_classPrivateFieldSet(_batch, this, false);
|
|
168
|
-
this.cometd.endBatch();
|
|
169
|
-
}
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
case "/meta/disconnect":
|
|
173
|
-
{
|
|
174
|
-
if (_classPrivateFieldGet(_batch, this)) {
|
|
175
|
-
_classPrivateFieldSet(_batch, this, false);
|
|
176
|
-
this.cometd.endBatch();
|
|
177
|
-
}
|
|
178
|
-
_classPrivateFieldSet(_state, this, {});
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return message;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
function _reload(config) {
|
|
186
|
-
if (_classPrivateFieldGet(_state, this).handshakeResponse) {
|
|
187
|
-
_classPrivateFieldSet(_reloading, this, true);
|
|
188
|
-
const transport = this.cometd.getTransport();
|
|
189
|
-
if (transport) {
|
|
190
|
-
transport.abort();
|
|
191
|
-
}
|
|
192
|
-
this.configure(config);
|
|
193
|
-
const state = JSON.stringify(_classPrivateFieldGet(_state, this));
|
|
194
|
-
this.cometd._debug("Reload extension saving state", state);
|
|
195
|
-
window.sessionStorage.setItem(_classPrivateFieldGet(_name, this), state);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
function _similarState(oldState) {
|
|
199
|
-
// We want to check here that the CometD object
|
|
200
|
-
// did not change much between reloads.
|
|
201
|
-
// We just check the URL for now, but in future
|
|
202
|
-
// further checks may involve the transport type
|
|
203
|
-
// and other configuration parameters.
|
|
204
|
-
return _classPrivateFieldGet(_state, this).url === oldState.url;
|
|
205
|
-
}
|
|
206
|
-
function _onHandshakeReply(message) {
|
|
207
|
-
// Unsuccessful handshakes should
|
|
208
|
-
// not be saved in case of reloads.
|
|
209
|
-
if (message.successful !== true) {
|
|
210
|
-
_classPrivateFieldSet(_state, this, {});
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export { ReloadExtension };
|
|
@@ -1,252 +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 _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
7
|
-
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
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
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Base class with the common functionality for transports based on requests.
|
|
12
|
-
* The key responsibility is to allow at most 2 outstanding requests to the server,
|
|
13
|
-
* to avoid that requests are sent behind a long poll.
|
|
14
|
-
* To achieve this, we have one reserved request for the long poll, and all other
|
|
15
|
-
* requests are serialized one after the other.
|
|
16
|
-
*/
|
|
17
|
-
var _requestIds = /*#__PURE__*/new WeakMap();
|
|
18
|
-
var _metaConnectRequest = /*#__PURE__*/new WeakMap();
|
|
19
|
-
var _requests = /*#__PURE__*/new WeakMap();
|
|
20
|
-
var _envelopes = /*#__PURE__*/new WeakMap();
|
|
21
|
-
var _RequestTransport_brand = /*#__PURE__*/new WeakSet();
|
|
22
|
-
class RequestTransport extends Transport {
|
|
23
|
-
constructor(...args) {
|
|
24
|
-
super(...args);
|
|
25
|
-
_classPrivateMethodInitSpec(this, _RequestTransport_brand);
|
|
26
|
-
_classPrivateFieldInitSpec(this, _requestIds, 0);
|
|
27
|
-
_classPrivateFieldInitSpec(this, _metaConnectRequest, null);
|
|
28
|
-
_classPrivateFieldInitSpec(this, _requests, []);
|
|
29
|
-
_classPrivateFieldInitSpec(this, _envelopes, []);
|
|
30
|
-
}
|
|
31
|
-
complete(request, success, metaConnect) {
|
|
32
|
-
if (metaConnect) {
|
|
33
|
-
_assertClassBrand(_RequestTransport_brand, this, _metaConnectComplete).call(this, request);
|
|
34
|
-
} else {
|
|
35
|
-
_assertClassBrand(_RequestTransport_brand, this, _complete).call(this, request, success);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Performs the actual send depending on the transport type details.
|
|
40
|
-
* @param envelope the envelope to send
|
|
41
|
-
* @param request the request information
|
|
42
|
-
* @return {boolean} whether the send succeeded
|
|
43
|
-
*/
|
|
44
|
-
transportSend(envelope, request) {
|
|
45
|
-
throw new Error("Abstract");
|
|
46
|
-
}
|
|
47
|
-
transportSuccess(envelope, request, responses) {
|
|
48
|
-
if (!request.expired) {
|
|
49
|
-
this.clearTimeout(request.timeout);
|
|
50
|
-
this.debug("Transport", this.type, "cancelled waiting for message replies");
|
|
51
|
-
this.complete(request, true, request.metaConnect);
|
|
52
|
-
if (responses && responses.length > 0) {
|
|
53
|
-
envelope.onSuccess(responses);
|
|
54
|
-
} else {
|
|
55
|
-
envelope.onFailure(request.xhr, envelope.messages, {
|
|
56
|
-
httpCode: 204
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
transportFailure(envelope, request, failure) {
|
|
62
|
-
if (!request.expired) {
|
|
63
|
-
this.clearTimeout(request.timeout);
|
|
64
|
-
this.debug("Transport", this.type, "cancelled waiting for failed message replies");
|
|
65
|
-
this.complete(request, false, request.metaConnect);
|
|
66
|
-
envelope.onFailure(request.xhr, envelope.messages, failure);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
send(envelope, metaConnect) {
|
|
70
|
-
if (metaConnect) {
|
|
71
|
-
_assertClassBrand(_RequestTransport_brand, this, _metaConnectSend).call(this, envelope);
|
|
72
|
-
} else {
|
|
73
|
-
_assertClassBrand(_RequestTransport_brand, this, _queueSend).call(this, envelope);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
abort() {
|
|
77
|
-
super.abort();
|
|
78
|
-
for (let i = 0; i < _classPrivateFieldGet(_requests, this).length; ++i) {
|
|
79
|
-
const request = _classPrivateFieldGet(_requests, this)[i];
|
|
80
|
-
if (request) {
|
|
81
|
-
this.debug("Aborting request", request);
|
|
82
|
-
if (!this.abortXHR(request.xhr)) {
|
|
83
|
-
this.transportFailure(request.envelope, request, {
|
|
84
|
-
reason: "abort"
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const metaConnectRequest = _classPrivateFieldGet(_metaConnectRequest, this);
|
|
90
|
-
if (metaConnectRequest) {
|
|
91
|
-
this.debug("Aborting /meta/connect request", metaConnectRequest);
|
|
92
|
-
if (!this.abortXHR(metaConnectRequest.xhr)) {
|
|
93
|
-
this.transportFailure(metaConnectRequest.envelope, metaConnectRequest, {
|
|
94
|
-
reason: "abort"
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
this.reset(true);
|
|
99
|
-
}
|
|
100
|
-
reset(init) {
|
|
101
|
-
super.reset(init);
|
|
102
|
-
_classPrivateFieldSet(_metaConnectRequest, this, null);
|
|
103
|
-
_classPrivateFieldSet(_requests, this, []);
|
|
104
|
-
_classPrivateFieldSet(_envelopes, this, []);
|
|
105
|
-
}
|
|
106
|
-
abortXHR(xhr) {
|
|
107
|
-
if (xhr) {
|
|
108
|
-
try {
|
|
109
|
-
const state = xhr.readyState;
|
|
110
|
-
xhr.abort();
|
|
111
|
-
return state !== window.XMLHttpRequest.UNSENT;
|
|
112
|
-
} catch (x) {
|
|
113
|
-
this.debug(x);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
xhrStatus(xhr) {
|
|
119
|
-
if (xhr) {
|
|
120
|
-
try {
|
|
121
|
-
return xhr.status;
|
|
122
|
-
} catch (x) {
|
|
123
|
-
this.debug(x);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return -1;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
function _coalesceEnvelopes(envelope) {
|
|
130
|
-
while (_classPrivateFieldGet(_envelopes, this).length > 0) {
|
|
131
|
-
const envelopeAndRequest = _classPrivateFieldGet(_envelopes, this)[0];
|
|
132
|
-
const newEnvelope = envelopeAndRequest[0];
|
|
133
|
-
const newRequest = envelopeAndRequest[1];
|
|
134
|
-
if (newEnvelope.url === envelope.url && newEnvelope.sync === envelope.sync) {
|
|
135
|
-
_classPrivateFieldGet(_envelopes, this).shift();
|
|
136
|
-
envelope.messages = envelope.messages.concat(newEnvelope.messages);
|
|
137
|
-
this.debug("Coalesced", newEnvelope.messages.length, "messages from request", newRequest.id);
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function _onTransportTimeout(envelope, request, delay) {
|
|
144
|
-
const result = this.notifyTransportTimeout(envelope.messages);
|
|
145
|
-
if (result > 0) {
|
|
146
|
-
this.debug("Transport", this.type, "extended waiting for message replies of request", request.id, ":", result, "ms");
|
|
147
|
-
request.timeout = this.setTimeout(() => {
|
|
148
|
-
_assertClassBrand(_RequestTransport_brand, this, _onTransportTimeout).call(this, envelope, request, delay + result);
|
|
149
|
-
}, result);
|
|
150
|
-
} else {
|
|
151
|
-
request.expired = true;
|
|
152
|
-
const errorMessage = "Transport " + this + " expired waiting for message replies of request " + request.id + ": " + delay + " ms";
|
|
153
|
-
const failure = {
|
|
154
|
-
reason: errorMessage
|
|
155
|
-
};
|
|
156
|
-
const xhr = request.xhr;
|
|
157
|
-
failure.httpCode = this.xhrStatus(xhr);
|
|
158
|
-
this.abortXHR(xhr);
|
|
159
|
-
this.debug(errorMessage);
|
|
160
|
-
this.complete(request, false, request.metaConnect);
|
|
161
|
-
envelope.onFailure(xhr, envelope.messages, failure);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
function _transportSend(envelope, request) {
|
|
165
|
-
if (this.transportSend(envelope, request)) {
|
|
166
|
-
request.expired = false;
|
|
167
|
-
if (!envelope.sync) {
|
|
168
|
-
let delay = this.configuration.maxNetworkDelay;
|
|
169
|
-
if (request.metaConnect === true) {
|
|
170
|
-
delay += this.advice.timeout;
|
|
171
|
-
}
|
|
172
|
-
this.debug("Transport", this.type, "started waiting for message replies of request", request.id, ":", delay, "ms");
|
|
173
|
-
request.timeout = this.setTimeout(() => {
|
|
174
|
-
_assertClassBrand(_RequestTransport_brand, this, _onTransportTimeout).call(this, envelope, request, delay);
|
|
175
|
-
}, delay);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
function _queueSend(envelope) {
|
|
180
|
-
var _this$requestIds;
|
|
181
|
-
const requestId = _classPrivateFieldSet(_requestIds, this, (_this$requestIds = _classPrivateFieldGet(_requestIds, this), ++_this$requestIds));
|
|
182
|
-
const request = {
|
|
183
|
-
id: requestId,
|
|
184
|
-
metaConnect: false,
|
|
185
|
-
envelope: envelope
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
// Consider the /meta/connect requests which should always be present.
|
|
189
|
-
if (_classPrivateFieldGet(_requests, this).length < this.configuration.maxConnections - 1) {
|
|
190
|
-
_classPrivateFieldGet(_requests, this).push(request);
|
|
191
|
-
_assertClassBrand(_RequestTransport_brand, this, _transportSend).call(this, envelope, request);
|
|
192
|
-
} else {
|
|
193
|
-
this.debug("Transport", this.type, "queueing request", requestId, "envelope", envelope);
|
|
194
|
-
_classPrivateFieldGet(_envelopes, this).push([envelope, request]);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
function _metaConnectComplete(request) {
|
|
198
|
-
const requestId = request.id;
|
|
199
|
-
this.debug("Transport", this.type, "/meta/connect complete, request", requestId);
|
|
200
|
-
if (_classPrivateFieldGet(_metaConnectRequest, this) !== null && _classPrivateFieldGet(_metaConnectRequest, this).id !== requestId) {
|
|
201
|
-
throw new Error("/meta/connect request mismatch, completing request " + requestId);
|
|
202
|
-
}
|
|
203
|
-
_classPrivateFieldSet(_metaConnectRequest, this, null);
|
|
204
|
-
}
|
|
205
|
-
function _complete(request, success) {
|
|
206
|
-
const index = _classPrivateFieldGet(_requests, this).indexOf(request);
|
|
207
|
-
// The index can be negative if the request has been aborted
|
|
208
|
-
if (index >= 0) {
|
|
209
|
-
_classPrivateFieldGet(_requests, this).splice(index, 1);
|
|
210
|
-
}
|
|
211
|
-
if (_classPrivateFieldGet(_envelopes, this).length > 0) {
|
|
212
|
-
const envelopeAndRequest = _classPrivateFieldGet(_envelopes, this).shift();
|
|
213
|
-
const nextEnvelope = envelopeAndRequest[0];
|
|
214
|
-
const nextRequest = envelopeAndRequest[1];
|
|
215
|
-
this.debug("Transport dequeued request", nextRequest.id);
|
|
216
|
-
if (success) {
|
|
217
|
-
if (this.configuration.autoBatch) {
|
|
218
|
-
_assertClassBrand(_RequestTransport_brand, this, _coalesceEnvelopes).call(this, nextEnvelope);
|
|
219
|
-
}
|
|
220
|
-
_assertClassBrand(_RequestTransport_brand, this, _queueSend).call(this, nextEnvelope);
|
|
221
|
-
this.debug("Transport", this.type, "completed request", request.id, nextEnvelope);
|
|
222
|
-
} else {
|
|
223
|
-
// Keep the semantic of calling callbacks asynchronously.
|
|
224
|
-
this.setTimeout(() => {
|
|
225
|
-
this.complete(nextRequest, false, nextRequest.metaConnect);
|
|
226
|
-
const failure = {
|
|
227
|
-
reason: "Previous request failed"
|
|
228
|
-
};
|
|
229
|
-
const xhr = nextRequest.xhr;
|
|
230
|
-
failure.httpCode = this.xhrStatus(xhr);
|
|
231
|
-
nextEnvelope.onFailure(xhr, nextEnvelope.messages, failure);
|
|
232
|
-
}, 0);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
function _metaConnectSend(envelope) {
|
|
237
|
-
var _this$requestIds2;
|
|
238
|
-
if (_classPrivateFieldGet(_metaConnectRequest, this) !== null) {
|
|
239
|
-
throw new Error("Concurrent /meta/connect requests not allowed, request id=" + _classPrivateFieldGet(_metaConnectRequest, this).id + " not yet completed");
|
|
240
|
-
}
|
|
241
|
-
const requestId = _classPrivateFieldSet(_requestIds, this, (_this$requestIds2 = _classPrivateFieldGet(_requestIds, this), ++_this$requestIds2));
|
|
242
|
-
this.debug("Transport", this.type, "/meta/connect send, request", requestId, "envelope", envelope);
|
|
243
|
-
const request = {
|
|
244
|
-
id: requestId,
|
|
245
|
-
metaConnect: true,
|
|
246
|
-
envelope: envelope
|
|
247
|
-
};
|
|
248
|
-
_assertClassBrand(_RequestTransport_brand, this, _transportSend).call(this, envelope, request);
|
|
249
|
-
_classPrivateFieldSet(_metaConnectRequest, this, request);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export { RequestTransport };
|