51 lines
1 KiB
JavaScript
51 lines
1 KiB
JavaScript
var http = require("http");
|
|
var express = require("express");
|
|
var app = express();
|
|
var server = http.createServer(app);
|
|
var port = process.env.PORT || 3000;
|
|
server.listen(port);
|
|
//
|
|
app.use(express.static("data"));
|
|
|
|
//http socket.io server
|
|
var io = require('socket.io')(server, {
|
|
'pingInterval': 1000,
|
|
'pingTimeout': 3000
|
|
});
|
|
|
|
//socket.io events
|
|
io.on('connection', function(socket) {
|
|
|
|
//entry log.
|
|
console.log('someone connected.');
|
|
|
|
//on 'sound'
|
|
socket.on('sound', function(sound) {
|
|
|
|
//relay the message to everybody EXCEPT the sender
|
|
socket.broadcast.emit('sound', sound);
|
|
|
|
//DEBUG
|
|
console.log('sound.name :' + sound.name);
|
|
console.log('sound.action :' + sound.action);
|
|
console.log('sound.group :' + sound.group);
|
|
});
|
|
|
|
//on 'clap'
|
|
socket.on('clap', function(clap) {
|
|
|
|
//relay the message to everybody INCLUDING sender
|
|
io.emit('clap', clap);
|
|
|
|
//DEBUG
|
|
console.log('clap.name :' + clap.name);
|
|
});
|
|
|
|
//on 'disconnect'
|
|
socket.on('disconnect', function() {
|
|
|
|
console.log('someone disconnected.');
|
|
|
|
});
|
|
});
|