{"version":3,"file":"ngx-mqtt.mjs","sources":["../../../projects/ngx-mqtt/src/lib/mqtt.model.ts","../../../projects/ngx-mqtt/src/lib/mqtt.module.ts","../../../projects/ngx-mqtt/src/lib/mqtt.service.ts","../../../projects/ngx-mqtt/src/public-api.ts","../../../projects/ngx-mqtt/src/ngx-mqtt.ts"],"sourcesContent":["import { Stream } from 'stream';\nimport { MqttClient, IClientOptions, IClientPublishOptions, IPacket } from 'mqtt-browser';\n\nexport enum MqttConnectionState {\n  CLOSED,\n  CONNECTING,\n  CONNECTED\n}\n\nexport interface IMqttServiceOptions extends IClientOptions {\n  /**\n   * whether a new connection should be created\n   * on creating an instance of the service\n   */\n  connectOnCreate?: boolean;\n  /** the hostname of the mqtt broker */\n  hostname?: string;\n  /** the port to connect with websocket to the broker */\n  port?: number;\n  /** the path parameters to connect to e.g. `/mqtt` */\n  path?: string;\n  protocol?: 'wss' | 'ws';\n  /** if the url is provided, hostname, port path and protocol are ignored */\n  url?: string;\n}\n\nexport interface IMqttMessage extends IPacket {\n  /** the mqtt topic to which this message was published to */\n  topic: string;\n  /** the payload */\n  payload: Uint8Array;\n  /** the quality of service */\n  qos: number;\n  /** if this message is a retained message */\n  retain: boolean;\n  /** if this message is a duplicate */\n  dup: boolean;\n}\n\nexport interface IPublishOptions extends IClientPublishOptions { }\nexport interface IOnConnectEvent extends IMqttMessage { }\nexport interface IOnErrorEvent extends Error {\n  type?: string;\n}\nexport interface IOnMessageEvent extends IMqttMessage { }\nexport interface IOnSubackEvent {\n  granted: boolean;\n  filter: string;\n}\n\nexport interface IMqttClient extends MqttClient {\n  stream: Stream;\n}\n\nexport interface IOnPacketsendEvent extends IPacket { }\nexport interface IOnPacketreceiveEvent extends IPacket { }\n","import {\n  NgModule,\n  ModuleWithProviders,\n  InjectionToken\n} from '@angular/core';\nimport { IMqttClient, IMqttServiceOptions } from './mqtt.model';\n\nexport const MQTT_SERVICE_OPTIONS: IMqttServiceOptions = {\n  connectOnCreate: true,\n  hostname: 'localhost',\n  port: 1884,\n  path: ''\n};\n\nexport const MqttServiceConfig = new InjectionToken<IMqttServiceOptions>('NgxMqttServiceConfig');\nexport const MqttClientService = new InjectionToken<IMqttClient>('NgxMqttClientService');\n\n@NgModule()\nexport class MqttModule {\n  static forRoot(config: IMqttServiceOptions, client?: IMqttClient): ModuleWithProviders<MqttModule> {\n    return {\n      ngModule: MqttModule,\n      providers: [\n        {\n          provide: MqttServiceConfig,\n          useValue: config\n        },\n        {\n          provide: MqttClientService,\n          useValue: client\n        }\n      ]\n    };\n  }\n}\n","import { EventEmitter, Inject, Injectable } from '@angular/core';\nimport { connect, IClientPublishOptions, IClientSubscribeOptions, ISubscriptionGrant, MqttClient } from 'mqtt-browser';\nimport { Packet } from 'mqtt-packet';\n\nimport { BehaviorSubject, merge, Observable, Observer, Subject, Subscription, Unsubscribable, using } from 'rxjs';\nimport { filter, publish, publishReplay, refCount } from 'rxjs/operators';\n\nimport {\n  IMqttMessage,\n  IMqttServiceOptions,\n  IOnConnectEvent,\n  IOnErrorEvent,\n  IOnPacketreceiveEvent,\n  IOnPacketsendEvent,\n  IOnSubackEvent,\n  IPublishOptions,\n  MqttConnectionState\n} from './mqtt.model';\n\nimport { MqttClientService, MqttServiceConfig } from './mqtt.module';\n\n// A javascript function that takes two objects and merges them recursively\nfunction mergeDeep(target: any, ...sources: any[]): any {\n  if (!sources.length) {\n    return target;\n  }\n  const source = sources.shift();\n\n  if (isObject(target) && isObject(source)) {\n    for (const key in source) {\n      if (isObject(source[key])) {\n        if (!target[key]) {\n          Object.assign(target, { [key]: {} });\n        }\n        mergeDeep(target[key], source[key]);\n      } else {\n        Object.assign(target, { [key]: source[key] });\n      }\n    }\n  }\n\n  return mergeDeep(target, ...sources);\n}\n\nfunction isObject(item: any): item is Object {\n  return item && typeof item === 'object' && !Array.isArray(item);\n}\n\n/**\n * With an instance of MqttService, you can observe and subscribe to MQTT in multiple places, e.g. in different components,\n * to only subscribe to the broker once per MQTT filter.\n * It also handles proper unsubscription from the broker, if the last observable with a filter is closed.\n */\n@Injectable({\n  providedIn: 'root',\n})\nexport class MqttService {\n  private client!: MqttClient;\n\n  /**\n   * The constructor needs [connection options]{@link IMqttServiceOptions} regarding the broker and some\n   * options to configure behavior of this service, like if the connection to the broker\n   * should be established on creation of this service or not.\n   */\n  constructor(\n    @Inject(MqttServiceConfig) private options: IMqttServiceOptions,\n    @Inject(MqttClientService) client?: MqttClient\n  ) {\n    if (options.connectOnCreate !== false) {\n      this.connect({}, client);\n    }\n\n    this.state.subscribe();\n  }\n\n  /**\n   * gets the _clientId\n   */\n  public get clientId() {\n    return this._clientId;\n  }\n\n  /** An EventEmitter to listen to connect messages */\n  public get onConnect(): EventEmitter<IOnConnectEvent> {\n    return this._onConnect;\n  }\n\n  /** An EventEmitter to listen to reconnect messages */\n  public get onReconnect(): EventEmitter<void> {\n    return this._onReconnect;\n  }\n\n  /** An EventEmitter to listen to close messages */\n  public get onClose(): EventEmitter<void> {\n    return this._onClose;\n  }\n\n  /** An EventEmitter to listen to offline events */\n  public get onOffline(): EventEmitter<void> {\n    return this._onOffline;\n  }\n\n  /** An EventEmitter to listen to error events */\n  public get onError(): EventEmitter<IOnErrorEvent> {\n    return this._onError;\n  }\n\n  /** An EventEmitter to listen to close messages */\n  public get onEnd(): EventEmitter<void> {\n    return this._onEnd;\n  }\n\n  /** An EventEmitter to listen to message events */\n  public get onMessage(): EventEmitter<Packet> {\n    return this._onMessage;\n  }\n\n  /** An EventEmitter to listen to packetsend messages */\n  public get onPacketsend(): EventEmitter<IOnPacketsendEvent> {\n    return this._onPacketsend;\n  }\n\n  /** An EventEmitter to listen to packetreceive messages */\n  public get onPacketreceive(): EventEmitter<IOnPacketreceiveEvent> {\n    return this._onPacketreceive;\n  }\n\n  /** An EventEmitter to listen to suback events */\n  public get onSuback(): EventEmitter<IOnSubackEvent> {\n    return this._onSuback;\n  }\n  /** a map of all mqtt observables by filter */\n  public observables: { [filterString: string]: Observable<IMqttMessage> } = {};\n  /** the connection state */\n  public state: Subject<MqttConnectionState> = new BehaviorSubject<MqttConnectionState>(MqttConnectionState.CLOSED);\n  /** an observable of the last mqtt message */\n  public messages: Subject<IMqttMessage> = new Subject<IMqttMessage>();\n\n  private _clientId = this._generateClientId();\n  private _connectTimeout = 10000;\n  private _reconnectPeriod = 10000;\n  private _url!: string;\n\n  private _onConnect: EventEmitter<IOnConnectEvent> = new EventEmitter<IOnConnectEvent>();\n  private _onReconnect: EventEmitter<void> = new EventEmitter<void>();\n  private _onClose: EventEmitter<void> = new EventEmitter<void>();\n  private _onOffline: EventEmitter<void> = new EventEmitter<void>();\n  private _onError: EventEmitter<IOnErrorEvent> = new EventEmitter<IOnErrorEvent>();\n  private _onEnd: EventEmitter<void> = new EventEmitter<void>();\n  private _onMessage: EventEmitter<Packet> = new EventEmitter<Packet>();\n  private _onSuback: EventEmitter<IOnSubackEvent> = new EventEmitter<IOnSubackEvent>();\n  private _onPacketsend: EventEmitter<IOnPacketsendEvent> = new EventEmitter<IOnPacketsendEvent>();\n  private _onPacketreceive: EventEmitter<IOnPacketreceiveEvent> = new EventEmitter<IOnPacketreceiveEvent>();\n\n  /**\n   * This static method shall be used to determine whether a MQTT\n   * topic matches a given filter. The matching rules are specified in the MQTT\n   * standard documentation and in the library test suite.\n   *\n   * @param  {string}  filter A filter may contain wildcards like '#' and '+'.\n   * @param  {string}  topic  A topic may not contain wildcards.\n   * @return {boolean}        true on match and false otherwise.\n   */\n  public static filterMatchesTopic(filterString: string, topic: string): boolean {\n    if (filterString[0] === '#' && topic[0] === '$') {\n      return false;\n    }\n    // Preparation: split and reverse on '/'. The JavaScript split function is sane.\n    const fs = (filterString || '').split('/').reverse();\n    const ts = (topic || '').split('/').reverse();\n    // This function is tail recursive and compares both arrays one element at a time.\n    const match = (): boolean => {\n      // Cutting of the last element of both the filter and the topic using pop().\n      const f = fs.pop();\n      const t = ts.pop();\n      switch (f) {\n        // In case the filter level is '#', this is a match no matter whether\n        // the topic is undefined on this level or not ('#' matches parent element as well!).\n        case '#':\n          return true;\n        // In case the filter level is '+', we shall dive into the recursion only if t is not undefined.\n        case '+':\n          return t ? match() : false;\n        // In all other cases the filter level must match the topic level,\n        // both must be defined and the filter tail must match the topic\n        // tail (which is determined by the recursive call of match()).\n        default:\n          return f === t && (f === undefined ? true : match());\n      }\n    };\n    return match();\n  }\n\n  /**\n   * connect manually connects to the mqtt broker.\n   */\n  public connect(opts?: IMqttServiceOptions, client?: MqttClient) {\n    const options = mergeDeep(this.options || {}, opts);\n    const protocol = options.protocol || 'ws';\n    const hostname = options.hostname || 'localhost';\n    if (options.url) {\n      this._url = options.url;\n    } else {\n      this._url = `${protocol}://${hostname}`;\n      this._url += options.port ? `:${options.port}` : '';\n      this._url += options.path ? `${options.path}` : '';\n    }\n    this.state.next(MqttConnectionState.CONNECTING);\n    const mergedOptions = mergeDeep({\n      clientId: this._clientId,\n      reconnectPeriod: this._reconnectPeriod,\n      connectTimeout: this._connectTimeout\n    }, options);\n\n    if (this.client) {\n      this.client.end(true);\n    }\n\n    if (!client) {\n      this.client = connect(this._url, mergedOptions);\n    } else {\n      this.client = client;\n    }\n    this._clientId = mergedOptions.clientId;\n\n    this.client.on('connect', this._handleOnConnect);\n    this.client.on('reconnect', this._handleOnReconnect);\n    this.client.on('close', this._handleOnClose);\n    this.client.on('offline', this._handleOnOffline);\n    this.client.on('error', this._handleOnError);\n    (this.client as any).stream.on('error', this._handleOnError);\n    this.client.on('end', this._handleOnEnd);\n    this.client.on('message', this._handleOnMessage);\n    this.client.on('packetsend', this._handleOnPacketsend);\n    this.client.on('packetreceive', this._handleOnPacketreceive);\n  }\n\n  /**\n   * disconnect disconnects from the mqtt client.\n   * This method `should` be executed when leaving the application.\n   */\n  public disconnect(force = true) {\n    if (!this.client) {\n      throw new Error('mqtt client not connected');\n    }\n    this.client.end(force);\n  }\n\n  /**\n   * With this method, you can observe messages for a mqtt topic.\n   * The observable will only emit messages matching the filter.\n   * The first one subscribing to the resulting observable executes a mqtt subscribe.\n   * The last one unsubscribing this filter executes a mqtt unsubscribe.\n   * Every new subscriber gets the latest message.\n   */\n  public observeRetained(filterString: string, opts: IClientSubscribeOptions = { qos: 1 }): Observable<IMqttMessage> {\n    return this._generalObserve(filterString, () => publishReplay(1), opts);\n  }\n\n  /**\n   * With this method, you can observe messages for a mqtt topic.\n   * The observable will only emit messages matching the filter.\n   * The first one subscribing to the resulting observable executes a mqtt subscribe.\n   * The last one unsubscribing this filter executes a mqtt unsubscribe.\n   */\n  public observe(filterString: string, opts: IClientSubscribeOptions = { qos: 1 }): Observable<IMqttMessage> {\n    return this._generalObserve(filterString, () => publish(), opts);\n  }\n\n  /**\n   * With this method, you can observe messages for a mqtt topic.\n   * The observable will only emit messages matching the filter.\n   * The first one subscribing to the resulting observable executes a mqtt subscribe.\n   * The last one unsubscribing this filter executes a mqtt unsubscribe.\n   * Depending on the publish function, the messages will either be replayed after new\n   * subscribers subscribe or the messages are just passed through\n   */\n  private _generalObserve(filterString: string, publishFn: Function, opts: IClientSubscribeOptions): Observable<IMqttMessage> {\n    if (!this.client) {\n      throw new Error('mqtt client not connected');\n    }\n    if (!this.observables[filterString]) {\n      const rejected: Subject<IMqttMessage> = new Subject();\n      this.observables[filterString] = using(\n        // resourceFactory: Do the actual ref-counting MQTT subscription.\n        // refcount is decreased on unsubscribe.\n        () => {\n          const subscription: Subscription = new Subscription();\n          this.client.subscribe(filterString, opts, (err: any, granted: ISubscriptionGrant[]) => {\n            if (granted) { // granted can be undefined when an error occurs when the client is disconnecting\n              granted.forEach((granted_: ISubscriptionGrant) => {\n                if (granted_.qos === 128) {\n                  delete this.observables[granted_.topic];\n                  this.client.unsubscribe(granted_.topic);\n                  rejected.error(`subscription for '${granted_.topic}' rejected!`);\n                }\n                this._onSuback.emit({ filter: filterString, granted: granted_.qos !== 128 });\n              });\n            }\n          });\n          subscription.add(() => {\n            delete this.observables[filterString];\n            this.client.unsubscribe(filterString);\n          });\n          return subscription;\n        },\n        // observableFactory: Create the observable that is consumed from.\n        // This part is not executed until the Observable returned by\n        // `observe` gets actually subscribed.\n        (subscription: Unsubscribable | void) => merge(rejected, this.messages))\n        .pipe(\n          filter((msg: IMqttMessage) => MqttService.filterMatchesTopic(filterString, msg.topic)),\n          publishFn(),\n          refCount()\n        ) as Observable<IMqttMessage>;\n    }\n    return this.observables[filterString];\n  }\n\n  /**\n   * This method returns an observable for a topic with optional options.\n   * After subscribing, the actual mqtt publication will be executed and\n   * the observable will emit an empty value and completes, if publishing was successful\n   * or throws an error, if the publication fails.\n   */\n  public publish(topic: string, message: string | Buffer, options: IClientPublishOptions = {}): Observable<void> {\n    if (!this.client) {\n      throw new Error('mqtt client not connected');\n    }\n    return Observable.create((obs: Observer<void>) => {\n      this.client.publish(topic, message, options, (error: Error | undefined) => {\n        if (error) {\n          obs.error(error);\n        } else {\n          obs.next();\n          obs.complete();\n        }\n      });\n    });\n  }\n\n  /**\n   * This method publishes a message for a topic with optional options.\n   * If an error occurs, it will throw.\n   */\n  public unsafePublish(topic: string, message: string | Buffer, options: IPublishOptions = {}): void {\n    if (!this.client) {\n      throw new Error('mqtt client not connected');\n    }\n    this.client.publish(topic, message, options, (error: Error | undefined) => {\n      if (error) {\n        throw (error);\n      }\n    });\n  }\n\n  private _handleOnConnect = (e: IOnConnectEvent) => {\n    if (this.options.connectOnCreate === true) {\n      Object.keys(this.observables).forEach((filterString: string) => {\n        this.client.subscribe(filterString);\n      });\n    }\n    this.state.next(MqttConnectionState.CONNECTED);\n    this._onConnect.emit(e);\n  }\n\n  private _handleOnReconnect = () => {\n    if (this.options.connectOnCreate === true) {\n      Object.keys(this.observables).forEach((filterString: string) => {\n        this.client.subscribe(filterString);\n      });\n    }\n    this.state.next(MqttConnectionState.CONNECTING);\n    this._onReconnect.emit();\n  }\n\n  private _handleOnClose = () => {\n    this.state.next(MqttConnectionState.CLOSED);\n    this._onClose.emit();\n  }\n\n  private _handleOnOffline = () => {\n    this._onOffline.emit();\n  }\n\n  private _handleOnError = (e: IOnErrorEvent) => {\n    this._onError.emit(e);\n    console.error(e);\n  }\n\n  private _handleOnEnd = () => {\n    this._onEnd.emit();\n  }\n\n  private _handleOnMessage = (topic: string, payload: Buffer, packet: Packet) => {\n    this._onMessage.emit(packet);\n    if (packet.cmd === 'publish') {\n      this.messages.next(packet as any);\n    }\n  }\n\n  private _handleOnPacketsend = (e: IOnPacketsendEvent) => {\n    this._onPacketsend.emit(e);\n  }\n\n  private _handleOnPacketreceive = (e: IOnPacketreceiveEvent) => {\n    this._onPacketreceive.emit(e);\n  }\n\n  private _generateClientId() {\n    return 'client-' + Math.random().toString(36).substr(2, 19);\n  }\n}\n","/*\n * Public API Surface of ngx-mqtt\n */\n\nexport * from './lib/mqtt.model';\nexport * from './lib/mqtt.service';\nexport * from './lib/mqtt.module';","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;IAGY,oBAIX;AAJD,CAAA,UAAY,mBAAmB,EAAA;AAC7B,IAAA,mBAAA,CAAA,mBAAA,CAAA,QAAA,CAAA,GAAA,CAAA,CAAA,GAAA,QAAM,CAAA;AACN,IAAA,mBAAA,CAAA,mBAAA,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA,GAAA,YAAU,CAAA;AACV,IAAA,mBAAA,CAAA,mBAAA,CAAA,WAAA,CAAA,GAAA,CAAA,CAAA,GAAA,WAAS,CAAA;AACX,CAAC,EAJW,mBAAmB,KAAnB,mBAAmB,GAI9B,EAAA,CAAA,CAAA;;ACAY,MAAA,oBAAoB,GAAwB;AACvD,IAAA,eAAe,EAAE,IAAI;AACrB,IAAA,QAAQ,EAAE,WAAW;AACrB,IAAA,IAAI,EAAE,IAAI;AACV,IAAA,IAAI,EAAE,EAAE;EACR;MAEW,iBAAiB,GAAG,IAAI,cAAc,CAAsB,sBAAsB,EAAE;MACpF,iBAAiB,GAAG,IAAI,cAAc,CAAc,sBAAsB,EAAE;MAG5E,UAAU,CAAA;AACrB,IAAA,OAAO,OA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