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@60:
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: $(".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: // 50,
rc-web@42: // function() { $(this).animate({color:red}); }
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: setTimeout(function(){metroCss(0, "black", "4")},150);
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@60: socket.on("chronFromServer", function(chron) { $("div#client_chronometer").text(chron); });
rc-web@42:
rc-web@42: // server time
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: $("div#datetime").text("" +datetime);
rc-web@42: });
rc-web@42:
rc-web@42: /////////////////////////////////////////////////
rc-web@42: // countdown to change
rc-web@42: socket.on("countinFromServer", countinClient);
rc-web@58: function countinClient(groupID, currentseconds,mm,text,colour,background,unit){
rc-web@42: var groupPage=document.getElementById('group').value
rc-web@59: if (groupID == groupPage) {
rc-web@59: $("#counttitle").css('color','white');
rc-web@59: $("#counttitle").text(text);
rc-web@60: $("#count").text(currentseconds);
rc-web@59: document.getElementById("count").style.color=colour;
rc-web@60: }}
rc-web@42:
rc-web@42: /////////////////////////////////////////////////
rc-web@42: // countdown to change
rc-web@42: socket.on("counterText", cText);
rc-web@42: function cText(groupID, currentseconds,text){
rc-web@58: $("#totalcountdown"+groupID).text(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@65: //function pageFlip(unit) { $('#sections').trigger('goto', [parseFloat(unit)]); }
rc-web@42:
rc-web@42: /////////////////////////////////////////////////
rc-web@42: // call the fancy jquery functions
rc-web@65: 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@54: //var testSound = new buzz.sound( 'audio/testfile', { formats: [ 'ogg', 'mp3' ] } );
rc-web@42: socket.on("pageFlipfromserver", pageTurn);
rc-web@65: function pageTurn (group,unit,time,mm,seqcounter,nextunit) {
rc-web@42: var groupPage=document.getElementById('group').value;
rc-web@42: if (group == groupPage) {
rc-web@65: console.log(unit + " ---> " + nextunit)
rc-web@42: var g= pad2(group);
rc-web@42: var p= pad2(unit);
rc-web@65: var units=8;
rc-web@65: var next=(((unit+1)%units)+units)%units
rc-web@65: //$("#live").load("music.html #"+unit +" *");
rc-web@65: $("#live").load("music.html #"+unit);
rc-web@54:
rc-web@65: //$("#live").html("")
rc-web@65: $("#preview").html("
').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@60: $('#lines').prepend($(' ').prepend($('').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: });