Support changing server URL

This commit is contained in:
Tony Garnock-Jones 2013-10-31 19:08:28 -04:00
parent 671c5dbda6
commit 261ab7783a
2 changed files with 17 additions and 3 deletions

View File

@ -25,6 +25,10 @@
<form class="form-horizontal" name="nym_form">
<fieldset>
<div class="control-group">
<label class="control-label" for="wsurl">Server:</label>
<div class="controls">
<input type="text" id="wsurl" name="wsurl" value="ws://localhost:8000/">
</div>
<label class="control-label" for="nym">Nym:</label>
<div class="controls">
<input type="text" id="nym" name="nym" value="pseud">

View File

@ -174,12 +174,16 @@ WebSocketConnection.prototype.handleEvent = function (e) {
}
};
WebSocketConnection.prototype.reconnect = function () {
var self = this;
WebSocketConnection.prototype.forceclose = function () {
if (this.sock) {
this.sock.close();
this.sock = null;
}
};
WebSocketConnection.prototype.reconnect = function () {
var self = this;
this.forceclose();
this.sock = new WebSocket(this.wsurl);
this.sock.onopen = World.wrap(function (e) { return self.onopen(e); });
this.sock.onmessage = World.wrap(function (e) { return self.onmessage(e); });
@ -301,7 +305,8 @@ $(document).ready(function () {
console.log('starting ground boot');
// World.spawn(new Spy());
spawnJQueryDriver();
World.spawn(new WebSocketConnection("broker", "ws://localhost:8000/", true));
var wsconn = new WebSocketConnection("broker", $("#wsurl").val(), true);
World.spawn(wsconn);
World.spawn({
// Monitor connection, notifying connectivity changes
state: null,
@ -333,6 +338,7 @@ $(document).ready(function () {
return [sub(["jQuery", "#send_chat", "click", __]),
sub(["jQuery", "#nym", "change", __]),
sub(["jQuery", "#status", "change", __]),
sub(["jQuery", "#wsurl", "change", __]),
pub(["broker", 0, [this.nym(), "says", __]]),
pub(["broker", 0, [this.nym(), "status", this.currentStatus()]]),
sub(["broker", 0, [__, "says", __]], 0, 1),
@ -360,6 +366,10 @@ $(document).ready(function () {
case "#status":
World.updateRoutes(this.subscriptions());
break;
case "#wsurl":
wsconn.forceclose();
wsconn.wsurl = $("#wsurl").val();
break;
default:
console.log("Got jquery event from as-yet-unhandled subscription",
e.message[2], e.message[3]);