new EmitterPubsubBroker(options)
Creates a broker.
Parameters:
Name | Type | Description |
---|---|---|
options |
EmitterPubsubBroker.Options | string | Options or a connect if a string. If connect string is empty, then an in-memory connector is used. |
Extends
- EventEmitter
Methods
close() → {Promise.<undefined>}
Closes broker.
Returns:
- Type
- Promise.<undefined>
getClients(channel) → {Set.<EventEmitter>|undefined}
Returns internal set of channel clients of EmitterPubsubBroker instance. The result MUST NOT be modified.
Parameters:
Name | Type | Description |
---|---|---|
channel |
string | Channel. |
Returns:
- Type
- Set.<EventEmitter> | undefined
getSubscriptions(client) → {Set.<string>|undefined}
Returns set of client subscriptions. The result MUST NOT be modified.
Parameters:
Name | Type | Description |
---|---|---|
client |
EventEmitter | Emitter. |
Returns:
- Type
- Set.<string> | undefined
publish(channel, name, …args) → {Promise.<undefined>}
Publish an event to a channel.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
channel |
string | Channel. |
|
name |
string | Event name. |
|
args |
* |
<repeatable> |
Arguments. |
Returns:
- Type
- Promise.<undefined>
send(client, channel, name, …args) → {Promise.<undefined>}
Publish an event to a channel, excluding the sender. The client
object MUST have an unique id
field.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
client |
EventEmitter | Emitter. |
|
channel |
string | Channel. |
|
name |
string | Event name. |
|
args |
* |
<repeatable> |
Arguments. |
Returns:
- Type
- Promise.<undefined>
subscribe(client, channel) → {Promise.<undefined>}
Subscribes emitter to a channel.
Parameters:
Name | Type | Description |
---|---|---|
client |
EventEmitter | Emitter. |
channel |
string | Channel. |
Returns:
- Type
- Promise.<undefined>
unsubscribe(client, channel) → {Promise.<undefined>}
Unsubscribes emitter from a channel.
Parameters:
Name | Type | Description |
---|---|---|
client |
EventEmitter | Emitter. |
channel |
string | Channel. |
Returns:
- Type
- Promise.<undefined>
unsubscribeAll(client) → {Promise.<undefined>}
Unsubscribes emitter from all channels.
Parameters:
Name | Type | Description |
---|---|---|
client |
EventEmitter | Emitter. |
Returns:
- Type
- Promise.<undefined>
Type Definitions
Deserialize(data) → {Promise.<Object>|Object}
Messages deserialisation. Serialised messages will be used
internally via a communication Connector
. May also return
promises for an asynchronous execution.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | Serialised data. |
Returns:
Data.
- Type
- Promise.<Object> | Object
Encoder(args) → {Promise.<Object>|Object}
Messages encoder. Encoded messages will be used to emit messages via event emitters. May also return promises for an asynchronous execution.
Parameters:
Name | Type | Description |
---|---|---|
args |
* | Emit arguments. |
Returns:
Data to send.
- Type
- Promise.<Object> | Object
Options
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
connect |
string |
<optional> |
Connect string for a connector. |
|
prefix |
string |
<optional> |
'emitter-pubsub-broker:'
|
Prefix for a connector. |
includeChannel |
boolean |
<optional> |
false
|
Include channel as the first argument. |
encoder |
EmitterPubsubBroker.Encoder |
<optional> |
Optional encoder to run before broadcasting. |
|
method |
string |
<optional> |
'emit'
|
An alternative emit method. |
serialize |
EmitterPubsubBroker.Serialize |
<optional> |
msgpack.encode
|
Serialisation function to use with a connector. |
deserialize |
EmitterPubsubBroker.Deserialize |
<optional> |
msgpack.decode
|
Deserialisation function to use with a connector. |
connector |
Connector |
<optional> |
Custom connector implementation. |
Type:
- Object
Serialize(data) → {Promise.<Object>|Object}
Messages serialisation. Serialised messages will be used internally
via a communication Connector
. May also return promises
for an asynchronous execution.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | Data. |
Returns:
Serialised data.
- Type
- Promise.<Object> | Object
Events
error
Connector error. Does not throw if there are no listeners.
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | Error. |