-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrooms.mjs
More file actions
40 lines (33 loc) · 1008 Bytes
/
Copy pathrooms.mjs
File metadata and controls
40 lines (33 loc) · 1008 Bytes
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
import { WSServerRoomManager, WSServerRoom } from '../../../src/node.js';
const wsServer = new WSServerRoomManager({
port: 8889,
origins: '*',
maxUsersByRoom: 10,
roomClass: class extends WSServerRoom {
onMsg(msg, clientMeta, client) {
return {
time: Date.now(),
user: 'Anon. ' + clientMeta.id.slice(0, 4),
msg,
};
}
onSendClient(clientMeta) {
return { user: 'Anon. ' + clientMeta.id.slice(0, 4) };
}
onCreate(name, msg = null, clientMeta = null, client = null) {
// Some bot examples
this.timer = setInterval(() => this.broadcastCmd('foo', { foo: 'bar' }), 5000);
this.timer2 = setInterval(() => this.broadcast({
time: Date.now(),
user: 'Bot',
msg: "I'm a bot, I send a message every 10 seconds",
}), 10000);
}
onDispose() {
// Clear the timer when the room is deleted
clearInterval(this.timer);
clearInterval(this.timer2);
}
},
});
wsServer.start();