annotate www/oi/js/nodescore-client.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 d802954248a7
children
rev   line source
rob@100 1 /////////////////////////////////////////////////
rob@100 2 // connect to websocket
rob@100 3
rob@100 4 var socket = io.connect();
rob@100 5 function initPage() { socket.emit("initPage");
rob@100 6 console.log("init.client.log")
rob@100 7 }
rob@100 8
rob@100 9 //socket.on("metroPulse", metronomeTick);
rob@100 10 /////////////////////////////////////////////////
rob@100 11
rob@100 12 socket.on("metroPulse", pulseInClient);
rob@100 13 function pulseInClient(pulse,groupID,metrobeat){
rob@100 14 var groupPage=document.getElementById('group').value
rob@100 15 if (groupID == groupPage) {
rob@100 16 metronomeTick(1000, groupID, metrobeat);
rob@100 17 }
rob@100 18 }
rob@100 19
rob@100 20 //////////////////////////////////////////////////
rob@100 21 // AUDIO SCORE CUES
rob@100 22
rob@100 23 var audioUnit1 = new Audio('audio/testfile.ogg');
rob@100 24 var audioUnit49 = new Audio('audio/testfile.ogg');
rob@100 25 var audioUnit3 = new Audio('audio/testfile.ogg');
rob@100 26 var audioUnit4 = new Audio('audio/testfile.ogg');
rob@100 27
rob@100 28 function playAudio(a) {
rob@100 29 a.play();
rob@100 30 }
rob@100 31
rob@100 32 //playAudio(audio_unit_1);
rob@100 33
rob@100 34
rob@100 35 /////////////////////////////////////////////////
rob@100 36 function metroCss(beat, beatcolor,text){
rob@100 37 var color = beatcolor;
rob@100 38 $(".metrocase > div").each(function(){$(this).stop()});
rob@100 39 $(".metrocase > div").each(function(){$(this).css('background-color', beatcolor)});
rob@100 40 $(".metrocase > div").each(function(){$(this).text(" ")});
rob@100 41 }
rob@100 42
rob@100 43 function metronomeTick(pulse, voice,metrobeat) {
rob@100 44 var color = "gray"
rob@100 45 metroCss(0, "red", "4")
rob@100 46 setTimeout(function(){metroCss(0, "black", "4")},150);
rob@100 47 };
rob@100 48
rob@100 49 /////////////////////////////////////////////////
rob@100 50 // update the stopwatch value on the client page in line with server
rob@100 51 socket.on("chronFromServer", function(chron) { $("div#client_chronometer").text(chron); });
rob@100 52
rob@100 53 // server time
rob@100 54 socket.on("dateTime", function(datetime) {
rob@100 55 $("div#datetime").text("" +datetime);
rob@100 56 });
rob@100 57
rob@100 58 /////////////////////////////////////////////////
rob@100 59
rob@100 60 // countin (solo part)
rob@100 61
rob@100 62 socket.on("countinFromServer", countinClient);
rob@100 63 function countinClient(groupID, currentseconds,mm,text,colour,background,unit){
rob@100 64 var groupPage=document.getElementById('group').value
rob@100 65 if (groupID == groupPage) {
rob@100 66 $("#counttitle").css('color','black');
rob@100 67 $("#counttitle").text(text);
rob@100 68 $("#count").text(currentseconds);
rob@100 69 document.getElementById("count").style.color=colour;
rob@100 70 }}
rob@100 71
rob@100 72 /////////////////////////////////////////////////
rob@100 73
rob@100 74 // countdown to change (solo)
rob@100 75
rob@100 76 socket.on("counterText", cText);
rob@100 77 function cText(groupID, currentseconds,text){
rob@100 78 $("#totalcountdown"+groupID).text(text);
rob@100 79 var groupPage=document.getElementById('group').value
rob@100 80 if (groupID == groupPage) {
rob@100 81 //console.log(text)
rob@100 82 $("#totalcountdown").text(text);
rob@100 83 }}
rob@100 84
rob@100 85 // when voice is changed in UI grab and update from server
rob@100 86
rob@100 87 function changeSoloVoice(v) { socket.emit("changeSoloVoice", v); }
rob@100 88
rob@100 89 // makes sure page is loaded if not it grabs svg etc
rob@100 90
rob@100 91 socket.on("pageIni", pageIni);
rob@100 92 function pageIni (group,unit,time,mm,seqcounter,nextunit) {
rob@100 93 //console.log(unit + " ---> " + nextunit)
rob@100 94 var soloist = $("#group").attr('value'); //4//$("#group").value;
rob@100 95 if (group==1){
rob@100 96 var n1 = $("#previewbox-1").html().indexOf("svg");
rob@100 97 //console.log(n1)
rob@100 98 if (n1 == -1){
rob@100 99 //console.log("n1 == -1 so load svg:")
rob@100 100 $("#previewbox-1").html("<img src='svg/"+(unit) + ".svg" + "' width='100%'>")
rob@100 101 }
rob@100 102 }
rob@100 103
rob@100 104 if (group==2){
rob@100 105 var n2 = $("#previewbox-2").html().indexOf("svg");
rob@100 106 if (n2 == -1){
rob@100 107 $("#previewbox-2").html("<img src='svg/"+(unit) + ".svg" + "' width='100%'>")
rob@100 108 }
rob@100 109 }
rob@100 110
rob@100 111 if (group==3){
rob@100 112 var n3 = $("#previewbox-3").html().indexOf("svg");
rob@100 113 if (n3 == -1){
rob@100 114 $("#previewbox-3").html("<img src='svg/"+(unit) + ".svg" + "' width='100%'>")
rob@100 115 }
rob@100 116 }
rob@100 117
rob@100 118 if (group==4){
rob@100 119 var n4 = $("#previewbox-4").html().indexOf("svg");
rob@100 120 if (n4 == -1){
rob@100 121 $("#previewbox-4").html("<img src='svg/"+(unit) + ".svg" + "' width='100%'>")
rob@100 122 }
rob@100 123 }
rob@100 124
rob@100 125
rob@100 126 if (group==soloist) {
rob@100 127 //console.log("INI sooolooooist=: ---------------------- : " + soloist)
rob@100 128 var n = $("#previewbox-solo").html().indexOf("svg");
rob@100 129 if (n == -1){
rob@100 130 $("#previewbox-solo").html("<img src='svg/"+(unit) + ".svg" + "' width='100%'>")
rob@100 131 $("#previewbox-solo-next").html("<img src='svg/"+(nextunit) + ".svg" + "' width='100%'>")
rob@100 132 }
rob@100 133 }
rob@100 134
rob@100 135
rob@100 136 }
rob@100 137
rob@100 138
rob@100 139 socket.on("pageFlip", pageFlip);
rob@100 140
rob@100 141 // some if logic to check if file is already displayed
rob@100 142 // if not load it - client doesnt need to be present at start
rob@100 143
rob@100 144 function pageFlip (group,unit,time,mm,seqcounter,nextunit) {
rob@100 145 var soloist = $("#group").attr('value');
rob@100 146
rob@100 147 if (group==1){
rob@100 148 $("#previewbox-1").html("<img src='svg/"+(unit) + ".svg" + "' width='100%'>")
rob@100 149 }
rob@100 150
rob@100 151 if (group==2){
rob@100 152 $("#previewbox-2").html("<img src='svg/"+(unit) + ".svg" + "' width='100%'>")
rob@100 153 }
rob@100 154
rob@100 155 if (group==3){
rob@100 156
rob@100 157 $("#previewbox-3").html("<img src='svg/"+(unit) + ".svg" + "' width='100%'>")
rob@100 158 }
rob@100 159
rob@100 160 if (group==4){
rob@100 161 $("#previewbox-4").html("<img src='svg/"+(unit) + ".svg" + "' width='100%'>")
rob@100 162 }
rob@100 163
rob@100 164
rob@100 165 // page flip for solo part section
rob@100 166
rob@100 167 if (group==soloist) {
rob@100 168
rob@100 169 // changes the svg and preview images
rob@100 170 $("#previewbox-solo").html("<img src='svg/"+(unit) + ".svg" + "' width='100%'>")
rob@100 171 $("#previewbox-solo-next").html("<img src='svg/"+(nextunit) + ".svg" + "' width='100%'>")
rob@100 172
rob@100 173 // check for audio assets to play
rob@100 174 // audio assets should have a value attribute which should be compared with the unit
rob@100 175 // if the unit has an associated audio attribute it should play
rob@100 176
rob@100 177 if ( window["audioUnit"+unit] ){
rob@100 178 console.log("audio asset detected for this unit... playing now...")
rob@100 179 playAudio(window["audioUnit"+unit]);
rob@100 180 } else { console.log("no audio for this unit.."); }
rob@100 181 }
rob@100 182
rob@100 183 // check for effect associated with unit
rob@100 184 // maybe in future we could use the webAudio API?
rob@100 185
rob@100 186 }
rob@100 187
rob@100 188
rob@100 189
rob@100 190 ////////////////////////////////////////////////
rob@100 191
rob@100 192 /* commented out for now as interferes with chat
rob@100 193 need to introduce metakey...manyana... not so usefull anyway really...
rob@100 194
rob@100 195 keyboard controls
rob@100 196 +++++++++++++++++++++++++
rob@100 197
rob@100 198 SPACE to toggle visibilty of preview
rob@100 199 m to toggle visibilty of metronome
rob@100 200 s to toggle visibilty of stopwatch
rob@100 201 h to hide all above
rob@100 202
rob@100 203
rob@100 204 */
rob@100 205
rob@100 206 function toggle_visibility(id) {
rob@100 207 var e = document.getElementById(id);
rob@100 208 if(e.style.display == 'block')
rob@100 209 e.style.display = 'none';
rob@100 210 else
rob@100 211 e.style.display = 'block';
rob@100 212 }
rob@100 213
rob@100 214 $(document).keypress(function(e){
rob@100 215 // console.log(e.which);
rob@100 216 // "0" button for hide chat
rob@100 217 var hcheckWebkitandIE=(e.which==48 ? 1 : 0);
rob@100 218 var hcheckMoz=(e.which==48 ? 1 : 0);
rob@100 219 if (hcheckWebkitandIE || hcheckMoz) {
rob@100 220 toggle_visibility('comms')
rob@100 221 }
rob@100 222 });
rob@100 223
rob@100 224 //*/
rob@100 225
rob@100 226 ////////////////////////////////////////////////
rob@100 227 // this needs to have a variable to define the websocket
rob@100 228 // otherwise we will pings from all sockets connected
rob@100 229 // no! the server broadcasts the ping and the clients emit the pong!
rob@100 230 // ah but then the time reported back from the server needs to be targeted
rob@100 231 // to specific client..
rob@100 232
rob@100 233 //////////////////////////////////////////////
rob@100 234 // Latency "Pong"
rob@100 235
rob@100 236 socket.on("timeFromServer", function(n) {
rob@100 237 socket.emit("clientTimeResponse",n); });
rob@100 238
rob@100 239 socket.on("latencyFromServer", function(latency) {
rob@100 240 $("#client_latency").text("Latency: "+latency+"ms.")
rob@100 241 });
rob@100 242
rob@100 243 function getLatencies(x) { socket.emit("getLatencies", x); }
rob@100 244
rob@100 245 //////////////////////////////////////////////
rob@100 246
rob@100 247
rob@100 248 socket.on('connect', function () {
rob@100 249 $('#chat').addClass('connected');
rob@100 250 });
rob@100 251
rob@100 252 socket.on('announcement', function (msg) {
rob@100 253 $('#Lines').append($('<p>').append($('<em>').text(msg)));
rob@100 254 });
rob@100 255
rob@100 256 socket.on('nicknames', function (nicknames) {
rob@100 257 $('#nicknames').empty().append($('<span>Online: </span>'));
rob@100 258 for (var i in nicknames) {
rob@100 259 $('#nicknames').append($('<b>').text(nicknames[i]));
rob@100 260 }
rob@100 261 });
rob@100 262
rob@100 263 socket.on('user message', message);
rob@100 264 socket.on('reconnect', function () {
rob@100 265 $('#lines').remove();
rob@100 266 message('System', 'Reconnected to the server');
rob@100 267 });
rob@100 268
rob@100 269 socket.on('reconnecting', function () {
rob@100 270 message('System', 'Attempting to re-connect to the server');
rob@100 271 });
rob@100 272
rob@100 273 socket.on('error', function (e) {
rob@100 274 message('System', e ? e : 'A unknown error occurred');
rob@100 275 });
rob@100 276
rob@100 277 function message (from, msg) {
rob@100 278 $('#lines').prepend($('<p>').prepend($('<b>').text(from), msg));
rob@100 279 }
rob@100 280
rob@100 281 // dom manipulation
rob@100 282 $(function () {
rob@100 283 $('#set-nickname').submit(function (ev) {
rob@100 284 socket.emit('nickname', $('#nick').val(), function (set) {
rob@100 285 if (!set) {
rob@100 286 clear();
rob@100 287 return $('#chat').addClass('nickname-set');
rob@100 288 }
rob@100 289 $('#nickname-err').css('visibility', 'visible');
rob@100 290 });
rob@100 291 return false;
rob@100 292 });
rob@100 293
rob@100 294 $('#send-message').submit(function () {
rob@100 295 message('me', $('#message').val());
rob@100 296 socket.emit('user message', $('#message').val());
rob@100 297 clear();
rob@100 298 $('#lines').get(0).scrollTop = 10000000;
rob@100 299 return false;
rob@100 300 });
rob@100 301
rob@100 302 function clear () {
rob@100 303 $('#message').val('').focus();
rob@100 304 };
rob@100 305 });