View difference between Paste ID: wZjwttk6 and Ku7i07Hu
SHOW: | | - or go back to the newest paste.
1
var express = require('express');
2
var app = express();
3
var http = require('http');
4
var server = http.createServer(app);
5
var io = require('socket.io').listen(server);
6
7
io.enable('browser client minification');
8
io.enable('browser client etag');
9
io.enable('browser client gzip');
10
io.set('log level', 1);
11
io.set('transports', ['websocket', 'htmlfile', 'xhr-polling', 'jsonp-polling']);
12
13
server.listen(8080, '192.241.129.20');
14
15
app.get('/', function(req, res){
16
	console.log("REQUEST\t/\t" + req.addr);
17
	res.sendfile(__dirname + '/index.html');
18
});
19
20
io.sockets.on('connection', function(socket){
21
	socket.name = "User " + Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
22
	socket.emit("System", "You are " + socket.name);
23-
	socket.broadcast(socket.name, "connected.");
23+
	socket.broadcast.emit(socket.name, "connected.");
24
	console.log("JOIN\t" + socket.name);
25
26
	socket.on('message', function(message){
27-
		if(socket.channel){
27+
		console.log("MESSAGE\t" + socket.name + "\t" + message);
28-
			console.log("MESSAGE\t" + socket.name + "\t" + message);
28+
		io.sockets.emit(socket.name, message);
29-
			sendToChannel(socket.channel, ["message", moment().unix(), socket.user.uuid, socket.user.name, message]);
29+
30-
		}else
30+
31-
			socket.emit("notLoggedIn");
31+
32
		console.log("LEAVE\t" + socket.name);
33
		io.sockets.emit(socket.name, "disconnected.");
34
	});
35
});
36-
		socket.broadcast(socket.name, "disconnected.");
36+
37
console.log("Started.");