angelia.io 2.4.79 → 3.4.81

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
@@ -227,7 +227,7 @@ class ClientWebWorker {
227
227
  }
228
228
  }
229
229
 
230
- class Client {
230
+ export class Client {
231
231
  constructor(options) {
232
232
  if (!options || typeof options === 'string') {
233
233
  options = {
@@ -441,18 +441,3 @@ class Client {
441
441
  }
442
442
  }
443
443
  }
444
-
445
- ;(function (root) {
446
- if (typeof exports !== 'undefined') {
447
- if (typeof module !== 'undefined' && module.exports) {
448
- exports = module.exports = Client
449
- }
450
- exports.Client = Client
451
- } else if (typeof define === 'function' && define.amd) {
452
- define([], function () {
453
- return Client
454
- })
455
- } else {
456
- root.Client = Client
457
- }
458
- })(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,13 +1,32 @@
1
1
  {
2
2
  "name": "angelia.io",
3
- "version": "2.4.79",
3
+ "version": "3.4.81",
4
4
  "description": "WebSockets Server and Client API for node.js and the browser, with rooms support.",
5
+ "author": "@titoBouzout @boredofnames",
6
+ "license": "GPL",
5
7
  "homepage": "https://github.com/titoBouzout/angelia.io",
6
8
  "repository": {
7
9
  "type": "git",
8
10
  "url": "git+https://github.com/titoBouzout/angelia.io"
9
11
  },
12
+ "type": "module",
10
13
  "main": "index.js",
14
+ "dependencies": {
15
+ "bufferutil": "^4.0.3",
16
+ "is-class": "^0.0.9",
17
+ "isobject": "^4.0.0",
18
+ "to-fast-properties": "^3.0.1",
19
+ "utf-8-validate": "^6.x.x",
20
+ "ws": "^8.x.x"
21
+ },
22
+ "exports": {
23
+ "./server": {
24
+ "default": "./server/Server.js"
25
+ },
26
+ "./client": {
27
+ "default": "./client/index.js"
28
+ }
29
+ },
11
30
  "keywords": [
12
31
  "Client",
13
32
  "Server",
@@ -24,16 +43,6 @@
24
43
  "io",
25
44
  "ws"
26
45
  ],
27
- "author": "@titoBouzout @boredofnames",
28
- "license": "GPL",
29
- "dependencies": {
30
- "bufferutil": "^4.0.3",
31
- "is-class": "^0.0.9",
32
- "isobject": "^4.0.0",
33
- "to-fast-properties": "^3.0.1",
34
- "utf-8-validate": "^5.0.4",
35
- "ws": "^7.x.x"
36
- },
37
46
  "prettier": {
38
47
  "printWidth": 70,
39
48
  "useTabs": true,
@@ -1,5 +1,3 @@
1
- 'use strict'
2
-
3
1
  const inspect = Symbol.for('nodejs.util.inspect.custom')
4
2
 
5
3
  class Listeners {
@@ -196,4 +194,6 @@ class Listeners {
196
194
 
197
195
  Listeners.prototype.isClass()
198
196
 
199
- 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'
7
12
 
8
- const toFastProperties = require('to-fast-properties')
13
+ import * as http from 'http'
14
+ import * as https from 'https'
15
+
16
+ import WebSocket, { WebSocketServer, Sender } from 'ws'
9
17
 
10
18
  class ServerSingleton {
11
19
  constructor() {
@@ -49,16 +57,18 @@ 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
+ Sender,
69
+ Socket,
70
+ WebSocket,
71
+ WebSocketServer,
62
72
  WebSocketFrame: {
63
73
  readOnly: false,
64
74
  mask: false,
@@ -79,11 +89,8 @@ class ServerSingleton {
79
89
  },
80
90
  })
81
91
 
82
- this.pingData = this.WebSocket.Sender.frame(
83
- Buffer.from(''),
84
- this.WebSocketFrame,
85
- )
86
- this.disconnectData = this.WebSocket.Sender.frame(
92
+ this.pingData = this.Sender.frame(Buffer.from(''), this.WebSocketFrame)
93
+ this.disconnectData = this.Sender.frame(
87
94
  Buffer.from(JSON.stringify([['disconnect', true]])),
88
95
  this.WebSocketFrame,
89
96
  )
@@ -111,7 +118,7 @@ class ServerSingleton {
111
118
  })
112
119
  this.timeoutCheck = this.timeout / 2
113
120
 
114
- this.ensureFastProperties()
121
+ // this.ensureFastProperties()
115
122
 
116
123
  // updates ping and checks for disconnections
117
124
  setInterval(this.ping, this.timeoutCheck)
@@ -124,8 +131,7 @@ class ServerSingleton {
124
131
  res.end()
125
132
  }
126
133
  if (this.cert && this.key) {
127
- let fs = require('fs')
128
- this.http = require('https').createServer(
134
+ this.http = https.createServer(
129
135
  {
130
136
  cert: fs.readFileSync(this.cert), // fullchain.pem
131
137
  key: fs.readFileSync(this.key), // privkey.pem
@@ -133,11 +139,11 @@ class ServerSingleton {
133
139
  handle,
134
140
  )
135
141
  } else {
136
- this.http = require('http').createServer(handle)
142
+ this.http = http.createServer(handle)
137
143
  }
138
144
  }
139
145
 
140
- let io = new this.WebSocket.Server({
146
+ let io = new this.WebSocketServer({
141
147
  server: this.http,
142
148
  perMessageDeflate: false,
143
149
  maxPayload: this.maxMessageSize * 1024 * 1024,
@@ -175,7 +181,7 @@ class ServerSingleton {
175
181
  },
176
182
  })
177
183
 
178
- this.ensureFastProperties()
184
+ // this.ensureFastProperties()
179
185
  }
180
186
 
181
187
  // emits to everyone connected to the server
@@ -284,7 +290,7 @@ class ServerSingleton {
284
290
  let json = JSON.stringify(messages)
285
291
  this.bytesSent += json.length
286
292
  socket.bytesSent += json.length
287
- this.cache[id] = this.WebSocket.Sender.frame(
293
+ this.cache[id] = this.Sender.frame(
288
294
  Buffer.from(json),
289
295
  this.WebSocketFrame,
290
296
  )
@@ -512,6 +518,6 @@ class ServerSingleton {
512
518
  }
513
519
  }
514
520
 
515
- const Server = new ServerSingleton()
521
+ export const Server = new ServerSingleton()
516
522
 
517
- module.exports = Server
523
+ export { Room, 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,
@@ -96,7 +94,9 @@ class Socket {
96
94
  this.io.on('error', this.onerror)
97
95
  this.io.on('message', this.onmessage)
98
96
  }
99
- onclose(code, message) {
97
+ onclose(code, message, isBinary) {
98
+ message = message.toString()
99
+
100
100
  this.server.sockets.delete(this)
101
101
 
102
102
  for (let room of this.rooms) {
@@ -138,7 +138,9 @@ class Socket {
138
138
  return false
139
139
  }
140
140
  }
141
- onmessage(e) {
141
+ onmessage(e, isBinary) {
142
+ e = isBinary ? e.toString() : e
143
+
142
144
  if (e === '') {
143
145
  this.server.pong(this)
144
146
  } else {
@@ -225,5 +227,3 @@ class Socket {
225
227
  }
226
228
  }
227
229
  }
228
-
229
- 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')