socket: null,
start: function (kiwi_server) {
- gateway.socket = io.connect(kiwi_server);
- gateway.socket.on('connect', function () {
- gateway.sendData = function (data, callback) {
- gateway.socket.emit('message', {sid: this.session_id, data: $.toJSON(data)}, callback);
- };
- gateway.socket.on('message', gateway.parse);
- gateway.socket.on('disconnect', function () {
- // Teardown procedure here
- $(gateway).trigger("ondisconnect", {});
+ if (typeof kiwi_server !== 'undefined') {
+ gateway.socket = io.connect(kiwi_server);
+ gateway.socket.on('connect', function () {
+ console.debug("Connecting to " + kiwi_server);
+ gateway.sendData = function (data, callback) {
+ gateway.socket.emit('message', {sid: this.session_id, data: $.toJSON(data)}, callback);
+ };
+ gateway.socket.on('message', gateway.parse);
+ gateway.socket.on('disconnect', function () {
+ // Teardown procedure here
+ $(gateway).trigger("ondisconnect", {});
+ });
});
- });
+ }
},
connect: function (host, port, ssl, callback) {
debug
*/
parse: function (item) {
+ console.debug('a',item);
if (item.event !== undefined) {
$(gateway).trigger("on" + item.event, item);
- if (touchscreen)
link(rel="stylesheet", type="text/css", href="css/touchscreen_tweaks.css")
- script(src="http://192.168.1.127:7777/socket.io/socket.io.js")
+ script(type="text/javascript", src="/socket.io/socket.io.js")
script(type="text/javascript", src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js")
script(type="text/javascript", src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js")
script(type="text/javascript", src="js/jquery.json-2.2.min.js")
var agent = '#{agent}';
var touchscreen = #{touchscreen};
var init_data = {};
- var kiwi_server = '#{proto}://192.168.1.127:7777/';
+ var kiwi_server = '#{proto}://192.168.1.127:7777/kiwi';
var touch_scroll;
$(document).ready(function(){
http = require('http'),
https = require('https'),
fs = require('fs'),
+ url = require('url'),
+ static_server = require('node-static'),
ws = require('socket.io'),
+ jade = require('jade'),
_ = require('./lib/underscore.min.js'),
starttls = require('./lib/starttls.js');
}
};
+var fileServer = new (static_server.Server)(__dirname + '/client');
+
+var httpHandler = function (request, response) {
+ var uri, subs, useragent, agent, server_set, server, nick, debug, touchscreen;
+ if (config.handle_http) {
+ uri = url.parse(request.url);
+ subs = uri.pathname.substr(0, 4);
+ if ((subs === '/js/') || (subs === '/css') || (subs === '/img')) {
+ request.addListener('end', function () {
+ fileServer.serve(request, response);
+ });
+ } else if (uri.pathname === '/') {
+ useragent = (response.headers) ? response.headers['user-agent']: '';
+ if (useragent.indexOf('android') !== -1) {
+ agent = 'android';
+ touchscreen = true;
+ } else if (useragent.indexOf('iphone') !== -1) {
+ agent = 'iphone';
+ touchscreen = true;
+ } else if (useragent.indexOf('ipad') !== -1) {
+ agent = 'ipad';
+ touchscreen = true;
+ } else if (useragent.indexOf('ipod') !== -1) {
+ agent = 'ipod';
+ touchscreen = true;
+ } else {
+ agent = 'normal';
+ touchscreen = false;
+ }
+ if (uri.query) {
+ server_set = (uri.query.server !== '');
+ server = uri.query.server || 'irc.anonnet.org';
+ nick = uri.query.nick || '';
+ debug = (uri.query.debug !== '');
+ } else {
+ server = 'irc.anonnet.org';
+ nick = '';
+ }
+ response.setHeader('Connection', 'close');
+ response.setHeader('X-Generated-By', 'KiwiIRC');
+ jade.renderFile(__dirname + '/client/index.html.jade', { locals: { "touchscreen": touchscreen, "debug": debug, "server_set": server_set, "server": server, "nick": nick, "agent": agent, "config": config }}, function (err, html) {
+ if (!err) {
+ response.write(html);
+ } else {
+ response.statusCode = 500;
+ }
+ response.end();
+ });
+ } else if (uri.pathname.substr(0, 10) === '/socket.io') {
+ // Do nothing!
+ } else {
+ response.statusCode = 404;
+ response.end();
+ }
+ }
+};
+
//setup websocket listener
if (config.listen_ssl) {
- var httpServer = https.createServer({key: fs.readFileSync(__dirname + '/' + config.ssl_key), cert: fs.readFileSync(__dirname + '/' + config.ssl_cert)});
+ var httpServer = https.createServer({key: fs.readFileSync(__dirname + '/' + config.ssl_key), cert: fs.readFileSync(__dirname + '/' + config.ssl_cert)}, httpHandler);
var io = ws.listen(httpServer, {secure: true});
httpServer.listen(config.port, config.bind_address);
} else {
- var httpServer = http.createServer();
+ var httpServer = http.createServer(httpHandler);
var io = ws.listen(httpServer, {secure: false});
httpServer.listen(config.port, config.bind_address);
}
-io.sockets.on('connection', function (websocket) {
+io.of('/kiwi').on('connection', function (websocket) {
websocket.on('irc connect', function (nick, host, port, ssl, callback) {
var ircSocket;
//setup IRC connection