-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
55 lines (36 loc) · 1006 Bytes
/
Copy pathserver.js
File metadata and controls
55 lines (36 loc) · 1006 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*!
* RTGSE (Real Time Geolocation Sharing Experiment) using Websockets, Google Maps and NodeJS.
*
* Copyright (c) 2011 Sebastien P.
*
* http://rtgse.nodester.com/
* http://twitter.com/_sebastienp
*
* MIT licensed.
*/
var express = require("express"),
io = require("socket.io"),
app = express.createServer(),
count = 0,
clients = {};
app.configure(function () {
app.use(express.static(__dirname + "/public"));
});
app.get("/", function (req, res) {
res.render("./public/index.html");
});
app.listen(9880);
io.listen(app).on("connection", function (client) {
var id = client.sessionId;
count && client.send(JSON.stringify(clients));
count += 1;
client.on("disconnect", function () {
client.broadcast('{"type":"disconnect","id":' + id + "}");
delete clients[id];
count -= 1;
}).on("message", function (message) {
clients[id] = message;
client.broadcast(JSON.stringify(message));
});
});
console.log("Express server started on port %s", app.address().port);