quickblox 2.17.9-logger → 2.19.0
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/LICENSE +4 -0
- package/README.md +1 -2
- package/package.json +2 -1
- package/quickblox.js +111 -7055
- package/quickblox.min.js +1 -1
- package/src/modules/chat/qbChat.js +17 -27
- package/src/modules/webrtc/qbWebRTCSignalingProcessor.js +1 -2
- package/src/modules/webrtc/qbWebRTCSignalingProvider.js +1 -2
- package/src/qbConfig.js +2 -2
- package/src/qbStrophe.js +49 -59
- package/{src/libs/strophe → strophejs-1.4.0/dist}/strophe.common.js +14 -14
- package/{src/libs/strophe → strophejs-1.4.0/dist}/strophe.esm.js +14 -14
- package/{src/libs/strophe → strophejs-1.4.0/dist}/strophe.umd.js +17 -17
- package/strophejs-1.4.0/dist/strophe.umd.min.js +1 -0
- package/src/libs/strophe/strophe.umd.min.js +0 -1
- package/strophejs-1.4.0/.eslintrc.json +0 -264
- package/strophejs-1.4.0/.gitattributes +0 -1
- package/strophejs-1.4.0/CHANGELOG.md +0 -250
- package/strophejs-1.4.0/LICENSE.txt +0 -19
- package/strophejs-1.4.0/Makefile +0 -92
- package/strophejs-1.4.0/README.md +0 -45
- package/strophejs-1.4.0/RELEASE_CHECKLIST.md +0 -16
- package/strophejs-1.4.0/contrib/discojs/README.txt +0 -42
- package/strophejs-1.4.0/contrib/discojs/css/disco.css +0 -16
- package/strophejs-1.4.0/contrib/discojs/index.html +0 -47
- package/strophejs-1.4.0/contrib/discojs/punjab.tac +0 -18
- package/strophejs-1.4.0/contrib/discojs/scripts/basic.js +0 -102
- package/strophejs-1.4.0/contrib/discojs/scripts/disco.js +0 -60
- package/strophejs-1.4.0/docs.css +0 -797
- package/strophejs-1.4.0/examples/amd.html +0 -21
- package/strophejs-1.4.0/examples/attach/README +0 -37
- package/strophejs-1.4.0/examples/attach/__init__.py +0 -0
- package/strophejs-1.4.0/examples/attach/attacher/__init__.py +0 -0
- package/strophejs-1.4.0/examples/attach/attacher/views.py +0 -18
- package/strophejs-1.4.0/examples/attach/boshclient.py +0 -158
- package/strophejs-1.4.0/examples/attach/manage.py +0 -11
- package/strophejs-1.4.0/examples/attach/settings.py +0 -85
- package/strophejs-1.4.0/examples/attach/templates/attacher/index.html +0 -88
- package/strophejs-1.4.0/examples/attach/urls.py +0 -19
- package/strophejs-1.4.0/examples/basic.html +0 -23
- package/strophejs-1.4.0/examples/basic.js +0 -73
- package/strophejs-1.4.0/examples/echobot.html +0 -25
- package/strophejs-1.4.0/examples/echobot.js +0 -79
- package/strophejs-1.4.0/examples/main.js +0 -59
- package/strophejs-1.4.0/examples/prebind.html +0 -39
- package/strophejs-1.4.0/examples/prebind.js +0 -103
- package/strophejs-1.4.0/examples/restore.html +0 -24
- package/strophejs-1.4.0/examples/restore.js +0 -71
- package/strophejs-1.4.0/package-lock.json +0 -8634
- package/strophejs-1.4.0/package.json +0 -84
- package/strophejs-1.4.0/rollup.config.js +0 -76
- package/strophejs-1.4.0/src/bosh.js +0 -916
- package/strophejs-1.4.0/src/core.js +0 -3535
- package/strophejs-1.4.0/src/md5.js +0 -204
- package/strophejs-1.4.0/src/sha1.js +0 -172
- package/strophejs-1.4.0/src/shared-connection-worker.js +0 -114
- package/strophejs-1.4.0/src/shims.js +0 -123
- package/strophejs-1.4.0/src/strophe.js +0 -14
- package/strophejs-1.4.0/src/utils.js +0 -63
- package/strophejs-1.4.0/src/websocket.js +0 -561
- package/strophejs-1.4.0/src/worker-websocket.js +0 -152
- package/strophejs-1.4.0/tests/index.html +0 -21
- package/strophejs-1.4.0/tests/main.js +0 -49
- package/strophejs-1.4.0/tests/tests.js +0 -929
- package/strophejs-1.6.1/.eslintrc.json +0 -264
- package/strophejs-1.6.1/.gitattributes +0 -1
- package/strophejs-1.6.1/.nvmrc +0 -1
- package/strophejs-1.6.1/CHANGELOG.md +0 -288
- package/strophejs-1.6.1/LICENSE.txt +0 -19
- package/strophejs-1.6.1/Makefile +0 -92
- package/strophejs-1.6.1/README.md +0 -46
- package/strophejs-1.6.1/RELEASE_CHECKLIST.md +0 -18
- package/strophejs-1.6.1/babel.config.json +0 -10
- package/strophejs-1.6.1/contrib/discojs/README.txt +0 -42
- package/strophejs-1.6.1/contrib/discojs/css/disco.css +0 -16
- package/strophejs-1.6.1/contrib/discojs/index.html +0 -47
- package/strophejs-1.6.1/contrib/discojs/punjab.tac +0 -18
- package/strophejs-1.6.1/contrib/discojs/scripts/basic.js +0 -102
- package/strophejs-1.6.1/contrib/discojs/scripts/disco.js +0 -60
- package/strophejs-1.6.1/docs.css +0 -797
- package/strophejs-1.6.1/examples/amd.html +0 -21
- package/strophejs-1.6.1/examples/attach/README +0 -37
- package/strophejs-1.6.1/examples/attach/__init__.py +0 -0
- package/strophejs-1.6.1/examples/attach/attacher/__init__.py +0 -0
- package/strophejs-1.6.1/examples/attach/attacher/views.py +0 -18
- package/strophejs-1.6.1/examples/attach/boshclient.py +0 -158
- package/strophejs-1.6.1/examples/attach/manage.py +0 -11
- package/strophejs-1.6.1/examples/attach/settings.py +0 -85
- package/strophejs-1.6.1/examples/attach/templates/attacher/index.html +0 -88
- package/strophejs-1.6.1/examples/attach/urls.py +0 -19
- package/strophejs-1.6.1/examples/basic.html +0 -23
- package/strophejs-1.6.1/examples/basic.js +0 -73
- package/strophejs-1.6.1/examples/echobot.html +0 -25
- package/strophejs-1.6.1/examples/echobot.js +0 -79
- package/strophejs-1.6.1/examples/main.js +0 -59
- package/strophejs-1.6.1/examples/prebind.html +0 -39
- package/strophejs-1.6.1/examples/prebind.js +0 -103
- package/strophejs-1.6.1/examples/restore.html +0 -24
- package/strophejs-1.6.1/examples/restore.js +0 -71
- package/strophejs-1.6.1/package-lock.json +0 -18461
- package/strophejs-1.6.1/package.json +0 -87
- package/strophejs-1.6.1/rollup.config.js +0 -70
- package/strophejs-1.6.1/src/bosh.js +0 -916
- package/strophejs-1.6.1/src/builder.js +0 -239
- package/strophejs-1.6.1/src/constants.js +0 -155
- package/strophejs-1.6.1/src/core.js +0 -2377
- package/strophejs-1.6.1/src/sasl-anon.js +0 -17
- package/strophejs-1.6.1/src/sasl-external.js +0 -27
- package/strophejs-1.6.1/src/sasl-oauthbearer.js +0 -30
- package/strophejs-1.6.1/src/sasl-plain.js +0 -32
- package/strophejs-1.6.1/src/sasl-sha1.js +0 -24
- package/strophejs-1.6.1/src/sasl-sha256.js +0 -24
- package/strophejs-1.6.1/src/sasl-sha384.js +0 -24
- package/strophejs-1.6.1/src/sasl-sha512.js +0 -24
- package/strophejs-1.6.1/src/sasl-xoauth2.js +0 -27
- package/strophejs-1.6.1/src/sasl.js +0 -143
- package/strophejs-1.6.1/src/scram.js +0 -182
- package/strophejs-1.6.1/src/shared-connection-worker.js +0 -114
- package/strophejs-1.6.1/src/shims.js +0 -122
- package/strophejs-1.6.1/src/strophe.js +0 -15
- package/strophejs-1.6.1/src/utils.js +0 -626
- package/strophejs-1.6.1/src/websocket.js +0 -556
- package/strophejs-1.6.1/src/worker-websocket.js +0 -149
- package/strophejs-1.6.1/tests.js +0 -993
|
@@ -1,556 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
This program is distributed under the terms of the MIT license.
|
|
3
|
-
Please see the LICENSE file for details.
|
|
4
|
-
|
|
5
|
-
Copyright 2006-2008, OGG, LLC
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/* global window, clearTimeout */
|
|
9
|
-
|
|
10
|
-
import { DOMParser, WebSocket } from './shims';
|
|
11
|
-
import { $build, Strophe } from './core';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/** Class: Strophe.WebSocket
|
|
15
|
-
* _Private_ helper class that handles WebSocket Connections
|
|
16
|
-
*
|
|
17
|
-
* The Strophe.WebSocket class is used internally by Strophe.Connection
|
|
18
|
-
* to encapsulate WebSocket sessions. It is not meant to be used from user's code.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/** File: websocket.js
|
|
22
|
-
* A JavaScript library to enable XMPP over Websocket in Strophejs.
|
|
23
|
-
*
|
|
24
|
-
* This file implements XMPP over WebSockets for Strophejs.
|
|
25
|
-
* If a Connection is established with a Websocket url (ws://...)
|
|
26
|
-
* Strophe will use WebSockets.
|
|
27
|
-
* For more information on XMPP-over-WebSocket see RFC 7395:
|
|
28
|
-
* http://tools.ietf.org/html/rfc7395
|
|
29
|
-
*
|
|
30
|
-
* WebSocket support implemented by Andreas Guth (andreas.guth@rwth-aachen.de)
|
|
31
|
-
*/
|
|
32
|
-
Strophe.Websocket = class Websocket {
|
|
33
|
-
|
|
34
|
-
/** PrivateConstructor: Strophe.Websocket
|
|
35
|
-
* Create and initialize a Strophe.WebSocket object.
|
|
36
|
-
* Currently only sets the connection Object.
|
|
37
|
-
*
|
|
38
|
-
* Parameters:
|
|
39
|
-
* (Strophe.Connection) connection - The Strophe.Connection that will use WebSockets.
|
|
40
|
-
*
|
|
41
|
-
* Returns:
|
|
42
|
-
* A new Strophe.WebSocket object.
|
|
43
|
-
*/
|
|
44
|
-
constructor (connection) {
|
|
45
|
-
this._conn = connection;
|
|
46
|
-
this.strip = "wrapper";
|
|
47
|
-
|
|
48
|
-
const service = connection.service;
|
|
49
|
-
if (service.indexOf("ws:") !== 0 && service.indexOf("wss:") !== 0) {
|
|
50
|
-
// If the service is not an absolute URL, assume it is a path and put the absolute
|
|
51
|
-
// URL together from options, current URL and the path.
|
|
52
|
-
let new_service = "";
|
|
53
|
-
if (connection.options.protocol === "ws" && window.location.protocol !== "https:") {
|
|
54
|
-
new_service += "ws";
|
|
55
|
-
} else {
|
|
56
|
-
new_service += "wss";
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
new_service += "://" + window.location.host;
|
|
60
|
-
if (service.indexOf("/") !== 0) {
|
|
61
|
-
new_service += window.location.pathname + service;
|
|
62
|
-
} else {
|
|
63
|
-
new_service += service;
|
|
64
|
-
}
|
|
65
|
-
connection.service = new_service;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** PrivateFunction: _buildStream
|
|
70
|
-
* _Private_ helper function to generate the <stream> start tag for WebSockets
|
|
71
|
-
*
|
|
72
|
-
* Returns:
|
|
73
|
-
* A Strophe.Builder with a <stream> element.
|
|
74
|
-
*/
|
|
75
|
-
_buildStream () {
|
|
76
|
-
return $build("open", {
|
|
77
|
-
"xmlns": Strophe.NS.FRAMING,
|
|
78
|
-
"to": this._conn.domain,
|
|
79
|
-
"version": '1.0'
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** PrivateFunction: _checkStreamError
|
|
84
|
-
* _Private_ checks a message for stream:error
|
|
85
|
-
*
|
|
86
|
-
* Parameters:
|
|
87
|
-
* (Strophe.Request) bodyWrap - The received stanza.
|
|
88
|
-
* connectstatus - The ConnectStatus that will be set on error.
|
|
89
|
-
* Returns:
|
|
90
|
-
* true if there was a streamerror, false otherwise.
|
|
91
|
-
*/
|
|
92
|
-
_checkStreamError (bodyWrap, connectstatus) {
|
|
93
|
-
let errors;
|
|
94
|
-
if (bodyWrap.getElementsByTagNameNS) {
|
|
95
|
-
errors = bodyWrap.getElementsByTagNameNS(Strophe.NS.STREAM, "error");
|
|
96
|
-
} else {
|
|
97
|
-
errors = bodyWrap.getElementsByTagName("stream:error");
|
|
98
|
-
}
|
|
99
|
-
if (errors.length === 0) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const error = errors[0];
|
|
104
|
-
|
|
105
|
-
let condition = "";
|
|
106
|
-
let text = "";
|
|
107
|
-
|
|
108
|
-
const ns = "urn:ietf:params:xml:ns:xmpp-streams";
|
|
109
|
-
for (let i=0; i<error.childNodes.length; i++) {
|
|
110
|
-
const e = error.childNodes[i];
|
|
111
|
-
if (e.getAttribute("xmlns") !== ns) {
|
|
112
|
-
break;
|
|
113
|
-
} if (e.nodeName === "text") {
|
|
114
|
-
text = e.textContent;
|
|
115
|
-
} else {
|
|
116
|
-
condition = e.nodeName;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
let errorString = "WebSocket stream error: ";
|
|
121
|
-
if (condition) {
|
|
122
|
-
errorString += condition;
|
|
123
|
-
} else {
|
|
124
|
-
errorString += "unknown";
|
|
125
|
-
}
|
|
126
|
-
if (text) {
|
|
127
|
-
errorString += " - " + text;
|
|
128
|
-
}
|
|
129
|
-
Strophe.error(errorString);
|
|
130
|
-
|
|
131
|
-
// close the connection on stream_error
|
|
132
|
-
this._conn._changeConnectStatus(connectstatus, condition);
|
|
133
|
-
this._conn._doDisconnect();
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/** PrivateFunction: _reset
|
|
138
|
-
* Reset the connection.
|
|
139
|
-
*
|
|
140
|
-
* This function is called by the reset function of the Strophe Connection.
|
|
141
|
-
* Is not needed by WebSockets.
|
|
142
|
-
*/
|
|
143
|
-
_reset () { // eslint-disable-line class-methods-use-this
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/** PrivateFunction: _connect
|
|
148
|
-
* _Private_ function called by Strophe.Connection.connect
|
|
149
|
-
*
|
|
150
|
-
* Creates a WebSocket for a connection and assigns Callbacks to it.
|
|
151
|
-
* Does nothing if there already is a WebSocket.
|
|
152
|
-
*/
|
|
153
|
-
_connect () {
|
|
154
|
-
// Ensure that there is no open WebSocket from a previous Connection.
|
|
155
|
-
this._closeSocket();
|
|
156
|
-
this.socket = new WebSocket(this._conn.service, "xmpp");
|
|
157
|
-
this.socket.onopen = () => this._onOpen();
|
|
158
|
-
this.socket.onerror = (e) => this._onError(e);
|
|
159
|
-
this.socket.onclose = (e) => this._onClose(e);
|
|
160
|
-
// Gets replaced with this._onMessage once _onInitialMessage is called
|
|
161
|
-
this.socket.onmessage = (message) => this._onInitialMessage(message);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/** PrivateFunction: _connect_cb
|
|
165
|
-
* _Private_ function called by Strophe.Connection._connect_cb
|
|
166
|
-
*
|
|
167
|
-
* checks for stream:error
|
|
168
|
-
*
|
|
169
|
-
* Parameters:
|
|
170
|
-
* (Strophe.Request) bodyWrap - The received stanza.
|
|
171
|
-
*/
|
|
172
|
-
_connect_cb (bodyWrap) {
|
|
173
|
-
const error = this._checkStreamError(bodyWrap, Strophe.Status.CONNFAIL);
|
|
174
|
-
if (error) {
|
|
175
|
-
return Strophe.Status.CONNFAIL;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/** PrivateFunction: _handleStreamStart
|
|
180
|
-
* _Private_ function that checks the opening <open /> tag for errors.
|
|
181
|
-
*
|
|
182
|
-
* Disconnects if there is an error and returns false, true otherwise.
|
|
183
|
-
*
|
|
184
|
-
* Parameters:
|
|
185
|
-
* (Node) message - Stanza containing the <open /> tag.
|
|
186
|
-
*/
|
|
187
|
-
_handleStreamStart (message) {
|
|
188
|
-
let error = false;
|
|
189
|
-
|
|
190
|
-
// Check for errors in the <open /> tag
|
|
191
|
-
const ns = message.getAttribute("xmlns");
|
|
192
|
-
if (typeof ns !== "string") {
|
|
193
|
-
error = "Missing xmlns in <open />";
|
|
194
|
-
} else if (ns !== Strophe.NS.FRAMING) {
|
|
195
|
-
error = "Wrong xmlns in <open />: " + ns;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const ver = message.getAttribute("version");
|
|
199
|
-
if (typeof ver !== "string") {
|
|
200
|
-
error = "Missing version in <open />";
|
|
201
|
-
} else if (ver !== "1.0") {
|
|
202
|
-
error = "Wrong version in <open />: " + ver;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (error) {
|
|
206
|
-
this._conn._changeConnectStatus(Strophe.Status.CONNFAIL, error);
|
|
207
|
-
this._conn._doDisconnect();
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/** PrivateFunction: _onInitialMessage
|
|
214
|
-
* _Private_ function that handles the first connection messages.
|
|
215
|
-
*
|
|
216
|
-
* On receiving an opening stream tag this callback replaces itself with the real
|
|
217
|
-
* message handler. On receiving a stream error the connection is terminated.
|
|
218
|
-
*/
|
|
219
|
-
_onInitialMessage (message) {
|
|
220
|
-
if (message.data.indexOf("<open ") === 0 || message.data.indexOf("<?xml") === 0) {
|
|
221
|
-
// Strip the XML Declaration, if there is one
|
|
222
|
-
const data = message.data.replace(/^(<\?.*?\?>\s*)*/, "");
|
|
223
|
-
if (data === '') return;
|
|
224
|
-
|
|
225
|
-
const streamStart = new DOMParser().parseFromString(data, "text/xml").documentElement;
|
|
226
|
-
this._conn.xmlInput(streamStart);
|
|
227
|
-
this._conn.rawInput(message.data);
|
|
228
|
-
|
|
229
|
-
//_handleStreamSteart will check for XML errors and disconnect on error
|
|
230
|
-
if (this._handleStreamStart(streamStart)) {
|
|
231
|
-
//_connect_cb will check for stream:error and disconnect on error
|
|
232
|
-
this._connect_cb(streamStart);
|
|
233
|
-
}
|
|
234
|
-
} else if (message.data.indexOf("<close ") === 0) { // <close xmlns="urn:ietf:params:xml:ns:xmpp-framing />
|
|
235
|
-
// Parse the raw string to an XML element
|
|
236
|
-
const parsedMessage = new DOMParser().parseFromString(message.data, "text/xml").documentElement;
|
|
237
|
-
// Report this input to the raw and xml handlers
|
|
238
|
-
this._conn.xmlInput(parsedMessage);
|
|
239
|
-
this._conn.rawInput(message.data);
|
|
240
|
-
const see_uri = parsedMessage.getAttribute("see-other-uri");
|
|
241
|
-
if (see_uri) {
|
|
242
|
-
const service = this._conn.service;
|
|
243
|
-
// Valid scenarios: WSS->WSS, WS->ANY
|
|
244
|
-
const isSecureRedirect = (service.indexOf("wss:") >= 0 && see_uri.indexOf("wss:") >= 0) || (service.indexOf("ws:") >= 0);
|
|
245
|
-
if (isSecureRedirect) {
|
|
246
|
-
this._conn._changeConnectStatus(
|
|
247
|
-
Strophe.Status.REDIRECT,
|
|
248
|
-
"Received see-other-uri, resetting connection"
|
|
249
|
-
);
|
|
250
|
-
this._conn.reset();
|
|
251
|
-
this._conn.service = see_uri;
|
|
252
|
-
this._connect();
|
|
253
|
-
}
|
|
254
|
-
} else {
|
|
255
|
-
this._conn._changeConnectStatus(
|
|
256
|
-
Strophe.Status.CONNFAIL,
|
|
257
|
-
"Received closing stream"
|
|
258
|
-
);
|
|
259
|
-
this._conn._doDisconnect();
|
|
260
|
-
}
|
|
261
|
-
} else {
|
|
262
|
-
this._replaceMessageHandler();
|
|
263
|
-
const string = this._streamWrap(message.data);
|
|
264
|
-
const elem = new DOMParser().parseFromString(string, "text/xml").documentElement;
|
|
265
|
-
this._conn._connect_cb(elem, null, message.data);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/** PrivateFunction: _replaceMessageHandler
|
|
270
|
-
*
|
|
271
|
-
* Called by _onInitialMessage in order to replace itself with the general message handler.
|
|
272
|
-
* This method is overridden by Strophe.WorkerWebsocket, which manages a
|
|
273
|
-
* websocket connection via a service worker and doesn't have direct access
|
|
274
|
-
* to the socket.
|
|
275
|
-
*/
|
|
276
|
-
_replaceMessageHandler () {
|
|
277
|
-
this.socket.onmessage = (m) => this._onMessage(m);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/** PrivateFunction: _disconnect
|
|
281
|
-
* _Private_ function called by Strophe.Connection.disconnect
|
|
282
|
-
*
|
|
283
|
-
* Disconnects and sends a last stanza if one is given
|
|
284
|
-
*
|
|
285
|
-
* Parameters:
|
|
286
|
-
* (Request) pres - This stanza will be sent before disconnecting.
|
|
287
|
-
*/
|
|
288
|
-
_disconnect (pres) {
|
|
289
|
-
if (this.socket && this.socket.readyState !== WebSocket.CLOSED) {
|
|
290
|
-
if (pres) {
|
|
291
|
-
this._conn.send(pres);
|
|
292
|
-
}
|
|
293
|
-
const close = $build("close", { "xmlns": Strophe.NS.FRAMING });
|
|
294
|
-
this._conn.xmlOutput(close.tree());
|
|
295
|
-
const closeString = Strophe.serialize(close);
|
|
296
|
-
this._conn.rawOutput(closeString);
|
|
297
|
-
try {
|
|
298
|
-
this.socket.send(closeString);
|
|
299
|
-
} catch (e) {
|
|
300
|
-
Strophe.warn("Couldn't send <close /> tag.");
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
setTimeout(() => this._conn._doDisconnect(), 0);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/** PrivateFunction: _doDisconnect
|
|
307
|
-
* _Private_ function to disconnect.
|
|
308
|
-
*
|
|
309
|
-
* Just closes the Socket for WebSockets
|
|
310
|
-
*/
|
|
311
|
-
_doDisconnect () {
|
|
312
|
-
Strophe.debug("WebSockets _doDisconnect was called");
|
|
313
|
-
this._closeSocket();
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/** PrivateFunction _streamWrap
|
|
317
|
-
* _Private_ helper function to wrap a stanza in a <stream> tag.
|
|
318
|
-
* This is used so Strophe can process stanzas from WebSockets like BOSH
|
|
319
|
-
*/
|
|
320
|
-
_streamWrap (stanza) { // eslint-disable-line class-methods-use-this
|
|
321
|
-
return "<wrapper>" + stanza + '</wrapper>';
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
/** PrivateFunction: _closeSocket
|
|
326
|
-
* _Private_ function to close the WebSocket.
|
|
327
|
-
*
|
|
328
|
-
* Closes the socket if it is still open and deletes it
|
|
329
|
-
*/
|
|
330
|
-
_closeSocket () {
|
|
331
|
-
if (this.socket) {
|
|
332
|
-
try {
|
|
333
|
-
this.socket.onclose = null;
|
|
334
|
-
this.socket.onerror = null;
|
|
335
|
-
this.socket.onmessage = null;
|
|
336
|
-
this.socket.close();
|
|
337
|
-
} catch (e) {
|
|
338
|
-
Strophe.debug(e.message);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
this.socket = null;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/** PrivateFunction: _emptyQueue
|
|
345
|
-
* _Private_ function to check if the message queue is empty.
|
|
346
|
-
*
|
|
347
|
-
* Returns:
|
|
348
|
-
* True, because WebSocket messages are send immediately after queueing.
|
|
349
|
-
*/
|
|
350
|
-
_emptyQueue () { // eslint-disable-line class-methods-use-this
|
|
351
|
-
return true;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/** PrivateFunction: _onClose
|
|
355
|
-
* _Private_ function to handle websockets closing.
|
|
356
|
-
*/
|
|
357
|
-
_onClose (e) {
|
|
358
|
-
if (this._conn.connected && !this._conn.disconnecting) {
|
|
359
|
-
Strophe.error("Websocket closed unexpectedly");
|
|
360
|
-
this._conn._doDisconnect();
|
|
361
|
-
} else if (e && e.code === 1006 && !this._conn.connected && this.socket) {
|
|
362
|
-
// in case the onError callback was not called (Safari 10 does not
|
|
363
|
-
// call onerror when the initial connection fails) we need to
|
|
364
|
-
// dispatch a CONNFAIL status update to be consistent with the
|
|
365
|
-
// behavior on other browsers.
|
|
366
|
-
Strophe.error("Websocket closed unexcectedly");
|
|
367
|
-
this._conn._changeConnectStatus(
|
|
368
|
-
Strophe.Status.CONNFAIL,
|
|
369
|
-
"The WebSocket connection could not be established or was disconnected."
|
|
370
|
-
);
|
|
371
|
-
this._conn._doDisconnect();
|
|
372
|
-
} else {
|
|
373
|
-
Strophe.debug("Websocket closed");
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
/** PrivateFunction: _no_auth_received
|
|
378
|
-
*
|
|
379
|
-
* Called on stream start/restart when no stream:features
|
|
380
|
-
* has been received.
|
|
381
|
-
*/
|
|
382
|
-
_no_auth_received (callback) {
|
|
383
|
-
Strophe.error("Server did not offer a supported authentication mechanism");
|
|
384
|
-
this._conn._changeConnectStatus(
|
|
385
|
-
Strophe.Status.CONNFAIL,
|
|
386
|
-
Strophe.ErrorCondition.NO_AUTH_MECH
|
|
387
|
-
);
|
|
388
|
-
if (callback) {
|
|
389
|
-
callback.call(this._conn);
|
|
390
|
-
}
|
|
391
|
-
this._conn._doDisconnect();
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/** PrivateFunction: _onDisconnectTimeout
|
|
395
|
-
* _Private_ timeout handler for handling non-graceful disconnection.
|
|
396
|
-
*
|
|
397
|
-
* This does nothing for WebSockets
|
|
398
|
-
*/
|
|
399
|
-
_onDisconnectTimeout () {} // eslint-disable-line class-methods-use-this
|
|
400
|
-
|
|
401
|
-
/** PrivateFunction: _abortAllRequests
|
|
402
|
-
* _Private_ helper function that makes sure all pending requests are aborted.
|
|
403
|
-
*/
|
|
404
|
-
_abortAllRequests () {} // eslint-disable-line class-methods-use-this
|
|
405
|
-
|
|
406
|
-
/** PrivateFunction: _onError
|
|
407
|
-
* _Private_ function to handle websockets errors.
|
|
408
|
-
*
|
|
409
|
-
* Parameters:
|
|
410
|
-
* (Object) error - The websocket error.
|
|
411
|
-
*/
|
|
412
|
-
_onError (error) {
|
|
413
|
-
Strophe.error("Websocket error " + JSON.stringify(error));
|
|
414
|
-
this._conn._changeConnectStatus(
|
|
415
|
-
Strophe.Status.CONNFAIL,
|
|
416
|
-
"The WebSocket connection could not be established or was disconnected."
|
|
417
|
-
);
|
|
418
|
-
this._disconnect();
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/** PrivateFunction: _onIdle
|
|
422
|
-
* _Private_ function called by Strophe.Connection._onIdle
|
|
423
|
-
*
|
|
424
|
-
* sends all queued stanzas
|
|
425
|
-
*/
|
|
426
|
-
_onIdle () {
|
|
427
|
-
const data = this._conn._data;
|
|
428
|
-
if (data.length > 0 && !this._conn.paused) {
|
|
429
|
-
for (let i=0; i<data.length; i++) {
|
|
430
|
-
if (data[i] !== null) {
|
|
431
|
-
let stanza;
|
|
432
|
-
if (data[i] === "restart") {
|
|
433
|
-
stanza = this._buildStream().tree();
|
|
434
|
-
} else {
|
|
435
|
-
stanza = data[i];
|
|
436
|
-
}
|
|
437
|
-
const rawStanza = Strophe.serialize(stanza);
|
|
438
|
-
this._conn.xmlOutput(stanza);
|
|
439
|
-
this._conn.rawOutput(rawStanza);
|
|
440
|
-
this.socket.send(rawStanza);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
this._conn._data = [];
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/** PrivateFunction: _onMessage
|
|
448
|
-
* _Private_ function to handle websockets messages.
|
|
449
|
-
*
|
|
450
|
-
* This function parses each of the messages as if they are full documents.
|
|
451
|
-
* [TODO : We may actually want to use a SAX Push parser].
|
|
452
|
-
*
|
|
453
|
-
* Since all XMPP traffic starts with
|
|
454
|
-
* <stream:stream version='1.0'
|
|
455
|
-
* xml:lang='en'
|
|
456
|
-
* xmlns='jabber:client'
|
|
457
|
-
* xmlns:stream='http://etherx.jabber.org/streams'
|
|
458
|
-
* id='3697395463'
|
|
459
|
-
* from='SERVER'>
|
|
460
|
-
*
|
|
461
|
-
* The first stanza will always fail to be parsed.
|
|
462
|
-
*
|
|
463
|
-
* Additionally, the seconds stanza will always be <stream:features> with
|
|
464
|
-
* the stream NS defined in the previous stanza, so we need to 'force'
|
|
465
|
-
* the inclusion of the NS in this stanza.
|
|
466
|
-
*
|
|
467
|
-
* Parameters:
|
|
468
|
-
* (string) message - The websocket message.
|
|
469
|
-
*/
|
|
470
|
-
_onMessage (message) {
|
|
471
|
-
let elem;
|
|
472
|
-
// check for closing stream
|
|
473
|
-
const close = '<close xmlns="urn:ietf:params:xml:ns:xmpp-framing" />';
|
|
474
|
-
if (message.data === close) {
|
|
475
|
-
this._conn.rawInput(close);
|
|
476
|
-
this._conn.xmlInput(message);
|
|
477
|
-
if (!this._conn.disconnecting) {
|
|
478
|
-
this._conn._doDisconnect();
|
|
479
|
-
}
|
|
480
|
-
return;
|
|
481
|
-
} else if (message.data.search("<open ") === 0) {
|
|
482
|
-
// This handles stream restarts
|
|
483
|
-
elem = new DOMParser().parseFromString(message.data, "text/xml").documentElement;
|
|
484
|
-
if (!this._handleStreamStart(elem)) {
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
} else {
|
|
488
|
-
const data = this._streamWrap(message.data);
|
|
489
|
-
elem = new DOMParser().parseFromString(data, "text/xml").documentElement;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
if (this._checkStreamError(elem, Strophe.Status.ERROR)) {
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
//handle unavailable presence stanza before disconnecting
|
|
497
|
-
if (this._conn.disconnecting &&
|
|
498
|
-
elem.firstChild.nodeName === "presence" &&
|
|
499
|
-
elem.firstChild.getAttribute("type") === "unavailable") {
|
|
500
|
-
this._conn.xmlInput(elem);
|
|
501
|
-
this._conn.rawInput(Strophe.serialize(elem));
|
|
502
|
-
// if we are already disconnecting we will ignore the unavailable stanza and
|
|
503
|
-
// wait for the </stream:stream> tag before we close the connection
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
this._conn._dataRecv(elem, message.data);
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
/** PrivateFunction: _onOpen
|
|
510
|
-
* _Private_ function to handle websockets connection setup.
|
|
511
|
-
*
|
|
512
|
-
* The opening stream tag is sent here.
|
|
513
|
-
*/
|
|
514
|
-
_onOpen () {
|
|
515
|
-
Strophe.debug("Websocket open");
|
|
516
|
-
const start = this._buildStream();
|
|
517
|
-
this._conn.xmlOutput(start.tree());
|
|
518
|
-
|
|
519
|
-
const startString = Strophe.serialize(start);
|
|
520
|
-
this._conn.rawOutput(startString);
|
|
521
|
-
this.socket.send(startString);
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
/** PrivateFunction: _reqToData
|
|
525
|
-
* _Private_ function to get a stanza out of a request.
|
|
526
|
-
*
|
|
527
|
-
* WebSockets don't use requests, so the passed argument is just returned.
|
|
528
|
-
*
|
|
529
|
-
* Parameters:
|
|
530
|
-
* (Object) stanza - The stanza.
|
|
531
|
-
*
|
|
532
|
-
* Returns:
|
|
533
|
-
* The stanza that was passed.
|
|
534
|
-
*/
|
|
535
|
-
_reqToData (stanza) { // eslint-disable-line class-methods-use-this
|
|
536
|
-
return stanza;
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
/** PrivateFunction: _send
|
|
540
|
-
* _Private_ part of the Connection.send function for WebSocket
|
|
541
|
-
*
|
|
542
|
-
* Just flushes the messages that are in the queue
|
|
543
|
-
*/
|
|
544
|
-
_send () {
|
|
545
|
-
this._conn.flush();
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
/** PrivateFunction: _sendRestart
|
|
549
|
-
*
|
|
550
|
-
* Send an xmpp:restart stanza.
|
|
551
|
-
*/
|
|
552
|
-
_sendRestart () {
|
|
553
|
-
clearTimeout(this._conn._idleTimeout);
|
|
554
|
-
this._conn._onIdle.bind(this._conn)();
|
|
555
|
-
}
|
|
556
|
-
};
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
This program is distributed under the terms of the MIT license.
|
|
3
|
-
Please see the LICENSE file for details.
|
|
4
|
-
|
|
5
|
-
Copyright 2020, JC Brand
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import './websocket.js';
|
|
9
|
-
import { $build, Strophe } from './core.js';
|
|
10
|
-
|
|
11
|
-
const lmap = {};
|
|
12
|
-
lmap['debug'] = Strophe.LogLevel.DEBUG;
|
|
13
|
-
lmap['info'] = Strophe.LogLevel.INFO;
|
|
14
|
-
lmap['warn'] = Strophe.LogLevel.WARN;
|
|
15
|
-
lmap['error'] = Strophe.LogLevel.ERROR;
|
|
16
|
-
lmap['fatal'] = Strophe.LogLevel.FATAL;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/** Class: Strophe.WorkerWebsocket
|
|
20
|
-
* _Private_ helper class that handles a websocket connection inside a shared worker.
|
|
21
|
-
*/
|
|
22
|
-
Strophe.WorkerWebsocket = class WorkerWebsocket extends Strophe.Websocket {
|
|
23
|
-
|
|
24
|
-
/** PrivateConstructor: Strophe.WorkerWebsocket
|
|
25
|
-
* Create and initialize a Strophe.WorkerWebsocket object.
|
|
26
|
-
*
|
|
27
|
-
* Parameters:
|
|
28
|
-
* (Strophe.Connection) connection - The Strophe.Connection
|
|
29
|
-
*
|
|
30
|
-
* Returns:
|
|
31
|
-
* A new Strophe.WorkerWebsocket object.
|
|
32
|
-
*/
|
|
33
|
-
constructor (connection) {
|
|
34
|
-
super(connection);
|
|
35
|
-
this._conn = connection;
|
|
36
|
-
this.worker = new SharedWorker(this._conn.options.worker, 'Strophe XMPP Connection');
|
|
37
|
-
this.worker.onerror = (e) => {
|
|
38
|
-
console?.error(e);
|
|
39
|
-
Strophe.log(Strophe.LogLevel.ERROR, `Shared Worker Error: ${e}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get socket () {
|
|
44
|
-
return {
|
|
45
|
-
'send': str => this.worker.port.postMessage(['send', str])
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
_connect () {
|
|
50
|
-
this._messageHandler = (m) => this._onInitialMessage(m);
|
|
51
|
-
this.worker.port.start();
|
|
52
|
-
this.worker.port.onmessage = (ev) => this._onWorkerMessage(ev);
|
|
53
|
-
this.worker.port.postMessage(['_connect', this._conn.service, this._conn.jid]);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
_attach (callback) {
|
|
57
|
-
this._messageHandler = (m) => this._onMessage(m);
|
|
58
|
-
this._conn.connect_callback = callback;
|
|
59
|
-
this.worker.port.start();
|
|
60
|
-
this.worker.port.onmessage = (ev) => this._onWorkerMessage(ev);
|
|
61
|
-
this.worker.port.postMessage(['_attach', this._conn.service]);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
_attachCallback (status, jid) {
|
|
65
|
-
if (status === Strophe.Status.ATTACHED) {
|
|
66
|
-
this._conn.jid = jid;
|
|
67
|
-
this._conn.authenticated = true;
|
|
68
|
-
this._conn.connected = true;
|
|
69
|
-
this._conn.restored = true;
|
|
70
|
-
this._conn._changeConnectStatus(Strophe.Status.ATTACHED);
|
|
71
|
-
} else if (status === Strophe.Status.ATTACHFAIL) {
|
|
72
|
-
this._conn.authenticated = false;
|
|
73
|
-
this._conn.connected = false;
|
|
74
|
-
this._conn.restored = false;
|
|
75
|
-
this._conn._changeConnectStatus(Strophe.Status.ATTACHFAIL);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
_disconnect (readyState, pres) {
|
|
80
|
-
pres && this._conn.send(pres);
|
|
81
|
-
const close = $build("close", { "xmlns": Strophe.NS.FRAMING });
|
|
82
|
-
this._conn.xmlOutput(close.tree());
|
|
83
|
-
const closeString = Strophe.serialize(close);
|
|
84
|
-
this._conn.rawOutput(closeString);
|
|
85
|
-
this.worker.port.postMessage(['send', closeString]);
|
|
86
|
-
this._conn._doDisconnect();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
_onClose (e) {
|
|
90
|
-
if (this._conn.connected && !this._conn.disconnecting) {
|
|
91
|
-
Strophe.error("Websocket closed unexpectedly");
|
|
92
|
-
this._conn._doDisconnect();
|
|
93
|
-
} else if (e && e.code === 1006 && !this._conn.connected) {
|
|
94
|
-
// in case the onError callback was not called (Safari 10 does not
|
|
95
|
-
// call onerror when the initial connection fails) we need to
|
|
96
|
-
// dispatch a CONNFAIL status update to be consistent with the
|
|
97
|
-
// behavior on other browsers.
|
|
98
|
-
Strophe.error("Websocket closed unexcectedly");
|
|
99
|
-
this._conn._changeConnectStatus(
|
|
100
|
-
Strophe.Status.CONNFAIL,
|
|
101
|
-
"The WebSocket connection could not be established or was disconnected."
|
|
102
|
-
);
|
|
103
|
-
this._conn._doDisconnect();
|
|
104
|
-
} else {
|
|
105
|
-
Strophe.debug("Websocket closed");
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
_closeSocket () {
|
|
110
|
-
this.worker.port.postMessage(['_closeSocket']);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** PrivateFunction: _replaceMessageHandler
|
|
114
|
-
*
|
|
115
|
-
* Called by _onInitialMessage in order to replace itself with the general message handler.
|
|
116
|
-
* This method is overridden by Strophe.WorkerWebsocket, which manages a
|
|
117
|
-
* websocket connection via a service worker and doesn't have direct access
|
|
118
|
-
* to the socket.
|
|
119
|
-
*/
|
|
120
|
-
_replaceMessageHandler () {
|
|
121
|
-
this._messageHandler = (m) => this._onMessage(m);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/** PrivateFunction: _onWorkerMessage
|
|
125
|
-
* _Private_ function that handles messages received from the service worker
|
|
126
|
-
*/
|
|
127
|
-
_onWorkerMessage (ev) {
|
|
128
|
-
const { data } = ev;
|
|
129
|
-
const method_name = data[0];
|
|
130
|
-
if (method_name === '_onMessage') {
|
|
131
|
-
this._messageHandler(data[1]);
|
|
132
|
-
} else if (method_name in this) {
|
|
133
|
-
try {
|
|
134
|
-
this[method_name].apply(this, ev.data.slice(1));
|
|
135
|
-
} catch (e) {
|
|
136
|
-
Strophe.log(Strophe.LogLevel.ERROR, e);
|
|
137
|
-
}
|
|
138
|
-
} else if (method_name === 'log') {
|
|
139
|
-
const level = data[1];
|
|
140
|
-
const msg = data[2]
|
|
141
|
-
Strophe.log(lmap[level], msg);
|
|
142
|
-
} else {
|
|
143
|
-
Strophe.log(
|
|
144
|
-
Strophe.LogLevel.ERROR,
|
|
145
|
-
`Found unhandled service worker message: ${data}`
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|