quickblox 2.17.2-logger → 2.17.4-logger

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