From b7be4766124bd5714c05b5bba0ca8afd58e288fc Mon Sep 17 00:00:00 2001 From: Darren Date: Sat, 6 Aug 2011 19:24:02 +0100 Subject: [PATCH] Separated any front end references from gateway.js --- js/front.js | 5 +++++ js/gateway.js | 10 +++++++--- node/kiwi.js | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/js/front.js b/js/front.js index 3989776..7a632a1 100644 --- a/js/front.js +++ b/js/front.js @@ -24,6 +24,7 @@ var front = { $(gateway).bind("onmotd", front.onMOTD); $(gateway).bind("onoptions", front.onOptions); $(gateway).bind("onconnect", front.onConnect); + $(gateway).bind("onconnect_fail", front.onConnectFail); $(gateway).bind("ondisconnect", front.onDisconnect); $(gateway).bind("onnick", front.onNick); $(gateway).bind("onuserlist", front.onUserList); @@ -418,6 +419,10 @@ var front = { front.tabviews.server.addMsg(null, ' ', '=== Failed to connect :(', 'status'); } }, + onConnectFail: function (e, data) { + var reason = (typeof data.reason === 'string') ? data.reason : ''; + front.tabviews.server.addMsg(null, '', 'There\'s a problem connecting! (' + reason + ')', 'error'); + }, onDisconnect: function (e, data) { var tab; for (tab in front.tabviews) { diff --git a/js/gateway.js b/js/gateway.js index 73ed97d..d7ebc56 100644 --- a/js/gateway.js +++ b/js/gateway.js @@ -23,15 +23,19 @@ var gateway = { if (typeof gateway.kiwi_server !== 'undefined') { gateway.socket = io.connect(kiwi_server, {'max reconnection attempts': 3}); gateway.socket.of('/kiwi').on('connect_failed', function (reason) { + // TODO: When does this even actually get fired? I can't find a case! ~Darren console.debug('Unable to connect Socket.IO', reason); - front.tabviews.server.addMsg(null, ' ', 'Unable to connect to Kiwi IRC.\n' + reason, 'error'); + //front.tabviews.server.addMsg(null, ' ', 'Unable to connect to Kiwi IRC.\n' + reason, 'error'); gateway.socket.disconnect(); - $(gateway).trigger("ondisconnect", {}); + $(gateway).trigger("onconnect_fail", {reason: reason}); gateway.sendData = function () {}; }).on('error', function (e) { + $(gateway).trigger("onconnect_fail", {}); console.debug(e); + console.log(e); }); gateway.socket.on('connect', function () { + console.log('connect event'); gateway.sendData = function (data, callback) { gateway.socket.emit('message', {sid: this.session_id, data: $.toJSON(data)}, callback); }; @@ -43,7 +47,7 @@ var gateway = { gateway.socket.emit('irc connect', gateway.nick, host, port, ssl, callback); }); gateway.socket.on('too_many_connections', function () { - front.tabviews.server.addMsg(null, ' ', 'Unable to connect to Kiwi IRC.\nYour IP address has too many connections to Kiwi IRC', 'error'); + $(gateway).trigger("onconnect_fail", {reason: 'too_many_connections'}); }); } }, diff --git a/node/kiwi.js b/node/kiwi.js index bfd0e16..40da463 100644 --- a/node/kiwi.js +++ b/node/kiwi.js @@ -586,7 +586,7 @@ io.of('/kiwi').authorization(function (handshakeData, callback) { break; case 'action': if ((args.target) && (args.msg)) { - websocket.sendServerLine('PRIVMSG ' + args.target + ' :ACTION ' + args.msg); + websocket.sendServerLine('PRIVMSG ' + args.target + ' :' + String.fromCharCode(1) + 'ACTION ' + args.msg + String.fromCharCode(1)); } break; case 'raw': -- 2.25.1