angelia.io 2.4.78 → 3.4.80

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
@@ -50,7 +50,10 @@ class ClientWebWorker {
50
50
  }
51
51
 
52
52
  connect(options) {
53
- if (this.reconnect && (!this.io || this.io.readyState === WebSocket.CLOSED)) {
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 !(k === undefined || k === null || v === undefined || v === null)
71
+ return !(
72
+ k === undefined ||
73
+ k === null ||
74
+ v === undefined ||
75
+ v === null
76
+ )
69
77
  })
70
- .map(([k, v]) => encodeURIComponent(k) + '=' + encodeURIComponent(v))
78
+ .map(
79
+ ([k, v]) =>
80
+ encodeURIComponent(k) + '=' + encodeURIComponent(v),
81
+ )
71
82
  .join('&')
72
83
 
73
84
  url = url.toString()
@@ -216,7 +227,7 @@ class ClientWebWorker {
216
227
  }
217
228
  }
218
229
 
219
- class Client {
230
+ export class Client {
220
231
  constructor(options) {
221
232
  if (!options || typeof options === 'string') {
222
233
  options = {
@@ -232,11 +243,17 @@ class Client {
232
243
  }
233
244
 
234
245
  const io = new Worker(
235
- URL.createObjectURL(new Blob(["'use strict';new (" + ClientWebWorker.toString() + ')']), {
236
- type: 'application/javascript; charset=utf-8',
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 = options.dontConnect !== undefined ? !options.dontConnect : true
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('unload', () => this.disconnect(true), true)
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: typeof this.params === 'function' ? this.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('ws - socket.on("' + k + '", callback) key and callback cannot be empty')
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('ws - socket.off("' + k + '", callback)', k, 'key not found')
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('ws - socket.off("' + k + '", callback)', v, 'callback not found')
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
  }
@@ -405,18 +441,3 @@ class Client {
405
441
  }
406
442
  }
407
443
  }
408
-
409
- ;(function (root) {
410
- if (typeof exports !== 'undefined') {
411
- if (typeof module !== 'undefined' && module.exports) {
412
- exports = module.exports = Client
413
- }
414
- exports.Client = Client
415
- } else if (typeof define === 'function' && define.amd) {
416
- define([], function () {
417
- return Client
418
- })
419
- } else {
420
- root.Client = Client
421
- }
422
- })(this)
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
- module.exports = function() {
2
- throw new Error(`
1
+ throw new Error(`
3
2
  Usage on Server:
4
3
  import Server from 'angelia.io/server'
5
4
 
@@ -8,4 +7,3 @@ import Client from 'angelia.io/client'
8
7
 
9
8
  See readme: https://github.com/titoBouzout/angelia.io
10
9
  `)
11
- }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "angelia.io",
3
- "version": "2.4.78",
3
+ "version": "3.4.80",
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": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/titoBouzout/angelia.io"
9
9
  },
10
+ "type": "module",
10
11
  "main": "index.js",
11
12
  "keywords": [
12
13
  "Client",
@@ -32,19 +33,21 @@
32
33
  "isobject": "^4.0.0",
33
34
  "to-fast-properties": "^3.0.1",
34
35
  "utf-8-validate": "^5.0.4",
35
- "ws": "^7.x.x"
36
+ "ws": "^8.x.x"
36
37
  },
37
38
  "prettier": {
38
- "printWidth": 100,
39
+ "printWidth": 70,
39
40
  "useTabs": true,
40
41
  "semi": false,
41
42
  "singleQuote": true,
43
+ "quoteProps": "as-needed",
42
44
  "jsxSingleQuote": false,
43
45
  "trailingComma": "all",
44
46
  "bracketSpacing": true,
45
- "jsxBracketSameLine": false,
47
+ "bracketSameLine": false,
46
48
  "arrowParens": "avoid",
47
- "quoteProps": "preserve",
48
- "proseWrap": "preserve"
49
+ "proseWrap": "never",
50
+ "endOfLine": "lf",
51
+ "singleAttributePerLine": true
49
52
  }
50
53
  }
package/publish.bat CHANGED
@@ -1,13 +1 @@
1
-
2
- git add --all
3
- git commit -m "update"
4
-
5
- call npm version patch
6
-
7
- git add --all
8
- git commit -m "update version"
9
-
10
- git push --all --prune
11
-
12
- call npm publish
13
-
1
+ publish-package
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  const inspect = Symbol.for('nodejs.util.inspect.custom')
4
2
 
5
3
  class Listeners {
@@ -135,12 +133,14 @@ class Listeners {
135
133
  // isobject <https://github.com/jonschlinkert/isobject>
136
134
  // MIT license - Copyright (c) 2014-2017, Jon Schlinkert.
137
135
  isObject(o) {
138
- return o != null && typeof o === 'object' && Array.isArray(o) === false
136
+ return (
137
+ o != null && typeof o === 'object' && Array.isArray(o) === false
138
+ )
139
139
  }
140
140
  // is-class <https://github.com/miguelmota/is-class>
141
141
  // MIT license - Copyright (C) 2014 Miguel Mota
142
142
  isClass() {
143
- ;(function(root) {
143
+ ;(function (root) {
144
144
  const toString = Function.prototype.toString
145
145
 
146
146
  function fnBody(fn) {
@@ -163,7 +163,9 @@ class Listeners {
163
163
  const body = fnBody(fn)
164
164
  return (
165
165
  /classCallCheck\(/.test(body) ||
166
- /TypeError\("Cannot call a class as a function"\)/.test(body)
166
+ /TypeError\("Cannot call a class as a function"\)/.test(
167
+ body,
168
+ )
167
169
  )
168
170
  }
169
171
  })(Listeners.prototype)
@@ -192,4 +194,6 @@ class Listeners {
192
194
 
193
195
  Listeners.prototype.isClass()
194
196
 
195
- module.exports = Listeners
197
+ const listeners = new Listeners()
198
+
199
+ export { listeners as Listeners }
package/server/Server.js CHANGED
@@ -1,11 +1,19 @@
1
- 'use strict'
2
-
3
1
  const inspect = Symbol.for('nodejs.util.inspect.custom')
4
2
 
5
- const Listeners = new (require('./Listeners.js'))()
6
- const Manager = require('./rooms/Manager.js')
3
+ import { Listeners } from './Listeners.js'
4
+
5
+ import { Manager } from './rooms/Manager.js'
6
+ import { Room } from './rooms/Room.js'
7
+ // const toFastProperties = require('to-fast-properties')
8
+ import url from 'node:url'
9
+ import { Socket } from './Socket.js'
10
+
11
+ import fs from 'node:fs'
12
+
13
+ import * as http from 'http'
14
+ import * as https from 'https'
7
15
 
8
- const toFastProperties = require('to-fast-properties')
16
+ import WebSocket, { WebSocketServer } from 'ws'
9
17
 
10
18
  class ServerSingleton {
11
19
  constructor() {
@@ -49,16 +57,17 @@ class ServerSingleton {
49
57
 
50
58
  _track: Manager.track,
51
59
  rooms: Manager.rooms,
52
- Room: require('./rooms/Room.js'),
60
+ Room,
53
61
  observe: Manager.observe,
54
62
 
55
63
  cacheIds: Symbol('cache'),
56
64
  cacheId: 1,
57
65
  cache: Object.create(null),
58
66
 
59
- URL: require('url'),
60
- Socket: require('./Socket.js'),
61
- WebSocket: require('ws'),
67
+ URL: url,
68
+ Socket,
69
+ WebSocket,
70
+ WebSocketServer,
62
71
  WebSocketFrame: {
63
72
  readOnly: false,
64
73
  mask: false,
@@ -79,7 +88,10 @@ class ServerSingleton {
79
88
  },
80
89
  })
81
90
 
82
- this.pingData = this.WebSocket.Sender.frame(Buffer.from(''), this.WebSocketFrame)
91
+ this.pingData = this.WebSocket.Sender.frame(
92
+ Buffer.from(''),
93
+ this.WebSocketFrame,
94
+ )
83
95
  this.disconnectData = this.WebSocket.Sender.frame(
84
96
  Buffer.from(JSON.stringify([['disconnect', true]])),
85
97
  this.WebSocketFrame,
@@ -88,20 +100,27 @@ class ServerSingleton {
88
100
 
89
101
  listen(options) {
90
102
  Object.assign(this, {
91
- port: +options.port > 0 && +options.port <= 65535 ? +options.port : this.port,
103
+ port:
104
+ +options.port > 0 && +options.port <= 65535
105
+ ? +options.port
106
+ : this.port,
92
107
  hostname: options.hostname || this.hostname,
93
- maxMessageSize: +options.maxMessageSize > 0 ? +options.maxMessageSize : this.maxMessageSize,
108
+ maxMessageSize:
109
+ +options.maxMessageSize > 0
110
+ ? +options.maxMessageSize
111
+ : this.maxMessageSize,
94
112
  cert: options.cert || this.cert,
95
113
  key: options.key || this.key,
96
114
  http: options.http || this.http,
97
115
 
98
116
  since: Date.now(),
99
117
  now: Date.now(),
100
- timeout: +options.timeout >= 10000 ? +options.timeout : this.timeout,
118
+ timeout:
119
+ +options.timeout >= 10000 ? +options.timeout : this.timeout,
101
120
  })
102
121
  this.timeoutCheck = this.timeout / 2
103
122
 
104
- this.ensureFastProperties()
123
+ // this.ensureFastProperties()
105
124
 
106
125
  // updates ping and checks for disconnections
107
126
  setInterval(this.ping, this.timeoutCheck)
@@ -114,8 +133,7 @@ class ServerSingleton {
114
133
  res.end()
115
134
  }
116
135
  if (this.cert && this.key) {
117
- let fs = require('fs')
118
- this.http = require('https').createServer(
136
+ this.http = https.createServer(
119
137
  {
120
138
  cert: fs.readFileSync(this.cert), // fullchain.pem
121
139
  key: fs.readFileSync(this.key), // privkey.pem
@@ -123,18 +141,20 @@ class ServerSingleton {
123
141
  handle,
124
142
  )
125
143
  } else {
126
- this.http = require('http').createServer(handle)
144
+ this.http = http.createServer(handle)
127
145
  }
128
146
  }
129
147
 
130
- let io = new this.WebSocket.Server({
148
+ let io = new this.WebSocketServer({
131
149
  server: this.http,
132
150
  perMessageDeflate: false,
133
151
  maxPayload: this.maxMessageSize * 1024 * 1024,
134
152
  clientTracking: false,
135
153
  backlog: 1024,
136
154
  skipUTF8Validation:
137
- options.skipUTF8Validation !== undefined ? options.skipUTF8Validation : false,
155
+ options.skipUTF8Validation !== undefined
156
+ ? options.skipUTF8Validation
157
+ : false,
138
158
  })
139
159
 
140
160
  io.on('connection', this.onconnect)
@@ -163,7 +183,7 @@ class ServerSingleton {
163
183
  },
164
184
  })
165
185
 
166
- this.ensureFastProperties()
186
+ // this.ensureFastProperties()
167
187
  }
168
188
 
169
189
  // emits to everyone connected to the server
@@ -212,7 +232,11 @@ class ServerSingleton {
212
232
  Object.assign(socket, {
213
233
  ip: (
214
234
  this.ip(request.connection.remoteAddress) ||
215
- this.ip((request.headers['x-forwarded-for'] || '').split(/\s*,\s*/)[0]) ||
235
+ this.ip(
236
+ (request.headers['x-forwarded-for'] || '').split(
237
+ /\s*,\s*/,
238
+ )[0],
239
+ ) ||
216
240
  request.connection.remoteAddress ||
217
241
  (request.headers['x-forwarded-for'] || '').split(/\s*,\s*/)[0]
218
242
  ).replace(/^::ffff:/, ''),
@@ -268,7 +292,10 @@ class ServerSingleton {
268
292
  let json = JSON.stringify(messages)
269
293
  this.bytesSent += json.length
270
294
  socket.bytesSent += json.length
271
- this.cache[id] = this.WebSocket.Sender.frame(Buffer.from(json), this.WebSocketFrame)
295
+ this.cache[id] = this.WebSocket.Sender.frame(
296
+ Buffer.from(json),
297
+ this.WebSocketFrame,
298
+ )
272
299
  } else {
273
300
  this.messagesSentCacheHit++
274
301
  }
@@ -286,7 +313,8 @@ class ServerSingleton {
286
313
  if (delay > this.timeout) {
287
314
  // timedout
288
315
  socket.timedout = true
289
- this.events.timeout && this.events.timeout(socket.proxy, delay)
316
+ this.events.timeout &&
317
+ this.events.timeout(socket.proxy, delay)
290
318
  socket.io.terminate()
291
319
  } else if (delay > this.timeoutCheck - 5000) {
292
320
  /*
@@ -335,11 +363,21 @@ class ServerSingleton {
335
363
  }
336
364
  default: {
337
365
  if (
338
- /^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(i) ||
339
- /^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(i) ||
340
- /^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(i) ||
341
- /^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(i) ||
342
- /^(::f{4}:)?169\.254\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(i) ||
366
+ /^(::f{4}:)?10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(
367
+ i,
368
+ ) ||
369
+ /^(::f{4}:)?192\.168\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(
370
+ i,
371
+ ) ||
372
+ /^(::f{4}:)?172\.(1[6-9]|2\d|30|31)\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(
373
+ i,
374
+ ) ||
375
+ /^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(
376
+ i,
377
+ ) ||
378
+ /^(::f{4}:)?169\.254\.([0-9]{1,3})\.([0-9]{1,3})$/i.test(
379
+ i,
380
+ ) ||
343
381
  /^f[cd][0-9a-f]{2}:/i.test(i) ||
344
382
  /^fe80:/i.test(i)
345
383
  )
@@ -441,7 +479,10 @@ class ServerSingleton {
441
479
  // listeners
442
480
  for (let l in this.events) {
443
481
  // listener
444
- console.log('this.events.' + l, this.HasFastProperties(this.events[l]))
482
+ console.log(
483
+ 'this.events.' + l,
484
+ this.HasFastProperties(this.events[l]),
485
+ )
445
486
  // methods
446
487
  if (this.events[l].fns) {
447
488
  for (let m in this.events[l].fns) {
@@ -454,9 +495,15 @@ class ServerSingleton {
454
495
  }
455
496
 
456
497
  // classes
457
- console.log('this.events', this.HasFastProperties(this.events.classes))
498
+ console.log(
499
+ 'this.events',
500
+ this.HasFastProperties(this.events.classes),
501
+ )
458
502
  for (let m in this.events.classes) {
459
- console.log('this.events.' + m, this.HasFastProperties(this.events.classes[m]))
503
+ console.log(
504
+ 'this.events.' + m,
505
+ this.HasFastProperties(this.events.classes[m]),
506
+ )
460
507
  // class
461
508
  for (let f in this.events.classes[m]) {
462
509
  // methods
@@ -475,4 +522,4 @@ class ServerSingleton {
475
522
 
476
523
  const Server = new ServerSingleton()
477
524
 
478
- module.exports = Server
525
+ export { Server, Server as default }
package/server/Socket.js CHANGED
@@ -1,10 +1,8 @@
1
- 'use strict'
2
-
3
1
  const inspect = Symbol.for('nodejs.util.inspect.custom')
4
2
 
5
- const { leave } = require('./rooms/constants.js')
3
+ import { leave } from './rooms/constants.js'
6
4
 
7
- class Socket {
5
+ export class Socket {
8
6
  constructor(socket, server) {
9
7
  Object.assign(this, {
10
8
  server: server,
@@ -84,7 +82,8 @@ class Socket {
84
82
  }
85
83
  disconnect(noReconnect) {
86
84
  if (noReconnect) {
87
- for (let m of this.server.disconnectData) this.io._socket.write(m)
85
+ for (let m of this.server.disconnectData)
86
+ this.io._socket.write(m)
88
87
  }
89
88
  this.io.close()
90
89
  }
@@ -224,5 +223,3 @@ class Socket {
224
223
  }
225
224
  }
226
225
  }
227
-
228
- module.exports = Socket
package/server/index.js CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict'
1
+ export { Server as default } from './Server.js'
2
2
 
3
- module.exports = require('./Server.js')
3
+ export * from './Server.js'
@@ -1,8 +1,6 @@
1
- 'use strict'
1
+ import { join, leave } from './constants.js'
2
2
 
3
- const { join, leave } = require('./constants.js')
4
-
5
- const Rooms = require('./Rooms.js')
3
+ import { Rooms } from './Rooms.js'
6
4
 
7
5
  class ManagerSingleton {
8
6
  constructor() {
@@ -107,6 +105,4 @@ class ManagerSingleton {
107
105
  }
108
106
  }
109
107
 
110
- const Manager = new ManagerSingleton()
111
-
112
- module.exports = Manager
108
+ export const Manager = new ManagerSingleton()
@@ -1,8 +1,6 @@
1
- 'use strict'
1
+ import { join, leave, parent, add, remove } from './constants.js'
2
2
 
3
- const { join, leave, parent, add, remove } = require('./constants.js')
4
-
5
- class Room {
3
+ export class Room {
6
4
  constructor() {
7
5
  this.sockets = new Set()
8
6
  }
@@ -97,5 +95,3 @@ class Room {
97
95
  return this.sockets[Symbol.iterator]()
98
96
  }
99
97
  }
100
-
101
- module.exports = Room
@@ -1,8 +1,6 @@
1
- 'use strict'
1
+ import { add, remove } from './constants.js'
2
2
 
3
- const { add, remove } = require('./constants.js')
4
-
5
- class Rooms {
3
+ export class Rooms {
6
4
  constructor(path) {
7
5
  Object.assign(this, {
8
6
  path: path,
@@ -36,5 +34,3 @@ class Rooms {
36
34
  return this.rooms[Symbol.iterator]()
37
35
  }
38
36
  }
39
-
40
- module.exports = Rooms
@@ -1,17 +1,6 @@
1
- const join = Symbol.for('Room.join')
2
- const leave = Symbol.for('Room.leave')
3
- const parent = Symbol.for('Room.parent')
1
+ export const join = Symbol.for('Room.join')
2
+ export const leave = Symbol.for('Room.leave')
3
+ export const parent = Symbol.for('Room.parent')
4
4
 
5
- const add = Symbol.for('Rooms.add')
6
- const remove = Symbol.for('Rooms.remove')
7
-
8
- module.exports = {
9
- // Room
10
- join,
11
- leave,
12
- parent,
13
-
14
- // Rooms
15
- add,
16
- remove,
17
- }
5
+ export const add = Symbol.for('Rooms.add')
6
+ export const remove = Symbol.for('Rooms.remove')