comparison www/m.a/js/nodescore-client.js @ 42:49c94f63b8b0

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