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