From d0c8f67f3a6c1d0cb7a51ebeb31890aa44258cc5 Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Tue, 3 Dec 2024 09:25:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/form/index.ts | 51 ++++++++++++++++++++++++++++----------------- utils/singlr.ts | 2 ++ 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/pages/form/index.ts b/pages/form/index.ts index d943760..0bc0d05 100644 --- a/pages/form/index.ts +++ b/pages/form/index.ts @@ -16,6 +16,7 @@ Page({ }, onShow() { const that = this; + onStop() this.setData({ isJoin: false }) @@ -29,7 +30,6 @@ Page({ } }, }) - onStop() wx.getStorage({ key: 'historicalList', success(res: any) { @@ -39,6 +39,7 @@ Page({ if (that.data.meetingForm.roomNum) { that.setData({ meetingForm: { + roomNum: that.data.meetingForm.roomNum, roomName: res.data[res.data.length - 1].nickName }, }) @@ -93,12 +94,11 @@ Page({ }); }, async getRoomRtcToken(roomNum: string, callBack: Function): Promise { - Promise.all([GetRoomRtcToken(roomNum), GetRoomRtcToken(roomNum + 'a'), GetAgoraConf()]).then(res => { - if (res[0].code === 200 && res[1].code === 200 && res[2].code === 200) { + Promise.all([GetRoomRtcToken(roomNum), GetAgoraConf()]).then(res => { + if (res[0].code === 200 && res[1].code === 200) { callBack({ token: res[0].data, - tokenA: res[1].data, - appid: res[2].data + appid: res[1].data }) } }) @@ -131,21 +131,34 @@ Page({ key: "user", data: res.data }) - startSignalr(() => { - this.getRoomRtcToken(this.data.meetingForm.roomNum, (option) => { - agora.setOption({ - token: option.token, - tokenA: option.tokenA, - channelId: this.data.meetingForm.roomNum, - appId: option.appid, - uid: res.data.uid, - screenShareId: res.data.screenShareId, - }) - wx.navigateTo({ - url: `/pages/meeting/index?roomNum=${this.data.meetingForm.roomNum}&nickName=${this.data.meetingForm.roomName}` - }) + setTimeout(() => { + startSignalr((str) => { + if (str) { + this.setData({ + isJoin: false + }) + Message.error({ + context: this, + offset: [90, 32], + duration: 3000, + content: str, + }); + } else { + this.getRoomRtcToken(this.data.meetingForm.roomNum, (option) => { + agora.setOption({ + token: option.token, + channelId: this.data.meetingForm.roomNum, + appId: option.appid, + uid: res.data.uid, + screenShareId: res.data.screenShareId, + }) + wx.navigateTo({ + url: `/pages/meeting/index?roomNum=${this.data.meetingForm.roomNum}&nickName=${this.data.meetingForm.roomName}` + }) + }) + } }) - }) + }, 1000); } else { this.setData({ isJoin: false diff --git a/utils/singlr.ts b/utils/singlr.ts index 473cef6..02e24f0 100644 --- a/utils/singlr.ts +++ b/utils/singlr.ts @@ -14,6 +14,8 @@ export const startSignalr = async (callBack: Function) => { .build(); connection.start().then(() => { callBack() + }).catch((err) => { + callBack('服务器启动失败!请稍后重试。') }) connection.onclose(() => { startConnection()