NodeConnection

Description

Variables Summary

Classes Summary

Variables

CONNECTION_ATTEMPTS

define{number}
Connection attempts to make before failing

CONNECTION_TIMEOUT

define{number}
Milliseconds to wait before a particular connection attempt is considered failed. NOTE: It's okay for the connection timeout to be long because the expected behavior of WebSockets is to send a "close" event as soon as they realize they can't connect. So, we should rarely hit the connection timeout even if we try to connect to a port that isn't open.

MAX_COUNTER_VALUE

define
{number} Maximum value of the command ID counter

RETRY_DELAY

define{number}
Milliseconds to wait before retrying connecting

Classes

Properties

Private

_autoReconnect

type{boolean}
Whether to attempt reconnection if connection fails
Private

_commandCount

type{number}
Unique ID for commands
Private

_pendingCommandDeferreds

type{Array.<jQuery.Deferred>}
Array (indexed on command ID) of deferred objects that should be resolved/rejected with the response of commands.
Private

_pendingInterfaceRefreshDeferreds

type{Array.<jQuery.Deferred>}
List of deferred objects that should be resolved pending a successful refresh of the API
Private

_port

type{?number}
The port the WebSocket is currently connected to
Private

_registeredModules

type{Array.<string>}
List of module pathnames that should be re-registered if there is a disconnection/connection (i.e. if the server died).
Private

_ws

type{WebSocket}
The connection to the server

domains

type{Object}
Exposes the domains registered with the server. This object will have a property for each registered domain. Each of those properties will be an object containing properties for all the commands in that domain. So, myConnection.base.enableDebugger would point to the function to call to enable the debugger. This object is automatically replaced every time the API changes (based on the base:newDomains event from the server). Therefore, code that uses this object should not keep their own pointer to the domain property.

Methods

Private

_cleanup

Private

_getConnectionTimeout STATIC

Returns: number
Timeout value in milliseconds
Private

_getNextCommandID

Returns: number
The next command ID to use. Always representable as an unsigned 32-bit integer.
Private

_receive

message WebSocket.Message
Message object from WebSocket
Private

_refreshInterface

Private

_send

m Object,string
Object to send. Must be JSON.stringify-able.

connect

Connect to the node server. After connecting, the NodeConnection object will trigger a "close" event when the underlying socket is closed. If the connection is set to autoReconnect, then the event will also include a jQuery promise for the connection.

autoReconnect boolean
Whether to automatically try to reconnect to the server if the connection succeeds and then later disconnects. Note if this connection fails initially, the autoReconnect flag is set to false. Future calls to connect() can reset it to true
Returns: jQuery.Promise
Promise that resolves/rejects when the connection succeeds/fails

connected

Determines whether the NodeConnection is currently connected

return{boolean}
Whether the NodeConnection is connected.

disconnect

Explicitly disconnects from the server. Note that even if autoReconnect was set to true at connection time, the connection will not reconnect after this call. Reconnection can be manually done by calling connect() again.

loadDomains

Load domains into the server by path

List Array.<string>
of absolute paths to load
autoReload boolean
Whether to auto-reload the domains if the server fails and restarts. Note that the reload is initiated by the client, so it will only happen after the client reconnects.
Returns: jQuery.Promise
Promise that resolves after the load has succeeded and the new API is availale at NodeConnection.domains, or that rejects on failure.