rc@74: ///////////////////////////////////////////////// rc@74: // connect to websocket rc@74: rc@74: var socket = io.connect(); rc@74: rc@74: function initPage() { socket.emit("initPage"); rc@74: console.log("init.client.log") rc@74: } rc@74: rc@74: //socket.on("metroPulse", metronomeTick); rc@74: ///////////////////////////////////////////////// rc@74: socket.on("metroPulse", pulseInClient); rc@74: function pulseInClient(pulse,groupID,metrobeat){ rc@74: var groupPage=document.getElementById('group').value rc@74: if (groupID == groupPage) { rc@74: metronomeTick(1000, groupID, metrobeat); rc@74: } rc@74: } rc@74: rc@74: ///////////////////////////////////////////////// rc@74: function metroCss(beat, beatcolor,text){ rc@74: var color = beatcolor; rc@74: $(".metrocase > div").each(function(){$(this).stop()}); rc@74: $(".metrocase > div").each(function(){$(this).css('background-color', beatcolor)}); rc@74: $(".metrocase > div").each(function(){$(this).text(" ")}); rc@74: } rc@74: rc@74: function metronomeTick(pulse, voice,metrobeat) { rc@74: var color = "gray" rc@74: metroCss(0, "red", "4") rc@74: setTimeout(function(){metroCss(0, "black", "4")},150); rc@74: }; rc@74: rc@74: ///////////////////////////////////////////////// rc@74: // update the stopwatch value on the client page in line with server rc@74: socket.on("chronFromServer", function(chron) { $("div#client_chronometer").text(chron); }); rc@74: rc@74: // server time rc@74: socket.on("dateTime", function(datetime) { rc@74: $("div#datetime").text("" +datetime); rc@74: }); rc@74: rc@74: ///////////////////////////////////////////////// rc@74: // countdown to change rc@74: socket.on("countinFromServer", countinClient); rc@74: function countinClient(groupID, currentseconds,mm,text,colour,background,unit){ rc@74: var groupPage=document.getElementById('group').value rc@74: if (groupID == groupPage) { rob@79: $("#counttitle").css('color','black'); rc@74: $("#counttitle").text(text); rc@74: $("#count").text(currentseconds); rc@74: document.getElementById("count").style.color=colour; rc@74: }} rc@74: rc@74: ///////////////////////////////////////////////// rc@74: // countdown to change rc@74: socket.on("counterText", cText); rc@74: function cText(groupID, currentseconds,text){ rc@74: $("#totalcountdown"+groupID).text(text); rc@74: var groupPage=document.getElementById('group').value rc@74: if (groupID == groupPage) { rc@74: //console.log(text) rc@74: $("#totalcountdown").text(text); rc@74: }} rc@74: rc@74: /////////////////////////////////////// rc@74: //function pageFlip(unit) { $('#sections').trigger('goto', [parseFloat(unit)]); } rc@74: rc@74: ///////////////////////////////////////////////// rc@74: // call the fancy jquery functions rc@74: function slideTo (target) { $('#sections').trigger('goto', [target]); } rc@74: function pad2(number) { return (number < 10 ? '0' : '') + number } rc@74: rc@74: ///////////////////////////////////////////////// rc@74: //var testSound = new buzz.sound( 'audio/testfile', { formats: [ 'ogg', 'mp3' ] } ); rc@74: socket.on("pageFlipfromserver", pageTurn); rc@74: function pageTurn (group,unit,time,mm,seqcounter,nextunit) { rc@74: var groupPage=document.getElementById('group').value; rc@74: if (group == groupPage) { rc@74: console.log(unit + " ---> " + nextunit) rc@74: $("#live").load("music.html #"+unit); rc@74: $("#preview").html("

n e x t :

") rc@74: //$("#previewbox-"+group).html("") rc@74: } rc@74: else { rc@74: console.log("not for this group... ignoring... for group:" + group ); rc@74: } rc@74: } rc@74: rc@74: socket.on("pageIni", pageIni); rc@74: function pageIni (group,unit,time,mm,seqcounter,nextunit) { rc@74: console.log(unit + " ---> " + nextunit) rc@74: //$("#live").load("music.html #"+unit); rc@74: //$("#preview").html("

n e x t :

