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