From cbcccdbd4b9fc0e39bf040d8581088f3a34de552 Mon Sep 17 00:00:00 2001 From: Darren Date: Mon, 3 Oct 2011 22:42:33 +0100 Subject: [PATCH] Merge with irc handler in FF --- client/js/front.js | 14 ++++++++++++++ server/app.js | 21 +++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/client/js/front.js b/client/js/front.js index 8902a08..dc4e68e 100644 --- a/client/js/front.js +++ b/client/js/front.js @@ -533,6 +533,20 @@ kiwi.front = { }(msg)); return msg; + }, + + registerProtocolHandler: function () { + var state, uri; + url = kiwi_server.replace(/\/kiwi$/, '/?ircuri=%s'); + try { + //state = window.navigator.isProtocolHandlerRegistered('irc', url); + //if (state !== 'registered') { + window.navigator.registerProtocolHandler('irc', url, 'Kiwi IRC'); + //} + } catch (e) { + console.log('Unable to register Kiwi IRC as a handler for irc:// links'); + console.error(e); + } } }; diff --git a/server/app.js b/server/app.js index 2f26013..cbaff4d 100644 --- a/server/app.js +++ b/server/app.js @@ -529,7 +529,7 @@ this.ircSocketDataHandler = function (data, websocket, ircSocket) { this.httpHandler = function (request, response) { var uri, uri_parts, subs, useragent, agent, server_set, server, nick, debug, touchscreen, hash, - min = {}, public_http_path, port, ssl, host, obj, args, + min = {}, public_http_path, port, ssl, host, obj, args, ircuri, pass, target, modifiers, query, secure = (typeof request.client.encrypted === 'object'); //try { @@ -547,7 +547,24 @@ this.httpHandler = function (request, response) { subs = uri.pathname.substr(0, 4); public_http_path = kiwi.kiwi_root + '/' + kiwi.config.public_http; - if (uri.pathname === '/js/all.js') { + + if (typeof uri.query.ircuri !== 'undefined') { + ircuri = url.parse(uri.query.ircuri, true); + if (ircuri.protocol === 'irc:') { + uri_parts = /^\/([^,\?]*)((,[^,\?]*)*)?$/.exec(ircuri.pathname); + target = uri_parts[1]; + modifiers = (typeof uri_parts[2] !== 'undefined') ? uri_parts[2].split(',') : []; + query = ircuri.query; + + nick = _.detect(modifiers, function (mod) { + return mod === ',isnick'; + }); + console.log(request.headers); + response.statusCode = 303; + response.setHeader('Location', 'http' + ((secure) ? 's' : '') + '://' + request.headers.host + '/client/' + ircuri.host + '/' + ((!nick) ? target : '')); + response.end(); + } + } else if (uri.pathname === '/js/all.js') { if (kiwi.cache.alljs === '') { min.underscore = fs.readFileSync(public_http_path + 'js/underscore.min.js'); -- 2.25.1