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