annotate www/m/js/nodescore-client.js @ 22:bb02a593b7d5

server side push of datetime to client
author tzara <rc-web@kiben.net>
date Wed, 11 Jul 2012 09:51:05 +0100
parents aaf429469697
children e1a02869da08
rev   line source
rc-web@12 1 /////////////////////////////////////////////////
rc-web@12 2 // connect to websocket
rc-web@12 3
rc-web@12 4 var socket = io.connect();
rc-web@12 5
rc-web@12 6 //socket.on("metroPulse", metronomeTick);
rc-web@12 7 /////////////////////////////////////////////////
rc-web@12 8 socket.on("metroPulse", pulseInClient);
rc-web@12 9 function pulseInClient(pulse,groupID,metrobeat){
rc-web@12 10 var groupPage=document.getElementById('group').value
rc-web@12 11 if (groupID == groupPage) {
rc-web@12 12 metronomeTick(1000, groupID, metrobeat);
rc-web@12 13 }
rc-web@12 14 }
rc-web@12 15 /////////////////////////////////////////////////
rc-web@12 16 function metroCss(beat, beatcolor,text){
rc-web@12 17 var color = beatcolor;
rc-web@12 18
rc-web@12 19 $(".metrocase > div").each(function(){$(this).stop()});
rc-web@12 20 $(".metrocase > div").each(function(){$(this).css('background-color', beatcolor)});
rc-web@12 21 $(".metrocase > div").each(function(){$(this).text(" ")});
rc-web@12 22 $(".metrocase > div").each(function(){$(this).animate({opacity: 0.5},
rc-web@12 23 50,
rc-web@12 24 function() { $(this).animate({opacity:0.0}); }
rc-web@12 25 );
rc-web@12 26 })
rc-web@12 27 }
rc-web@12 28
rc-web@12 29 function metronomeTick(pulse, voice,metrobeat) {
rc-web@12 30 var color = "gray"
rc-web@12 31 metroCss(0, "red", "4")
rc-web@12 32 };
rc-web@12 33
rc-web@12 34 /////////////////////////////////////////////////
rc-web@12 35
rc-web@12 36 // update the stopwatch value on the client page in line with server
rc-web@12 37 socket.on("chronFromServer", function(chron) {
rc-web@12 38 $("div#client_chronometer").text(chron);
rc-web@12 39 });
rc-web@12 40
rc-web@20 41
rc-web@22 42 // server time
rc-web@22 43
rc-web@22 44 //var groupPage=document.getElementById('group').value
rc-web@22 45 //if (groupID == groupPage) {
rc-web@22 46 socket.on("dateTime", function(datetime) {
rc-web@22 47 // console.log(datetime)
rc-web@22 48 $("div#datetime").text("server time: " +datetime);
rc-web@22 49
rc-web@22 50 });
rc-web@20 51
rc-web@20 52
rc-web@20 53 /////////////////////////////////////////////////
rc-web@20 54 // countdown to change
rc-web@20 55
rc-web@20 56 socket.on("countinFromServer", countinClient);
rc-web@20 57 function countinClient(groupID, currentseconds,mm,text,colour,background){
rc-web@20 58 var groupPage=document.getElementById('group').value
rc-web@20 59 if (groupID == groupPage) {
rc-web@20 60 console.log(currentseconds);
rc-web@20 61 document.getElementById("countinnumber").style.visibility="visible";
rc-web@20 62 document.getElementById("countinnumber").style.visibility="visible";
rc-web@20 63 //$("#countin").text(text);
rc-web@20 64 $("#countinnumber").text(currentseconds);
rc-web@20 65 $("#countinnumber").css('background-color', background);
rc-web@20 66
rc-web@20 67 document.getElementById("countinnumber").style.color=colour;
rc-web@20 68
rc-web@20 69 if ( currentseconds == 0) {
rc-web@20 70 document.getElementById("countinnumber").style.visibility='hidden';
rc-web@20 71 // document.getElementById("countin").style.visibility='hidden';
rc-web@20 72 }
rc-web@20 73 }}
rc-web@20 74
rc-web@12 75 /////////////////////////////////////////////////
rc-web@12 76
rc-web@12 77 function pageFlip(unit) {
rc-web@12 78 console.log("flipping page:"+ unit);
rc-web@12 79 $('#sections').trigger('goto', [parseFloat(unit)]);
rc-web@16 80 // $('#sections-preview').trigger('goto', [parseFloat(unit+1)]);
rc-web@12 81 //metroStart(1000);
rc-web@12 82 //document.getElementById("countdowncase").style.visibility="hidden";
rc-web@12 83 }
rc-web@12 84
rc-web@16 85
rc-web@16 86
rc-web@12 87 /////////////////////////////////////////////////
rc-web@16 88
rc-web@12 89 // call the fancy jquery functions
rc-web@12 90
rc-web@12 91 function slideTo (target) { $('#sections').trigger('goto', [target]); }
rc-web@12 92 function pad2(number) { return (number < 10 ? '0' : '') + number }
rc-web@12 93
rc-web@12 94 /////////////////////////////////////////////////
rc-web@12 95
rc-web@12 96 socket.on("pageFlipfromserver", pageTurn);
rc-web@12 97 function pageTurn (group,unit,time,mm) {
rc-web@12 98 var groupPage=document.getElementById('group').value;
rc-web@16 99 //console.log("fromservercommand has been executed on client");
rc-web@12 100 if (group == groupPage) {
rc-web@12 101 var g= pad2(group);
rc-web@12 102 var p= pad2(unit);
rc-web@16 103 // pageFlip(unit);
rc-web@20 104 pageTurnB(unit)
rc-web@16 105
rc-web@16 106 }
rc-web@12 107 else {
rc-web@12 108 console.log("not for this group... ignoring... for group:" + group );
rc-web@12 109 }
rc-web@12 110 }
rc-web@12 111
rc-web@16 112 function pageTurnB(unit) {
rc-web@21 113 var units=6;
rc-web@21 114 var section = "seta/"
rc-web@20 115 var next=(((unit+1)%units)+units)%units
rc-web@20 116 console.log("HOP TURN" + unit+ "next:" + next);
rc-web@20 117 // $("#live").html($("#unit"+unit).html());
rc-web@21 118 $("#live").load(section+"music.html #"+unit +" *");
rc-web@20 119
rc-web@21 120 $("#preview").html('<img src=' + section+"img/thumbs/"+next + ".png" + '>');
rc-web@16 121 }
rc-web@16 122
rc-web@18 123 ////////////////////////////////////////////////
rc-web@20 124
rc-web@20 125 /*
rc-web@20 126
rc-web@20 127 keyboard controls
rc-web@20 128 +++++++++++++++++++++++++
rc-web@20 129
rc-web@20 130 SPACE to toggle visibilty of preview
rc-web@20 131 m to toggle visibilty of metronome
rc-web@20 132 s to toggle visibilty of stopwatch
rc-web@20 133 h to hide all above
rc-web@20 134
rc-web@20 135 */
rc-web@20 136
rc-web@18 137 function toggle_visibility(id) {
rc-web@18 138 var e = document.getElementById(id);
rc-web@18 139 if(e.style.display == 'block')
rc-web@18 140 e.style.display = 'none';
rc-web@18 141 else
rc-web@18 142 e.style.display = 'block';
rc-web@18 143 }
rc-web@18 144
rc-web@18 145 $(document).keypress(function(e){
rc-web@19 146 // "space bar" for next unit preview
rc-web@18 147 var checkWebkitandIE=(e.which==32 ? 1 : 0);
rc-web@18 148 var checkMoz=(e.which==32 ? 1 : 0);
rc-web@19 149 // "m" button for metronome
rc-web@19 150 var mcheckWebkitandIE=(e.which==109 ? 1 : 0);
rc-web@19 151 var mcheckMoz=(e.which==109 ? 1 : 0);
rc-web@19 152 // "s" button for stopwatch/chronometer
rc-web@19 153 var ccheckWebkitandIE=(e.which==115 ? 1 : 0);
rc-web@19 154 var ccheckMoz=(e.which==115 ? 1 : 0);
rc-web@19 155
rc-web@19 156 // "h" button for hideall
rc-web@19 157 var hcheckWebkitandIE=(e.which==104 ? 1 : 0);
rc-web@19 158 var hcheckMoz=(e.which==104 ? 1 : 0);
rc-web@19 159
rc-web@19 160 console.log(e.which);
rc-web@19 161 if (checkWebkitandIE || checkMoz) { toggle_visibility('preview') }
rc-web@19 162 if (mcheckWebkitandIE || mcheckMoz) { toggle_visibility('metro') }
rc-web@19 163 if (ccheckWebkitandIE || ccheckMoz) { toggle_visibility('client_chronometer') }
rc-web@19 164 if (hcheckWebkitandIE || hcheckMoz) {
rc-web@19 165 toggle_visibility('client_chronometer')
rc-web@19 166 toggle_visibility('metro')
rc-web@19 167 toggle_visibility('preview')
rc-web@19 168 }
rc-web@18 169 });
rc-web@18 170
rc-web@18 171 ////////////////////////////////////////////////