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