comparison www/m/js/nodescore-client.js @ 38:ea8d61c851c0

added chat server and more work on interface
author tzara <rc-web@kiben.net>
date Wed, 22 Aug 2012 12:51:28 +0000
parents c4719d1b7633
children 3ba24da53406
comparison
equal deleted inserted replaced
37:1b8d0935b749 38:ea8d61c851c0
17 var color = beatcolor; 17 var color = beatcolor;
18 18
19 $(".metrocase > div").each(function(){$(this).stop()}); 19 $(".metrocase > div").each(function(){$(this).stop()});
20 $(".metrocase > div").each(function(){$(this).css('background-color', beatcolor)}); 20 $(".metrocase > div").each(function(){$(this).css('background-color', beatcolor)});
21 $(".metrocase > div").each(function(){$(this).text(" ")}); 21 $(".metrocase > div").each(function(){$(this).text(" ")});
22 $(".metrocase > div").each(function(){$(this).animate({opacity: 0.6}, 22 $(".metrocase > div").each(function(){$(this).animate({opacity: 1},
23 50, 23 50,
24 function() { $(this).animate({opacity:0.0}); } 24 function() { $(this).animate({opacity:0.0}); }
25 ); 25 );
26 }) 26 })
27 } 27 }
55 55
56 socket.on("countinFromServer", countinClient); 56 socket.on("countinFromServer", countinClient);
57 function countinClient(groupID, currentseconds,mm,text,colour,background){ 57 function countinClient(groupID, currentseconds,mm,text,colour,background){
58 var groupPage=document.getElementById('group').value 58 var groupPage=document.getElementById('group').value
59 if (groupID == groupPage) { 59 if (groupID == groupPage) {
60 document.getElementById("countinnumber").style.visibility="visible"; 60 document.getElementById("count").style.visibility="visible";
61 document.getElementById("countinnumber").style.visibility="visible"; 61 document.getElementById("count").style.visibility="visible";
62 $("#countinnumber").text(currentseconds); 62
63 $("#countinnumber").css('background-color', background); 63 $("#counttitle").text(text);
64 $("#count").text(currentseconds);
65 //$("#cnt").text(currentseconds);
66
67 $("#count").css('background-color', background);
64 68
65 document.getElementById("countinnumber").style.color=colour; 69 document.getElementById("count").style.color=colour;
66 70
67 if ( currentseconds == 0) { 71 // if ( currentseconds == 0) {
68 document.getElementById("countinnumber").style.visibility='hidden'; 72 //document.getElementById("midcomms").style.visibility='hidden';
69 } 73 // }
70 }} 74 }}
71 75 /////////////////////////////////////////////////
72 ///////////////////////////////////////////////// 76
77 /////////////////////////////////////////////////
78 // countdown to change
79
80 socket.on("counterText", counterText);
81 function counterText(groupID, currentseconds,text){
82 var groupPage=document.getElementById('group').value
83 if (groupID == groupPage) {
84 console.log()
85 $("#totalcountdown").text(text);
86 }}
87
88 ///////////////////////////////////////
73 89
74 function pageFlip(unit) { 90 function pageFlip(unit) {
75 console.log("flipping page:"+ unit); 91 console.log("flipping page:"+ unit);
76 $('#sections').trigger('goto', [parseFloat(unit)]); 92 $('#sections').trigger('goto', [parseFloat(unit)]);
77 } 93 }
78
79 94
80 95
81 ///////////////////////////////////////////////// 96 /////////////////////////////////////////////////
82 97
83 // call the fancy jquery functions 98 // call the fancy jquery functions
110 $("#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 $("#preview").html("<h3 style='background:transparent; position: absolute; top:14px; right:14px;';> n e x t : </h3><img src='thumbs/"+next + ".png" + "' width='400'>")
111 } 126 }
112 127
113 //////////////////////////////////////////////// 128 ////////////////////////////////////////////////
114 129
115 /* 130 /* commented out for now as interferes with chat
131 need to introduce metakey...manyana... not so usefull anyway really...
116 132
117 keyboard controls 133 keyboard controls
118 +++++++++++++++++++++++++ 134 +++++++++++++++++++++++++
119 135
120 SPACE to toggle visibilty of preview 136 SPACE to toggle visibilty of preview
121 m to toggle visibilty of metronome 137 m to toggle visibilty of metronome
122 s to toggle visibilty of stopwatch 138 s to toggle visibilty of stopwatch
123 h to hide all above 139 h to hide all above
124 140
125 */ 141
126 142
127 function toggle_visibility(id) { 143 function toggle_visibility(id) {
128 var e = document.getElementById(id); 144 var e = document.getElementById(id);
129 if(e.style.display == 'block') 145 if(e.style.display == 'block')
130 e.style.display = 'none'; 146 e.style.display = 'none';
156 toggle_visibility('metro') 172 toggle_visibility('metro')
157 toggle_visibility('preview') 173 toggle_visibility('preview')
158 } 174 }
159 }); 175 });
160 176
177 */
178
161 //////////////////////////////////////////////// 179 ////////////////////////////////////////////////
162 // this needs to have a variable to define the websocket 180 // this needs to have a variable to define the websocket
163 // otherwise we will pings from all sockets connected 181 // otherwise we will pings from all sockets connected
164 // no! the server broadcasts the ping and the clients emit the pong! 182 // no! the server broadcasts the ping and the clients emit the pong!
165 // ah but then the time reported back from the server needs to be targeted 183 // ah but then the time reported back from the server needs to be targeted
176 }); 194 });
177 195
178 function getLatencies(x) { socket.emit("getLatencies", x); } 196 function getLatencies(x) { socket.emit("getLatencies", x); }
179 197
180 ////////////////////////////////////////////// 198 //////////////////////////////////////////////
199
200
201 socket.on('connect', function () {
202 $('#chat').addClass('connected');
203 });
204
205 socket.on('announcement', function (msg) {
206 $('#lines').append($('<p>').append($('<em>').text(msg)));
207 });
208
209 socket.on('nicknames', function (nicknames) {
210 $('#nicknames').empty().append($('<span>Online: </span>'));
211 for (var i in nicknames) {
212 $('#nicknames').append($('<b>').text(nicknames[i]));
213 }
214 });
215
216 socket.on('user message', message);
217 socket.on('reconnect', function () {
218 $('#lines').remove();
219 message('System', 'Reconnected to the server');
220 });
221
222 socket.on('reconnecting', function () {
223 message('System', 'Attempting to re-connect to the server');
224 });
225
226 socket.on('error', function (e) {
227 message('System', e ? e : 'A unknown error occurred');
228 });
229
230 function message (from, msg) {
231 $('#lines').append($('<p>').append($('<b>').text(from), msg));
232 }
233
234 // dom manipulation
235 $(function () {
236 $('#set-nickname').submit(function (ev) {
237 socket.emit('nickname', $('#nick').val(), function (set) {
238 if (!set) {
239 clear();
240 return $('#chat').addClass('nickname-set');
241 }
242 $('#nickname-err').css('visibility', 'visible');
243 });
244 return false;
245 });
246
247 $('#send-message').submit(function () {
248 message('me', $('#message').val());
249 socket.emit('user message', $('#message').val());
250 clear();
251 $('#lines').get(0).scrollTop = 10000000;
252 return false;
253 });
254
255 function clear () {
256 $('#message').val('').focus();
257 };
258 });