-_kiwi.model.Gateway = function () {\r
+_kiwi.model.Gateway = Backbone.Model.extend({\r
\r
- // Set to a reference to this object within initialize()\r
- var that = null;\r
-\r
- this.initialize = function () {\r
- that = this;\r
+ initialize: function () {\r
\r
// For ease of access. The socket.io object\r
this.socket = this.get('socket');\r
\r
// Used to check if a disconnection was unplanned\r
this.disconnect_requested = false;\r
- };\r
-\r
+ },\r
\r
\r
- this.reconnect = function (callback) {\r
- var that = this,\r
- transport_path;\r
\r
+ reconnect: function (callback) {\r
this.disconnect_requested = true;\r
this.socket.close();\r
\r
this.socket = null;\r
this.connect(callback);\r
- };\r
+ },\r
\r
\r
\r
* Connects to the server\r
* @param {Function} callback A callback function to be invoked once Kiwi's server has connected to the IRC server\r
*/\r
- this.connect = function (callback) {\r
+ connect: function (callback) {\r
+ var that = this;\r
+\r
this.connect_callback = callback;\r
\r
// Keep note of the server we are connecting to\r
this.socket.on('reconnecting_failed', function () {\r
console.log("_kiwi.gateway.socket.on('reconnect_failed')");\r
});\r
- };\r
+ },\r
\r
\r
/**\r
* Return a new network object with the new connection details\r
*/\r
- this.newConnection = function(connection_info, callback_fn) {\r
+ newConnection: function(connection_info, callback_fn) {\r
var that = this;\r
\r
// If not connected, connect first then re-call this function\r
callback_fn && callback_fn(err);\r
}\r
});\r
- };\r
+ },\r
\r
\r
/**\r
* Make a new IRC connection and return its connection ID\r
*/\r
- this.makeIrcConnection = function(connection_info, callback_fn) {\r
+ makeIrcConnection: function(connection_info, callback_fn) {\r
var server_info = {\r
nick: connection_info.nick,\r
hostname: connection_info.host,\r
callback_fn && callback_fn(err);\r
}\r
});\r
- };\r
+ },\r
\r
\r
- this.isConnected = function () {\r
+ isConnected: function () {\r
// TODO: Check this. Might want to use .readyState\r
return this.socket;\r
- };\r
+ },\r
\r
\r
\r
- this.parseKiwi = function (command, data) {\r
+ parseKiwi: function (command, data) {\r
var args;\r
\r
switch (command) {\r
\r
this.trigger('kiwi:' + command, data);\r
this.trigger('kiwi', data);\r
- };\r
+ },\r
\r
/**\r
* Parses the response from the server\r
*/\r
- this.parse = function (command, data) {\r
+ parse: function (command, data) {\r
var network_trigger = '';\r
\r
// Trigger the connection specific events (used by Network objects)\r
if (typeof data.connection_id !== 'undefined') {\r
network_trigger = 'connection:' + data.connection_id.toString();\r
\r
- that.trigger(network_trigger, {\r
+ this.trigger(network_trigger, {\r
event_name: command,\r
event_data: data\r
});\r
\r
// Some events trigger a more in-depth event name\r
if (command == 'message' && data.type) {\r
- that.trigger('connection ' + network_trigger, {\r
+ this.trigger('connection ' + network_trigger, {\r
event_name: 'message:' + data.type,\r
event_data: data\r
});\r
}\r
\r
if (command == 'channel' && data.type) {\r
- that.trigger('connection ' + network_trigger, {\r
+ this.trigger('connection ' + network_trigger, {\r
event_name: 'channel:' + data.type,\r
event_data: data\r
});\r
}\r
\r
// Trigger the global events\r
- that.trigger('connection', {event_name: command, event_data: data});\r
- that.trigger('connection:' + command, data);\r
- };\r
+ this.trigger('connection', {event_name: command, event_data: data});\r
+ this.trigger('connection:' + command, data);\r
+ },\r
\r
- this.rpcCall = function(method, connection_id) {\r
+ rpcCall: function(method, connection_id) {\r
var args = Array.prototype.slice.call(arguments, 0);\r
\r
if (typeof args[1] === 'undefined' || args[1] === null)\r
args[1] = _kiwi.app.connections.active_connection.get('connection_id');\r
\r
return this.rpc.call.apply(this.rpc, args);\r
- };\r
+ },\r
\r
/**\r
* Sends a PRIVMSG message\r
* @param {String} msg The message to send\r
* @param {Function} callback A callback function\r
*/\r
- this.privmsg = function (connection_id, target, msg, callback) {\r
+ privmsg: function (connection_id, target, msg, callback) {\r
var args = {\r
target: target,\r
msg: msg\r
};\r
\r
this.rpcCall('irc.privmsg', connection_id, args, callback);\r
- };\r
+ },\r
\r
/**\r
* Sends a NOTICE message\r
* @param {String} msg The message to send\r
* @param {Function} callback A callback function\r
*/\r
- this.notice = function (connection_id, target, msg, callback) {\r
+ notice: function (connection_id, target, msg, callback) {\r
var args = {\r
target: target,\r
msg: msg\r
};\r
\r
this.rpcCall('irc.notice', connection_id, args, callback);\r
- };\r
+ },\r
\r
/**\r
* Sends a CTCP message\r
* @param {String} params Additional paramaters\r
* @param {Function} callback A callback function\r
*/\r
- this.ctcp = function (connection_id, is_request, type, target, params, callback) {\r
+ ctcp: function (connection_id, is_request, type, target, params, callback) {\r
var args = {\r
is_request: is_request,\r
type: type,\r
};\r
\r
this.rpcCall('irc.ctcp', connection_id, args, callback);\r
- };\r
+ },\r
\r
- this.ctcpRequest = function (connection_id, type, target, params, callback) {\r
+ ctcpRequest: function (connection_id, type, target, params, callback) {\r
this.ctcp(connection_id, true, type, target, params, callback);\r
- };\r
- this.ctcpResponse = function (connection_id, type, target, params, callback) {\r
+ },\r
+ ctcpResponse: function (connection_id, type, target, params, callback) {\r
this.ctcp(connection_id, false, type, target, params, callback);\r
- };\r
+ },\r
\r
/**\r
* @param {String} target The target of the message (e.g. a channel or nick)\r
* @param {String} msg The message to send\r
* @param {Function} callback A callback function\r
*/\r
- this.action = function (connection_id, target, msg, callback) {\r
+ action: function (connection_id, target, msg, callback) {\r
this.ctcp(connection_id, true, 'ACTION', target, msg, callback);\r
- };\r
+ },\r
\r
/**\r
* Joins a channel\r
* @param {String} key The key to the channel\r
* @param {Function} callback A callback function\r
*/\r
- this.join = function (connection_id, channel, key, callback) {\r
+ join: function (connection_id, channel, key, callback) {\r
var args = {\r
channel: channel,\r
key: key\r
};\r
\r
this.rpcCall('irc.join', connection_id, args, callback);\r
- };\r
+ },\r
\r
/**\r
* Retrieves channel information\r
*/\r
- this.channelInfo = function (connection_id, channel, callback) {\r
+ channelInfo: function (connection_id, channel, callback) {\r
var args = {\r
channel: channel\r
};\r
\r
this.rpcCall('irc.channel_info', connection_id, args, callback);\r
- };\r
+ },\r
\r
/**\r
* Leaves a channel\r
* @param {String} message Optional part message\r
* @param {Function} callback A callback function\r
*/\r
- this.part = function (connection_id, channel, message, callback) {\r
+ part: function (connection_id, channel, message, callback) {\r
"use strict";\r
\r
// The message param is optional, so juggle args if it is missing\r
};\r
\r
this.rpcCall('irc.part', connection_id, args, callback);\r
- };\r
+ },\r
\r
/**\r
* Queries or modifies a channell topic\r
* @param {String} new_topic The new topic to set\r
* @param {Function} callback A callback function\r
*/\r
- this.topic = function (connection_id, channel, new_topic, callback) {\r
+ topic: function (connection_id, channel, new_topic, callback) {\r
var args = {\r
channel: channel,\r
topic: new_topic\r
};\r
\r
this.rpcCall('irc.topic', connection_id, args, callback);\r
- };\r
+ },\r
\r
/**\r
* Kicks a user from a channel\r
* @param {String} reason The reason for kicking the user\r
* @param {Function} callback A callback function\r
*/\r
- this.kick = function (connection_id, channel, nick, reason, callback) {\r
+ kick: function (connection_id, channel, nick, reason, callback) {\r
var args = {\r
channel: channel,\r
nick: nick,\r
};\r
\r
this.rpcCall('irc.kick', connection_id, args, callback);\r
- };\r
+ },\r
\r
/**\r
* Disconnects us from the server\r
* @param {String} msg The quit message to send to the IRC server\r
* @param {Function} callback A callback function\r
*/\r
- this.quit = function (connection_id, msg, callback) {\r
+ quit: function (connection_id, msg, callback) {\r
msg = msg || "";\r
\r
var args = {\r
};\r
\r
this.rpcCall('irc.quit', connection_id, args, callback);\r
- };\r
+ },\r
\r
/**\r
* Sends a string unmodified to the IRC server\r
* @param {String} data The data to send to the IRC server\r
* @param {Function} callback A callback function\r
*/\r
- this.raw = function (connection_id, data, callback) {\r
+ raw: function (connection_id, data, callback) {\r
var args = {\r
data: data\r
};\r
\r
this.rpcCall('irc.raw', connection_id, args, callback);\r
- };\r
+ },\r
\r
/**\r
* Changes our nickname\r
* @param {String} new_nick Our new nickname\r
* @param {Function} callback A callback function\r
*/\r
- this.changeNick = function (connection_id, new_nick, callback) {\r
+ changeNick: function (connection_id, new_nick, callback) {\r
var args = {\r
nick: new_nick\r
};\r
\r
this.rpcCall('irc.nick', connection_id, args, callback);\r
- };\r
+ },\r
\r
/**\r
* Sets a mode for a target\r
*/\r
- this.mode = function (connection_id, target, mode_string, callback) {\r
+ mode: function (connection_id, target, mode_string, callback) {\r
var args = {\r
data: 'MODE ' + target + ' ' + mode_string\r
};\r
\r
this.rpcCall('irc.raw', connection_id, args, callback);\r
- };\r
+ },\r
\r
/**\r
* Sends ENCODING change request to server.\r
* @param {String} new_encoding The new proposed encode\r
* @param {Fucntion} callback A callback function\r
*/\r
- this.setEncoding = function (connection_id, new_encoding, callback) {\r
+ setEncoding: function (connection_id, new_encoding, callback) {\r
var args = {\r
encoding: new_encoding\r
};\r
\r
this.rpcCall('irc.encoding', connection_id, args, callback);\r
- };\r
-\r
-\r
- return new (Backbone.Model.extend(this))(arguments);\r
-};\r
+ }\r
+});\r