Skip to content

Instantly share code, notes, and snippets.

@stefania11
Last active September 10, 2015 12:34
Show Gist options
  • Save stefania11/af88b0aa5bdb7480f045 to your computer and use it in GitHub Desktop.
Save stefania11/af88b0aa5bdb7480f045 to your computer and use it in GitHub Desktop.
//general call in express for socket connection//
var app = require('express')();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
io.on('connection', function(){ /* … */ });
server.listen(3000);
//example from how we use it in Michael Says//
if (_socketEnabled) {
var socket = io.connect('http://localhost:3000');
socket.on('news', function (data) {
console.log(data);
});
socket.on('hit', function (data) {
console.log(data.sound);
console.log(typeof data.sound);
if(data.sound == 1){
hit1();
}
// more code here for every key//
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment