rc-web@42: ///////////////////////////////////////////////// rc-web@42: // connect to websocket rc-web@42: rc-web@42: var socket = io.connect(); rc-web@42: rc-web@42: //socket.on("metroPulse", metronomeTick); rc-web@42: ///////////////////////////////////////////////// rc-web@42: socket.on("metroPulse", pulseInClient); rc-web@42: function pulseInClient(pulse,groupID,metrobeat){ rc-web@42: var groupPage=document.getElementById('group').value rc-web@42: if (groupID == groupPage) { rc-web@42: metronomeTick(1000, groupID, metrobeat); rc-web@42: } rc-web@42: } rc-web@42: ///////////////////////////////////////////////// rc-web@42: function metroCss(beat, beatcolor,text){ rc-web@42: var color = beatcolor; rc-web@42: rc-web@42: $(".metrocase > div").each(function(){$(this).stop()}); rc-web@42: $(".metrocase > div").each(function(){$(this).css('background-color', beatcolor)}); rc-web@42: $(".metrocase > div").each(function(){$(this).text(" ")}); rc-web@42: $(".metrocase > div").each(function(){$(this).animate({color: blue;}, rc-web@42: 1, rc-web@42: function() { $(this).animate({opacity:0}); } rc-web@42: ); rc-web@42: }) rc-web@42: } rc-web@42: rc-web@42: function metronomeTick(pulse, voice,metrobeat) { rc-web@42: var color = "gray" rc-web@42: metroCss(0, "red", "4") rc-web@42: }; rc-web@42: rc-web@42: ///////////////////////////////////////////////// rc-web@42: rc-web@42: // update the stopwatch value on the client page in line with server rc-web@42: socket.on("chronFromServer", function(chron) { rc-web@42: $("div#client_chronometer").text(chron); rc-web@42: }); rc-web@42: rc-web@42: rc-web@42: // server time rc-web@42: rc-web@42: //var groupPage=document.getElementById('group').value rc-web@42: //if (groupID == groupPage) { rc-web@42: socket.on("dateTime", function(datetime) { rc-web@42: // console.log(datetime) rc-web@42: $("div#datetime").text("Server Time: " +datetime); rc-web@42: rc-web@42: }); rc-web@42: rc-web@42: rc-web@42: ///////////////////////////////////////////////// rc-web@42: // countdown to change rc-web@42: rc-web@42: socket.on("countinFromServer", countinClient); rc-web@42: function countinClient(groupID, currentseconds,mm,text,colour,background){ rc-web@42: var groupPage=document.getElementById('group').value rc-web@42: if (groupID == groupPage) { rc-web@42: document.getElementById("count").style.visibility="visible"; rc-web@42: document.getElementById("count").style.visibility="visible"; rc-web@42: $("#counttitle").text(text); rc-web@42: $("#count").text(currentseconds); rc-web@42: //$("#cnt").text(currentseconds); rc-web@42: $("#count").css('background-color', background); rc-web@42: document.getElementById("count").style.color=colour; rc-web@42: // if ( currentseconds == 0) { rc-web@42: //document.getElementById("midcomms").style.visibility='hidden'; rc-web@42: // } rc-web@42: }} rc-web@42: ///////////////////////////////////////////////// rc-web@42: rc-web@42: ///////////////////////////////////////////////// rc-web@42: // countdown to change rc-web@42: rc-web@42: socket.on("counterText", cText); rc-web@42: function cText(groupID, currentseconds,text){ rc-web@42: var groupPage=document.getElementById('group').value rc-web@42: if (groupID == groupPage) { rc-web@42: console.log(text) rc-web@42: $("#totalcountdown").text(text); rc-web@42: }} rc-web@42: rc-web@42: /////////////////////////////////////// rc-web@42: rc-web@42: function pageFlip(unit) { rc-web@42: console.log("flipping page:"+ unit); rc-web@42: $('#sections').trigger('goto', [parseFloat(unit)]); rc-web@42: } rc-web@42: rc-web@42: rc-web@42: ///////////////////////////////////////////////// rc-web@42: rc-web@42: // call the fancy jquery functions rc-web@42: rc-web@42: function slideTo (target) { $('#sections').trigger('goto', [target]); } rc-web@42: function pad2(number) { return (number < 10 ? '0' : '') + number } rc-web@42: rc-web@42: ///////////////////////////////////////////////// rc-web@42: rc-web@42: socket.on("pageFlipfromserver", pageTurn); rc-web@42: function pageTurn (group,unit,time,mm) { rc-web@42: var groupPage=document.getElementById('group').value; rc-web@42: if (group == groupPage) { rc-web@42: var g= pad2(group); rc-web@42: var p= pad2(unit); rc-web@42: // pageFlip(unit); rc-web@42: pageTurnB(unit) rc-web@42: rc-web@42: } rc-web@42: else { rc-web@42: console.log("not for this group... ignoring... for group:" + group ); rc-web@42: } rc-web@42: } rc-web@42: rc-web@42: function pageTurnB(unit) { rc-web@42: var units=6; rc-web@42: var next=(((unit+1)%units)+units)%units rc-web@42: console.log("HOP TURN" + unit+ "next:" + next); rc-web@42: $("#live").load("icmc2012.html #"+unit +" *"); rc-web@42: $("#preview").html("

n e x t :

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

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

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