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.
Files changed (124) hide show
  1. package/LICENSE +4 -0
  2. package/README.md +1 -2
  3. package/package.json +2 -1
  4. package/quickblox.js +111 -7055
  5. package/quickblox.min.js +1 -1
  6. package/src/modules/chat/qbChat.js +17 -27
  7. package/src/modules/webrtc/qbWebRTCSignalingProcessor.js +1 -2
  8. package/src/modules/webrtc/qbWebRTCSignalingProvider.js +1 -2
  9. package/src/qbConfig.js +2 -2
  10. package/src/qbStrophe.js +49 -59
  11. package/{src/libs/strophe → strophejs-1.4.0/dist}/strophe.common.js +14 -14
  12. package/{src/libs/strophe → strophejs-1.4.0/dist}/strophe.esm.js +14 -14
  13. package/{src/libs/strophe → strophejs-1.4.0/dist}/strophe.umd.js +17 -17
  14. package/strophejs-1.4.0/dist/strophe.umd.min.js +1 -0
  15. package/src/libs/strophe/strophe.umd.min.js +0 -1
  16. package/strophejs-1.4.0/.eslintrc.json +0 -264
  17. package/strophejs-1.4.0/.gitattributes +0 -1
  18. package/strophejs-1.4.0/CHANGELOG.md +0 -250
  19. package/strophejs-1.4.0/LICENSE.txt +0 -19
  20. package/strophejs-1.4.0/Makefile +0 -92
  21. package/strophejs-1.4.0/README.md +0 -45
  22. package/strophejs-1.4.0/RELEASE_CHECKLIST.md +0 -16
  23. package/strophejs-1.4.0/contrib/discojs/README.txt +0 -42
  24. package/strophejs-1.4.0/contrib/discojs/css/disco.css +0 -16
  25. package/strophejs-1.4.0/contrib/discojs/index.html +0 -47
  26. package/strophejs-1.4.0/contrib/discojs/punjab.tac +0 -18
  27. package/strophejs-1.4.0/contrib/discojs/scripts/basic.js +0 -102
  28. package/strophejs-1.4.0/contrib/discojs/scripts/disco.js +0 -60
  29. package/strophejs-1.4.0/docs.css +0 -797
  30. package/strophejs-1.4.0/examples/amd.html +0 -21
  31. package/strophejs-1.4.0/examples/attach/README +0 -37
  32. package/strophejs-1.4.0/examples/attach/__init__.py +0 -0
  33. package/strophejs-1.4.0/examples/attach/attacher/__init__.py +0 -0
  34. package/strophejs-1.4.0/examples/attach/attacher/views.py +0 -18
  35. package/strophejs-1.4.0/examples/attach/boshclient.py +0 -158
  36. package/strophejs-1.4.0/examples/attach/manage.py +0 -11
  37. package/strophejs-1.4.0/examples/attach/settings.py +0 -85
  38. package/strophejs-1.4.0/examples/attach/templates/attacher/index.html +0 -88
  39. package/strophejs-1.4.0/examples/attach/urls.py +0 -19
  40. package/strophejs-1.4.0/examples/basic.html +0 -23
  41. package/strophejs-1.4.0/examples/basic.js +0 -73
  42. package/strophejs-1.4.0/examples/echobot.html +0 -25
  43. package/strophejs-1.4.0/examples/echobot.js +0 -79
  44. package/strophejs-1.4.0/examples/main.js +0 -59
  45. package/strophejs-1.4.0/examples/prebind.html +0 -39
  46. package/strophejs-1.4.0/examples/prebind.js +0 -103
  47. package/strophejs-1.4.0/examples/restore.html +0 -24
  48. package/strophejs-1.4.0/examples/restore.js +0 -71
  49. package/strophejs-1.4.0/package-lock.json +0 -8634
  50. package/strophejs-1.4.0/package.json +0 -84
  51. package/strophejs-1.4.0/rollup.config.js +0 -76
  52. package/strophejs-1.4.0/src/bosh.js +0 -916
  53. package/strophejs-1.4.0/src/core.js +0 -3535
  54. package/strophejs-1.4.0/src/md5.js +0 -204
  55. package/strophejs-1.4.0/src/sha1.js +0 -172
  56. package/strophejs-1.4.0/src/shared-connection-worker.js +0 -114
  57. package/strophejs-1.4.0/src/shims.js +0 -123
  58. package/strophejs-1.4.0/src/strophe.js +0 -14
  59. package/strophejs-1.4.0/src/utils.js +0 -63
  60. package/strophejs-1.4.0/src/websocket.js +0 -561
  61. package/strophejs-1.4.0/src/worker-websocket.js +0 -152
  62. package/strophejs-1.4.0/tests/index.html +0 -21
  63. package/strophejs-1.4.0/tests/main.js +0 -49
  64. package/strophejs-1.4.0/tests/tests.js +0 -929
  65. package/strophejs-1.6.1/.eslintrc.json +0 -264
  66. package/strophejs-1.6.1/.gitattributes +0 -1
  67. package/strophejs-1.6.1/.nvmrc +0 -1
  68. package/strophejs-1.6.1/CHANGELOG.md +0 -288
  69. package/strophejs-1.6.1/LICENSE.txt +0 -19
  70. package/strophejs-1.6.1/Makefile +0 -92
  71. package/strophejs-1.6.1/README.md +0 -46
  72. package/strophejs-1.6.1/RELEASE_CHECKLIST.md +0 -18
  73. package/strophejs-1.6.1/babel.config.json +0 -10
  74. package/strophejs-1.6.1/contrib/discojs/README.txt +0 -42
  75. package/strophejs-1.6.1/contrib/discojs/css/disco.css +0 -16
  76. package/strophejs-1.6.1/contrib/discojs/index.html +0 -47
  77. package/strophejs-1.6.1/contrib/discojs/punjab.tac +0 -18
  78. package/strophejs-1.6.1/contrib/discojs/scripts/basic.js +0 -102
  79. package/strophejs-1.6.1/contrib/discojs/scripts/disco.js +0 -60
  80. package/strophejs-1.6.1/docs.css +0 -797
  81. package/strophejs-1.6.1/examples/amd.html +0 -21
  82. package/strophejs-1.6.1/examples/attach/README +0 -37
  83. package/strophejs-1.6.1/examples/attach/__init__.py +0 -0
  84. package/strophejs-1.6.1/examples/attach/attacher/__init__.py +0 -0
  85. package/strophejs-1.6.1/examples/attach/attacher/views.py +0 -18
  86. package/strophejs-1.6.1/examples/attach/boshclient.py +0 -158
  87. package/strophejs-1.6.1/examples/attach/manage.py +0 -11
  88. package/strophejs-1.6.1/examples/attach/settings.py +0 -85
  89. package/strophejs-1.6.1/examples/attach/templates/attacher/index.html +0 -88
  90. package/strophejs-1.6.1/examples/attach/urls.py +0 -19
  91. package/strophejs-1.6.1/examples/basic.html +0 -23
  92. package/strophejs-1.6.1/examples/basic.js +0 -73
  93. package/strophejs-1.6.1/examples/echobot.html +0 -25
  94. package/strophejs-1.6.1/examples/echobot.js +0 -79
  95. package/strophejs-1.6.1/examples/main.js +0 -59
  96. package/strophejs-1.6.1/examples/prebind.html +0 -39
  97. package/strophejs-1.6.1/examples/prebind.js +0 -103
  98. package/strophejs-1.6.1/examples/restore.html +0 -24
  99. package/strophejs-1.6.1/examples/restore.js +0 -71
  100. package/strophejs-1.6.1/package-lock.json +0 -18461
  101. package/strophejs-1.6.1/package.json +0 -87
  102. package/strophejs-1.6.1/rollup.config.js +0 -70
  103. package/strophejs-1.6.1/src/bosh.js +0 -916
  104. package/strophejs-1.6.1/src/builder.js +0 -239
  105. package/strophejs-1.6.1/src/constants.js +0 -155
  106. package/strophejs-1.6.1/src/core.js +0 -2377
  107. package/strophejs-1.6.1/src/sasl-anon.js +0 -17
  108. package/strophejs-1.6.1/src/sasl-external.js +0 -27
  109. package/strophejs-1.6.1/src/sasl-oauthbearer.js +0 -30
  110. package/strophejs-1.6.1/src/sasl-plain.js +0 -32
  111. package/strophejs-1.6.1/src/sasl-sha1.js +0 -24
  112. package/strophejs-1.6.1/src/sasl-sha256.js +0 -24
  113. package/strophejs-1.6.1/src/sasl-sha384.js +0 -24
  114. package/strophejs-1.6.1/src/sasl-sha512.js +0 -24
  115. package/strophejs-1.6.1/src/sasl-xoauth2.js +0 -27
  116. package/strophejs-1.6.1/src/sasl.js +0 -143
  117. package/strophejs-1.6.1/src/scram.js +0 -182
  118. package/strophejs-1.6.1/src/shared-connection-worker.js +0 -114
  119. package/strophejs-1.6.1/src/shims.js +0 -122
  120. package/strophejs-1.6.1/src/strophe.js +0 -15
  121. package/strophejs-1.6.1/src/utils.js +0 -626
  122. package/strophejs-1.6.1/src/websocket.js +0 -556
  123. package/strophejs-1.6.1/src/worker-websocket.js +0 -149
  124. package/strophejs-1.6.1/tests.js +0 -993
