-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathsockets.js
More file actions
28 lines (25 loc) · 744 Bytes
/
sockets.js
File metadata and controls
28 lines (25 loc) · 744 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
/**
* Example for using socket events in a module
*
* Note: you **MUST** set in your module manifest:
* "socket": true
*
* Example assumes you have created a module called 'mymodule'
*/
// Create a socket event handler to listen to incomming sockets and dispatch to callbacks
game.socket.on(`module.mymodule`, (data) => {
if (data.operation === 'myEvent') handleMyEvent(data);
if (data.operation === 'myOtherEvent') handleMyOtherEvent(data);
});
// Emit a socket event
game.socket.emit('module.mymodule', {
operation: 'myEvent',
user: game.user.id,
content: 'Hello',
});
function handleMyEvent(data) {
console.log(`User [${data.user}] says: ${data.content}`);
}
function handleMyOtherEvent(data) {
// do something
}