annotate www/emma/js/nodescore-slides.js @ 101:52e44ee1c791 tip master

enabled all scores in autostart script
author Rob Canning <rc@kiben.net>
date Tue, 21 Apr 2015 16:20:57 +0100
parents 753414e075a0
children
rev   line source
rc-web@66 1 /////////////////////////////////////////////////
rc-web@66 2 // connect to websocket
rc-web@66 3
rc-web@66 4 var socket = io.connect();
rc-web@66 5
rc-web@70 6 function initPage() { socket.emit("initPage");
rc-web@70 7 console.log("init.client.log")
rc-web@70 8 }
rc-web@70 9
rc-web@66 10 //socket.on("metroPulse", metronomeTick);
rc-web@66 11 /////////////////////////////////////////////////
rc-web@66 12 socket.on("metroPulse", pulseInClient);
rc-web@66 13 function pulseInClient(pulse,groupID,metrobeat){
rc-web@66 14 var groupPage=document.getElementById('group').value
rc-web@66 15 if (groupID == groupPage) {
rc-web@66 16 metronomeTick(1000, groupID, metrobeat);
rc-web@66 17 }
rc-web@66 18 }
rc-web@70 19
rc-web@66 20 /////////////////////////////////////////////////
rc-web@66 21 function metroCss(beat, beatcolor,text){
rc-web@66 22 var color = beatcolor;
rc-web@66 23 $(".metrocase > div").each(function(){$(this).stop()});
rc-web@66 24 $(".metrocase > div").each(function(){$(this).css('background-color', beatcolor)});
rc-web@66 25 $(".metrocase > div").each(function(){$(this).text(" ")});
rc-web@66 26 }
rc-web@66 27
rc-web@66 28 function metronomeTick(pulse, voice,metrobeat) {
rc-web@66 29 var color = "gray"
rc-web@66 30 metroCss(0, "red", "4")
rc-web@66 31 setTimeout(function(){metroCss(0, "black", "4")},150);
rc-web@66 32 };
rc-web@66 33
rc-web@66 34 /////////////////////////////////////////////////
rc-web@66 35 // update the stopwatch value on the client page in line with server
rc-web@66 36 socket.on("chronFromServer", function(chron) { $("div#client_chronometer").text(chron); });
rc-web@66 37
rc-web@66 38 // server time
rc-web@66 39 socket.on("dateTime", function(datetime) {
rc-web@66 40 $("div#datetime").text("" +datetime);
rc-web@66 41 });
rc-web@66 42
rc-web@66 43 /////////////////////////////////////////////////
rc-web@66 44 // countdown to change
rc-web@66 45 socket.on("countinFromServer", countinClient);
rc-web@66 46 function countinClient(groupID, currentseconds,mm,text,colour,background,unit){
rc-web@66 47 var groupPage=document.getElementById('group').value
rc-web@66 48 if (groupID == groupPage) {
rc-web@66 49 $("#counttitle").css('color','white');
rc-web@66 50 $("#counttitle").text(text);
rc-web@66 51 $("#count").text(currentseconds);
rc-web@66 52 document.getElementById("count").style.color=colour;
rc-web@66 53 }}
rc-web@66 54
rc-web@66 55 /////////////////////////////////////////////////
rc-web@66 56 // countdown to change
rc-web@66 57 socket.on("counterText", cText);
rc-web@66 58 function cText(groupID, currentseconds,text){
rc-web@66 59 $("#totalcountdown"+groupID).text(text);
rc-web@66 60 var groupPage=document.getElementById('group').value
rc-web@66 61 if (groupID == groupPage) {
rc-web@66 62 //console.log(text)
rc-web@66 63 $("#totalcountdown").text(text);
rc-web@66 64 }}
rc-web@66 65
rc-web@66 66 ///////////////////////////////////////
rc-web@66 67 //function pageFlip(unit) { $('#sections').trigger('goto', [parseFloat(unit)]); }
rc-web@66 68
rc-web@66 69 /////////////////////////////////////////////////
rc-web@66 70 // call the fancy jquery functions
rc-web@66 71 function slideTo (target) { $('#sections').trigger('goto', [target]); }
rc-web@66 72 function pad2(number) { return (number < 10 ? '0' : '') + number }
rc-web@66 73
rc-web@66 74 /////////////////////////////////////////////////
rc-web@66 75 //var testSound = new buzz.sound( 'audio/testfile', { formats: [ 'ogg', 'mp3' ] } );
rc-web@66 76 socket.on("pageFlipfromserver", pageTurn);
rc-web@66 77 function pageTurn (group,unit,time,mm,seqcounter,nextunit) {
rc-web@66 78 var groupPage=document.getElementById('group').value;
rc-web@66 79 if (group == groupPage) {
rc-web@66 80 console.log(unit + " ---> " + nextunit)
rc-web@66 81 $("#live").load("music.html #"+unit);
rc-web@66 82 $("#preview").html("<h3 style='background:transparent; position: relative; font-size:1.5em;top:14px; left:10px;';> n e x t : </h3><img src='thumbs/"+ (nextunit) + ".png" + "' width='305'>")
rc-web@70 83 //$("#previewbox-"+group).html("<img src='svg/"+(unit) + ".svg" + "' width='515'>")
rc-web@66 84 }
rc-web@66 85 else {
rc-web@70 86 console.log("not for this group... ignoring... for group:" + group );
rc-web@66 87 }
rc-web@66 88 }
rc-web@66 89
rc-web@70 90 socket.on("pageIni", pageIni);
rc-web@70 91 function pageIni (group,unit,time,mm,seqcounter,nextunit) {
rc-web@70 92 console.log(unit + " ---> " + nextunit)
rc-web@70 93 //$("#live").load("music.html #"+unit);
rc-web@70 94 //$("#preview").html("<h3 style='background:transparent; position: relative; font-size:1.5em;top:14px; left:10px;';> n e x t : </h3><img src='thumbs/"+ (nextunit) + ".png" + "' width='305'>")
rc-web@70 95 $("#previewbox-"+group).html("<img src='svg/"+(unit) + ".svg" + "' width='515'>")
rc-web@70 96 }
rc-web@70 97
rc-web@66 98 ////////////////////////////////////////////////
rc-web@66 99
rc-web@66 100 /* commented out for now as interferes with chat
rc-web@66 101 need to introduce metakey...manyana... not so usefull anyway really...
rc-web@66 102
rc-web@66 103 keyboard controls
rc-web@66 104 +++++++++++++++++++++++++
rc-web@66 105
rc-web@66 106 SPACE to toggle visibilty of preview
rc-web@66 107 m to toggle visibilty of metronome
rc-web@66 108 s to toggle visibilty of stopwatch
rc-web@66 109 h to hide all above
rc-web@66 110
rc-web@66 111
rc-web@66 112 */
rc-web@66 113 function toggle_visibility(id) {
rc-web@66 114 var e = document.getElementById(id);
rc-web@66 115 if(e.style.display == 'block')
rc-web@66 116 e.style.display = 'none';
rc-web@66 117 else
rc-web@66 118 e.style.display = 'block';
rc-web@66 119 }
rc-web@66 120
rc-web@66 121 $(document).keypress(function(e){
rc-web@66 122 // "space bar" for next unit preview
rc-web@66 123 var checkWebkitandIE=(e.which==32 ? 1 : 0);
rc-web@66 124 var checkMoz=(e.which==32 ? 1 : 0);
rc-web@66 125 // "m" button for metronome
rc-web@66 126 var mcheckWebkitandIE=(e.which==109 ? 1 : 0);
rc-web@66 127 var mcheckMoz=(e.which==109 ? 1 : 0);
rc-web@66 128 // "s" button for stopwatch/chronometer
rc-web@66 129 var ccheckWebkitandIE=(e.which==115 ? 1 : 0);
rc-web@66 130 var ccheckMoz=(e.which==115 ? 1 : 0);
rc-web@66 131
rc-web@66 132 // "h" button for hideall
rc-web@66 133 var hcheckWebkitandIE=(e.which==104 ? 1 : 0);
rc-web@66 134 var hcheckMoz=(e.which==104 ? 1 : 0);
rc-web@66 135
rc-web@66 136 // console.log(e.which);
rc-web@66 137 // if (checkWebkitandIE || checkMoz) { toggle_visibility('preview') }
rc-web@66 138 // if (mcheckWebkitandIE || mcheckMoz) { toggle_visibility('comms') }
rc-web@66 139 // if (ccheckWebkitandIE || ccheckMoz) { toggle_visibility('client_chronometer') }
rc-web@66 140 if (hcheckWebkitandIE || hcheckMoz) {
rc-web@66 141 toggle_visibility('info')
rc-web@66 142 //toggle_visibility('comms')
rc-web@66 143 //toggle_visibility('preview')
rc-web@66 144 }
rc-web@66 145 });
rc-web@66 146
rc-web@66 147 //*/
rc-web@66 148
rc-web@66 149 ////////////////////////////////////////////////
rc-web@66 150 // this needs to have a variable to define the websocket
rc-web@66 151 // otherwise we will pings from all sockets connected
rc-web@66 152 // no! the server broadcasts the ping and the clients emit the pong!
rc-web@66 153 // ah but then the time reported back from the server needs to be targeted
rc-web@66 154 // to specific client..
rc-web@66 155 //////////////////////////////////////////////
rc-web@66 156 // Latency "Pong"
rc-web@66 157 socket.on("timeFromServer", function(n) {
rc-web@66 158 socket.emit("clientTimeResponse",n); });
rc-web@66 159
rc-web@66 160 socket.on("latencyFromServer", function(latency) {
rc-web@66 161 $("#client_latency").text("Latency: "+latency+"ms.")
rc-web@66 162
rc-web@66 163 });
rc-web@66 164
rc-web@66 165 function getLatencies(x) { socket.emit("getLatencies", x); }
rc-web@66 166
rc-web@66 167 //////////////////////////////////////////////
rc-web@66 168
rc-web@66 169
rc-web@66 170 socket.on('connect', function () {
rc-web@66 171 $('#chat').addClass('connected');
rc-web@66 172 });
rc-web@66 173
rc-web@66 174 socket.on('announcement', function (msg) {
rc-web@66 175 $('#lines').append($('<p>').append($('<em>').text(msg)));
rc-web@66 176 });
rc-web@66 177
rc-web@66 178 socket.on('nicknames', function (nicknames) {
rc-web@66 179 $('#nicknames').empty().append($('<span>Online: </span>'));
rc-web@66 180 for (var i in nicknames) {
rc-web@66 181 $('#nicknames').append($('<b>').text(nicknames[i]));
rc-web@66 182 }
rc-web@66 183 });
rc-web@66 184
rc-web@66 185 socket.on('user message', message);
rc-web@66 186 socket.on('reconnect', function () {
rc-web@66 187 $('#lines').remove();
rc-web@66 188 message('System', 'Reconnected to the server');
rc-web@66 189 });
rc-web@66 190
rc-web@66 191 socket.on('reconnecting', function () {
rc-web@66 192 message('System', 'Attempting to re-connect to the server');
rc-web@66 193 });
rc-web@66 194
rc-web@66 195 socket.on('error', function (e) {
rc-web@66 196 message('System', e ? e : 'A unknown error occurred');
rc-web@66 197 });
rc-web@66 198
rc-web@66 199 function message (from, msg) {
rc-web@66 200 $('#lines').prepend($('<p>').prepend($('<b>').text(from), msg));
rc-web@66 201 }
rc-web@66 202
rc-web@66 203 // dom manipulation
rc-web@66 204 $(function () {
rc-web@66 205 $('#set-nickname').submit(function (ev) {
rc-web@66 206 socket.emit('nickname', $('#nick').val(), function (set) {
rc-web@66 207 if (!set) {
rc-web@66 208 clear();
rc-web@66 209 return $('#chat').addClass('nickname-set');
rc-web@66 210 }
rc-web@66 211 $('#nickname-err').css('visibility', 'visible');
rc-web@66 212 });
rc-web@66 213 return false;
rc-web@66 214 });
rc-web@66 215
rc-web@66 216 $('#send-message').submit(function () {
rc-web@66 217 message('me', $('#message').val());
rc-web@66 218 socket.emit('user message', $('#message').val());
rc-web@66 219 clear();
rc-web@66 220 $('#lines').get(0).scrollTop = 10000000;
rc-web@66 221 return false;
rc-web@66 222 });
rc-web@66 223
rc-web@66 224 function clear () {
rc-web@66 225 $('#message').val('').focus();
rc-web@66 226 };
rc-web@66 227 });