From 8b0eb78733997d0b47d3e0e707e4d00b806a5340 Mon Sep 17 00:00:00 2001 From: Darren Date: Mon, 22 Oct 2012 19:31:47 +0100 Subject: [PATCH] socket.io resource now base_path + '/transport'. #97 --- client/assets/dev/model_application.js | 10 +++++++--- client/assets/dev/model_gateway.js | 13 +++++++++++++ client/index.html | 8 ++++---- server/weblistener.js | 24 +++++++++++++----------- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/client/assets/dev/model_application.js b/client/assets/dev/model_application.js index fef9064..54a3ad5 100644 --- a/client/assets/dev/model_application.js +++ b/client/assets/dev/model_application.js @@ -27,7 +27,7 @@ kiwi.model.Application = function () { } // The base url to the kiwi server - this.set('base_path', options[0].base_path ? options[0].base_path : '/client'); + this.set('base_path', options[0].base_path ? options[0].base_path : '/kiwi'); // Best guess at where the kiwi server is this.detectKiwiServer(); @@ -51,12 +51,16 @@ kiwi.model.Application = function () { this.view.barsHide(true); this.panels.server.server_login.bind('server_connect', function (event) { - var server_login = this; + var server_login = this, + transport_path = ''; auto_connect_details = event; server_login.networkConnecting(); - $script(that.kiwi_server + '/socket.io/socket.io.js?ts='+(new Date().getTime()), function () { + // Path to get the socket.io transport code + transport_path = that.kiwi_server + that.get('base_path') + '/transport/socket.io.js?ts='+(new Date().getTime()); + + $script(transport_path, function () { if (!window.io) { kiwiServerNotFound(); return; diff --git a/client/assets/dev/model_gateway.js b/client/assets/dev/model_gateway.js index b184704..c68e114 100644 --- a/client/assets/dev/model_gateway.js +++ b/client/assets/dev/model_gateway.js @@ -59,7 +59,20 @@ kiwi.model.Gateway = function () { * @param {Function} callback A callback function to be invoked once Kiwi's server has connected to the IRC server */ this.connect = function (host, port, ssl, password, callback) { + var resource; + + // Work out the resource URL for socket.io + if (kiwi.app.get('base_path').substr(0, 1) === '/') { + resource = kiwi.app.get('base_path'); + resource = resource.substr(1, resource.length-1); + resource += '/transport'; + } else { + resource = kiwi.app.get('base_path') + '/transport'; + } + this.socket = io.connect(this.get('kiwi_server'), { + 'resource': resource, + 'try multiple transports': true, 'connect timeout': 3000, 'max reconnection attempts': 7, diff --git a/client/index.html b/client/index.html index bd33cc1..c7c8170 100644 --- a/client/index.html +++ b/client/index.html @@ -6,14 +6,14 @@ KiwiIRC - +
@@ -100,7 +100,7 @@
@@ -246,7 +246,7 @@ } // Entry path for the kiwi application - var base_path = '/client'; + var base_path = '/kiwi'; // Start loading scripts loadNextScript(); diff --git a/server/weblistener.js b/server/weblistener.js index 5a95721..15fef47 100644 --- a/server/weblistener.js +++ b/server/weblistener.js @@ -7,6 +7,7 @@ var ws = require('socket.io'), dns = require('dns'), url = require('url'), _ = require('underscore'), + config = require('./configuration.js'), Client = require('./client.js').Client, HttpHandler = require('./httphandler.js').HttpHandler; @@ -14,24 +15,24 @@ var ws = require('socket.io'), var http_handler; -var WebListener = function (config, transports) { +var WebListener = function (web_config, transports) { var hs, opts, that = this; events.EventEmitter.call(this); - http_handler = new HttpHandler(config); + http_handler = new HttpHandler(web_config); - if (config.ssl) { + if (web_config.ssl) { opts = { - key: fs.readFileSync(__dirname + '/' + config.ssl_key), - cert: fs.readFileSync(__dirname + '/' + config.ssl_cert) + key: fs.readFileSync(__dirname + '/' + web_config.ssl_key), + cert: fs.readFileSync(__dirname + '/' + web_config.ssl_cert) }; // Do we have an intermediate certificate? - if (typeof config.ssl_ca !== 'undefined') { - opts.ca = fs.readFileSync(__dirname + '/' + config.ssl_ca); + if (typeof web_config.ssl_ca !== 'undefined') { + opts.ca = fs.readFileSync(__dirname + '/' + web_config.ssl_ca); } @@ -39,9 +40,9 @@ var WebListener = function (config, transports) { // Start socket.io listening on this weblistener this.ws = ws.listen(hs, {ssl: true}); - hs.listen(config.port, config.address); + hs.listen(web_config.port, web_config.address); - console.log('Listening on ' + config.address + ':' + config.port.toString() + ' with SSL'); + console.log('Listening on ' + web_config.address + ':' + web_config.port.toString() + ' with SSL'); } else { // Start some plain-text server up @@ -49,15 +50,16 @@ var WebListener = function (config, transports) { // Start socket.io listening on this weblistener this.ws = ws.listen(hs, {ssl: false}); - hs.listen(config.port, config.address); + hs.listen(web_config.port, web_config.address); - console.log('Listening on ' + config.address + ':' + config.port.toString() + ' without SSL'); + console.log('Listening on ' + web_config.address + ':' + web_config.port.toString() + ' without SSL'); } this.ws.set('log level', 1); this.ws.enable('browser client minification'); this.ws.enable('browser client etag'); this.ws.set('transports', transports); + this.ws.set('resource', (config.get().http_base_path || '') + '/transport'); this.ws.of('/kiwi').authorization(authoriseConnection).on('connection', function () { newConnection.apply(that, arguments); -- 2.25.1