60 lines
1.2 KiB
JavaScript
60 lines
1.2 KiB
JavaScript
|
// Create SocketIO instance, connect
|
||
|
var socket = new io.connect('http://kiben.net:8889');
|
||
|
|
||
|
// Add a connect listener
|
||
|
socket.on('connect',function() {
|
||
|
|
||
|
console.log('Client has connected to the server!: id='+ sessionid);
|
||
|
});
|
||
|
|
||
|
socket.on('cue',function(who,what) {
|
||
|
console.log('Received a message from the server!',who, what);
|
||
|
document.getElementById('msg').innerHTML = what;
|
||
|
|
||
|
switch (what) {
|
||
|
case 1:
|
||
|
play_cue('cue1');
|
||
|
break;
|
||
|
case 2:
|
||
|
play_cue('cue2');
|
||
|
break;
|
||
|
case 3:
|
||
|
play_cue('cue3');
|
||
|
break;
|
||
|
case 4:
|
||
|
play_cue('cue4');
|
||
|
break;
|
||
|
case 5:
|
||
|
play_cue('cue5');
|
||
|
break;
|
||
|
case 6:
|
||
|
play_cue('cue6');
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
});
|
||
|
|
||
|
socket.on('loc',function(sessionid,where) {
|
||
|
console.log('The client has disconnected!');
|
||
|
var loc = sessionid + ":" +where;
|
||
|
document.getElementById('clientloc').innerHTML = loc;
|
||
|
});
|
||
|
|
||
|
|
||
|
// Add a disconnect listener
|
||
|
socket.on('disconnect',function() {
|
||
|
console.log('The client has disconnected!');
|
||
|
});
|
||
|
|
||
|
// Sends a message to the server via sockets
|
||
|
|
||
|
function sendCue(who,what) {
|
||
|
//socket.send(who,what);
|
||
|
socket.emit("cue",who,what);
|
||
|
}
|
||
|
|
||
|
function sendLoc(lat,lon) {
|
||
|
var id = socket.id;
|
||
|
socket.emit("loc",id,lat,lon);
|
||
|
}
|