annotate www/martin/js/nodescore-client.js @ 93:6889df0494a4

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