angelia.io 4.0.87 → 4.0.88

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "angelia.io",
3
- "version": "4.0.87",
3
+ "version": "4.0.88",
4
4
  "description": "WebSockets Server and Client API for node.js and the browser, with rooms support.",
5
5
  "author": "@titoBouzout @boredofnames",
6
6
  "license": "GPL",
package/readme.md CHANGED
@@ -213,8 +213,7 @@ As in `socket.on('connect', () => console.log('connect happened!'))`
213
213
  flag `persistent`
214
214
  4. a socket will leave automatically all rooms on disconnection
215
215
  5. `socket.rooms` is a set with all the rooms the socket joined
216
- 6. a room list is an iterable that returns all of the sockets in the
217
- room
216
+ 6. `id` is assigned to the room on creation
218
217
 
219
218
  ```js
220
219
  import { Room, Rooms } from 'angelia.io/server'
@@ -245,14 +244,14 @@ const games = new Rooms(GameRoom)
245
244
 
246
245
  class Connection {
247
246
  connect(socket) {
248
- game.join(socket, 'room id here')
249
- socket.room.id === 'room id here'
247
+ games.join(socket, 'room id here')
248
+ socket.game.id === 'room id here'
250
249
  console.log(socket.rooms)
251
- game.leave(socket, 'room id here')
250
+ games.leave(socket, 'room id here')
252
251
 
253
- game.join(socket, 'a different room')
254
- socket.room.id === 'a different room'
255
- game.leave(socket, 'a different room')
252
+ games.join(socket, 'a different room')
253
+ socket.game.id === 'a different room'
254
+ games.leave(socket, 'a different room')
256
255
  }
257
256
  }
258
257
 
@@ -262,6 +261,8 @@ Server.listen()
262
261
 
263
262
  ### `Room` Class
264
263
 
264
+ Iterating `room` returns the sockets
265
+
265
266
  | signature | kind | description |
266
267
  | ------------------------------------- | ------- | ------------------------------------------------ |
267
268
  | `onCreate(socket)` | method | dispatched when the room is created |
@@ -277,6 +278,16 @@ Server.listen()
277
278
  | `broadcastOnce(socket, key, [value])` | method | emits once to other sockets in the room |
278
279
  | `id` | any | the room id |
279
280
 
281
+ ### `Rooms` Class
282
+
283
+ Iterating `rooms` returns the rooms
284
+
285
+ | signature | kind | description |
286
+ | --------------------- | ------ | ------------------------------ |
287
+ | `get(id)` | method | returns room with such an `id` |
288
+ | `join(socket, [id])` | method | adds socket to room `id` |
289
+ | `leave(socket, [id])` | method | removes socket from room `id` |
290
+
280
291
  ## Authors
281
292
 
282
293
  - Tito Bouzout https://github.com/titoBouzout
package/server/Rooms.js CHANGED
@@ -1,14 +1,18 @@
1
1
  import { join, leave } from './constants.js'
2
2
 
3
3
  export class Rooms {
4
- constructor(Room) {
5
- this.Room = Room
4
+ /** @param {Object} RoomClass */
5
+ constructor(RoomClass) {
6
+ this.RoomClass = RoomClass
6
7
  this.rooms = new Map()
7
8
  }
9
+ get(id) {
10
+ return this.rooms.get(id)
11
+ }
8
12
  join(socket, id = undefined) {
9
13
  let room = this.rooms.get(id)
10
14
  if (!room) {
11
- room = new this.Room()
15
+ room = new this.RoomClass()
12
16
  room.id = room.id || id
13
17
  this.rooms.set(id, room)
14
18