From: Darren Date: Sat, 6 Aug 2011 18:24:02 +0000 (+0100) Subject: Separated any front end references from gateway.js X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b7be4766124bd5714c05b5bba0ca8afd58e288fc;p=KiwiIRC.git Separated any front end references from gateway.js --- 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':