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