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