EventClient
@auvious/common / Exports / EventClient
Class: EventClient
Event client implementation for auvious' services.
Setup to work via the mqtt protocol with the paho-mqtt package.
More info: http://www.eclipse.org/paho/clients/js
Hierarchy
EventFiringClient
<EventClientHandlers
>↳
EventClient
Implements
Table of contents
Constructors
Properties
- _clientId
- _connectionURL
- _eventHandlers
- _mqttClient
- _mqttOptions
- _password
- _realEventHandlers
- _sslEnabled
- _subscriptions
- _username
- log
- refreshConnectionOnUpdatedCredentials
- state
- PROMISE_TIMEOUT_MILLISEC
Accessors
Methods
- _cleanEventHandlers
- _setEventHandlers
- cleanEventHandlers
- connect
- connected
- disconnect
- dispose
- setEventHandlers
- subscribe
- unsubscribe
- updateCredentials
Constructors
constructor
• new EventClient(mqttUrl?
, assetsLocation?
, host?
, port?
, path?
, sslEnabled?
, user?
, pass?
, refreshConnectionOnUpdatedCredentials?
)
Parameters
Name | Type | Default value |
---|---|---|
mqttUrl? | string | undefined |
assetsLocation? | string | undefined |
host? | string | undefined |
port? | number | undefined |
path | string | "/mqtt" |
sslEnabled? | boolean | undefined |
user? | string | undefined |
pass? | string | undefined |
refreshConnectionOnUpdatedCredentials | boolean | true |
Overrides
EventFiringClient<EventClientHandlers\>.constructor
Properties
_clientId
• Private
_clientId: any
_connectionURL
• Private
_connectionURL: string
_eventHandlers
• Protected
_eventHandlers: EventClientHandlers
Inherited from
EventFiringClient._eventHandlers
_mqttClient
• Private
_mqttClient: Object
Type declaration
Name | Type |
---|---|
options | { getPassword : () => Promise <string > ; getUsername : () => Promise <string > ; setPassword : (arg : string ) => void ; setUsername : (arg : string ) => void } |
options.getPassword | [object Object] |
options.getUsername | [object Object] |
options.setPassword | [object Object] |
options.setUsername | [object Object] |
addListener | (...args : [event: string | symbol, listener: Function]) => Promise <void > |
end | (force : boolean , callback : () => void ) => void |
getConnected | () => Promise <boolean > |
setConnected | (arg : boolean ) => void |
subscribe | (topic : string | string [], opts : IClientSubscribeOptions , callback? : ClientSubscribeCallback ) => Promise <void > |
unsubscribe | (...args : [topic: string | string[], opts?: Object, callback?: PacketCallback]) => Promise <void > |
_mqttOptions
• Private
_mqttOptions: IClientOptions
_password
• Private
_password: string
_realEventHandlers
• Protected
_realEventHandlers: any
Inherited from
EventFiringClient._realEventHandlers
_sslEnabled
• Private
_sslEnabled: boolean
_subscriptions
• Private
_subscriptions: Map
<string
, EventClientSubscription
>
_username
• Private
_username: string
log
• Protected
log: Logger
Inherited from
EventFiringClient.log
refreshConnectionOnUpdatedCredentials
• Protected
refreshConnectionOnUpdatedCredentials: boolean
= true
state
• Private
state: EventClientState
= EventClientState.Disconnected
PROMISE_TIMEOUT_MILLISEC
▪ Static
Protected
PROMISE_TIMEOUT_MILLISEC: number
= 5000
Accessors
_defaultHandlers
• Protected
get
_defaultHandlers(): EventClientHandlers
Returns
Overrides
EventFiringClient._defaultHandlers
initialized
• get
initialized(): boolean
Returns
boolean
subscriptionHandlers
• Protected
get
subscriptionHandlers(): EventClientHandlers
Returns
Methods
_cleanEventHandlers
▸ Protected
_cleanEventHandlers(): void
Clean event handler callbacks.
We actually just reassign to the default callbacks.
Returns
void
Inherited from
EventFiringClient._cleanEventHandlers
_setEventHandlers
▸ Protected
_setEventHandlers(handlers
): void
Sets event handler callbacks.
Every event handler callback defaults to _defaultHandlers which just prints the event to console.
An event callback that was not passed in the argument, will default to either:
- the previous callback is ever set.
- the _defaultHandlers's corresponding callback.
The default behaviour when appendToPrevious = true is to append the handlers passed in the arguments.
If appendToPrevious is set to false the previous handlers will be cleaned before we the the argument handlers.
Parameters
Name | Type |
---|---|
handlers | EventClientHandlers |
Returns
void
Inherited from
EventFiringClient._setEventHandlers
cleanEventHandlers
▸ cleanEventHandlers(): void
Exposes cleanEventHandlers of EventFiringClient's implementation to the public api.
Returns
void
connect
▸ connect(handlers?
): Promise
<IEventClientSubscription
>
Connect the client with the server.
Events are fired via the callbacks of the EventClientHandlers argument.
Parameters
Name | Type |
---|---|
handlers? | EventClientHandlers |
Returns
Promise
<IEventClientSubscription
>
connected
▸ connected(): Promise
<boolean
>
Returns
Promise
<boolean
>
disconnect
▸ disconnect(): Promise
<void
>
Disconnect the client from the server.
The current event handlers are not cleaned. They can be reused from a followup .connect() without args.
Returns
Promise
<void
>
dispose
▸ dispose(subscription
): void
Parameters
Name | Type |
---|---|
subscription | IEventClientSubscription |
Returns
void
Implementation of
IEventClientSubscriptionDisposer.dispose
setEventHandlers
▸ setEventHandlers(handlers
): IEventClientSubscription
Exposes setEventHandlers of EventFiringClient's implementation to the public api.
Parameters
Name | Type |
---|---|
handlers | EventClientHandlers |
Returns
subscribe
▸ subscribe(topic
): Promise
<Event
<any
>>
Subscribe to a topic to listen to receive events sent to that.
Parameters
Name | Type |
---|---|
topic | string |
Returns
Promise
<Event
<any
>>
unsubscribe
▸ unsubscribe(topic
): Promise
<Event
<any
>>
Unsubscribe from a topic to listen to stop receiving events sent to that.
Parameters
Name | Type |
---|---|
topic | string |
Returns
Promise
<Event
<any
>>
updateCredentials
▸ updateCredentials(username
, password
): Promise
<void
>
Parameters
Name | Type |
---|---|
username | string |
password | string |
Returns
Promise
<void
>