-
Notifications
You must be signed in to change notification settings - Fork 5
/
room.js
45 lines (34 loc) · 829 Bytes
/
room.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict'
const { Room } = require('colyseus')
const config = require('config')
class RelayRoom extends Room {
onInit () {
this.maxClients = config.app.maxClients
this.users = {}
}
onJoin (client) {
console.log(client.sessionId, '-> *')
this.broadcast({
action: 'create',
target: client.sessionId
})
this.users[client.sessionId] = client
}
onLeave (client) {
console.log(client.sessionId, '<!>')
this.broadcast({
action: 'destroy',
target: client.sessionId
})
delete this.users[client.sessionId]
}
onMessage (client, data) {
console.log(client.sessionId, '->', data.target)
this.send(this.users[data.target], {
action: 'signal',
data: data.data,
target: client.sessionId
})
}
}
module.exports = RelayRoom