Constructor
new ChannelClient()
Note: Do not instantiate this class directly. Returned by Channel.connect.
Methods
afterAction(middleware)
Register middleware that fires after the action. This is passed the return value of the action.
Parameters:
Name | Type | Description |
---|---|---|
middleware |
Channel#ChannelClient~Middleware | Function to be executed after invoking the action. |
- Tutorials:
beforeAction(middleware)
Register middleware that fires before the action.
Parameters:
Name | Type | Description |
---|---|---|
middleware |
Channel#ChannelClient~Middleware | Function to be executed before invoking the action. |
- Tutorials:
disconnect() → {Promise.<void>}
Disconnect from the channel.
Returns:
- Type
- Promise.<void>
dispatch(action, payload) → {Promise.<any>}
Dispatch the given to the channel provider. Returns a promise that resolves with the response from the provider for that action.
Parameters:
Name | Type | Description |
---|---|---|
action |
string | Name of the action to be invoked by the channel provider. |
payload |
* | Payload to be sent along with the action. |
- Tutorials:
Returns:
- Type
- Promise.<any>
onDisconnection(listener)
Register a listener that is called on channel disconnection. It is passed the disconnection event of the disconnecting channel.
Parameters:
Name | Type | Description |
---|---|---|
listener |
Channel~ConnectionEvent |
- Tutorials:
onError(middleware)
Register an error handler. This is called before responding on any error.
Parameters:
Name | Type | Description |
---|---|---|
middleware |
function | Function to be executed in case of an error. |
- Tutorials:
register(action, listener)
Register an action to be called by the provider of the channel.
Parameters:
Name | Type | Description |
---|---|---|
action |
string | Name of the action to be registered for the channel provider to later invoke. |
listener |
Action | Function representing the action to be taken on a provider dispatch. |
- Tutorials:
remove(action)
Remove an action by action name.
Parameters:
Name | Type | Description |
---|---|---|
action |
string | Name of the action to be removed. |
- Tutorials:
setDefaultAction(middleware)
Sets a default action. This is used any time an action that has not been registered is invoked. Default behavior if not set is to throw an error.
Parameters:
Name | Type | Description |
---|---|---|
middleware |
Channel#ChannelClient~Middleware | Function to be executed when a client invokes an action name that has not been registered. |
- Tutorials:
Type Definitions
Action(payload, identity)
Channel action callback signature
Parameters:
Name | Type | Description |
---|---|---|
payload |
* | Payload sent along with the message. |
identity |
Identity | Identity of the sender. |
Middleware(action, payload, identity)
Middleware function signature
Parameters:
Name | Type | Description |
---|---|---|
action |
string | Action to be invoked. |
payload |
* | Payload sent along with the message. |
identity |
Identity | Identity of the sender. |