246 lines
5.9 KiB
TypeScript
246 lines
5.9 KiB
TypeScript
import { GetCheckoutRoomNum, PostAnonLogin, GetAgoraConf, GetRoomRtcToken, GetOpenId } from '../../api/form/index'
|
|
import { Message } from 'tdesign-miniprogram';
|
|
import { startSignalr, onStop } from '../../utils/singlr';
|
|
import { agora } from '../../utils/agora'
|
|
Page({
|
|
data: {
|
|
meetingForm: {
|
|
roomNum: '',
|
|
roomName: '',
|
|
},
|
|
isRecord: false,
|
|
isCamera: false,
|
|
netWorkErrorDialog: false,
|
|
historicalList: [],
|
|
isJoin: false
|
|
},
|
|
onShow() {
|
|
const that = this;
|
|
wx.getStorage({
|
|
key: 'isConnected',
|
|
success(res: any) {
|
|
if (res.data) {
|
|
that.setData({
|
|
netWorkErrorDialog: true,
|
|
})
|
|
}
|
|
},
|
|
})
|
|
onStop()
|
|
wx.getStorage({
|
|
key: 'historicalList',
|
|
success(res: any) {
|
|
that.setData({
|
|
historicalList: res.data
|
|
})
|
|
that.setData({
|
|
meetingForm: {
|
|
roomNum: res.data[res.data.length - 1].roomNum,
|
|
roomName: res.data[res.data.length - 1].nickName
|
|
},
|
|
})
|
|
},
|
|
})
|
|
},
|
|
onLoad() {
|
|
wx.authorize({
|
|
scope: 'scope.record',
|
|
success: () => {
|
|
this.setData({
|
|
isRecord: true,
|
|
})
|
|
},
|
|
fail: () => {
|
|
this.setData({
|
|
isRecord: false,
|
|
})
|
|
}
|
|
});
|
|
wx.authorize({
|
|
scope: 'scope.camera',
|
|
success: () => {
|
|
this.setData({
|
|
isCamera: true,
|
|
})
|
|
},
|
|
fail: () => {
|
|
this.setData({
|
|
isCamera: false,
|
|
})
|
|
}
|
|
});
|
|
},
|
|
async getRoomRtcToken(roomNum: string, callBack: Function): Promise<void> {
|
|
Promise.all([GetRoomRtcToken(roomNum), GetRoomRtcToken(roomNum + 'a'), GetAgoraConf()]).then(res => {
|
|
if (res[0].code === 200 && res[1].code === 200 && res[2].code === 200) {
|
|
callBack({
|
|
token: res[0].data,
|
|
tokenA: res[1].data,
|
|
appid: res[2].data
|
|
})
|
|
}
|
|
})
|
|
},
|
|
closeDialog() {
|
|
wx.setStorage({
|
|
key: "isConnected",
|
|
data: false
|
|
})
|
|
this.setData({
|
|
netWorkErrorDialog: false
|
|
})
|
|
},
|
|
joinMeeting() {
|
|
this.closeDialog()
|
|
if (this.data.isJoin) {
|
|
return
|
|
}
|
|
this.setData({
|
|
isJoin: true
|
|
})
|
|
const navigateToMeeting = async (deviceId: string): Promise<void> => {
|
|
await PostAnonLogin({
|
|
deviceId,
|
|
nickName: this.data.meetingForm.roomName,
|
|
roomNum: this.data.meetingForm.roomNum,
|
|
}).then(res => {
|
|
if (res.code === 200) {
|
|
wx.setStorage({
|
|
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}`
|
|
})
|
|
})
|
|
})
|
|
}
|
|
this.setData({
|
|
isJoin: false
|
|
})
|
|
}).catch(() => {
|
|
this.setData({
|
|
isJoin: false
|
|
})
|
|
})
|
|
}
|
|
if (!this.data.meetingForm.roomNum) {
|
|
Message.error({
|
|
context: this,
|
|
offset: [90, 32],
|
|
duration: 3000,
|
|
content: '请输入会议号!',
|
|
});
|
|
this.setData({
|
|
isJoin: false
|
|
})
|
|
return
|
|
}
|
|
if (!this.data.meetingForm.roomName) {
|
|
Message.error({
|
|
context: this,
|
|
offset: [90, 32],
|
|
duration: 3000,
|
|
content: '请输入入会名称!',
|
|
});
|
|
this.setData({
|
|
isJoin: false
|
|
})
|
|
return
|
|
}
|
|
const that = this;
|
|
GetCheckoutRoomNum(this.data.meetingForm.roomNum).then(res => {
|
|
if (res.code === 200) {
|
|
if (res.data) {
|
|
wx.login({
|
|
success: (res) => {
|
|
const { code } = res
|
|
GetOpenId(code).then(res => {
|
|
if (res.code === 200) {
|
|
navigateToMeeting(res.data)
|
|
} else {
|
|
that.setData({
|
|
isJoin: false
|
|
})
|
|
}
|
|
}).catch(() => {
|
|
that.setData({
|
|
isJoin: false
|
|
})
|
|
})
|
|
},
|
|
fail: () => {
|
|
that.setData({
|
|
isJoin: false
|
|
})
|
|
}
|
|
})
|
|
} else {
|
|
this.setData({
|
|
isJoin: false
|
|
})
|
|
Message.error({
|
|
context: this,
|
|
offset: [90, 32],
|
|
duration: 3000,
|
|
content: '房间号不存在!',
|
|
});
|
|
}
|
|
}
|
|
}).catch(() => {
|
|
this.setData({
|
|
isJoin: false
|
|
})
|
|
})
|
|
},
|
|
setting() {
|
|
wx.openSetting({
|
|
success: (res) => {
|
|
this.setData({
|
|
isCamera: res.authSetting['scope.camera'],
|
|
isRecord: res.authSetting['scope.record'],
|
|
})
|
|
}
|
|
})
|
|
},
|
|
changeMeetingForm(e) {
|
|
switch (e.target.dataset.type) {
|
|
case 'roomNum':
|
|
this.setData({
|
|
meetingForm: {
|
|
roomNum: e.type === 'clear' ? '' : e.detail.value,
|
|
roomName: this.data.meetingForm.roomName,
|
|
}
|
|
})
|
|
break;
|
|
case 'roomName':
|
|
this.setData({
|
|
meetingForm: {
|
|
roomNum: this.data.meetingForm.roomNum,
|
|
roomName: e.type === 'clear' ? '' : e.detail.value,
|
|
}
|
|
})
|
|
break;
|
|
}
|
|
},
|
|
setForm(e) {
|
|
const { item } = e.currentTarget.dataset;
|
|
this.setData({
|
|
meetingForm: {
|
|
roomNum: item.roomNum,
|
|
roomName: item.nickName
|
|
},
|
|
})
|
|
this.joinMeeting()
|
|
}
|
|
}) |