quickblox 2.17.2-logger → 2.17.3-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.
- package/package.json +1 -2
- package/quickblox.js +36560 -38627
- package/quickblox.min.js +1 -1
- package/src/libs/strophe/strophe.common.js +6657 -0
- package/src/libs/strophe/strophe.esm.js +6649 -0
- package/src/libs/strophe/strophe.umd.js +6862 -0
- package/src/libs/strophe/strophe.umd.min.js +1 -0
- package/src/modules/chat/qbChat.js +9 -0
- package/src/modules/webrtc/qbWebRTCSignalingProcessor.js +2 -1
- package/src/modules/webrtc/qbWebRTCSignalingProvider.js +2 -2
- package/src/qbConfig.js +1 -1
- package/src/qbStrophe.js +2 -1
- package/strophejs-1.4.0/.eslintrc.json +264 -0
- package/strophejs-1.4.0/.gitattributes +1 -0
- package/strophejs-1.4.0/CHANGELOG.md +250 -0
- package/strophejs-1.4.0/LICENSE.txt +19 -0
- package/strophejs-1.4.0/Makefile +92 -0
- package/strophejs-1.4.0/README.md +45 -0
- package/strophejs-1.4.0/RELEASE_CHECKLIST.md +16 -0
- package/strophejs-1.4.0/contrib/discojs/README.txt +42 -0
- package/strophejs-1.4.0/contrib/discojs/css/disco.css +16 -0
- package/strophejs-1.4.0/contrib/discojs/index.html +47 -0
- package/strophejs-1.4.0/contrib/discojs/punjab.tac +18 -0
- package/strophejs-1.4.0/contrib/discojs/scripts/basic.js +102 -0
- package/strophejs-1.4.0/contrib/discojs/scripts/disco.js +60 -0
- package/strophejs-1.4.0/docs.css +797 -0
- package/strophejs-1.4.0/examples/amd.html +21 -0
- package/strophejs-1.4.0/examples/attach/README +37 -0
- 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 +18 -0
- package/strophejs-1.4.0/examples/attach/boshclient.py +158 -0
- package/strophejs-1.4.0/examples/attach/manage.py +11 -0
- package/strophejs-1.4.0/examples/attach/settings.py +85 -0
- package/strophejs-1.4.0/examples/attach/templates/attacher/index.html +88 -0
- package/strophejs-1.4.0/examples/attach/urls.py +19 -0
- package/strophejs-1.4.0/examples/basic.html +23 -0
- package/strophejs-1.4.0/examples/basic.js +73 -0
- package/strophejs-1.4.0/examples/echobot.html +25 -0
- package/strophejs-1.4.0/examples/echobot.js +79 -0
- package/strophejs-1.4.0/examples/main.js +59 -0
- package/strophejs-1.4.0/examples/prebind.html +39 -0
- package/strophejs-1.4.0/examples/prebind.js +103 -0
- package/strophejs-1.4.0/examples/restore.html +24 -0
- package/strophejs-1.4.0/examples/restore.js +71 -0
- package/strophejs-1.4.0/package-lock.json +8631 -0
- package/strophejs-1.4.0/package.json +84 -0
- package/strophejs-1.4.0/rollup.config.js +76 -0
- package/strophejs-1.4.0/src/bosh.js +916 -0
- package/strophejs-1.4.0/src/core.js +3530 -0
- package/strophejs-1.4.0/src/md5.js +204 -0
- package/strophejs-1.4.0/src/sha1.js +172 -0
- package/strophejs-1.4.0/src/shared-connection-worker.js +114 -0
- package/strophejs-1.4.0/src/shims.js +123 -0
- package/strophejs-1.4.0/src/strophe.js +14 -0
- package/strophejs-1.4.0/src/utils.js +63 -0
- package/strophejs-1.4.0/src/websocket.js +557 -0
- package/strophejs-1.4.0/src/worker-websocket.js +150 -0
- package/strophejs-1.4.0/tests/index.html +21 -0
- package/strophejs-1.4.0/tests/main.js +49 -0
- package/strophejs-1.4.0/tests/tests.js +929 -0
- package/strophejs-1.6.1/.eslintrc.json +264 -0
- package/strophejs-1.6.1/.gitattributes +1 -0
- package/strophejs-1.6.1/.nvmrc +1 -0
- package/strophejs-1.6.1/CHANGELOG.md +288 -0
- package/strophejs-1.6.1/LICENSE.txt +19 -0
- package/strophejs-1.6.1/Makefile +92 -0
- package/strophejs-1.6.1/README.md +46 -0
- package/strophejs-1.6.1/RELEASE_CHECKLIST.md +18 -0
- package/strophejs-1.6.1/babel.config.json +10 -0
- package/strophejs-1.6.1/contrib/discojs/README.txt +42 -0
- package/strophejs-1.6.1/contrib/discojs/css/disco.css +16 -0
- package/strophejs-1.6.1/contrib/discojs/index.html +47 -0
- package/strophejs-1.6.1/contrib/discojs/punjab.tac +18 -0
- package/strophejs-1.6.1/contrib/discojs/scripts/basic.js +102 -0
- package/strophejs-1.6.1/contrib/discojs/scripts/disco.js +60 -0
- package/strophejs-1.6.1/docs.css +797 -0
- package/strophejs-1.6.1/examples/amd.html +21 -0
- package/strophejs-1.6.1/examples/attach/README +37 -0
- 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 +18 -0
- package/strophejs-1.6.1/examples/attach/boshclient.py +158 -0
- package/strophejs-1.6.1/examples/attach/manage.py +11 -0
- package/strophejs-1.6.1/examples/attach/settings.py +85 -0
- package/strophejs-1.6.1/examples/attach/templates/attacher/index.html +88 -0
- package/strophejs-1.6.1/examples/attach/urls.py +19 -0
- package/strophejs-1.6.1/examples/basic.html +23 -0
- package/strophejs-1.6.1/examples/basic.js +73 -0
- package/strophejs-1.6.1/examples/echobot.html +25 -0
- package/strophejs-1.6.1/examples/echobot.js +79 -0
- package/strophejs-1.6.1/examples/main.js +59 -0
- package/strophejs-1.6.1/examples/prebind.html +39 -0
- package/strophejs-1.6.1/examples/prebind.js +103 -0
- package/strophejs-1.6.1/examples/restore.html +24 -0
- package/strophejs-1.6.1/examples/restore.js +71 -0
- package/strophejs-1.6.1/package-lock.json +18461 -0
- package/strophejs-1.6.1/package.json +87 -0
- package/strophejs-1.6.1/rollup.config.js +70 -0
- package/strophejs-1.6.1/src/bosh.js +916 -0
- package/strophejs-1.6.1/src/builder.js +239 -0
- package/strophejs-1.6.1/src/constants.js +155 -0
- package/strophejs-1.6.1/src/core.js +2377 -0
- package/strophejs-1.6.1/src/sasl-anon.js +17 -0
- package/strophejs-1.6.1/src/sasl-external.js +27 -0
- package/strophejs-1.6.1/src/sasl-oauthbearer.js +30 -0
- package/strophejs-1.6.1/src/sasl-plain.js +32 -0
- package/strophejs-1.6.1/src/sasl-sha1.js +24 -0
- package/strophejs-1.6.1/src/sasl-sha256.js +24 -0
- package/strophejs-1.6.1/src/sasl-sha384.js +24 -0
- package/strophejs-1.6.1/src/sasl-sha512.js +24 -0
- package/strophejs-1.6.1/src/sasl-xoauth2.js +27 -0
- package/strophejs-1.6.1/src/sasl.js +143 -0
- package/strophejs-1.6.1/src/scram.js +182 -0
- package/strophejs-1.6.1/src/shared-connection-worker.js +114 -0
- package/strophejs-1.6.1/src/shims.js +122 -0
- package/strophejs-1.6.1/src/strophe.js +15 -0
- package/strophejs-1.6.1/src/utils.js +626 -0
- package/strophejs-1.6.1/src/websocket.js +556 -0
- package/strophejs-1.6.1/src/worker-websocket.js +149 -0
- package/strophejs-1.6.1/tests.js +993 -0
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
/* global ActiveXObject */
|
|
2
|
+
import * as shims from './shims';
|
|
3
|
+
import { ElementType, XHTML } from './constants.js';
|
|
4
|
+
|
|
5
|
+
export function utf16to8 (str) {
|
|
6
|
+
let out = '';
|
|
7
|
+
const len = str.length;
|
|
8
|
+
for (let i = 0; i < len; i++) {
|
|
9
|
+
const c = str.charCodeAt(i);
|
|
10
|
+
if (c >= 0x0000 && c <= 0x007f) {
|
|
11
|
+
out += str.charAt(i);
|
|
12
|
+
} else if (c > 0x07ff) {
|
|
13
|
+
out += String.fromCharCode(0xe0 | ((c >> 12) & 0x0f));
|
|
14
|
+
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3f));
|
|
15
|
+
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3f));
|
|
16
|
+
} else {
|
|
17
|
+
out += String.fromCharCode(0xc0 | ((c >> 6) & 0x1f));
|
|
18
|
+
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3f));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function xorArrayBuffers (x, y) {
|
|
25
|
+
const xIntArray = new Uint8Array(x);
|
|
26
|
+
const yIntArray = new Uint8Array(y);
|
|
27
|
+
const zIntArray = new Uint8Array(x.byteLength);
|
|
28
|
+
for (let i = 0; i < x.byteLength; i++) {
|
|
29
|
+
zIntArray[i] = xIntArray[i] ^ yIntArray[i];
|
|
30
|
+
}
|
|
31
|
+
return zIntArray.buffer;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function arrayBufToBase64 (buffer) {
|
|
35
|
+
// This function is due to mobz (https://stackoverflow.com/users/1234628/mobz)
|
|
36
|
+
// and Emmanuel (https://stackoverflow.com/users/288564/emmanuel)
|
|
37
|
+
let binary = '';
|
|
38
|
+
const bytes = new Uint8Array(buffer);
|
|
39
|
+
const len = bytes.byteLength;
|
|
40
|
+
for (let i = 0; i < len; i++) {
|
|
41
|
+
binary += String.fromCharCode(bytes[i]);
|
|
42
|
+
}
|
|
43
|
+
return window.btoa(binary);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function base64ToArrayBuf (str) {
|
|
47
|
+
return Uint8Array.from(atob(str), c => c.charCodeAt(0))?.buffer;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function stringToArrayBuf (str) {
|
|
51
|
+
const bytes = new TextEncoder('utf-8').encode(str);
|
|
52
|
+
return bytes.buffer;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function addCookies (cookies) {
|
|
56
|
+
/* Parameters:
|
|
57
|
+
* (Object) cookies - either a map of cookie names
|
|
58
|
+
* to string values or to maps of cookie values.
|
|
59
|
+
*
|
|
60
|
+
* For example:
|
|
61
|
+
* { "myCookie": "1234" }
|
|
62
|
+
*
|
|
63
|
+
* or:
|
|
64
|
+
* { "myCookie": {
|
|
65
|
+
* "value": "1234",
|
|
66
|
+
* "domain": ".example.org",
|
|
67
|
+
* "path": "/",
|
|
68
|
+
* "expires": expirationDate
|
|
69
|
+
* }
|
|
70
|
+
* }
|
|
71
|
+
*
|
|
72
|
+
* These values get passed to Strophe.Connection via
|
|
73
|
+
* options.cookies
|
|
74
|
+
*/
|
|
75
|
+
cookies = cookies || {};
|
|
76
|
+
for (const cookieName in cookies) {
|
|
77
|
+
if (Object.prototype.hasOwnProperty.call(cookies, cookieName)) {
|
|
78
|
+
let expires = '';
|
|
79
|
+
let domain = '';
|
|
80
|
+
let path = '';
|
|
81
|
+
const cookieObj = cookies[cookieName];
|
|
82
|
+
const isObj = typeof cookieObj === 'object';
|
|
83
|
+
const cookieValue = escape(unescape(isObj ? cookieObj.value : cookieObj));
|
|
84
|
+
if (isObj) {
|
|
85
|
+
expires = cookieObj.expires ? ';expires=' + cookieObj.expires : '';
|
|
86
|
+
domain = cookieObj.domain ? ';domain=' + cookieObj.domain : '';
|
|
87
|
+
path = cookieObj.path ? ';path=' + cookieObj.path : '';
|
|
88
|
+
}
|
|
89
|
+
document.cookie = cookieName + '=' + cookieValue + expires + domain + path;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let _xmlGenerator = null;
|
|
95
|
+
|
|
96
|
+
/** Function: Strophe.xmlGenerator
|
|
97
|
+
* Get the DOM document to generate elements.
|
|
98
|
+
*
|
|
99
|
+
* Returns:
|
|
100
|
+
* The currently used DOM document.
|
|
101
|
+
*/
|
|
102
|
+
export function xmlGenerator () {
|
|
103
|
+
if (!_xmlGenerator) {
|
|
104
|
+
_xmlGenerator = shims.getDummyXMLDOMDocument();
|
|
105
|
+
}
|
|
106
|
+
return _xmlGenerator;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Function: Strophe.xmlTextNode
|
|
110
|
+
* Creates an XML DOM text node.
|
|
111
|
+
*
|
|
112
|
+
* Provides a cross implementation version of document.createTextNode.
|
|
113
|
+
*
|
|
114
|
+
* Parameters:
|
|
115
|
+
* (String) text - The content of the text node.
|
|
116
|
+
*
|
|
117
|
+
* Returns:
|
|
118
|
+
* A new XML DOM text node.
|
|
119
|
+
*/
|
|
120
|
+
export function xmlTextNode (text) {
|
|
121
|
+
return xmlGenerator().createTextNode(text);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Function: Strophe.xmlHtmlNode
|
|
125
|
+
* Creates an XML DOM html node.
|
|
126
|
+
*
|
|
127
|
+
* Parameters:
|
|
128
|
+
* (String) html - The content of the html node.
|
|
129
|
+
*
|
|
130
|
+
* Returns:
|
|
131
|
+
* A new XML DOM text node.
|
|
132
|
+
*/
|
|
133
|
+
export function xmlHtmlNode (html) {
|
|
134
|
+
let node;
|
|
135
|
+
//ensure text is escaped
|
|
136
|
+
if (shims.DOMParser) {
|
|
137
|
+
const parser = new shims.DOMParser();
|
|
138
|
+
node = parser.parseFromString(html, 'text/xml');
|
|
139
|
+
} else {
|
|
140
|
+
node = new ActiveXObject('Microsoft.XMLDOM');
|
|
141
|
+
node.async = 'false';
|
|
142
|
+
node.loadXML(html);
|
|
143
|
+
}
|
|
144
|
+
return node;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Function: Strophe.xmlElement
|
|
148
|
+
* Create an XML DOM element.
|
|
149
|
+
*
|
|
150
|
+
* This function creates an XML DOM element correctly across all
|
|
151
|
+
* implementations. Note that these are not HTML DOM elements, which
|
|
152
|
+
* aren't appropriate for XMPP stanzas.
|
|
153
|
+
*
|
|
154
|
+
* Parameters:
|
|
155
|
+
* (String) name - The name for the element.
|
|
156
|
+
* (Array|Object) attrs - An optional array or object containing
|
|
157
|
+
* key/value pairs to use as element attributes. The object should
|
|
158
|
+
* be in the format {'key': 'value'} or {key: 'value'}. The array
|
|
159
|
+
* should have the format [['key1', 'value1'], ['key2', 'value2']].
|
|
160
|
+
* (String) text - The text child data for the element.
|
|
161
|
+
*
|
|
162
|
+
* Returns:
|
|
163
|
+
* A new XML DOM element.
|
|
164
|
+
*/
|
|
165
|
+
export function xmlElement (name) {
|
|
166
|
+
if (!name) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const node = xmlGenerator().createElement(name);
|
|
171
|
+
// FIXME: this should throw errors if args are the wrong type or
|
|
172
|
+
// there are more than two optional args
|
|
173
|
+
for (let a = 1; a < arguments.length; a++) {
|
|
174
|
+
const arg = arguments[a];
|
|
175
|
+
if (!arg) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (typeof arg === 'string' || typeof arg === 'number') {
|
|
179
|
+
node.appendChild(xmlTextNode(arg));
|
|
180
|
+
} else if (typeof arg === 'object' && typeof arg.sort === 'function') {
|
|
181
|
+
for (let i = 0; i < arg.length; i++) {
|
|
182
|
+
const attr = arg[i];
|
|
183
|
+
if (
|
|
184
|
+
typeof attr === 'object' &&
|
|
185
|
+
typeof attr.sort === 'function' &&
|
|
186
|
+
attr[1] !== undefined &&
|
|
187
|
+
attr[1] !== null
|
|
188
|
+
) {
|
|
189
|
+
node.setAttribute(attr[0], attr[1]);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
} else if (typeof arg === 'object') {
|
|
193
|
+
for (const k in arg) {
|
|
194
|
+
if (Object.prototype.hasOwnProperty.call(arg, k) && arg[k] !== undefined && arg[k] !== null) {
|
|
195
|
+
node.setAttribute(k, arg[k]);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return node;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Function: Strophe.XHTML.validTag
|
|
204
|
+
*
|
|
205
|
+
* Utility method to determine whether a tag is allowed
|
|
206
|
+
* in the XHTML_IM namespace.
|
|
207
|
+
*
|
|
208
|
+
* XHTML tag names are case sensitive and must be lower case.
|
|
209
|
+
*/
|
|
210
|
+
export function validTag (tag) {
|
|
211
|
+
for (let i = 0; i < XHTML.tags.length; i++) {
|
|
212
|
+
if (tag === XHTML.tags[i]) {
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Function: Strophe.XHTML.validAttribute
|
|
220
|
+
*
|
|
221
|
+
* Utility method to determine whether an attribute is allowed
|
|
222
|
+
* as recommended per XEP-0071
|
|
223
|
+
*
|
|
224
|
+
* XHTML attribute names are case sensitive and must be lower case.
|
|
225
|
+
*/
|
|
226
|
+
export function validAttribute (tag, attribute) {
|
|
227
|
+
if (typeof XHTML.attributes[tag] !== 'undefined' && XHTML.attributes[tag].length > 0) {
|
|
228
|
+
for (let i = 0; i < XHTML.attributes[tag].length; i++) {
|
|
229
|
+
if (attribute === XHTML.attributes[tag][i]) {
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Function: Strophe.XHTML.validCSS */
|
|
238
|
+
export function validCSS (style) {
|
|
239
|
+
for (let i = 0; i < XHTML.css.length; i++) {
|
|
240
|
+
if (style === XHTML.css[i]) {
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** Function: Strophe.createHtml
|
|
248
|
+
*
|
|
249
|
+
* Copy an HTML DOM element into an XML DOM.
|
|
250
|
+
*
|
|
251
|
+
* This function copies a DOM element and all its descendants and returns
|
|
252
|
+
* the new copy.
|
|
253
|
+
*
|
|
254
|
+
* Parameters:
|
|
255
|
+
* (HTMLElement) elem - A DOM element.
|
|
256
|
+
*
|
|
257
|
+
* Returns:
|
|
258
|
+
* A new, copied DOM element tree.
|
|
259
|
+
*/
|
|
260
|
+
export function createHtml (elem) {
|
|
261
|
+
let el;
|
|
262
|
+
if (elem.nodeType === ElementType.NORMAL) {
|
|
263
|
+
const tag = elem.nodeName.toLowerCase(); // XHTML tags must be lower case.
|
|
264
|
+
if (XHTML.validTag(tag)) {
|
|
265
|
+
try {
|
|
266
|
+
el = xmlElement(tag);
|
|
267
|
+
for (let i = 0; i < XHTML.attributes[tag].length; i++) {
|
|
268
|
+
const attribute = XHTML.attributes[tag][i];
|
|
269
|
+
let value = elem.getAttribute(attribute);
|
|
270
|
+
if (
|
|
271
|
+
typeof value === 'undefined' ||
|
|
272
|
+
value === null ||
|
|
273
|
+
value === '' ||
|
|
274
|
+
value === false ||
|
|
275
|
+
value === 0
|
|
276
|
+
) {
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
if (attribute === 'style' && typeof value === 'object' && typeof value.cssText !== 'undefined') {
|
|
280
|
+
value = value.cssText; // we're dealing with IE, need to get CSS out
|
|
281
|
+
}
|
|
282
|
+
// filter out invalid css styles
|
|
283
|
+
if (attribute === 'style') {
|
|
284
|
+
const css = [];
|
|
285
|
+
const cssAttrs = value.split(';');
|
|
286
|
+
for (let j = 0; j < cssAttrs.length; j++) {
|
|
287
|
+
const attr = cssAttrs[j].split(':');
|
|
288
|
+
const cssName = attr[0].replace(/^\s*/, '').replace(/\s*$/, '').toLowerCase();
|
|
289
|
+
if (validCSS(cssName)) {
|
|
290
|
+
const cssValue = attr[1].replace(/^\s*/, '').replace(/\s*$/, '');
|
|
291
|
+
css.push(cssName + ': ' + cssValue);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (css.length > 0) {
|
|
295
|
+
value = css.join('; ');
|
|
296
|
+
el.setAttribute(attribute, value);
|
|
297
|
+
}
|
|
298
|
+
} else {
|
|
299
|
+
el.setAttribute(attribute, value);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
for (let i = 0; i < elem.childNodes.length; i++) {
|
|
303
|
+
el.appendChild(createHtml(elem.childNodes[i]));
|
|
304
|
+
}
|
|
305
|
+
} catch (e) {
|
|
306
|
+
// invalid elements
|
|
307
|
+
el = xmlTextNode('');
|
|
308
|
+
}
|
|
309
|
+
} else {
|
|
310
|
+
el = xmlGenerator().createDocumentFragment();
|
|
311
|
+
for (let i = 0; i < elem.childNodes.length; i++) {
|
|
312
|
+
el.appendChild(createHtml(elem.childNodes[i]));
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
} else if (elem.nodeType === ElementType.FRAGMENT) {
|
|
316
|
+
el = xmlGenerator().createDocumentFragment();
|
|
317
|
+
for (let i = 0; i < elem.childNodes.length; i++) {
|
|
318
|
+
el.appendChild(createHtml(elem.childNodes[i]));
|
|
319
|
+
}
|
|
320
|
+
} else if (elem.nodeType === ElementType.TEXT) {
|
|
321
|
+
el = xmlTextNode(elem.nodeValue);
|
|
322
|
+
}
|
|
323
|
+
return el;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** Function: Strophe.copyElement
|
|
327
|
+
* Copy an XML DOM element.
|
|
328
|
+
*
|
|
329
|
+
* This function copies a DOM element and all its descendants and returns
|
|
330
|
+
* the new copy.
|
|
331
|
+
*
|
|
332
|
+
* Parameters:
|
|
333
|
+
* (XMLElement) elem - A DOM element.
|
|
334
|
+
*
|
|
335
|
+
* Returns:
|
|
336
|
+
* A new, copied DOM element tree.
|
|
337
|
+
*/
|
|
338
|
+
export function copyElement (elem) {
|
|
339
|
+
let el;
|
|
340
|
+
if (elem.nodeType === ElementType.NORMAL) {
|
|
341
|
+
el = xmlElement(elem.tagName);
|
|
342
|
+
|
|
343
|
+
for (let i = 0; i < elem.attributes.length; i++) {
|
|
344
|
+
el.setAttribute(elem.attributes[i].nodeName, elem.attributes[i].value);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
for (let i = 0; i < elem.childNodes.length; i++) {
|
|
348
|
+
el.appendChild(copyElement(elem.childNodes[i]));
|
|
349
|
+
}
|
|
350
|
+
} else if (elem.nodeType === ElementType.TEXT) {
|
|
351
|
+
el = xmlGenerator().createTextNode(elem.nodeValue);
|
|
352
|
+
}
|
|
353
|
+
return el;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/* Function: Strophe.xmlescape
|
|
357
|
+
* Excapes invalid xml characters.
|
|
358
|
+
*
|
|
359
|
+
* Parameters:
|
|
360
|
+
* (String) text - text to escape.
|
|
361
|
+
*
|
|
362
|
+
* Returns:
|
|
363
|
+
* Escaped text.
|
|
364
|
+
*/
|
|
365
|
+
export function xmlescape (text) {
|
|
366
|
+
text = text.replace(/\&/g, '&');
|
|
367
|
+
text = text.replace(/</g, '<');
|
|
368
|
+
text = text.replace(/>/g, '>');
|
|
369
|
+
text = text.replace(/'/g, ''');
|
|
370
|
+
text = text.replace(/"/g, '"');
|
|
371
|
+
return text;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/* Function: Strophe.xmlunescape
|
|
375
|
+
* Unexcapes invalid xml characters.
|
|
376
|
+
*
|
|
377
|
+
* Parameters:
|
|
378
|
+
* (String) text - text to unescape.
|
|
379
|
+
*
|
|
380
|
+
* Returns:
|
|
381
|
+
* Unescaped text.
|
|
382
|
+
*/
|
|
383
|
+
export function xmlunescape (text) {
|
|
384
|
+
text = text.replace(/\&/g, '&');
|
|
385
|
+
text = text.replace(/</g, '<');
|
|
386
|
+
text = text.replace(/>/g, '>');
|
|
387
|
+
text = text.replace(/'/g, "'");
|
|
388
|
+
text = text.replace(/"/g, '"');
|
|
389
|
+
return text;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** Function: Strophe.serialize
|
|
393
|
+
* Render a DOM element and all descendants to a String.
|
|
394
|
+
*
|
|
395
|
+
* Parameters:
|
|
396
|
+
* (XMLElement) elem - A DOM element.
|
|
397
|
+
*
|
|
398
|
+
* Returns:
|
|
399
|
+
* The serialized element tree as a String.
|
|
400
|
+
*/
|
|
401
|
+
export function serialize (elem) {
|
|
402
|
+
if (!elem) {
|
|
403
|
+
return null;
|
|
404
|
+
}
|
|
405
|
+
if (typeof elem.tree === 'function') {
|
|
406
|
+
elem = elem.tree();
|
|
407
|
+
}
|
|
408
|
+
const names = [...Array(elem.attributes.length).keys()].map(i => elem.attributes[i].nodeName);
|
|
409
|
+
names.sort();
|
|
410
|
+
let result = names.reduce(
|
|
411
|
+
(a, n) => `${a} ${n}="${xmlescape(elem.attributes.getNamedItem(n).value)}"`,
|
|
412
|
+
`<${elem.nodeName}`
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
if (elem.childNodes.length > 0) {
|
|
416
|
+
result += '>';
|
|
417
|
+
for (let i = 0; i < elem.childNodes.length; i++) {
|
|
418
|
+
const child = elem.childNodes[i];
|
|
419
|
+
switch (child.nodeType) {
|
|
420
|
+
case ElementType.NORMAL:
|
|
421
|
+
// normal element, so recurse
|
|
422
|
+
result += serialize(child);
|
|
423
|
+
break;
|
|
424
|
+
case ElementType.TEXT:
|
|
425
|
+
// text element to escape values
|
|
426
|
+
result += xmlescape(child.nodeValue);
|
|
427
|
+
break;
|
|
428
|
+
case ElementType.CDATA:
|
|
429
|
+
// cdata section so don't escape values
|
|
430
|
+
result += '<![CDATA[' + child.nodeValue + ']]>';
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
result += '</' + elem.nodeName + '>';
|
|
434
|
+
} else {
|
|
435
|
+
result += '/>';
|
|
436
|
+
}
|
|
437
|
+
return result;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** Function: Strophe.forEachChild
|
|
441
|
+
* Map a function over some or all child elements of a given element.
|
|
442
|
+
*
|
|
443
|
+
* This is a small convenience function for mapping a function over
|
|
444
|
+
* some or all of the children of an element. If elemName is null, all
|
|
445
|
+
* children will be passed to the function, otherwise only children
|
|
446
|
+
* whose tag names match elemName will be passed.
|
|
447
|
+
*
|
|
448
|
+
* Parameters:
|
|
449
|
+
* (XMLElement) elem - The element to operate on.
|
|
450
|
+
* (String) elemName - The child element tag name filter.
|
|
451
|
+
* (Function) func - The function to apply to each child. This
|
|
452
|
+
* function should take a single argument, a DOM element.
|
|
453
|
+
*/
|
|
454
|
+
export function forEachChild (elem, elemName, func) {
|
|
455
|
+
for (let i=0; i<elem.childNodes.length; i++) {
|
|
456
|
+
const childNode = elem.childNodes[i];
|
|
457
|
+
if (childNode.nodeType === ElementType.NORMAL &&
|
|
458
|
+
(!elemName || this.isTagEqual(childNode, elemName))) {
|
|
459
|
+
func(childNode);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/** Function: Strophe.isTagEqual
|
|
465
|
+
* Compare an element's tag name with a string.
|
|
466
|
+
*
|
|
467
|
+
* This function is case sensitive.
|
|
468
|
+
*
|
|
469
|
+
* Parameters:
|
|
470
|
+
* (XMLElement) el - A DOM element.
|
|
471
|
+
* (String) name - The element name.
|
|
472
|
+
*
|
|
473
|
+
* Returns:
|
|
474
|
+
* true if the element's tag name matches _el_, and false
|
|
475
|
+
* otherwise.
|
|
476
|
+
*/
|
|
477
|
+
export function isTagEqual (el, name) {
|
|
478
|
+
return el.tagName === name;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/** Function: Strophe.getText
|
|
482
|
+
* Get the concatenation of all text children of an element.
|
|
483
|
+
*
|
|
484
|
+
* Parameters:
|
|
485
|
+
* (XMLElement) elem - A DOM element.
|
|
486
|
+
*
|
|
487
|
+
* Returns:
|
|
488
|
+
* A String with the concatenated text of all text element children.
|
|
489
|
+
*/
|
|
490
|
+
export function getText (elem) {
|
|
491
|
+
if (!elem) { return null; }
|
|
492
|
+
|
|
493
|
+
let str = "";
|
|
494
|
+
if (elem.childNodes.length === 0 && elem.nodeType === ElementType.TEXT) {
|
|
495
|
+
str += elem.nodeValue;
|
|
496
|
+
}
|
|
497
|
+
for (let i=0; i<elem.childNodes.length; i++) {
|
|
498
|
+
if (elem.childNodes[i].nodeType === ElementType.TEXT) {
|
|
499
|
+
str += elem.childNodes[i].nodeValue;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return xmlescape(str);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/** Function: Strophe.escapeNode
|
|
506
|
+
* Escape the node part (also called local part) of a JID.
|
|
507
|
+
*
|
|
508
|
+
* Parameters:
|
|
509
|
+
* (String) node - A node (or local part).
|
|
510
|
+
*
|
|
511
|
+
* Returns:
|
|
512
|
+
* An escaped node (or local part).
|
|
513
|
+
*/
|
|
514
|
+
export function escapeNode (node) {
|
|
515
|
+
if (typeof node !== "string") { return node; }
|
|
516
|
+
return node.replace(/^\s+|\s+$/g, '')
|
|
517
|
+
.replace(/\\/g, "\\5c")
|
|
518
|
+
.replace(/ /g, "\\20")
|
|
519
|
+
.replace(/\"/g, "\\22")
|
|
520
|
+
.replace(/\&/g, "\\26")
|
|
521
|
+
.replace(/\'/g, "\\27")
|
|
522
|
+
.replace(/\//g, "\\2f")
|
|
523
|
+
.replace(/:/g, "\\3a")
|
|
524
|
+
.replace(/</g, "\\3c")
|
|
525
|
+
.replace(/>/g, "\\3e")
|
|
526
|
+
.replace(/@/g, "\\40");
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** Function: Strophe.unescapeNode
|
|
530
|
+
* Unescape a node part (also called local part) of a JID.
|
|
531
|
+
*
|
|
532
|
+
* Parameters:
|
|
533
|
+
* (String) node - A node (or local part).
|
|
534
|
+
*
|
|
535
|
+
* Returns:
|
|
536
|
+
* An unescaped node (or local part).
|
|
537
|
+
*/
|
|
538
|
+
export function unescapeNode (node) {
|
|
539
|
+
if (typeof node !== "string") { return node; }
|
|
540
|
+
return node.replace(/\\20/g, " ")
|
|
541
|
+
.replace(/\\22/g, '"')
|
|
542
|
+
.replace(/\\26/g, "&")
|
|
543
|
+
.replace(/\\27/g, "'")
|
|
544
|
+
.replace(/\\2f/g, "/")
|
|
545
|
+
.replace(/\\3a/g, ":")
|
|
546
|
+
.replace(/\\3c/g, "<")
|
|
547
|
+
.replace(/\\3e/g, ">")
|
|
548
|
+
.replace(/\\40/g, "@")
|
|
549
|
+
.replace(/\\5c/g, "\\");
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/** Function: Strophe.getNodeFromJid
|
|
553
|
+
* Get the node portion of a JID String.
|
|
554
|
+
*
|
|
555
|
+
* Parameters:
|
|
556
|
+
* (String) jid - A JID.
|
|
557
|
+
*
|
|
558
|
+
* Returns:
|
|
559
|
+
* A String containing the node.
|
|
560
|
+
*/
|
|
561
|
+
export function getNodeFromJid (jid) {
|
|
562
|
+
if (jid.indexOf("@") < 0) { return null; }
|
|
563
|
+
return jid.split("@")[0];
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/** Function: Strophe.getDomainFromJid
|
|
567
|
+
* Get the domain portion of a JID String.
|
|
568
|
+
*
|
|
569
|
+
* Parameters:
|
|
570
|
+
* (String) jid - A JID.
|
|
571
|
+
*
|
|
572
|
+
* Returns:
|
|
573
|
+
* A String containing the domain.
|
|
574
|
+
*/
|
|
575
|
+
export function getDomainFromJid (jid) {
|
|
576
|
+
const bare = getBareJidFromJid(jid);
|
|
577
|
+
if (bare.indexOf("@") < 0) {
|
|
578
|
+
return bare;
|
|
579
|
+
} else {
|
|
580
|
+
const parts = bare.split("@");
|
|
581
|
+
parts.splice(0, 1);
|
|
582
|
+
return parts.join('@');
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/** Function: Strophe.getResourceFromJid
|
|
587
|
+
* Get the resource portion of a JID String.
|
|
588
|
+
*
|
|
589
|
+
* Parameters:
|
|
590
|
+
* (String) jid - A JID.
|
|
591
|
+
*
|
|
592
|
+
* Returns:
|
|
593
|
+
* A String containing the resource.
|
|
594
|
+
*/
|
|
595
|
+
export function getResourceFromJid (jid) {
|
|
596
|
+
if (!jid) { return null; }
|
|
597
|
+
const s = jid.split("/");
|
|
598
|
+
if (s.length < 2) { return null; }
|
|
599
|
+
s.splice(0, 1);
|
|
600
|
+
return s.join('/');
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/** Function: Strophe.getBareJidFromJid
|
|
604
|
+
* Get the bare JID from a JID String.
|
|
605
|
+
*
|
|
606
|
+
* Parameters:
|
|
607
|
+
* (String) jid - A JID.
|
|
608
|
+
*
|
|
609
|
+
* Returns:
|
|
610
|
+
* A String containing the bare JID.
|
|
611
|
+
*/
|
|
612
|
+
export function getBareJidFromJid (jid) {
|
|
613
|
+
return jid ? jid.split("/")[0] : null;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
const utils = {
|
|
618
|
+
utf16to8,
|
|
619
|
+
xorArrayBuffers,
|
|
620
|
+
arrayBufToBase64,
|
|
621
|
+
base64ToArrayBuf,
|
|
622
|
+
stringToArrayBuf,
|
|
623
|
+
addCookies,
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
export { utils as default };
|