angelia.io 1.64.0 → 1.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client/index.js CHANGED
@@ -240,20 +240,18 @@ class Client {
240
240
  }
241
241
 
242
242
  const io = new Worker(
243
- URL.createObjectURL(
244
- new Blob(["'use strict';new (" + ClientWebWorker + ')']),
245
- {
246
- type: 'application/javascript; charset=utf-8',
247
- },
248
- ),
243
+ URL.createObjectURL(new Blob(["'use strict';new (" + ClientWebWorker + ')']), {
244
+ type: 'application/javascript; charset=utf-8',
245
+ }),
249
246
  )
247
+ let shouldConnect = options.dontConnect !== undefined ? !options.dontConnect : true
250
248
 
251
249
  Object.assign(this, {
252
250
  url: options.url,
253
251
  params: options.params,
254
252
  longLiveFlash: options.longLiveFlash,
255
-
256
- connected: true,
253
+ shouldConnect: shouldConnect,
254
+ connected: shouldConnect,
257
255
  messages: [],
258
256
  listeners: {
259
257
  '': [this.oncallback.bind(this)],
@@ -277,7 +275,7 @@ class Client {
277
275
  window.addEventListener('unload', () => this.disconnect(true), true)
278
276
 
279
277
  // to send messages fast without waiting for the connection
280
- Promise.resolve().then(() => this.connect())
278
+ shouldConnect && Promise.resolve().then(() => this.connect())
281
279
  }
282
280
 
283
281
  // public API
@@ -317,28 +315,16 @@ class Client {
317
315
  this.listeners[k].push(v)
318
316
  return () => this.off(k, v)
319
317
  } else {
320
- console.error(
321
- 'ws - socket.on("' +
322
- k +
323
- '", callback) key and callback cannot be empty',
324
- )
318
+ console.error('ws - socket.on("' + k + '", callback) key and callback cannot be empty')
325
319
  }
326
320
  }
327
321
  off(k, v) {
328
322
  if (!this.listeners[k]) {
329
- console.error(
330
- 'ws - socket.off("' + k + '", callback)',
331
- k,
332
- 'key not found',
333
- )
323
+ console.error('ws - socket.off("' + k + '", callback)', k, 'key not found')
334
324
  } else {
335
325
  let i = this.listeners[k].indexOf(v)
336
326
  if (i === -1) {
337
- console.error(
338
- 'ws - socket.off("' + k + '", callback)',
339
- v,
340
- 'callback not found',
341
- )
327
+ console.error('ws - socket.off("' + k + '", callback)', v, 'callback not found')
342
328
  } else {
343
329
  this.listeners[k].splice(i, 1)
344
330
  }
@@ -410,7 +396,7 @@ class Client {
410
396
  break
411
397
  }
412
398
  case 'connect': {
413
- this.connect()
399
+ if (this.shouldConnect) this.connect()
414
400
  break
415
401
  }
416
402
  case 'connected': {
@@ -419,10 +405,10 @@ class Client {
419
405
  }
420
406
  }
421
407
  }
422
- decode(s){
408
+ decode(s) {
423
409
  if (s.b) {
424
410
  return fetch(s.b).then(r => r.blob())
425
- } else if(s.a) {
411
+ } else if (s.a) {
426
412
  return fetch(s.a).then(r => r.arrayBuffer())
427
413
  }
428
414
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "angelia.io",
3
- "version": "1.64.0",
3
+ "version": "1.67.0",
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": {
@@ -32,7 +32,7 @@
32
32
  "isobject": "^4.0.0",
33
33
  "to-fast-properties": "^3.0.1",
34
34
  "utf-8-validate": "^5.0.4",
35
- "ws": "^7.4.3"
35
+ "ws": "^7.x.x"
36
36
  },
37
37
  "prettier": {
38
38
  "printWidth": 100,
package/readme.md CHANGED
@@ -85,13 +85,15 @@ const server = new Server.listen({
85
85
  })
86
86
  ```
87
87
 
88
- | name | kind | default | description |
89
- | ---------------- | ------ | ------- | --------------------------------------------------- |
90
- | `hostname` | String | '' | the hostname if any |
91
- | `port` | Number | 3001 | the port to use for this server |
92
- | `maxMessageSize` | Number | 5 | max size in mb of a message received |
93
- | `cert` | String | '' | path to the cert file for using https fullchain.pem |
94
- | `key` | String | '' | path to the key file for using https privkey.pem |
88
+ | name | kind | default | description |
89
+ | -------------------- | ------- | ------- | --------------------------------------------------- |
90
+ | `hostname` | String | '' | the hostname if any |
91
+ | `port` | Number | 3001 | the port to use for this server |
92
+ | `maxMessageSize` | Number | 5 | max size in mb of a message received |
93
+ | `skipUTF8Validation` | Boolean | false | allows to skip utf8 validation |
94
+ | `dontConnect` | Boolean | false | allows to instance the socket without connecting |
95
+ | `cert` | String | '' | path to the cert file for using https fullchain.pem |
96
+ | `key` | String | '' | path to the key file for using https privkey.pem |
95
97
 
96
98
  ### Server Object
97
99
 
package/server/Server.js CHANGED
@@ -78,10 +78,7 @@ class ServerSingleton {
78
78
  },
79
79
  })
80
80
 
81
- this.pingData = this.WebSocket.Sender.frame(
82
- Buffer.from(''),
83
- this.WebSocketFrame,
84
- )
81
+ this.pingData = this.WebSocket.Sender.frame(Buffer.from(''), this.WebSocketFrame)
85
82
  this.disconnectData = this.WebSocket.Sender.frame(
86
83
  Buffer.from(JSON.stringify([['disconnect', true]])),
87
84
  this.WebSocketFrame,
@@ -90,13 +87,9 @@ class ServerSingleton {
90
87
 
91
88
  listen(options) {
92
89
  Object.assign(this, {
93
- port:
94
- +options.port > 0 && +options.port <= 65535 ? +options.port : this.port,
90
+ port: +options.port > 0 && +options.port <= 65535 ? +options.port : this.port,
95
91
  hostname: options.hostname || this.hostname,
96
- maxMessageSize:
97
- +options.maxMessageSize > 0
98
- ? +options.maxMessageSize
99
- : this.maxMessageSize,
92
+ maxMessageSize: +options.maxMessageSize > 0 ? +options.maxMessageSize : this.maxMessageSize,
100
93
  cert: options.cert || this.cert,
101
94
  key: options.key || this.key,
102
95
 
@@ -135,6 +128,8 @@ class ServerSingleton {
135
128
  maxPayload: this.maxMessageSize * 1024 * 1024,
136
129
  clientTracking: false,
137
130
  backlog: 1024,
131
+ skipUTF8Validation:
132
+ options.skipUTF8Validation !== undefined ? options.skipUTF8Validation : false,
138
133
  })
139
134
 
140
135
  io.on('connection', this.onconnect)
@@ -229,9 +224,7 @@ class ServerSingleton {
229
224
  Object.assign(socket, {
230
225
  ip: (
231
226
  this.ip(request.connection.remoteAddress) ||
232
- this.ip(
233
- (request.headers['x-forwarded-for'] || '').split(/\s*,\s*/)[0],
234
- ) ||
227
+ this.ip((request.headers['x-forwarded-for'] || '').split(/\s*,\s*/)[0]) ||
235
228
  request.connection.remoteAddress ||
236
229
  (request.headers['x-forwarded-for'] || '').split(/\s*,\s*/)[0]
237
230
  ).replace(/^::ffff:/, ''),
@@ -287,10 +280,7 @@ class ServerSingleton {
287
280
  let json = JSON.stringify(messages)
288
281
  this.bytesSent += json.length
289
282
  socket.bytesSent += json.length
290
- this.cache[id] = this.WebSocket.Sender.frame(
291
- Buffer.from(json),
292
- this.WebSocketFrame,
293
- )
283
+ this.cache[id] = this.WebSocket.Sender.frame(Buffer.from(json), this.WebSocketFrame)
294
284
  } else {
295
285
  this.messagesSentCacheHit++
296
286
  }
@@ -349,12 +339,8 @@ class ServerSingleton {
349
339
  if (
350
340
  /^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(i) ||
351
341
  /^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(i) ||
352
- /^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(
353
- i,
354
- ) ||
355
- /^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(
356
- i,
357
- ) ||
342
+ /^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(i) ||
343
+ /^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(i) ||
358
344
  /^(::f{4}:)?169\.254\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(i) ||
359
345
  /^f[cd][0-9a-f]{2}:/i.test(i) ||
360
346
  /^fe80:/i.test(i)
@@ -472,10 +458,7 @@ class ServerSingleton {
472
458
  // classes
473
459
  console.log('this.events', this.HasFastProperties(this.events.classes))
474
460
  for (let m in this.events.classes) {
475
- console.log(
476
- 'this.events.' + m,
477
- this.HasFastProperties(this.events.classes[m]),
478
- )
461
+ console.log('this.events.' + m, this.HasFastProperties(this.events.classes[m]))
479
462
  // class
480
463
  for (let f in this.events.classes[m]) {
481
464
  // methods