|
@@ -43,7 +43,7 @@ export default class MqttService {
|
|
|
* @returns
|
|
* @returns
|
|
|
*/
|
|
*/
|
|
|
async send(params: object, qos = 0) {
|
|
async send(params: object, qos = 0) {
|
|
|
- console.log('发送', this.client_channel, this.mqtt_id, params)
|
|
|
|
|
|
|
+ console.log('发送mqtt', this.client_channel, this.mqtt_id, params)
|
|
|
if (!this.client_channel || !this.mqtt_id) return null
|
|
if (!this.client_channel || !this.mqtt_id) return null
|
|
|
const newParams = JSON.stringify({ ...params, from_id: this.client_id })
|
|
const newParams = JSON.stringify({ ...params, from_id: this.client_id })
|
|
|
return await publish(this.mqtt_id, this.client_channel, qos, false, newParams)
|
|
return await publish(this.mqtt_id, this.client_channel, qos, false, newParams)
|
|
@@ -80,17 +80,14 @@ export default class MqttService {
|
|
|
try {
|
|
try {
|
|
|
const { payload } = event.message
|
|
const { payload } = event.message
|
|
|
const data = JSON.parse(Buffer.from(payload).toString())
|
|
const data = JSON.parse(Buffer.from(payload).toString())
|
|
|
- // 排除自己发的消息
|
|
|
|
|
- if (data.from_id === this.client_id) return
|
|
|
|
|
- // 订阅房间,通知对方开始RTC
|
|
|
|
|
- if (data.type === 'join') {
|
|
|
|
|
- this.client_channel = data.channel
|
|
|
|
|
- this.send({ type: 'startRTC' })
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 通知对方开始RTC
|
|
|
|
|
+ if (data.type === 'join' && data.channel) { this.client_channel = data.channel; this.send({ type: 'startRTC' }) }
|
|
|
|
|
+ // 排除自己的消息
|
|
|
|
|
+ if (!data.from_id || data.from_id === this.client_id) return
|
|
|
// 离开就退出mqtt
|
|
// 离开就退出mqtt
|
|
|
if (data.type === 'leave') this.disconnect()
|
|
if (data.type === 'leave') this.disconnect()
|
|
|
-
|
|
|
|
|
this.store.setMqttMessage({ ...data })
|
|
this.store.setMqttMessage({ ...data })
|
|
|
|
|
+ console.log('接收mqtt', data)
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.log('mqtt消息解析失败')
|
|
console.log('mqtt消息解析失败')
|
|
|
}
|
|
}
|