Session
Extends:
Direct Subclass:
Example:
import { Session } from 'remote-protocol';
const session = new Session(objectStream);
Constructor Summary
Public Constructor | ||
public |
constructor(objectStream: Stream, opts: object) Create a new session with an object-stream to the other peer. |
Member Summary
Public Members | ||
public get |
True if the session is no longer readable. |
|
public get |
True if the session is open. |
|
public get |
The number of requests sent and waiting for response. |
Method Summary
Public Methods | ||
public |
Destroy this session and it's stream. |
|
public |
dispatch(value: *): * Convert the given value to a value that can be send ove to the other peer. |
|
public |
End this session stream. |
|
public |
Fetch an arbitrary value. |
|
public |
Request from the other peer to fetch the given action and send back it's response value. |
|
public |
Send an action for execution to the other peer. |
|
public |
Return session constructor name. |
Public Constructors
public constructor(objectStream: Stream, opts: object) source
Create a new session with an object-stream to the other peer.
Params:
Name | Type | Attribute | Description |
objectStream | Stream | An object duplex stream |
|
opts | object |
|
Options |
opts.timeout | null | number |
|
Default timeout for requests in milliseconds. If null is given, request will not timeout. |
opts.endTimeout | null | number |
|
Default timeout to end the session in milliseconds after the other ended the stream. |
Public Members
Public Methods
public destroy(err: Error): void source
Destroy this session and it's stream.
Params:
Name | Type | Attribute | Description |
err | Error |
|
Optional error |
Return:
void |
Emit:
error |
If an error given, emit and "error" event as well. |
close |
When the session destroyed |
public dispatch(value: *): * source
Convert the given value to a value that can be send ove to the other peer. If the value can be send as-is, return the same value (default implementation).
Params:
Name | Type | Attribute | Description |
value | * | The value to dispatch |
Return:
* |
public fetch(value: Action | *): * source
Fetch an arbitrary value. If the given value is instance of Action, fetch it. Otherwise return it as is.
Params:
Name | Type | Attribute | Description |
value | Action | * | The given value |
Return:
* |
public request(action: Action, opts: object, onFulfilled: function, onRejected: function): Session source
Request from the other peer to fetch the given action and send back it's response value.
Params:
Name | Type | Attribute | Description |
action | Action | the given action to fetch by the peer |
|
opts | object |
|
Options |
opts.timeout | number | null |
|
Override the default timeout for this request (See constructor). |
onFulfilled | function | a function that will be called with the response value on the
first arguments as-is (ie. without |
|
onRejected | function | a function that will be called with an error at the first argument if the fetching throws an error or the request timeout as reached. |