From a37b761aae6deb3b274cd8301340b62e0cfa9a69 Mon Sep 17 00:00:00 2001 From: Darren Date: Wed, 5 Sep 2012 11:17:39 +0100 Subject: [PATCH] Auto kiwi server detection + running from file --- client_backbone/dev/model_application.js | 40 ++- client_backbone/dev/view.js | 5 + client_backbone/index.html | 19 +- client_backbone/kiwi.js | 316 ++++++++++++++++++++--- client_backbone/kiwi.min.js | 2 +- 5 files changed, 339 insertions(+), 43 deletions(-) diff --git a/client_backbone/dev/model_application.js b/client_backbone/dev/model_application.js index 7eadae3..c01749f 100644 --- a/client_backbone/dev/model_application.js +++ b/client_backbone/dev/model_application.js @@ -7,9 +7,15 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { /** Instance of kiwi.model.PanelList */ this.panels = null; + /* Address for the kiwi server */ + this.kiwi_server = null; + this.initialize = function () { // Update `that` with this new Model object that = this; + + // Best guess at where the kiwi server is + this.detectKiwiServer(); }; this.start = function () { @@ -28,15 +34,41 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { this.view.barsHide(true); this.panels.server.server_login.bind('server_connect', function (event) { - auto_connect_details = event; - - kiwi.gateway.set('nick', event.nick); - kiwi.gateway.connect(event.server, 6667, false, false, function () {}); + var server_login = this; + server_login.networkConnecting(); + + // Attempt to load the transport scripts from the kiwi_server + loadScript(that.kiwi_server + '/socket.io/socket.io.js', function () { + auto_connect_details = event; + + kiwi.gateway.set('nick', event.nick); + kiwi.gateway.connect(event.server, 6667, false, false, function () {}); + }, function (error) { + console.log('Failed to load transport scripts from Kiwi server', error); + server_login.showError(); + }); }); }; + this.detectKiwiServer = function () { + // If running from file, default to localhost:7777 by default + if (window.location.protocol === 'file') { + this.kiwi_server = 'http://localhost:7777'; + + } else { + // Assume the kiwi server is on the same server + var proto = window.location.protocol === 'https' ? + 'https' : + 'http'; + + this.kiwi_server = proto + '://' + window.location.host + ':' + window.location.port; + } + + }; + + this.initializeClient = function () { this.view = new kiwi.view.Application({model: this, el: this.get('container')}); diff --git a/client_backbone/dev/view.js b/client_backbone/dev/view.js index ded9124..9865204 100644 --- a/client_backbone/dev/view.js +++ b/client_backbone/dev/view.js @@ -131,6 +131,11 @@ kiwi.view.ServerSelect = Backbone.View.extend({ networkConnecting: function (event) { this.setStatus('Connecting..', 'ok'); + }, + + showError: function (event) { + this.setStatus('Error connecting', 'error'); + $('form', this.$el).show(); } }); diff --git a/client_backbone/index.html b/client_backbone/index.html index 60c4a91..a05c776 100644 --- a/client_backbone/index.html +++ b/client_backbone/index.html @@ -63,6 +63,14 @@