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