socket.io resource now base_path + '/transport'. #97
authorDarren <darren@darrenwhitlen.com>
Mon, 22 Oct 2012 18:31:47 +0000 (19:31 +0100)
committerDarren <darren@darrenwhitlen.com>
Mon, 22 Oct 2012 18:31:47 +0000 (19:31 +0100)
client/assets/dev/model_application.js
client/assets/dev/model_gateway.js
client/index.html
server/weblistener.js

index fef90644f681697efb305bb12182927e76dbb9b4..54a3ad5024511701d2887003f1fdba7fa42f11fa 100644 (file)
@@ -27,7 +27,7 @@ kiwi.model.Application = function () {
             }\r
 \r
             // The base url to the kiwi server\r
-            this.set('base_path', options[0].base_path ? options[0].base_path : '/client');\r
+            this.set('base_path', options[0].base_path ? options[0].base_path : '/kiwi');\r
 \r
             // Best guess at where the kiwi server is\r
             this.detectKiwiServer();\r
@@ -51,12 +51,16 @@ kiwi.model.Application = function () {
             this.view.barsHide(true);\r
 \r
             this.panels.server.server_login.bind('server_connect', function (event) {\r
-                var server_login = this;\r
+                var server_login = this,\r
+                    transport_path = '';\r
                 auto_connect_details = event;\r
 \r
                 server_login.networkConnecting();\r
                 \r
-                $script(that.kiwi_server + '/socket.io/socket.io.js?ts='+(new Date().getTime()), function () {\r
+                // Path to get the socket.io transport code\r
+                transport_path = that.kiwi_server + that.get('base_path') + '/transport/socket.io.js?ts='+(new Date().getTime());\r
+                \r
+                $script(transport_path, function () {\r
                     if (!window.io) {\r
                         kiwiServerNotFound();\r
                         return;\r
index b18470425a736efbbed67f2379763f57bc5da6ba..c68e114dc879b3eae80d59612a298d431160bee0 100644 (file)
@@ -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\r
     */\r
     this.connect = function (host, port, ssl, password, callback) {\r
+        var resource;\r
+\r
+        // Work out the resource URL for socket.io\r
+        if (kiwi.app.get('base_path').substr(0, 1) === '/') {\r
+            resource = kiwi.app.get('base_path');\r
+            resource = resource.substr(1, resource.length-1);\r
+            resource += '/transport';\r
+        } else {\r
+            resource = kiwi.app.get('base_path') + '/transport';\r
+        }\r
+\r
         this.socket = io.connect(this.get('kiwi_server'), {\r
+            'resource': resource,\r
+            \r
             'try multiple transports': true,\r
             'connect timeout': 3000,\r
             'max reconnection attempts': 7,\r
index bd33cc1573ece35c9c803d9ca084108dc8619c58..c7c81706490f58a200864b2e2ce63bf65e2dda8c 100644 (file)
@@ -6,14 +6,14 @@
 
 <title> KiwiIRC </title>
 
-<link rel="stylesheet" type="text/css" href="/client/assets/css/style.css" />
+<link rel="stylesheet" type="text/css" href="/kiwi/assets/css/style.css" />
 
 </head>
 <body>
     <div id="kiwi">
         <div id="toolbar">
             <a class="kiwi_logo" href="http://www.kiwiirc.com/" target="_blank">
-                <h2><img src="/client/assets/img/ico.png" alt="KiwiIRC Logo" title="Kiwi IRC" /> Powered by Kiwi IRC</h2>
+                <h2><img src="/kiwi/assets/img/ico.png" alt="KiwiIRC Logo" title="Kiwi IRC" /> Powered by Kiwi IRC</h2>
             </a>
 
             <div id="tabs">
 
             <div style="position:relative;float:left;width:320px;margin-left:3em;color:#555555;">
                 <a class="kiwi_logo" href="http://www.kiwiirc.com/" target="_blank">
-                    <img src="/client/assets/img/ico.png" alt="KiwiIRC Logo" title="Kiwi IRC" /> <br />
+                    <img src="/kiwi/assets/img/ico.png" alt="KiwiIRC Logo" title="Kiwi IRC" /> <br />
                     <h1>Powered by Kiwi IRC</h1>
                 </a>
 
         }
 
         // Entry path for the kiwi application
-        var base_path = '/client';
+        var base_path = '/kiwi';
 
         // Start loading scripts
         loadNextScript();
index 5a957211a605dba4ee81b93a758a31e9baec659f..15fef4746a06b7e2c94fe533089e648f2e0a5eef 100644 (file)
@@ -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);