angelia.io 2.4.78 → 2.4.79
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/client/index.js +48 -12
- package/index.js +1 -1
- package/package.json +7 -5
- package/publish.bat +1 -13
- package/server/Listeners.js +7 -3
- package/server/Server.js +55 -16
- package/server/Socket.js +2 -1
package/client/index.js
CHANGED
|
@@ -50,7 +50,10 @@ class ClientWebWorker {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
connect(options) {
|
|
53
|
-
if (
|
|
53
|
+
if (
|
|
54
|
+
this.reconnect &&
|
|
55
|
+
(!this.io || this.io.readyState === WebSocket.CLOSED)
|
|
56
|
+
) {
|
|
54
57
|
let url = new URL(options.url)
|
|
55
58
|
|
|
56
59
|
// parms creation
|
|
@@ -65,9 +68,17 @@ class ClientWebWorker {
|
|
|
65
68
|
}
|
|
66
69
|
url.search = Object.entries(params)
|
|
67
70
|
.filter(([k, v]) => {
|
|
68
|
-
return !(
|
|
71
|
+
return !(
|
|
72
|
+
k === undefined ||
|
|
73
|
+
k === null ||
|
|
74
|
+
v === undefined ||
|
|
75
|
+
v === null
|
|
76
|
+
)
|
|
69
77
|
})
|
|
70
|
-
.map(
|
|
78
|
+
.map(
|
|
79
|
+
([k, v]) =>
|
|
80
|
+
encodeURIComponent(k) + '=' + encodeURIComponent(v),
|
|
81
|
+
)
|
|
71
82
|
.join('&')
|
|
72
83
|
|
|
73
84
|
url = url.toString()
|
|
@@ -232,11 +243,17 @@ class Client {
|
|
|
232
243
|
}
|
|
233
244
|
|
|
234
245
|
const io = new Worker(
|
|
235
|
-
URL.createObjectURL(
|
|
236
|
-
|
|
237
|
-
|
|
246
|
+
URL.createObjectURL(
|
|
247
|
+
new Blob(
|
|
248
|
+
["'use strict';new (" + ClientWebWorker.toString() + ')'],
|
|
249
|
+
{
|
|
250
|
+
type: 'application/javascript; charset=utf-8',
|
|
251
|
+
},
|
|
252
|
+
),
|
|
253
|
+
),
|
|
238
254
|
)
|
|
239
|
-
let shouldConnect =
|
|
255
|
+
let shouldConnect =
|
|
256
|
+
options.dontConnect !== undefined ? !options.dontConnect : true
|
|
240
257
|
|
|
241
258
|
Object.assign(this, {
|
|
242
259
|
url: options.url,
|
|
@@ -264,7 +281,11 @@ class Client {
|
|
|
264
281
|
this.on('disconnect', this.disconnect)
|
|
265
282
|
|
|
266
283
|
// to try to close the connection nicely
|
|
267
|
-
window.addEventListener(
|
|
284
|
+
window.addEventListener(
|
|
285
|
+
'unload',
|
|
286
|
+
() => this.disconnect(true),
|
|
287
|
+
true,
|
|
288
|
+
)
|
|
268
289
|
|
|
269
290
|
// to send messages fast without waiting for the connection
|
|
270
291
|
shouldConnect && this.connect()
|
|
@@ -277,7 +298,10 @@ class Client {
|
|
|
277
298
|
'connect',
|
|
278
299
|
{
|
|
279
300
|
url: this.url,
|
|
280
|
-
params:
|
|
301
|
+
params:
|
|
302
|
+
typeof this.params === 'function'
|
|
303
|
+
? this.params() || {}
|
|
304
|
+
: {},
|
|
281
305
|
},
|
|
282
306
|
])
|
|
283
307
|
}
|
|
@@ -307,16 +331,28 @@ class Client {
|
|
|
307
331
|
this.listeners[k].push(v)
|
|
308
332
|
return () => this.off(k, v)
|
|
309
333
|
} else {
|
|
310
|
-
console.error(
|
|
334
|
+
console.error(
|
|
335
|
+
'ws - socket.on("' +
|
|
336
|
+
k +
|
|
337
|
+
'", callback) key and callback cannot be empty',
|
|
338
|
+
)
|
|
311
339
|
}
|
|
312
340
|
}
|
|
313
341
|
off(k, v) {
|
|
314
342
|
if (!this.listeners[k]) {
|
|
315
|
-
console.error(
|
|
343
|
+
console.error(
|
|
344
|
+
'ws - socket.off("' + k + '", callback)',
|
|
345
|
+
k,
|
|
346
|
+
'key not found',
|
|
347
|
+
)
|
|
316
348
|
} else {
|
|
317
349
|
let i = this.listeners[k].indexOf(v)
|
|
318
350
|
if (i === -1) {
|
|
319
|
-
console.error(
|
|
351
|
+
console.error(
|
|
352
|
+
'ws - socket.off("' + k + '", callback)',
|
|
353
|
+
v,
|
|
354
|
+
'callback not found',
|
|
355
|
+
)
|
|
320
356
|
} else {
|
|
321
357
|
this.listeners[k].splice(i, 1)
|
|
322
358
|
}
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "angelia.io",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.79",
|
|
4
4
|
"description": "WebSockets Server and Client API for node.js and the browser, with rooms support.",
|
|
5
5
|
"homepage": "https://github.com/titoBouzout/angelia.io",
|
|
6
6
|
"repository": {
|
|
@@ -35,16 +35,18 @@
|
|
|
35
35
|
"ws": "^7.x.x"
|
|
36
36
|
},
|
|
37
37
|
"prettier": {
|
|
38
|
-
"printWidth":
|
|
38
|
+
"printWidth": 70,
|
|
39
39
|
"useTabs": true,
|
|
40
40
|
"semi": false,
|
|
41
41
|
"singleQuote": true,
|
|
42
|
+
"quoteProps": "as-needed",
|
|
42
43
|
"jsxSingleQuote": false,
|
|
43
44
|
"trailingComma": "all",
|
|
44
45
|
"bracketSpacing": true,
|
|
45
|
-
"
|
|
46
|
+
"bracketSameLine": false,
|
|
46
47
|
"arrowParens": "avoid",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
48
|
+
"proseWrap": "never",
|
|
49
|
+
"endOfLine": "lf",
|
|
50
|
+
"singleAttributePerLine": true
|
|
49
51
|
}
|
|
50
52
|
}
|
package/publish.bat
CHANGED
package/server/Listeners.js
CHANGED
|
@@ -135,12 +135,14 @@ class Listeners {
|
|
|
135
135
|
// isobject <https://github.com/jonschlinkert/isobject>
|
|
136
136
|
// MIT license - Copyright (c) 2014-2017, Jon Schlinkert.
|
|
137
137
|
isObject(o) {
|
|
138
|
-
return
|
|
138
|
+
return (
|
|
139
|
+
o != null && typeof o === 'object' && Array.isArray(o) === false
|
|
140
|
+
)
|
|
139
141
|
}
|
|
140
142
|
// is-class <https://github.com/miguelmota/is-class>
|
|
141
143
|
// MIT license - Copyright (C) 2014 Miguel Mota
|
|
142
144
|
isClass() {
|
|
143
|
-
;(function(root) {
|
|
145
|
+
;(function (root) {
|
|
144
146
|
const toString = Function.prototype.toString
|
|
145
147
|
|
|
146
148
|
function fnBody(fn) {
|
|
@@ -163,7 +165,9 @@ class Listeners {
|
|
|
163
165
|
const body = fnBody(fn)
|
|
164
166
|
return (
|
|
165
167
|
/classCallCheck\(/.test(body) ||
|
|
166
|
-
/TypeError\("Cannot call a class as a function"\)/.test(
|
|
168
|
+
/TypeError\("Cannot call a class as a function"\)/.test(
|
|
169
|
+
body,
|
|
170
|
+
)
|
|
167
171
|
)
|
|
168
172
|
}
|
|
169
173
|
})(Listeners.prototype)
|
package/server/Server.js
CHANGED
|
@@ -79,7 +79,10 @@ class ServerSingleton {
|
|
|
79
79
|
},
|
|
80
80
|
})
|
|
81
81
|
|
|
82
|
-
this.pingData = this.WebSocket.Sender.frame(
|
|
82
|
+
this.pingData = this.WebSocket.Sender.frame(
|
|
83
|
+
Buffer.from(''),
|
|
84
|
+
this.WebSocketFrame,
|
|
85
|
+
)
|
|
83
86
|
this.disconnectData = this.WebSocket.Sender.frame(
|
|
84
87
|
Buffer.from(JSON.stringify([['disconnect', true]])),
|
|
85
88
|
this.WebSocketFrame,
|
|
@@ -88,16 +91,23 @@ class ServerSingleton {
|
|
|
88
91
|
|
|
89
92
|
listen(options) {
|
|
90
93
|
Object.assign(this, {
|
|
91
|
-
port:
|
|
94
|
+
port:
|
|
95
|
+
+options.port > 0 && +options.port <= 65535
|
|
96
|
+
? +options.port
|
|
97
|
+
: this.port,
|
|
92
98
|
hostname: options.hostname || this.hostname,
|
|
93
|
-
maxMessageSize:
|
|
99
|
+
maxMessageSize:
|
|
100
|
+
+options.maxMessageSize > 0
|
|
101
|
+
? +options.maxMessageSize
|
|
102
|
+
: this.maxMessageSize,
|
|
94
103
|
cert: options.cert || this.cert,
|
|
95
104
|
key: options.key || this.key,
|
|
96
105
|
http: options.http || this.http,
|
|
97
106
|
|
|
98
107
|
since: Date.now(),
|
|
99
108
|
now: Date.now(),
|
|
100
|
-
timeout:
|
|
109
|
+
timeout:
|
|
110
|
+
+options.timeout >= 10000 ? +options.timeout : this.timeout,
|
|
101
111
|
})
|
|
102
112
|
this.timeoutCheck = this.timeout / 2
|
|
103
113
|
|
|
@@ -134,7 +144,9 @@ class ServerSingleton {
|
|
|
134
144
|
clientTracking: false,
|
|
135
145
|
backlog: 1024,
|
|
136
146
|
skipUTF8Validation:
|
|
137
|
-
options.skipUTF8Validation !== undefined
|
|
147
|
+
options.skipUTF8Validation !== undefined
|
|
148
|
+
? options.skipUTF8Validation
|
|
149
|
+
: false,
|
|
138
150
|
})
|
|
139
151
|
|
|
140
152
|
io.on('connection', this.onconnect)
|
|
@@ -212,7 +224,11 @@ class ServerSingleton {
|
|
|
212
224
|
Object.assign(socket, {
|
|
213
225
|
ip: (
|
|
214
226
|
this.ip(request.connection.remoteAddress) ||
|
|
215
|
-
this.ip(
|
|
227
|
+
this.ip(
|
|
228
|
+
(request.headers['x-forwarded-for'] || '').split(
|
|
229
|
+
/\s*,\s*/,
|
|
230
|
+
)[0],
|
|
231
|
+
) ||
|
|
216
232
|
request.connection.remoteAddress ||
|
|
217
233
|
(request.headers['x-forwarded-for'] || '').split(/\s*,\s*/)[0]
|
|
218
234
|
).replace(/^::ffff:/, ''),
|
|
@@ -268,7 +284,10 @@ class ServerSingleton {
|
|
|
268
284
|
let json = JSON.stringify(messages)
|
|
269
285
|
this.bytesSent += json.length
|
|
270
286
|
socket.bytesSent += json.length
|
|
271
|
-
this.cache[id] = this.WebSocket.Sender.frame(
|
|
287
|
+
this.cache[id] = this.WebSocket.Sender.frame(
|
|
288
|
+
Buffer.from(json),
|
|
289
|
+
this.WebSocketFrame,
|
|
290
|
+
)
|
|
272
291
|
} else {
|
|
273
292
|
this.messagesSentCacheHit++
|
|
274
293
|
}
|
|
@@ -286,7 +305,8 @@ class ServerSingleton {
|
|
|
286
305
|
if (delay > this.timeout) {
|
|
287
306
|
// timedout
|
|
288
307
|
socket.timedout = true
|
|
289
|
-
this.events.timeout &&
|
|
308
|
+
this.events.timeout &&
|
|
309
|
+
this.events.timeout(socket.proxy, delay)
|
|
290
310
|
socket.io.terminate()
|
|
291
311
|
} else if (delay > this.timeoutCheck - 5000) {
|
|
292
312
|
/*
|
|
@@ -335,11 +355,21 @@ class ServerSingleton {
|
|
|
335
355
|
}
|
|
336
356
|
default: {
|
|
337
357
|
if (
|
|
338
|
-
/^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
/^(::f{4}:)?
|
|
342
|
-
|
|
358
|
+
/^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(
|
|
359
|
+
i,
|
|
360
|
+
) ||
|
|
361
|
+
/^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(
|
|
362
|
+
i,
|
|
363
|
+
) ||
|
|
364
|
+
/^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(
|
|
365
|
+
i,
|
|
366
|
+
) ||
|
|
367
|
+
/^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(
|
|
368
|
+
i,
|
|
369
|
+
) ||
|
|
370
|
+
/^(::f{4}:)?169\.254\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(
|
|
371
|
+
i,
|
|
372
|
+
) ||
|
|
343
373
|
/^f[cd][0-9a-f]{2}:/i.test(i) ||
|
|
344
374
|
/^fe80:/i.test(i)
|
|
345
375
|
)
|
|
@@ -441,7 +471,10 @@ class ServerSingleton {
|
|
|
441
471
|
// listeners
|
|
442
472
|
for (let l in this.events) {
|
|
443
473
|
// listener
|
|
444
|
-
console.log(
|
|
474
|
+
console.log(
|
|
475
|
+
'this.events.' + l,
|
|
476
|
+
this.HasFastProperties(this.events[l]),
|
|
477
|
+
)
|
|
445
478
|
// methods
|
|
446
479
|
if (this.events[l].fns) {
|
|
447
480
|
for (let m in this.events[l].fns) {
|
|
@@ -454,9 +487,15 @@ class ServerSingleton {
|
|
|
454
487
|
}
|
|
455
488
|
|
|
456
489
|
// classes
|
|
457
|
-
console.log(
|
|
490
|
+
console.log(
|
|
491
|
+
'this.events',
|
|
492
|
+
this.HasFastProperties(this.events.classes),
|
|
493
|
+
)
|
|
458
494
|
for (let m in this.events.classes) {
|
|
459
|
-
console.log(
|
|
495
|
+
console.log(
|
|
496
|
+
'this.events.' + m,
|
|
497
|
+
this.HasFastProperties(this.events.classes[m]),
|
|
498
|
+
)
|
|
460
499
|
// class
|
|
461
500
|
for (let f in this.events.classes[m]) {
|
|
462
501
|
// methods
|
package/server/Socket.js
CHANGED