This repository has been archived by the owner on Jun 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
88 lines (88 loc) · 2.61 KB
/
server.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
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
(function() {
var app, assets, automate, express, getSocketId, io, port, _;
assets = require('connect-assets');
express = require('express');
app = express.createServer();
io = require('socket.io').listen(app);
_ = require('underscore');
app.configure(function() {
app.use(express.bodyParser());
app.use(assets());
app.use(express.logger());
return app.use(express.static('public'));
});
getSocketId = function(which, clients) {
var i, key, val;
which = which - 1;
i = 0;
for (key in clients) {
val = clients[key];
i++;
if (i - 1 === which) {
return val.id;
}
}
};
automate = function(the_socket, socket) {
var random;
random = '#' + Math.floor(Math.random() * 16777215).toString(16);
the_socket.emit('change-color', random);
return socket.broadcast.emit('change-color', random);
};
io.sockets.on('connection', function(socket) {
var clients, the_socket;
clients = io.sockets.sockets;
the_socket = io.sockets.socket(socket.id);
socket.emit('news', {
hello: 'type a color'
});
return socket.on('message', function(message) {
var key, the_x_socket, val, _chunks, _first_client, _message;
for (key in clients) {
val = clients[key];
_first_client = val.id;
break;
}
_message = message.mymsg;
_chunks = _message.split(" ");
switch (_chunks[0].toLowerCase()) {
case 'all':
the_socket.emit('change-color', _chunks[1]);
socket.broadcast.emit('change-color', _chunks[1]);
return socket.broadcast.emit('news', {
hello: _chunks[1]
});
case 'me':
return the_socket.emit('change-color', _chunks[1]);
case 'first':
io.sockets.socket(_first_client).emit('change-color', _chunks[1]);
socket.broadcast.emit('news', {
hello: _chunks[1]
});
return console.log(_first_client);
case 'x':
the_x_socket = io.sockets.socket(getSocketId(_chunks[2], clients));
return the_x_socket.emit('change-color', _chunks[1]);
}
});
});
app.get('/', function(req, res) {
return res.render("index.jade", {
title: 'Pepper'
});
});
app.get('/wall', function(req, res) {
return res.render("wall.jade", {
layout: false,
title: 'Pepper'
});
});
app.get('/sqr', function(req, res) {
return res.render("sqr.jade", {
layout: false,
title: 'Pepper'
});
});
app.listen(port = process.env.PORT || 5000);
console.log("Now listening on port " + port + "...");
}).call(this);