@@ -1,916 +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 ActiveXObject */
9
-
10
- import { DOMParser } from './shims'
11
- import { $build, Strophe } from './core';
12
-
13
-
14
- /** PrivateClass: Strophe.Request
15
- * _Private_ helper class that provides a cross implementation abstraction
16
- * for a BOSH related XMLHttpRequest.
17
- *
18
- * The Strophe.Request class is used internally to encapsulate BOSH request
19
- * information. It is not meant to be used from user's code.
20
- */
21
- Strophe.Request = class Request {
22
-
23
- /** PrivateConstructor: Strophe.Request
24
- * Create and initialize a new Strophe.Request object.
25
- *
26
- * Parameters:
27
- * (XMLElement) elem - The XML data to be sent in the request.
28
- * (Function) func - The function that will be called when the
29
- * XMLHttpRequest readyState changes.
30
- * (Integer) rid - The BOSH rid attribute associated with this request.
31
- * (Integer) sends - The number of times this same request has been sent.
32
- */
33
- constructor (elem, func, rid, sends) {
34
- this.id = ++Strophe._requestId;
35
- this.xmlData = elem;
36
- this.data = Strophe.serialize(elem);
37
- // save original function in case we need to make a new request
38
- // from this one.
39
- this.origFunc = func;
40
- this.func = func;
41
- this.rid = rid;
42
- this.date = NaN;
43
- this.sends = sends || 0;
44
- this.abort = false;
45
- this.dead = null;
46
-
47
- this.age = function () {
48
- if (!this.date) { return 0; }
49
- const now = new Date();
50
- return (now - this.date) / 1000;
51
- };
52
- this.timeDead = function () {
53
- if (!this.dead) { return 0; }
54
- const now = new Date();
55
- return (now - this.dead) / 1000;
56
- };
57
- this.xhr = this._newXHR();
58
- }
59
-
60
- /** PrivateFunction: getResponse
61
- * Get a response from the underlying XMLHttpRequest.
62
- *
63
- * This function attempts to get a response from the request and checks
64
- * for errors.
65
- *
66
- * Throws:
67
- * "parsererror" - A parser error occured.
68
- * "bad-format" - The entity has sent XML that cannot be processed.
69
- *
70
- * Returns:
71
- * The DOM element tree of the response.
72
- */
73
- getResponse () {
74
- let node = null;
75
- if (this.xhr.responseXML && this.xhr.responseXML.documentElement) {
76
- node = this.xhr.responseXML.documentElement;
77
- if (node.tagName === "parsererror") {
78
- Strophe.error("invalid response received");
79
- Strophe.error("responseText: " + this.xhr.responseText);
80
- Strophe.error("responseXML: " +
81
- Strophe.serialize(this.xhr.responseXML));
82
- throw new Error("parsererror");
83
- }
84
- } else if (this.xhr.responseText) {
85
- // In React Native, we may get responseText but no responseXML. We can try to parse it manually.
86
- Strophe.debug("Got responseText but no responseXML; attempting to parse it with DOMParser...");
87
- node = new DOMParser().parseFromString(this.xhr.responseText, 'application/xml').documentElement;
88
- if (!node) {
89
- throw new Error('Parsing produced null node');
90
- } else if (node.querySelector('parsererror')) {
91
- Strophe.error("invalid response received: " + node.querySelector('parsererror').textContent);
92
- Strophe.error("responseText: " + this.xhr.responseText);
93
- const error = new Error();
94
- error.name = Strophe.ErrorCondition.BAD_FORMAT;
95
- throw error;
96
- }
97
- }
98
- return node;
99
- }
100
-
101
- /** PrivateFunction: _newXHR
102
- * _Private_ helper function to create XMLHttpRequests.
103
- *
104
- * This function creates XMLHttpRequests across all implementations.
105
- *
106
- * Returns:
107
- * A new XMLHttpRequest.
108
- */
109
- _newXHR () {
110
- let xhr = null;
111
- if (window.XMLHttpRequest) {
112
- xhr = new XMLHttpRequest();
113
- if (xhr.overrideMimeType) {
114
- xhr.overrideMimeType("text/xml; charset=utf-8");
115
- }
116
- } else if (window.ActiveXObject) {
117
- xhr = new ActiveXObject("Microsoft.XMLHTTP");
118
- }
119
- // use Function.bind() to prepend ourselves as an argument
120
- xhr.onreadystatechange = this.func.bind(null, this);
121
- return xhr;
122
- }
123
- };
124
-
125
- /** Class: Strophe.Bosh
126
- * _Private_ helper class that handles BOSH Connections
127
- *
128
- * The Strophe.Bosh class is used internally by Strophe.Connection
129
- * to encapsulate BOSH sessions. It is not meant to be used from user's code.
130
- */
131
-
132
- /** File: bosh.js
133
- * A JavaScript library to enable BOSH in Strophejs.
134
- *
135
- * this library uses Bidirectional-streams Over Synchronous HTTP (BOSH)
136
- * to emulate a persistent, stateful, two-way connection to an XMPP server.
137
- * More information on BOSH can be found in XEP 124.
138
- */
139
-
140
- /** PrivateConstructor: Strophe.Bosh
141
- * Create and initialize a Strophe.Bosh object.
142
- *
143
- * Parameters:
144
- * (Strophe.Connection) connection - The Strophe.Connection that will use BOSH.
145
- *
146
- * Returns:
147
- * A new Strophe.Bosh object.
148
- */
149
- Strophe.Bosh = class Bosh {
150
-
151
- constructor (connection) {
152
- this._conn = connection;
153
- /* request id for body tags */
154
- this.rid = Math.floor(Math.random() * 4294967295);
155
- /* The current session ID. */
156
- this.sid = null;
157
-
158
- // default BOSH values
159
- this.hold = 1;
160
- this.wait = 60;
161
- this.window = 5;
162
- this.errors = 0;
163
- this.inactivity = null;
164
-
165
- this.lastResponseHeaders = null;
166
- this._requests = [];
167
- }
168
-
169
- /** PrivateFunction: _buildBody
170
- * _Private_ helper function to generate the <body/> wrapper for BOSH.
171
- *
172
- * Returns:
173
- * A Strophe.Builder with a <body/> element.
174
- */
175
- _buildBody () {
176
- const bodyWrap = $build('body', {
177
- 'rid': this.rid++,
178
- 'xmlns': Strophe.NS.HTTPBIND
179
- });
180
- if (this.sid !== null) {
181
- bodyWrap.attrs({'sid': this.sid});
182
- }
183
- if (this._conn.options.keepalive && this._conn._sessionCachingSupported()) {
184
- this._cacheSession();
185
- }
186
- return bodyWrap;
187
- }
188
-
189
- /** PrivateFunction: _reset
190
- * Reset the connection.
191
- *
192
- * This function is called by the reset function of the Strophe Connection
193
- */
194
- _reset () {
195
- this.rid = Math.floor(Math.random() * 4294967295);
196
- this.sid = null;
197
- this.errors = 0;
198
- if (this._conn._sessionCachingSupported()) {
199
- window.sessionStorage.removeItem('strophe-bosh-session');
200
- }
201
-
202
- this._conn.nextValidRid(this.rid);
203
- }
204
-
205
- /** PrivateFunction: _connect
206
- * _Private_ function that initializes the BOSH connection.
207
- *
208
- * Creates and sends the Request that initializes the BOSH connection.
209
- */
210
- _connect (wait, hold, route) {
211
- this.wait = wait || this.wait;
212
- this.hold = hold || this.hold;
213
- this.errors = 0;
214
-
215
- const body = this._buildBody().attrs({
216
- "to": this._conn.domain,
217
- "xml:lang": "en",
218
- "wait": this.wait,
219
- "hold": this.hold,
220
- "content": "text/xml; charset=utf-8",
221
- "ver": "1.6",
222
- "xmpp:version": "1.0",
223
- "xmlns:xmpp": Strophe.NS.BOSH
224
- });
225
- if (route){
226
- body.attrs({'route': route});
227
- }
228
-
229
- const _connect_cb = this._conn._connect_cb;
230
- this._requests.push(
231
- new Strophe.Request(
232
- body.tree(),
233
- this._onRequestStateChange.bind(this, _connect_cb.bind(this._conn)),
234
- body.tree().getAttribute("rid")
235
- )
236
- );
237
- this._throttledRequestHandler();
238
- }
239
-
240
- /** PrivateFunction: _attach
241
- * Attach to an already created and authenticated BOSH session.
242
- *
243
- * This function is provided to allow Strophe to attach to BOSH
244
- * sessions which have been created externally, perhaps by a Web
245
- * application. This is often used to support auto-login type features
246
- * without putting user credentials into the page.
247
- *
248
- * Parameters:
249
- * (String) jid - The full JID that is bound by the session.
250
- * (String) sid - The SID of the BOSH session.
251
- * (String) rid - The current RID of the BOSH session. This RID
252
- * will be used by the next request.
253
- * (Function) callback The connect callback function.
254
- * (Integer) wait - The optional HTTPBIND wait value. This is the
255
- * time the server will wait before returning an empty result for
256
- * a request. The default setting of 60 seconds is recommended.
257
- * Other settings will require tweaks to the Strophe.TIMEOUT value.
258
- * (Integer) hold - The optional HTTPBIND hold value. This is the
259
- * number of connections the server will hold at one time. This
260
- * should almost always be set to 1 (the default).
261
- * (Integer) wind - The optional HTTBIND window value. This is the
262
- * allowed range of request ids that are valid. The default is 5.
263
- */
264
- _attach (jid, sid, rid, callback, wait, hold, wind) {
265
- this._conn.jid = jid;
266
- this.sid = sid;
267
- this.rid = rid;
268
-
269
- this._conn.connect_callback = callback;
270
- this._conn.domain = Strophe.getDomainFromJid(this._conn.jid);
271
- this._conn.authenticated = true;
272
- this._conn.connected = true;
273
-
274
- this.wait = wait || this.wait;
275
- this.hold = hold || this.hold;
276
- this.window = wind || this.window;
277
-
278
- this._conn._changeConnectStatus(Strophe.Status.ATTACHED, null);
279
- }
280
-
281
- /** PrivateFunction: _restore
282
- * Attempt to restore a cached BOSH session
283
- *
284
- * Parameters:
285
- * (String) jid - The full JID that is bound by the session.
286
- * This parameter is optional but recommended, specifically in cases
287
- * where prebinded BOSH sessions are used where it's important to know
288
- * that the right session is being restored.
289
- * (Function) callback The connect callback function.
290
- * (Integer) wait - The optional HTTPBIND wait value. This is the
291
- * time the server will wait before returning an empty result for
292
- * a request. The default setting of 60 seconds is recommended.
293
- * Other settings will require tweaks to the Strophe.TIMEOUT value.
294
- * (Integer) hold - The optional HTTPBIND hold value. This is the
295
- * number of connections the server will hold at one time. This
296
- * should almost always be set to 1 (the default).
297
- * (Integer) wind - The optional HTTBIND window value. This is the
298
- * allowed range of request ids that are valid. The default is 5.
299
- */
300
- _restore (jid, callback, wait, hold, wind) {
301
- const session = JSON.parse(window.sessionStorage.getItem('strophe-bosh-session'));
302
- if (typeof session !== "undefined" &&
303
- session !== null &&
304
- session.rid &&
305
- session.sid &&
306
- session.jid &&
307
- ( typeof jid === "undefined" ||
308
- jid === null ||
309
- Strophe.getBareJidFromJid(session.jid) === Strophe.getBareJidFromJid(jid) ||
310
- // If authcid is null, then it's an anonymous login, so
311
- // we compare only the domains:
312
- ((Strophe.getNodeFromJid(jid) === null) && (Strophe.getDomainFromJid(session.jid) === jid))
313
- )
314
- ) {
315
- this._conn.restored = true;
316
- this._attach(session.jid, session.sid, session.rid, callback, wait, hold, wind);
317
- } else {
318
- const error = new Error("_restore: no restoreable session.");
319
- error.name = "StropheSessionError";
320
- throw error;
321
- }
322
- }
323
-
324
- /** PrivateFunction: _cacheSession
325
- * _Private_ handler for the beforeunload event.
326
- *
327
- * This handler is used to process the Bosh-part of the initial request.
328
- * Parameters:
329
- * (Strophe.Request) bodyWrap - The received stanza.
330
- */
331
- _cacheSession () {
332
- if (this._conn.authenticated) {
333
- if (this._conn.jid && this.rid && this.sid) {
334
- window.sessionStorage.setItem('strophe-bosh-session', JSON.stringify({
335
- 'jid': this._conn.jid,
336
- 'rid': this.rid,
337
- 'sid': this.sid
338
- }));
339
- }
340
- } else {
341
- window.sessionStorage.removeItem('strophe-bosh-session');
342
- }
343
- }
344
-
345
- /** PrivateFunction: _connect_cb
346
- * _Private_ handler for initial connection request.
347
- *
348
- * This handler is used to process the Bosh-part of the initial request.
349
- * Parameters:
350
- * (Strophe.Request) bodyWrap - The received stanza.
351
- */
352
- _connect_cb (bodyWrap) {
353
- const typ = bodyWrap.getAttribute("type");
354
- if (typ !== null && typ === "terminate") {
355
- // an error occurred
356
- let cond = bodyWrap.getAttribute("condition");
357
- Strophe.error("BOSH-Connection failed: " + cond);
358
- const conflict = bodyWrap.getElementsByTagName("conflict");
359
- if (cond !== null) {
360
- if (cond === "remote-stream-error" && conflict.length > 0) {
361
- cond = "conflict";
362
- }
363
- this._conn._changeConnectStatus(Strophe.Status.CONNFAIL, cond);
364
- } else {
365
- this._conn._changeConnectStatus(Strophe.Status.CONNFAIL, "unknown");
366
- }
367
- this._conn._doDisconnect(cond);
368
- return Strophe.Status.CONNFAIL;
369
- }
370
-
371
- // check to make sure we don't overwrite these if _connect_cb is
372
- // called multiple times in the case of missing stream:features
373
- if (!this.sid) {
374
- this.sid = bodyWrap.getAttribute("sid");
375
- }
376
- const wind = bodyWrap.getAttribute('requests');
377
- if (wind) { this.window = parseInt(wind, 10); }
378
- const hold = bodyWrap.getAttribute('hold');
379
- if (hold) { this.hold = parseInt(hold, 10); }
380
- const wait = bodyWrap.getAttribute('wait');
381
- if (wait) { this.wait = parseInt(wait, 10); }
382
- const inactivity = bodyWrap.getAttribute('inactivity');
383
- if (inactivity) { this.inactivity = parseInt(inactivity, 10); }
384
- }
385
-
386
- /** PrivateFunction: _disconnect
387
- * _Private_ part of Connection.disconnect for Bosh
388
- *
389
- * Parameters:
390
- * (Request) pres - This stanza will be sent before disconnecting.
391
- */
392
- _disconnect (pres) {
393
- this._sendTerminate(pres);
394
- }
395
-
396
- /** PrivateFunction: _doDisconnect
397
- * _Private_ function to disconnect.
398
- *
399
- * Resets the SID and RID.
400
- */
401
- _doDisconnect () {
402
- this.sid = null;
403
- this.rid = Math.floor(Math.random() * 4294967295);
404
- if (this._conn._sessionCachingSupported()) {
405
- window.sessionStorage.removeItem('strophe-bosh-session');
406
- }
407
-
408
- this._conn.nextValidRid(this.rid);
409
- }
410
-
411
- /** PrivateFunction: _emptyQueue
412
- * _Private_ function to check if the Request queue is empty.
413
- *
414
- * Returns:
415
- * True, if there are no Requests queued, False otherwise.
416
- */
417
- _emptyQueue () {
418
- return this._requests.length === 0;
419
- }
420
-
421
- /** PrivateFunction: _callProtocolErrorHandlers
422
- * _Private_ function to call error handlers registered for HTTP errors.
423
- *
424
- * Parameters:
425
- * (Strophe.Request) req - The request that is changing readyState.
426
- */
427
- _callProtocolErrorHandlers (req) {
428
- const reqStatus = Bosh._getRequestStatus(req);
429
- const err_callback = this._conn.protocolErrorHandlers.HTTP[reqStatus];
430
- if (err_callback) {
431
- err_callback.call(this, reqStatus);
432
- }
433
- }
434
-
435
- /** PrivateFunction: _hitError
436
- * _Private_ function to handle the error count.
437
- *
438
- * Requests are resent automatically until their error count reaches
439
- * 5. Each time an error is encountered, this function is called to
440
- * increment the count and disconnect if the count is too high.
441
- *
442
- * Parameters:
443
- * (Integer) reqStatus - The request status.
444
- */
445
- _hitError (reqStatus) {
446
- this.errors++;
447
- Strophe.warn("request errored, status: " + reqStatus +
448
- ", number of errors: " + this.errors);
449
- if (this.errors > 4) {
450
- this._conn._onDisconnectTimeout();
451
- }
452
- }
453
-
454
- /** PrivateFunction: _no_auth_received
455
- *
456
- * Called on stream start/restart when no stream:features
457
- * has been received and sends a blank poll request.
458
- */
459
- _no_auth_received (callback) {
460
- Strophe.warn("Server did not yet offer a supported authentication "+
461
- "mechanism. Sending a blank poll request.");
462
- if (callback) {
463
- callback = callback.bind(this._conn);
464
- } else {
465
- callback = this._conn._connect_cb.bind(this._conn);
466
- }
467
- const body = this._buildBody();
468
- this._requests.push(
469
- new Strophe.Request(
470
- body.tree(),
471
- this._onRequestStateChange.bind(this, callback),
472
- body.tree().getAttribute("rid")
473
- )
474
- );
475
- this._throttledRequestHandler();
476
- }
477
-
478
- /** PrivateFunction: _onDisconnectTimeout
479
- * _Private_ timeout handler for handling non-graceful disconnection.
480
- *
481
- * Cancels all remaining Requests and clears the queue.
482
- */
483
- _onDisconnectTimeout () {
484
- this._abortAllRequests();
485
- }
486
-
487
- /** PrivateFunction: _abortAllRequests
488
- * _Private_ helper function that makes sure all pending requests are aborted.
489
- */
490
- _abortAllRequests () {
491
- while (this._requests.length > 0) {
492
- const req = this._requests.pop();
493
- req.abort = true;
494
- req.xhr.abort();
495
- req.xhr.onreadystatechange = function () {};
496
- }
497
- }
498
-
499
- /** PrivateFunction: _onIdle
500
- * _Private_ handler called by Strophe.Connection._onIdle
501
- *
502
- * Sends all queued Requests or polls with empty Request if there are none.
503
- */
504
- _onIdle () {
505
- const data = this._conn._data;
506
- // if no requests are in progress, poll
507
- if (this._conn.authenticated && this._requests.length === 0 &&
508
- data.length === 0 && !this._conn.disconnecting) {
509
- Strophe.debug("no requests during idle cycle, sending blank request");
510
- data.push(null);
511
- }
512
-
513
- if (this._conn.paused) {
514
- return;
515
- }
516
-
517
- if (this._requests.length < 2 && data.length > 0) {
518
- const body = this._buildBody();
519
- for (let i=0; i<data.length; i++) {
520
- if (data[i] !== null) {
521
- if (data[i] === "restart") {
522
- body.attrs({
523
- "to": this._conn.domain,
524
- "xml:lang": "en",
525
- "xmpp:restart": "true",
526
- "xmlns:xmpp": Strophe.NS.BOSH
527
- });
528
- } else {
529
- body.cnode(data[i]).up();
530
- }
531
- }
532
- }
533
- delete this._conn._data;
534
- this._conn._data = [];
535
- this._requests.push(
536
- new Strophe.Request(
537
- body.tree(),
538
- this._onRequestStateChange.bind(this, this._conn._dataRecv.bind(this._conn)),
539
- body.tree().getAttribute("rid")
540
- )
541
- );
542
- this._throttledRequestHandler();
543
- }
544
-
545
- if (this._requests.length > 0) {
546
- const time_elapsed = this._requests[0].age();
547
- if (this._requests[0].dead !== null) {
548
- if (this._requests[0].timeDead() >
549
- Math.floor(Strophe.SECONDARY_TIMEOUT * this.wait)) {
550
- this._throttledRequestHandler();
551
- }
552
- }
553
- if (time_elapsed > Math.floor(Strophe.TIMEOUT * this.wait)) {
554
- Strophe.warn("Request " +
555
- this._requests[0].id +
556
- " timed out, over " + Math.floor(Strophe.TIMEOUT * this.wait) +
557
- " seconds since last activity");
558
- this._throttledRequestHandler();
559
- }
560
- }
561
- }
562
-
563
- /** PrivateFunction: _getRequestStatus
564
- *
565
- * Returns the HTTP status code from a Strophe.Request
566
- *
567
- * Parameters:
568
- * (Strophe.Request) req - The Strophe.Request instance.
569
- * (Integer) def - The default value that should be returned if no
570
- * status value was found.
571
- */
572
- static _getRequestStatus (req, def) {
573
- let reqStatus;
574
- if (req.xhr.readyState === 4) {
575
- try {
576
- reqStatus = req.xhr.status;
577
- } catch (e) {
578
- // ignore errors from undefined status attribute. Works
579
- // around a browser bug
580
- Strophe.error(
581
- "Caught an error while retrieving a request's status, " +
582
- "reqStatus: " + reqStatus);
583
- }
584
- }
585
- if (typeof(reqStatus) === "undefined") {
586
- reqStatus = typeof def === 'number' ? def : 0;
587
- }
588
- return reqStatus;
589
- }
590
-
591
- /** PrivateFunction: _onRequestStateChange
592
- * _Private_ handler for Strophe.Request state changes.
593
- *
594
- * This function is called when the XMLHttpRequest readyState changes.
595
- * It contains a lot of error handling logic for the many ways that
596
- * requests can fail, and calls the request callback when requests
597
- * succeed.
598
- *
599
- * Parameters:
600
- * (Function) func - The handler for the request.
601
- * (Strophe.Request) req - The request that is changing readyState.
602
- */
603
- _onRequestStateChange (func, req) {
604
- Strophe.debug("request id "+req.id+"."+req.sends+
605
- " state changed to "+req.xhr.readyState);
606
- if (req.abort) {
607
- req.abort = false;
608
- return;
609
- }
610
- if (req.xhr.readyState !== 4) {
611
- // The request is not yet complete
612
- return;
613
- }
614
- const reqStatus = Bosh._getRequestStatus(req);
615
- this.lastResponseHeaders = req.xhr.getAllResponseHeaders();
616
- if (this._conn.disconnecting && reqStatus >= 400) {
617
- this._hitError(reqStatus);
618
- this._callProtocolErrorHandlers(req);
619
- return;
620
- }
621
-
622
- const reqIs0 = (this._requests[0] === req);
623
- const reqIs1 = (this._requests[1] === req);
624
-
625
- const valid_request = reqStatus > 0 && reqStatus < 500;
626
- const too_many_retries = req.sends > this._conn.maxRetries;
627
- if (valid_request || too_many_retries) {
628
- // remove from internal queue
629
- this._removeRequest(req);
630
- Strophe.debug("request id "+req.id+" should now be removed");
631
- }
632
-
633
- if (reqStatus === 200) {
634
- // request succeeded
635
- // if request 1 finished, or request 0 finished and request
636
- // 1 is over Strophe.SECONDARY_TIMEOUT seconds old, we need to
637
- // restart the other - both will be in the first spot, as the
638
- // completed request has been removed from the queue already
639
- if (reqIs1 ||
640
- (reqIs0 && this._requests.length > 0 &&
641
- this._requests[0].age() > Math.floor(Strophe.SECONDARY_TIMEOUT * this.wait))) {
642
- this._restartRequest(0);
643
- }
644
- this._conn.nextValidRid(Number(req.rid) + 1);
645
- Strophe.debug("request id "+req.id+"."+req.sends+" got 200");
646
- func(req); // call handler
647
- this.errors = 0;
648
- } else if (reqStatus === 0 ||
649
- (reqStatus >= 400 && reqStatus < 600) ||
650
- reqStatus >= 12000) {
651
- // request failed
652
- Strophe.error("request id "+req.id+"."+req.sends+" error "+reqStatus+" happened");
653
- this._hitError(reqStatus);
654
- this._callProtocolErrorHandlers(req);
655
- if (reqStatus >= 400 && reqStatus < 500) {
656
- this._conn._changeConnectStatus(Strophe.Status.DISCONNECTING, null);
657
- this._conn._doDisconnect();
658
- }
659
- } else {
660
- Strophe.error("request id "+req.id+"."+req.sends+" error "+reqStatus+" happened");
661
- }
662
-
663
- if (!valid_request && !too_many_retries) {
664
- this._throttledRequestHandler();
665
- } else if (too_many_retries && !this._conn.connected) {
666
- this._conn._changeConnectStatus(Strophe.Status.CONNFAIL, "giving-up");
667
- }
668
- }
669
-
670
- /** PrivateFunction: _processRequest
671
- * _Private_ function to process a request in the queue.
672
- *
673
- * This function takes requests off the queue and sends them and
674
- * restarts dead requests.
675
- *
676
- * Parameters:
677
- * (Integer) i - The index of the request in the queue.
678
- */
679
- _processRequest (i) {
680
- let req = this._requests[i];
681
- const reqStatus = Bosh._getRequestStatus(req, -1);
682
-
683
- // make sure we limit the number of retries
684
- if (req.sends > this._conn.maxRetries) {
685
- this._conn._onDisconnectTimeout();
686
- return;
687
- }
688
- const time_elapsed = req.age();
689
- const primary_timeout = (!isNaN(time_elapsed) && time_elapsed > Math.floor(Strophe.TIMEOUT * this.wait));
690
- const secondary_timeout = (req.dead !== null && req.timeDead() > Math.floor(Strophe.SECONDARY_TIMEOUT * this.wait));
691
- const server_error = (req.xhr.readyState === 4 && (reqStatus < 1 || reqStatus >= 500));
692
-
693
- if (primary_timeout || secondary_timeout || server_error) {
694
- if (secondary_timeout) {
695
- Strophe.error(`Request ${this._requests[i].id} timed out (secondary), restarting`);
696
- }
697
- req.abort = true;
698
- req.xhr.abort();
699
- // setting to null fails on IE6, so set to empty function
700
- req.xhr.onreadystatechange = function () {};
701
- this._requests[i] = new Strophe.Request(req.xmlData, req.origFunc, req.rid, req.sends);
702
- req = this._requests[i];
703
- }
704
-
705
- if (req.xhr.readyState === 0) {
706
- Strophe.debug("request id "+req.id+"."+req.sends+" posting");
707
-
708
- try {
709
- const content_type = this._conn.options.contentType || "text/xml; charset=utf-8";
710
- req.xhr.open("POST", this._conn.service, this._conn.options.sync ? false : true);
711
- if (typeof req.xhr.setRequestHeader !== 'undefined') {
712
- // IE9 doesn't have setRequestHeader
713
- req.xhr.setRequestHeader("Content-Type", content_type);
714
- }
715
- if (this._conn.options.withCredentials) {
716
- req.xhr.withCredentials = true;
717
- }
718
- } catch (e2) {
719
- Strophe.error("XHR open failed: " + e2.toString());
720
- if (!this._conn.connected) {
721
- this._conn._changeConnectStatus(Strophe.Status.CONNFAIL, "bad-service");
722
- }
723
- this._conn.disconnect();
724
- return;
725
- }
726
-
727
- // Fires the XHR request -- may be invoked immediately
728
- // or on a gradually expanding retry window for reconnects
729
- const sendFunc = () => {
730
- req.date = new Date();
731
- if (this._conn.options.customHeaders){
732
- const headers = this._conn.options.customHeaders;
733
- for (const header in headers) {
734
- if (Object.prototype.hasOwnProperty.call(headers, header)) {
735
- req.xhr.setRequestHeader(header, headers[header]);
736
- }
737
- }
738
- }
739
- req.xhr.send(req.data);
740
- };
741
-
742
- // Implement progressive backoff for reconnects --
743
- // First retry (send === 1) should also be instantaneous
744
- if (req.sends > 1) {
745
- // Using a cube of the retry number creates a nicely
746
- // expanding retry window
747
- const backoff = Math.min(Math.floor(Strophe.TIMEOUT * this.wait),
748
- Math.pow(req.sends, 3)) * 1000;
749
- setTimeout(function() {
750
- // XXX: setTimeout should be called only with function expressions (23974bc1)
751
- sendFunc();
752
- }, backoff);
753
- } else {
754
- sendFunc();
755
- }
756
-
757
- req.sends++;
758
-
759
- if (this._conn.xmlOutput !== Strophe.Connection.prototype.xmlOutput) {
760
- if (req.xmlData.nodeName === this.strip && req.xmlData.childNodes.length) {
761
- this._conn.xmlOutput(req.xmlData.childNodes[0]);
762
- } else {
763
- this._conn.xmlOutput(req.xmlData);
764
- }
765
- }
766
- if (this._conn.rawOutput !== Strophe.Connection.prototype.rawOutput) {
767
- this._conn.rawOutput(req.data);
768
- }
769
- } else {
770
- Strophe.debug("_processRequest: " +
771
- (i === 0 ? "first" : "second") +
772
- " request has readyState of " +
773
- req.xhr.readyState);
774
- }
775
- }
776
-
777
- /** PrivateFunction: _removeRequest
778
- * _Private_ function to remove a request from the queue.
779
- *
780
- * Parameters:
781
- * (Strophe.Request) req - The request to remove.
782
- */
783
- _removeRequest (req) {
784
- Strophe.debug("removing request");
785
- for (let i=this._requests.length - 1; i>=0; i--) {
786
- if (req === this._requests[i]) {
787
- this._requests.splice(i, 1);
788
- }
789
- }
790
- // IE6 fails on setting to null, so set to empty function
791
- req.xhr.onreadystatechange = function () {};
792
- this._throttledRequestHandler();
793
- }
794
-
795
- /** PrivateFunction: _restartRequest
796
- * _Private_ function to restart a request that is presumed dead.
797
- *
798
- * Parameters:
799
- * (Integer) i - The index of the request in the queue.
800
- */
801
- _restartRequest (i) {
802
- const req = this._requests[i];
803
- if (req.dead === null) {
804
- req.dead = new Date();
805
- }
806
- this._processRequest(i);
807
- }
808
-
809
- /** PrivateFunction: _reqToData
810
- * _Private_ function to get a stanza out of a request.
811
- *
812
- * Tries to extract a stanza out of a Request Object.
813
- * When this fails the current connection will be disconnected.
814
- *
815
- * Parameters:
816
- * (Object) req - The Request.
817
- *
818
- * Returns:
819
- * The stanza that was passed.
820
- */
821
- _reqToData (req) {
822
- try {
823
- return req.getResponse();
824
- } catch (e) {
825
- if (e.message !== "parsererror") { throw e; }
826
- this._conn.disconnect("strophe-parsererror");
827
- }
828
- }
829
-
830
- /** PrivateFunction: _sendTerminate
831
- * _Private_ function to send initial disconnect sequence.
832
- *
833
- * This is the first step in a graceful disconnect. It sends
834
- * the BOSH server a terminate body and includes an unavailable
835
- * presence if authentication has completed.
836
- */
837
- _sendTerminate (pres) {
838
- Strophe.debug("_sendTerminate was called");
839
- const body = this._buildBody().attrs({type: "terminate"});
840
- if (pres) {
841
- body.cnode(pres.tree());
842
- }
843
- const req = new Strophe.Request(
844
- body.tree(),
845
- this._onRequestStateChange.bind(this, this._conn._dataRecv.bind(this._conn)),
846
- body.tree().getAttribute("rid")
847
- );
848
- this._requests.push(req);
849
- this._throttledRequestHandler();
850
- }
851
-
852
- /** PrivateFunction: _send
853
- * _Private_ part of the Connection.send function for BOSH
854
- *
855
- * Just triggers the RequestHandler to send the messages that are in the queue
856
- */
857
- _send () {
858
- clearTimeout(this._conn._idleTimeout);
859
- this._throttledRequestHandler();
860
- this._conn._idleTimeout = setTimeout(() => this._conn._onIdle(), 100);
861
- }
862
-
863
- /** PrivateFunction: _sendRestart
864
- *
865
- * Send an xmpp:restart stanza.
866
- */
867
- _sendRestart () {
868
- this._throttledRequestHandler();
869
- clearTimeout(this._conn._idleTimeout);
870
- }
871
-
872
- /** PrivateFunction: _throttledRequestHandler
873
- * _Private_ function to throttle requests to the connection window.
874
- *
875
- * This function makes sure we don't send requests so fast that the
876
- * request ids overflow the connection window in the case that one
877
- * request died.
878
- */
879
- _throttledRequestHandler () {
880
- if (!this._requests) {
881
- Strophe.debug("_throttledRequestHandler called with " +
882
- "undefined requests");
883
- } else {
884
- Strophe.debug("_throttledRequestHandler called with " +
885
- this._requests.length + " requests");
886
- }
887
-
888
- if (!this._requests || this._requests.length === 0) {
889
- return;
890
- }
891
-
892
- if (this._requests.length > 0) {
893
- this._processRequest(0);
894
- }
895
-
896
- if (this._requests.length > 1 &&
897
- Math.abs(this._requests[0].rid -
898
- this._requests[1].rid) < this.window) {
899
- this._processRequest(1);
900
- }
901
- }
902
- };
903
-
904
-
905
- /** Variable: strip
906
- *
907
- * BOSH-Connections will have all stanzas wrapped in a <body> tag when
908
- * passed to <Strophe.Connection.xmlInput> or <Strophe.Connection.xmlOutput>.
909
- * To strip this tag, User code can set <Strophe.Bosh.strip> to "body":
910
- *
911
- * > Strophe.Bosh.prototype.strip = "body";
912
- *
913
- * This will enable stripping of the body tag in both
914
- * <Strophe.Connection.xmlInput> and <Strophe.Connection.xmlOutput>.
915
- */
916
- Strophe.Bosh.prototype.strip = null;