Agent

  1. TOC

An Agent is the representation of a client’s Connection state on the server.

The Agent instance will be made available in all middleware contexts, where agent.custom can be particularly useful for storing custom context.

If the Connection was created through backend.connect() (i.e. the client is running on the server), then the Agent associated with a Connection can be accessed through connection.agent.

Properties

custom – Object

An object that consumers can use to pass information around through the middleware.

The agent.custom is passed onto the options field in database adapter calls as options.agentCustom. This allows further customisation at the database level e.g. in sharedb-mongo middleware.

clientId – string

The ID that ShareDB generates for the client. The client uses it as the src of its ops, unless it is reconnecting and keeps the ID from its previous connection instead.

The clientId can be set in 'connect' middleware, for example to restrict op sources. This doesn’t work for clients older than ShareDB v1.2, which are sent their ID before 'connect' runs.

backend – Backend

The Backend instance that created this Agent