comparison rlgterm.js @ 106:dc1414faee19

RLG-Web client: determine the host for WebSocket connections. Construct the URLs for WebSocket connections using window.location.host instead of hardcoding them.
author John "Elwin" Edwards <elwin@sdf.org>
date Sat, 14 Jul 2012 10:11:13 -0700
parents a9371002aecc
children 86a458080e80
comparison
equal deleted inserted replaced
105:a9371002aecc 106:dc1414faee19
73 "name": "Super-Rogue", 73 "name": "Super-Rogue",
74 "uname": "srogue" 74 "uname": "srogue"
75 } 75 }
76 }; 76 };
77 77
78 var wsHost = "localhost:8080";
79
80 var session = { 78 var session = {
81 /* The session id assigned by the server. */ 79 /* The session id assigned by the server. */
82 id: null, 80 id: null,
83 /* Login name and key */ 81 /* Login name and key */
84 lname: null, 82 lname: null,
521 } 519 }
522 return; 520 return;
523 } 521 }
524 if (statsock) 522 if (statsock)
525 return; 523 return;
526 statsock = new WebSocket("ws://" + wsHost + "/status"); 524 statsock = new WebSocket("ws://" + window.location.host + "/status");
527 statsock.onmessage = function (ev) { 525 statsock.onmessage = function (ev) {
528 var msg; 526 var msg;
529 try { 527 try {
530 msg = JSON.parse(ev.data); 528 msg = JSON.parse(ev.data);
531 } catch (e) { 529 } catch (e) {
740 } 738 }
741 return watcher; 739 return watcher;
742 } 740 }
743 741
744 function wsWatch(gamenumber) { 742 function wsWatch(gamenumber) {
745 var sockurl = "ws://" + wsHost + "/watch/" + String(gamenumber); 743 var sockurl = "ws://" + window.location.host + "/watch/" + String(gamenumber);
746 var ws = new WebSocket(sockurl); 744 var ws = new WebSocket(sockurl);
747 ws.onopen = function (event) { 745 ws.onopen = function (event) {
748 session.id = true; 746 session.id = true;
749 session.sock = ws; 747 session.sock = ws;
750 setmode("watch"); 748 setmode("watch");