Skip to main content

@auvious/common / 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​

Implements​

Table of contents​

Constructors​

Properties​

Accessors​

Methods​

Constructors​

constructor​

• new EventClient(mqttUrl?, assetsLocation?, host?, port?, path?, sslEnabled?, user?, pass?, refreshConnectionOnUpdatedCredentials?): EventClient

Parameters​

NameTypeDefault value
mqttUrl?stringundefined
assetsLocation?stringundefined
host?stringundefined
port?numberundefined
pathstring"/mqtt"
sslEnabled?booleanundefined
user?stringundefined
pass?stringundefined
refreshConnectionOnUpdatedCredentialsbooleantrue

Returns​

EventClient

Overrides​

EventFiringClient<EventClientHandlers>.constructor

Properties​

_clientId​

• Private _clientId: string


_connectionURL​

• Private _connectionURL: string


_eventHandlers​

• Protected _eventHandlers: EventClientHandlers

Inherited from​

EventFiringClient._eventHandlers


_mqttClient​

• Private _mqttClient: Object

Type declaration​

NameType
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


assetsLocation​

• Private Optional assetsLocation: 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​

• get _defaultHandlers(): EventClientHandlers

Returns​

EventClientHandlers

Overrides​

EventFiringClient._defaultHandlers


initialized​

• get initialized(): boolean

Returns​

boolean


subscriptionHandlers​

• get subscriptionHandlers(): EventClientHandlers

Returns​

EventClientHandlers

Methods​

_cleanEventHandlers​

▸ _cleanEventHandlers(): void

Clean event handler callbacks.

We actually just reassign to the default callbacks.

Returns​

void

Inherited from​

EventFiringClient._cleanEventHandlers


_setEventHandlers​

▸ _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​

NameType
handlersEventClientHandlers

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​

NameType
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​

NameType
subscriptionIEventClientSubscription

Returns​

void

Implementation of​

IEventClientSubscriptionDisposer.dispose


setEventHandlers​

▸ setEventHandlers(handlers): IEventClientSubscription

Exposes setEventHandlers of EventFiringClient's implementation to the public api.

Parameters​

NameType
handlersEventClientHandlers

Returns​

IEventClientSubscription


subscribe​

▸ subscribe(topic): Promise<Event<any>>

Subscribe to a topic to listen to receive events sent to that.

Parameters​

NameType
topicstring

Returns​

Promise<Event<any>>


unsubscribe​

▸ unsubscribe(topic): Promise<Event<any>>

Unsubscribe from a topic to listen to stop receiving events sent to that.

Parameters​

NameType
topicstring

Returns​

Promise<Event<any>>


updateCredentials​

▸ updateCredentials(username, password): Promise<void>

Parameters​

NameType
usernamestring
passwordstring

Returns​

Promise<void>