Skip to content

Connection

Class: jstp.Connection

Constructor: new Connection(transport, server, 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 to transport.connect().

Client-side only event emitted before attempting the reconnection.

Event: 'reconnect'

  • error <Error> | <null> The error that occurred during reconnection if any.

Client-side only event emitted after the reconnection attempt.

Event: 'client'

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'

Logging event emitted when an old style ('{}\0') heartbeat message is received.

Emitted only when process.env.NODE_ENV !== 'production'.

Event: 'incomingMessage'

Logging event emitted when a message is received.

Emitted only when process.env.NODE_ENV !== 'production'.

Event: 'outgoingMessage'

Logging event emitted when a message is sent.

Emitted only when process.env.NODE_ENV !== 'production'.

Event: 'inspect'

Logging event emitted when an 'inspect' message is received.

Event: 'messageRejected'

Logging event emitted when a message is rejected.

connection.handshake(app[, session], callback)

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 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)

Send an inspect message over the connection.

connection.callMethod(interfaceName, methodName, args, callback)

Send a call message over the connection.

connection.callMethodWithResend(interfaceName, methodName, args, callback)

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)

Send a ping message.

connection.startHeartbeat(interval)

Start periodically sending ping messages every interval milliseconds.

connection.stopHeartbeat()

Stop periodically sending ping messages.

connection.close()

Close the connection.

connection.getTransport()

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