Class: SSETransport
Client-side HTTP(S) + SSE bidirectional transport
Used for communication with the Spatium Signer Service. As soon as it is created, it immediately tries to connect to the provided url and start listening for incoming messages
See
Hierarchy
SimpleTransportDriver
↳ SSETransport
Implements
Constructors
constructor
• new SSETransport(url
, auth
)
Note
requests are attributed to accountId of an authorization session, thus storing data independently for each authorized user
Example
const auth = new AuthorizationSession('https://cloud.spatium.net/authorization/v1', uuid(randomBytes), ['read', 'secret']);
const transport = new SSETransport('https://cloud.spatium.net/signer/v1', auth);
// Connect to a signer service
await transport.connect();
// Assuming that the server side listens to and sends the same messages
// Listen to room 323-123-45
const subscription = transport.on({ room: '323-123-45' }, ({ topic }, data) => {
expect(topic).toBe('hello');
expect(data).toStrictEqual({ woo: 'hoo' });
});
// Sending a message to room 323-123-45
await transport.send({ room: '323-123-45', topic: 'hello' }, { woo: 'hoo' });
// Stop listening to a room
transport.off(subscription);
// Disconnect from signer service
await transport.disconnect();
Parameters
Name | Type | Description |
---|---|---|
url |
string |
signer service endpoint (HTTP(S)) |
auth |
AuthorizationSession |
authorization AuthorizationSession session to use |
Overrides
SimpleTransportDriver.constructor
Methods
connect
▸ connect(timeout?
): Promise
<void
>
Connect and start listening to events
Parameters
Name | Type |
---|---|
timeout? |
number |
Returns
Promise
<void
>
disconnect
▸ disconnect(): Promise
<void
>
Stop listening for messages and disconnect
Returns
Promise
<void
>
send
▸ send(meta
, data
): Promise
<void
>
Parameters
Name | Type |
---|---|
meta |
TransportMeta |
data |
unknown |
Returns
Promise
<void
>
Implementation of
TransportDriver.send