Connection¶
Class: jstp.Connection¶
Constructor: new Connection(transport, server, client)¶
transport<Transport>server<Server>client<Client>
Either server or client must be provided, but not both.
server is required for server side connection, whereas client is required
for client side connection.
You should not call this constructor manually, unless you implement a custom JSTP transport.
Recommended approach is to call connect() or connectAndInspect() functions
provided by these modules:
Event: 'reconnectAttempt'¶
transport<string>Transport name....options<any>Options passed totransport.connect().
Client-side only event emitted before attempting the reconnection.
Event: 'reconnect'¶
Client-side only event emitted after the reconnection attempt.
Event: 'client'¶
session<Session>connection<Connection>
Server-side only event emitted on successful session creation or restoration.
Event: 'call'¶
Logging event emitted when a 'call' message is received.
Logging events are not emitted when there is a dedicated logger specified in the client object.
Event: 'callback'¶
Logging event emitted when a 'callback' message is received.
Event: 'event'¶
Logging event emitted when an 'event' message is received.
Event: 'handshake'¶
error<Array>ok<string>|<number>Session ID if the session was created or count of the messages received by the other side if the session is restored.
Logging event emitted when a 'handshake' message response is received.
Event: 'heartbeat'¶
message<Object>Empty object.
Logging event emitted when an old style ('{}\0') heartbeat message is
received.
Emitted only when process.env.NODE_ENV !== 'production'.
Event: 'incomingMessage'¶
message<Object>Message object.
Logging event emitted when a message is received.
Emitted only when process.env.NODE_ENV !== 'production'.
Event: 'outgoingMessage'¶
message<Object>Message object.
Logging event emitted when a message is sent.
Emitted only when process.env.NODE_ENV !== 'production'.
Event: 'inspect'¶
intefaceName<string>
Logging event emitted when an 'inspect' message is received.
Event: 'messageRejected'¶
message<Object>Message object.
Logging event emitted when a message is rejected.
connection.handshake(app[, session], callback)¶
app<string>|<Object>session<Session>callback<Function>error<RemoteError>sessionId<string>
app may be 'name', 'name@version' or { name, version },
where version must be a valid semver range.
Send a handshake message over the connection.
When session is provided, uses 'session' authentication strategy,
'anonymous' authentication strategy is used otherwise.
connection.handshake(app, login, password, callback)¶
app<string>|<Object>login<string>password<string>callback<Function>error<RemoteError>sessionId<string>
app may be 'name', 'name@version' or { name, version },
where version must be a valid semver range.
Send a handshake message over the connection using 'login' authentication
strategy.
connection.inspectInterface(interfaceName, callback)¶
interfaceName<string>callback<Function>error<RemoteError>proxy<RemoteProxy>
Send an inspect message over the connection.
connection.callMethod(interfaceName, methodName, args, callback)¶
interfaceName<string>methodName<string>args<Array>callback<Function>error<RemoteError>...args<Array>
Send a call message over the connection.
connection.callMethodWithResend(interfaceName, methodName, args, callback)¶
interfaceName<string>methodName<string>args<Array>callback<Function>error<RemoteError>...args<Array>
Send a call message over the connection resending if not possible to get a callback.
connection.emitRemoteEvent(interfaceName, eventName, args)¶
Send an event message over the connection.
connection.ping(callback)¶
callback<Function>
Send a ping message.
connection.startHeartbeat(interval)¶
interval<number>
Start periodically sending ping messages every interval milliseconds.
connection.stopHeartbeat()¶
Stop periodically sending ping messages.
connection.close()¶
Close the connection.
connection.getTransport()¶
- Returns:
<Transport>
Returns underlying transport.
connection.server¶
connection.client¶
connection.id¶
Unique for this process connection identifier.
connection.remoteAddress¶
<any>
Value obtained from connection.getTransport().remoteAddress.
connection.handshakeDone¶
connection.username¶
May be null if connection was established without logging in.
connection.session¶
connection.application¶
connection.remoteProxies¶
<Object>[interfaceName]<RemoteProxy>