Skip to content

Class: Client

Wrapper for the standard WebSocket object. Instances of Client represent a single WebSocket connection to a Synapse server.

Hierarchy

  • Client

Index

Properties

Methods

Properties

Private callbacks

callbacks: object

Defined in lib/client/Client.ts:24

Stores callback functions associated with request strings.


Private index

index: number

Defined in lib/client/Client.ts:21

Stores the number of requests that have been processed by the instance. Used to tag requests with a unique identifier.


Private ws

ws: WebSocket

Defined in lib/client/Client.ts:18

The WebSocket connection to the server.

Methods

delete

delete(path: string, args: object): Promise‹Response

Defined in lib/client/Client.ts:105

Sends a DELETE request to the server and returns a Promise resolving to its eventual Response.

Parameters:

Name Type Default Description
path string - The resource path.
args object {} The arguments to accompany the request.

Returns: Promise‹Response


disconnect

disconnect(): void

Defined in lib/client/Client.ts:152

Closes the WebSocket connection.

Returns: void


get

get(path: string, args: object): Promise‹Response

Defined in lib/client/Client.ts:73

Sends a GET request to the server and returns a Promise resolving to its eventual Response.

Parameters:

Name Type Default Description
path string - The resource path.
args object {} The arguments to accompany the request.

Returns: Promise‹Response


options

options(path: string, args: object): Promise‹Response

Defined in lib/client/Client.ts:113

Sends an OPTIONS request to the server and returns a Promise resolving to its eventual Response.

Parameters:

Name Type Default Description
path string - The resource path.
args object {} The arguments to accompany the request.

Returns: Promise‹Response


patch

patch(path: string, args: object): Promise‹Response

Defined in lib/client/Client.ts:97

Sends a PATCH request to the server and returns a Promise resolving to its eventual Response.

Parameters:

Name Type Default Description
path string - The resource path.
args object {} The arguments to accompany the request.

Returns: Promise‹Response


post

post(path: string, args: object): Promise‹Response

Defined in lib/client/Client.ts:81

Sends a POST request to the server and returns a Promise resolving to its eventual Response.

Parameters:

Name Type Default Description
path string - The resource path.
args object {} The arguments to accompany the request.

Returns: Promise‹Response


put

put(path: string, args: object): Promise‹Response

Defined in lib/client/Client.ts:89

Sends a PUT request to the server and returns a Promise resolving to its eventual Response.

Parameters:

Name Type Default Description
path string - The resource path.
args object {} The arguments to accompany the request.

Returns: Promise‹Response


Private request

request(method: string, path: string, args: object): Promise‹Response

Defined in lib/client/Client.ts:58

Sends a request to the server and returns a Promise resolving to its eventual Response.

Parameters:

Name Type Default Description
method string - An HTTP method, or SUBSCRIBE / UNSUBSCRIBE.
path string - The resource path.
args object {} The arguments to accompany the request.

Returns: Promise‹Response


subscribe

subscribe(path: string, args: object, onChange: Function): Promise‹Response

Defined in lib/client/Client.ts:122

Sends a SUBSCRIBE request to the server and returns a Promise resolving to its eventual Response. The response to a SUBSCRIBE request is identical to an equivalent GET request—if successful, its payload property will contain the initial state of the resource itsquery property will contain the query string that can be passed to Client.prototype.unsubscribe to cancel the subscription. Any updates to the subscribed resource's state will be passed to the provided callback function onChange.

Parameters:

Name Type Default Description
path string - The resource path.
args object {} The arguments to accompany the request.
onChange Function null A function to be invoked with the new state of the subscribed resource, whenever it's state changes.

Returns: Promise‹Response


unsubscribe

unsubscribe(query: string): Promise‹Response

Defined in lib/client/Client.ts:141

Cancels any subscription associated with the given query string, which can be obtained from the initial response to a call to Client.prototype.subscribe.

Parameters:

Name Type Description
query string A query string.

Returns: Promise‹Response


Static connect

connect(uri: string, onClose: Function): Promise‹Client

Defined in lib/client/Client.ts:30

Static factory method which asynchronously produces a new instance of Client.

Parameters:

Name Type Default Description
uri string - A WebSocket connection URI.
onClose Function null A callback function to be executed whenever the connection is closed.

Returns: Promise‹Client