") rc@74: $("#previewbox-"+group).html("") rc@74: } rc@74: rc@74: //////////////////////////////////////////////// rc@74: rc@74: /* commented out for now as interferes with chat rc@74: need to introduce metakey...manyana... not so usefull anyway really... rc@74: rc@74: keyboard controls rc@74: +++++++++++++++++++++++++ rc@74: rc@74: SPACE to toggle visibilty of preview rc@74: m to toggle visibilty of metronome rc@74: s to toggle visibilty of stopwatch rc@74: h to hide all above rc@74: rc@74: rc@74: */ rc@74: function toggle_visibility(id) { rc@74: var e = document.getElementById(id); rc@74: if(e.style.display == 'block') rc@74: e.style.display = 'none'; rc@74: else rc@74: e.style.display = 'block'; rc@74: } rc@74: rc@74: $(document).keypress(function(e){ rc@74: // "space bar" for next unit preview rc@74: var checkWebkitandIE=(e.which==32 ? 1 : 0); rc@74: var checkMoz=(e.which==32 ? 1 : 0); rc@74: // "m" button for metronome rc@74: var mcheckWebkitandIE=(e.which==109 ? 1 : 0); rc@74: var mcheckMoz=(e.which==109 ? 1 : 0); rc@74: // "s" button for stopwatch/chronometer rc@74: var ccheckWebkitandIE=(e.which==115 ? 1 : 0); rc@74: var ccheckMoz=(e.which==115 ? 1 : 0); rc@74: rc@74: // "h" button for hideall rc@74: var hcheckWebkitandIE=(e.which==104 ? 1 : 0); rc@74: var hcheckMoz=(e.which==104 ? 1 : 0); rc@74: rc@74: // console.log(e.which); rc@74: // if (checkWebkitandIE || checkMoz) { toggle_visibility('preview') } rc@74: // if (mcheckWebkitandIE || mcheckMoz) { toggle_visibility('comms') } rc@74: // if (ccheckWebkitandIE || ccheckMoz) { toggle_visibility('client_chronometer') } rc@74: if (hcheckWebkitandIE || hcheckMoz) { rc@74: toggle_visibility('info') rc@74: //toggle_visibility('comms') rc@74: //toggle_visibility('preview') rc@74: } rc@74: }); rc@74: rc@74: //*/ rc@74: rc@74: //////////////////////////////////////////////// rc@74: // this needs to have a variable to define the websocket rc@74: // otherwise we will pings from all sockets connected rc@74: // no! the server broadcasts the ping and the clients emit the pong! rc@74: // ah but then the time reported back from the server needs to be targeted rc@74: // to specific client.. rc@74: ////////////////////////////////////////////// rc@74: // Latency "Pong" rc@74: socket.on("timeFromServer", function(n) { rc@74: socket.emit("clientTimeResponse",n); }); rc@74: rc@74: socket.on("latencyFromServer", function(latency) { rc@74: $("#client_latency").text("Latency: "+latency+"ms.") rc@74: rc@74: }); rc@74: rc@74: function getLatencies(x) { socket.emit("getLatencies", x); } rc@74: rc@74: ////////////////////////////////////////////// rc@74: rc@74: rc@74: socket.on('connect', function () { rc@74: $('#chat').addClass('connected'); rc@74: }); rc@74: rc@74: socket.on('announcement', function (msg) { rc@74: $('#lines').append($('

').append($('').text(msg))); rc@74: }); rc@74: rc@74: socket.on('nicknames', function (nicknames) { rc@74: $('#nicknames').empty().append($('Online: ')); rc@74: for (var i in nicknames) { rc@74: $('#nicknames').append($('').text(nicknames[i])); rc@74: } rc@74: }); rc@74: rc@74: socket.on('user message', message); rc@74: socket.on('reconnect', function () { rc@74: $('#lines').remove(); rc@74: message('System', 'Reconnected to the server'); rc@74: }); rc@74: rc@74: socket.on('reconnecting', function () { rc@74: message('System', 'Attempting to re-connect to the server'); rc@74: }); rc@74: rc@74: socket.on('error', function (e) { rc@74: message('System', e ? e : 'A unknown error occurred'); rc@74: }); rc@74: rc@74: function message (from, msg) { rc@74: $('#lines').prepend($('

').prepend($('').text(from), msg)); rc@74: } rc@74: rc@74: // dom manipulation rc@74: $(function () { rc@74: $('#set-nickname').submit(function (ev) { rc@74: socket.emit('nickname', $('#nick').val(), function (set) { rc@74: if (!set) { rc@74: clear(); rc@74: return $('#chat').addClass('nickname-set'); rc@74: } rc@74: $('#nickname-err').css('visibility', 'visible'); rc@74: }); rc@74: return false; rc@74: }); rc@74: rc@74: $('#send-message').submit(function () { rc@74: message('me', $('#message').val()); rc@74: socket.emit('user message', $('#message').val()); rc@74: clear(); rc@74: $('#lines').get(0).scrollTop = 10000000; rc@74: return false; rc@74: }); rc@74: rc@74: function clear () { rc@74: $('#message').val('').focus(); rc@74: }; rob@79: });