forked from cezarywojcik/ratboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsockethandler.js
More file actions
31 lines (28 loc) · 852 Bytes
/
sockethandler.js
File metadata and controls
31 lines (28 loc) · 852 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
/**
* File: sockethandler.js
* Desc: This file handles socket interaction.
* Assume exports.io exists and points to the socket.io object.
*/
exports.handler = function(socket) {
socket.on("room:join", function(data) {
var d = new Date();
if (!data.username || data.username.length === 0) {
socket.emit("room:systemmessage", {
content: "You have no username.",
timestamp: d.toString()
});
} else {
socket.join(data.room);
exports.io.to(data.room).emit("room:systemmessage", {
content: data.username + " has connected.",
timestamp: d.toString()
});
}
});
socket.on("room:message", function(data) {
exports.io.to(data.room).emit("room:message", data);
});
socket.on('disconnect', function() {
// do things
});
};