NetworkManager¶
(c) 2013-2014 http://ircanywhere.com
Author: Ricki Hastings
IRCAnywhere server/networks.js
-
class
NetworkManager.
NetworkManager
()¶ Responsible for handling everything related to networks, such as tracking changes removing, creating, changing tabs, creating and deleting networks etc.
Returns: void
-
NetworkManager.
flags
¶ An object containing the valid network statuses
Type: object
-
NetworkManager.
init
()¶ Called when the application is ready to proceed, this sets up event listeners for changes on networks and tabs collections and updates the Client object with the changes to essentially keep the object in sync with the collection so we can do fast lookups, but writes to the collection will propogate through and update Clients
Returns: void
-
NetworkManager.
getClients
()¶ Gets a list of networks, used by IRCFactory on synchronise to determine who to connect on startup, doesn’t ever really need to be called also can be modified with hooks to return more information if needed.
Returns: A promise containing the clients that should be started up
-
NetworkManager.
getClientsForUSer
(userId)¶ Gets a list of active networks for a user.
Arguments: - userId (string) – Id of the user
Returns: A promise that will resolve to the clients for the given user
-
NetworkManager.
getActiveChannelsForUser
(userId, networkId)¶ Gets a list of active channels for a user.
Arguments: - userId (string) – Id of the user
- networkId (string) – Id of the network
Returns: A promise that will resolve to the active channels for the given user
-
NetworkManager.
addNetworkApi
(req)¶ Handles the add network api call, basically handling authentication validating the parameters and input, and on success passes the information to addNetwork() which handles everything else
Arguments: - req (object) – A valid request object from express
Returns: An output object for the API call
-
NetworkManager.
editNetworkApi
(req)¶ Handles the edit network api call, everything the add network call does except it takes a network ID as a parameter validates the new data. On success it passes to editNetwork() which handles the rest.
Arguments: - req (object) – A valid request object from express
Returns: An output object for the API call
-
NetworkManager.
addNetwork
(user, network, status)¶ Adds a network using the settings specified to the user’s set of networks This just adds it to the database and doesn’t attempt to start it up.
Arguments: - user (object) – A valid user object from the users collection
- network (object) – A valid network object to insert
- status (string) – A valid network status
Returns: A promise to determine whether the insert worked or not
-
NetworkManager.
editNetwork
(user, network)¶ Edits an existing network, updating the record in the database. We’ll inform irc-factory that the network information has changed and perform a reconnect.
Arguments: - user (object) – A valid user object from the users collection
- network (object) – A valid network object to update
Returns: A promise to determine whether the insert worked or not
-
NetworkManager.
addTab
(client, target, type[, select, active])¶ Adds a tab to the client’s (network unique to user) tabs, this can be a channel or a username.
Arguments: - client (object) – A valid client object
- target (string) – The name of the tab being created
- type (string) – The type of the tab either ‘query’, ‘channel’ or ‘network’
- [select] (boolean) – Whether to mark the tab as selected or not, defaults to false
- [active] (boolean) – Whether to mark the tab as active or not, defaults to true
Returns: void
-
NetworkManager.
activeTab
(client[, target, activate])¶ Changes a tabs activity (not selection) - for example when you’re kicked from a channel the tab wont be removed it will be just set to active: false so when you see it in the interface it will appear as (#ircanywhere) instead of #ircanywhere We can omit target and call activeTab(client, false) to set them all to false (such as on disconnect)
Arguments: - client (object) – A valid client object
- [target] (string) – The name of the tab being altered, discard to mark all as active or inactive.
- activate (boolean) – Whether to set the tab as active or not
Returns: void
-
NetworkManager.
removeTab
(client[, target])¶ Removes the specified tab, be careful because this doesn’t re-select one, you’re expected to look for a removed tab, if it’s the currently selected one, go back to a different one.
Arguments: - client (object) – A valid client object
- [target] (string) – The name of the tab being altered, discard to remove all.
Returns: void
-
NetworkManager.
connectNetwork
(network)¶ Connect the specified network record, should only really be called when creating a new network as IRCFactory will load the client up on startup and then determine whether to connect the network itself based on the options.
However, it’s also called when it appears that there is no connected client on the /reconnect command (and any other similar commands). We can determine this (sloppy) from checking client.internal.status. If in the case that it does exist, it doesn’t matter if this is called really because irc-factory will prevent a re-write if the key is the same. We could consider looking at the response from factory synchronize but it might not yield a good result because of newly created clients since startup.
Arguments: - network (object) – A valid network or client object
Returns: void
-
NetworkManager.
changeStatus
(query, status)¶ Update the status for a specific network specified by a MongoDB query. The reason for this and not a straight ID is so we can do certain things such as checking if a network is marked as ‘disconnected’ during the closed event to determine whether to keep it as ‘disconnected’ or mark it as ‘closed’. So we can do much more elaborate queries here than just ID checking
Arguments: - query (object) – A MongoDB query to select a network
- status (boolean) – A valid network status
Returns: void