edusperoni / nativescript-mqtt

MQTT 3.1.1 for Nativescript
Apache License 2.0
12 stars 3 forks source link

Adding willMessage into ClientOptions #15

Closed ebizcoAU closed 3 years ago

ebizcoAU commented 3 years ago

In "mqtt.d.ts"

interface ClientOptions { host?: string; port?: number; useSSL?: boolean; path?: string; willMessage?: any={}; clientId?: string; retryOnDisconnect?: boolean; cleanSession?: boolean; }

In "mqtt.js"

function MQTTClient(options) { this.connectionSuccess = new common_1.EventHandler(); this.connectionFailure = new common_1.EventHandler(); this.connectionLost = new common_1.EventHandler(); this.messageArrived = new common_1.EventHandler(); this.messageDelivered = new common_1.EventHandler(); this.connected = false; this.host = options.host || 'localhost'; this.useSSL = options.useSSL || false; if (options.port) this.port = options.port; else this.port = this.useSSL ? 443 : 80; this.path = options.path || ''; this.clientId = options.clientId || common_1.guid(); this.retryOnDisconnect = options.retryOnDisconnect || false; this.willMessage = options.willMessage || ''; if (this.willMessage) { let mqttMessage = this.willMessage.bytes !== null ? new MQTT.Message(this.willMessage.bytes) : new MQTT.Message(this.willMessage.payload); mqttMessage.destinationName = this.willMessage.topic; mqttMessage.retained = this.willMessage.retained; mqttMessage.qos = this.willMessage.qos; new MQTT.Message(this.willMessage.payload) this.willMessage = mqttMessage; } this.cleanSession = (typeof options.cleanSession === undefined) ? true : false; this.mqttClient = new MQTT.Client(this.host, this.port, this.path, this.clientId); this.mqttClient.useSSL = this.useSSL; }