|
@@ -158,7 +158,6 @@ export default {
|
|
|
handleAlarm() {
|
|
|
this.alarmModel = false;
|
|
|
},
|
|
|
-
|
|
|
// voip相关方法
|
|
|
async getVoipDevices() {
|
|
|
const { list } = await getDeviceVoIPList();
|
|
@@ -246,7 +245,6 @@ export default {
|
|
|
};
|
|
|
await this.call(voiceCan);
|
|
|
},
|
|
|
-
|
|
|
async getSelf(options = {}) {
|
|
|
if (!this._caller.isPending()) {
|
|
|
return;
|
|
@@ -343,7 +341,6 @@ export default {
|
|
|
}
|
|
|
wx.hideLoading();
|
|
|
},
|
|
|
-
|
|
|
async call(e) {
|
|
|
const { sn, idx, type: roomtype } = e;
|
|
|
const target = this.contactList[idx];
|
|
@@ -376,15 +373,89 @@ export default {
|
|
|
console.error(`call error`, error);
|
|
|
}
|
|
|
},
|
|
|
+
|
|
|
+ connectMQTT(clientId, devId) {
|
|
|
+ const THRESHOLD = 2;
|
|
|
+ const params = {
|
|
|
+ keepalive: 60,
|
|
|
+ clean: true,
|
|
|
+ connectTimeout: 30 * 1000,
|
|
|
+ clientId:
|
|
|
+ "wx_mqtt_" + Math.random().toString(16).substring(2, 8),
|
|
|
+ username: "admin",
|
|
|
+ password: "public",
|
|
|
+ // 微信小程序特定配置
|
|
|
+ wsOptions: {
|
|
|
+ WebSocket: function (url) {
|
|
|
+ return wx.connectSocket({
|
|
|
+ url: url,
|
|
|
+ header: {
|
|
|
+ "content-type": "application/json",
|
|
|
+ },
|
|
|
+ protocols: ["mqtt"],
|
|
|
+ });
|
|
|
+ },
|
|
|
+ },
|
|
|
+ rejectUnauthorized: false, // 仅开发环境使用,生产环境应设为true或移除
|
|
|
+ };
|
|
|
+ let client = "";
|
|
|
+ let selectedService = uni.getStorageSync("sercviceChoice");
|
|
|
+ if (!selectedService || selectedService == "aloneServe") {
|
|
|
+ client = mqtt.connect("wxs://radar-power.cn:8084/mqtt", params);
|
|
|
+ }
|
|
|
+ // 存储client引用以便后续操作
|
|
|
+ this.mqttClient = client;
|
|
|
+ client.on("connect", () => {
|
|
|
+ console.log("MQTT连接成功");
|
|
|
+ client.subscribe(
|
|
|
+ `/mps/wx_${uni.setStorageSync("userId")}/notice`,
|
|
|
+ (err) => {
|
|
|
+ if (err) {
|
|
|
+ console.error("订阅失败", err);
|
|
|
+ } else {
|
|
|
+ console.log(`成功订阅设备主题: device/${clientId}`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ });
|
|
|
+ client.on("disconnect", () => {
|
|
|
+ console.log("MQTT不在连接");
|
|
|
+ });
|
|
|
+ client.on("error", (err) => {
|
|
|
+ setTimeout(() => {
|
|
|
+ this.connectMQTT(clientId, devId);
|
|
|
+ }, 5000);
|
|
|
+ });
|
|
|
+
|
|
|
+ client.on("reconnect", () => {});
|
|
|
+
|
|
|
+ client.on("close", () => {});
|
|
|
+
|
|
|
+ client.on("message", (topic, message) => {
|
|
|
+ // clearTimeout(this.inactivityTimer);
|
|
|
+ // this.inactivityTimer = setTimeout(() => {
|
|
|
+ // this.targetPoints = {};
|
|
|
+ // }, 1500);
|
|
|
+ // if (!match) return;
|
|
|
+ const data = JSON.parse(message.toString());
|
|
|
+ console.log("接收到消息:", topic, data);
|
|
|
+ });
|
|
|
+ },
|
|
|
},
|
|
|
onLoad(options) {
|
|
|
if (!isWmpf) {
|
|
|
this.getVoipDevices();
|
|
|
}
|
|
|
+ this.connectMQTT();
|
|
|
+ },
|
|
|
+ onUnload() {
|
|
|
+ if (this.mqttClient) this.mqttClient.end(true);
|
|
|
+ clearInterval(this.autoPlayinterval);
|
|
|
+ clearInterval(this.inactivityTimer);
|
|
|
+ },
|
|
|
+ onHide() {
|
|
|
+ if (this.mqttClient) this.mqttClient.end(true);
|
|
|
},
|
|
|
- onUnload() {},
|
|
|
- onHide() {},
|
|
|
- onShow() {},
|
|
|
onShareAppMessage() {},
|
|
|
};
|
|
|
</script>
|