* IRCD and the nick has been accepted.\r
*/\r
this.socket.on('connect', function () {\r
+ that.newConnection({\r
+ nick: that.get('nick'),\r
+ host: host,\r
+ port: port,\r
+ ssl: ssl,\r
+ password: password\r
+ }, callback);\r
+ /*\r
this.emit('kiwi', {command: 'connect', nick: that.get('nick'), hostname: host, port: port, ssl: ssl, password:password}, function (err, server_num) {\r
if (!err) {\r
that.server_num = server_num;\r
callback(err);\r
}\r
});\r
+ */\r
});\r
\r
this.socket.on('too_many_connections', function () {\r
\r
\r
\r
+ this.newConnection = function(connection_info, callback_fn) {\r
+ var that = this,\r
+ h = connection_info;\r
+\r
+ this.socket.emit('kiwi', {command: 'connect', nick: h.nick, hostname: h.host, port: h.port, ssl: h.ssl, password: h.password}, function (err, server_num) {\r
+ if (!err) {\r
+ that.server_num = server_num;\r
+\r
+ // TODO: Remove this whole premature connection thing when panel code is tidied\r
+ if (server_num != 0 && !_kiwi.app.connections.getByConnectionId(server_num)){\r
+ _kiwi.app.connections.add(new _kiwi.model.Network({connection_id: server_num}));\r
+ }\r
+\r
+ console.log("_kiwi.gateway.socket.on('connect')");\r
+ } else {\r
+ console.log("_kiwi.gateway.socket.on('error')", {reason: err});\r
+ callback_fn && callback_fn(err);\r
+ }\r
+ });\r
+ };\r
+\r
+\r
+\r
this.isConnected = function () {\r
return this.socket.socket.connected;\r
};\r
break;\r
\r
case 'connect':\r
- if (!_kiwi.app.connections.getByConnectionId(data.server)) {\r
- _kiwi.app.connections.add(new _kiwi.model.Network({connection_id: data.server}));\r
- }\r
that.set('nick', data.nick);\r
break;\r
\r