本文整理汇总了TypeScript中mqtt.MqttClient.publish方法的典型用法代码示例。如果您正苦于以下问题:TypeScript MqttClient.publish方法的具体用法?TypeScript MqttClient.publish怎么用?TypeScript MqttClient.publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mqtt.MqttClient
的用法示例。
在下文中一共展示了MqttClient.publish方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: reject
async process<T extends any>(command: Command): Promise<T> {
// wait until lambda connection is established
await this.connectionPromise
if (this.options.debug) {
console.log(`Running remotely: ${JSON.stringify(command)}`)
}
const promise = new Promise<T>((resolve, reject) => {
this.channel.subscribe(this.TOPIC_RESPONSE, () => {
this.channel.on('message', (topic, buffer) => {
if (this.TOPIC_RESPONSE === topic) {
const message = buffer.toString()
const result = JSON.parse(message) as RemoteResult
if (result.error) {
reject(result.error)
} else if (result.value) {
resolve(result.value)
} else {
resolve()
}
}
})
})
})
this.channel.publish(this.TOPIC_REQUEST, JSON.stringify(command))
return promise
}
示例2: close
async close(): Promise<void> {
this.channel.publish(
this.TOPIC_END,
JSON.stringify({ channelId: this.channelId, client: true }),
)
this.channel.end()
}
示例3: clearTimeout
channel.subscribe(this.TOPIC_CONNECTED, { qos: 1 }, () => {
channel.on('message', async topic => {
if (this.TOPIC_CONNECTED === topic) {
clearTimeout(timeout)
resolve()
}
})
channel.publish(
this.TOPIC_NEW_SESSION,
JSON.stringify({ channelId, options: this.options }),
{ qos: 1 },
)
})
示例4: reject
this.channel.subscribe(this.TOPIC_RESPONSE, () => {
this.channel.on('message', (topic, buffer) => {
if (this.TOPIC_RESPONSE === topic) {
const message = buffer.toString()
const result = JSON.parse(message) as RemoteResult
if (result.error) {
reject(result.error)
} else if (result.value) {
resolve(result.value)
} else {
resolve()
}
}
})
this.channel.publish(this.TOPIC_REQUEST, JSON.stringify(command))
})