///////////////////////////////////////////////// // connect to websocket var socket = io.connect(); //socket.on("metroPulse", metronomeTick); ///////////////////////////////////////////////// socket.on("metroPulse", pulseInClient); function pulseInClient(pulse,groupID,metrobeat){ var groupPage=document.getElementById('group').value if (groupID == groupPage) { metronomeTick(1000, groupID, metrobeat); } } ///////////////////////////////////////////////// function metroCss(beat, beatcolor,text){ var color = beatcolor; $(".metrocase > div").each(function(){$(this).stop()}); $(".metrocase > div").each(function(){$(this).css('background-color', beatcolor)}); $(".metrocase > div").each(function(){$(this).text(" ")}); $(".metrocase > div").each(function(){$(this).animate({opacity: 1}, 50, function() { $(this).animate({opacity:0.0}); } ); }) } function metronomeTick(pulse, voice,metrobeat) { var color = "gray" metroCss(0, "red", "4") }; ///////////////////////////////////////////////// // update the stopwatch value on the client page in line with server socket.on("chronFromServer", function(chron) { $("div#client_chronometer").text(chron); }); // server time //var groupPage=document.getElementById('group').value //if (groupID == groupPage) { socket.on("dateTime", function(datetime) { // console.log(datetime) $("div#datetime").text("Server Time: " +datetime); }); ///////////////////////////////////////////////// // countdown to change socket.on("countinFromServer", countinClient); function countinClient(groupID, currentseconds,mm,text,colour,background){ var groupPage=document.getElementById('group').value if (groupID == groupPage) { console.log(groupID, currentseconds,mm,text,colour,background) document.getElementById("count").style.visibility="visible"; //document.getElementById("count").style.visibility="visible"; $("#counttitle").text(text); $("#count").text(currentseconds); //$("#cnt").text(currentseconds); $("#count").css('background-color', background); document.getElementById("count").style.color=colour; // if ( currentseconds == 0) { //document.getElementById("midcomms").style.visibility='hidden'; // } }} ///////////////////////////////////////////////// ///////////////////////////////////////////////// // countdown to change socket.on("counterText", cText); function cText(groupID, currentseconds,text){ var groupPage=document.getElementById('group').value if (groupID == groupPage) { // console.log(text) $("#totalcountdown").text(text); }} /////////////////////////////////////// function pageFlip(unit) { console.log("flipping page:"+ unit); $('#sections').trigger('goto', [parseFloat(unit)]); } ///////////////////////////////////////////////// // call the fancy jquery functions function slideTo (target) { $('#sections').trigger('goto', [target]); } function pad2(number) { return (number < 10 ? '0' : '') + number } ///////////////////////////////////////////////// socket.on("pageFlipfromserver", pageTurn); function pageTurn (group,unit,time,mm) { var groupPage=document.getElementById('group').value; if (group == groupPage) { var g= pad2(group); var p= pad2(unit); // pageFlip(unit); pageTurnB(unit) testSound.play(); console.log("flipping page:"+ unit); } else { console.log("not for this group... ignoring... for group:" + group ); } } function pageTurnB(unit) { var units=6; var next=(((unit+1)%units)+units)%units console.log("HOP TURN" + unit+ "next:" + next); $("#live").load("music.html #"+unit +" *"); $("#preview").html("
').append($('').text(msg)));
});
socket.on('nicknames', function (nicknames) {
$('#nicknames').empty().append($('Online: '));
for (var i in nicknames) {
$('#nicknames').append($('').text(nicknames[i]));
}
});
socket.on('user message', message);
socket.on('reconnect', function () {
$('#lines').remove();
message('System', 'Reconnected to the server');
});
socket.on('reconnecting', function () {
message('System', 'Attempting to re-connect to the server');
});
socket.on('error', function (e) {
message('System', e ? e : 'A unknown error occurred');
});
function message (from, msg) {
$('#lines').append($(' ').append($('').text(from), msg));
}
// dom manipulation
$(function () {
$('#set-nickname').submit(function (ev) {
socket.emit('nickname', $('#nick').val(), function (set) {
if (!set) {
clear();
return $('#chat').addClass('nickname-set');
}
$('#nickname-err').css('visibility', 'visible');
});
return false;
});
$('#send-message').submit(function () {
message('me', $('#message').val());
socket.emit('user message', $('#message').val());
clear();
$('#lines').get(0).scrollTop = 10000000;
return false;
});
function clear () {
$('#message').val('').focus();
};
});