kiwi.gateway.set('kiwi_server', that.kiwi_server + '/kiwi');\r
kiwi.gateway.set('nick', event.nick);\r
\r
- kiwi.gateway.connect(event.server, event.port, event.ssl, event.password, function () {});\r
+ kiwi.gateway.connect(event.server, event.port, event.ssl, event.password, function (error) {\r
+ if (error) {\r
+ kiwiServerNotFound();\r
+ }\r
+ });\r
});\r
});\r
\r
'sync disconnect on unload': false\r
});\r
this.socket.on('connect_failed', function (reason) {\r
- // TODO: When does this even actually get fired? I can't find a case! ~Darren\r
- console.debug('Unable to connect Socket.IO', reason);\r
- console.log("kiwi.gateway.socket.on('connect_failed')");\r
- //kiwi.front.tabviews.server.addMsg(null, ' ', 'Unable to connect to Kiwi IRC.\n' + reason, 'error');\r
this.socket.disconnect();\r
this.trigger("connect_fail", {reason: reason});\r
});\r
console.log("kiwi.gateway.socket.on('connect')");\r
} else {\r
console.log("kiwi.gateway.socket.on('error')", {reason: err});\r
+ callback(err);\r
}\r
});\r
});\r
that.parse(data.command, data.data);\r
});\r
\r
+ this.socket.on('kiwi', function (data, callback) {\r
+ that.parseKiwi(data.command, data.data);\r
+ });\r
+\r
this.socket.on('disconnect', function () {\r
that.trigger("disconnect", {});\r
console.log("kiwi.gateway.socket.on('disconnect')");\r
};\r
\r
\r
+\r
+ this.parseKiwi = function (command, data) {\r
+ console.log('kiwi event', command, data);\r
+ };\r
/*\r
Events:\r
msg\r
* Parses the response from the server\r
*/\r
this.parse = function (command, data) {\r
- console.log('gateway event', command, data);\r
+ //console.log('gateway event', command, data);\r
if (command !== undefined) {\r
that.trigger('on' + command, data);\r
\r
Client.prototype.sendIrcCommand = function (command, data, callback) {
var c = {command: command, data: data};
- //console.log('C<--', c);
this.websocket.emit('irc', c, callback);
};
-Client.prototype.sendKiwiCommand = function (command, callback) {
- this.websocket.emit('kiwi', command, callback);
+Client.prototype.sendKiwiCommand = function (command, data, callback) {
+ var c = {command: command, data: data};
+ this.websocket.emit('kiwi', c, callback);
};
function handleClientMessage(msg, callback) {
// Run the client command
this.client_commands.run(msg.data.method, msg.data.args, server, callback);
-};
+}
});
con.on('error', function (err) {
- this.websocket.sendKiwiCommand('error', {server: con_num, error: err});
+ // TODO: Once multiple servers implemented, specify which server failed
+ //that.sendKiwiCommand('error', {server: con_num, error: err});
+ return callback(err.code, null);
});
con.on('close', function () {
});
}
- this.socket.on('error', function () {
- var a = Array.prototype.slice.call(arguments);
- a.unshift('error');
- that.emit.apply(this, a);
+ this.socket.on('error', function (event) {
+ that.emit('error', event);
});
this.socket.setEncoding('utf-8');