comparison lib/js/urweb.js @ 679:44f23712020d

Chat example working nicely, but without dead channel removal
author Adam Chlipala <adamc@hcoop.net>
date Thu, 26 Mar 2009 18:26:50 -0400
parents a8effb6159c2
children 6c9b8875f347
comparison
equal deleted inserted replaced
678:5ff1ff38e2db 679:44f23712020d
255 } catch (e) { } 255 } catch (e) { }
256 256
257 if (isok) { 257 if (isok) {
258 var lines = xhr.responseText.split("\n"); 258 var lines = xhr.responseText.split("\n");
259 if (lines.length < 2) 259 if (lines.length < 2)
260 throw "Empty message from remote server"; 260 return; //throw "Empty message from remote server";
261 261
262 for (var i = 0; i+1 < lines.length; i += 2) { 262 for (var i = 0; i+1 < lines.length; i += 2) {
263 var chn = lines[i]; 263 var chn = lines[i];
264 var msg = lines[i+1]; 264 var msg = lines[i+1];
265 265
283 } 283 }
284 284
285 connect(); 285 connect();
286 } 286 }
287 else { 287 else {
288 try { 288 /*try {
289 whine("Error querying remote server for messages! " + xhr.status); 289 whine("Error querying remote server for messages! " + xhr.status);
290 } catch (e) { } 290 } catch (e) { }*/
291 } 291 }
292 } 292 }
293 }; 293 };
294 294
295 onTimeout = function() { 295 onTimeout = function() {
298 }; 298 };
299 299
300 connect(); 300 connect();
301 } 301 }
302 302
303 var listener_started = false;
304
303 function rv(chn, parse, k) { 305 function rv(chn, parse, k) {
304 if (chn < 0) 306 if (chn < 0)
305 whine("Out-of-bounds channel receive"); 307 whine("Out-of-bounds channel receive");
308
309 if (!listener_started) {
310 listener_started = true;
311 listener();
312 }
306 313
307 var ch; 314 var ch;
308 315
309 if (chn >= channels.length || channels[chn] == null) { 316 if (chn >= channels.length || channels[chn] == null) {
310 ch = newChannel(); 317 ch = newChannel();
318 } else { 325 } else {
319 k(parse(msg))(null); 326 k(parse(msg))(null);
320 } 327 }
321 } 328 }
322 329
323 function unesc(s) { 330 function uf(s) {
324 return unescape(s).replace("+", " "); 331 return escape(s).replace(new RegExp ("/", "g"), "%2F");
325 } 332 }
333
334 function uu(s) {
335 return unescape(s).replace(new RegExp ("\\+", "g"), " ");
336 }