forked from webchallengeme/socketAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
26 lines (22 loc) · 730 Bytes
/
api.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
var port = 8001;
var static = require("node-static")
var file = new(static.Server)('./public')
var app = require('http').createServer(function (request, response) {
request.addListener('end', function () {
file.serve(request, response)
});
});
var io = require("socket.io").listen(app)
io.sockets.on("connection", function(socket){
socket.on("message",function(message){
console.log(message);
socket.emit("message", message); // Send message to sender
socket.broadcast.emit("message", message); // Send message to everyone except sender
});
socket.on("share",function(data){
console.log(data);
socket.emit("share", data);
socket.broadcast.emit("share", data);
});
});
app.listen(port);