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("
').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: });