perf: 优化会议

This commit is contained in:
kuaifan 2024-12-20 19:25:05 +08:00
parent 1acfd7ee34
commit 8a4b0c57f9

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="meeting-warp"> <div class="meeting-warp" :class="{'meeting-full': $isSubElectron}">
<!-- 加入/新建 --> <!-- 加入/新建 -->
<Modal <Modal
v-model="addShow" v-model="addShow"
@ -121,6 +121,16 @@
</div> </div>
</template> </template>
<style lang="scss" scoped>
.meeting-full {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #fff;
}
</style>
<script> <script>
import {mapState} from 'vuex' import {mapState} from 'vuex'
import Player from "./player.vue"; import Player from "./player.vue";
@ -486,11 +496,7 @@ export default {
content: '确定要离开会议吗?', content: '确定要离开会议吗?',
cancelText: '继续', cancelText: '继续',
okText: '退出', okText: '退出',
onOk: async _ => { onOk: this.onBeforeClose
await this.leave()
this.onBeforeClose()
resolve()
}
}); });
}) })
}, },
@ -500,14 +506,16 @@ export default {
const modal = type === 'warning' ? $A.modalWarning : $A.modalError; const modal = type === 'warning' ? $A.modalWarning : $A.modalError;
modal({ modal({
content: msg, content: msg,
onOk: async _ => { onOk: this.onBeforeClose
this.onBeforeClose()
resolve()
}
}); });
}, },
onBeforeClose() { async onBeforeClose() {
try {
await this.leave()
} catch (e) {
console.error(e)
}
if ($A.isSubElectron) { if ($A.isSubElectron) {
this.$Electron.sendMessage('windowDestroy'); this.$Electron.sendMessage('windowDestroy');
} else if (this.addData.sharekey) { } else if (this.addData.sharekey) {
@ -580,27 +588,33 @@ export default {
const localTracks = []; const localTracks = [];
try { try {
this.localUser.uid = await this.agoraClient.join(options.appid, options.channel, options.token, options.uid) this.localUser.uid = await this.agoraClient.join(options.appid, options.channel, options.token, options.uid)
if (this.addData.tracks.includes("audio")) { //
localTracks.push(this.localUser.audioTrack = await AgoraRTC.createMicrophoneAudioTrack()) await Promise.all(['audio', 'video'].map(async (trackType) => {
} const createTrack = trackType === 'audio' ? AgoraRTC.createMicrophoneAudioTrack : AgoraRTC.createCameraVideoTrack;
if (this.addData.tracks.includes("video")) { const trackKey = `${trackType}Track`;
localTracks.push(this.localUser.videoTrack = await AgoraRTC.createCameraVideoTrack()) try {
} this.localUser[trackKey] = await createTrack();
localTracks.push(this.localUser[trackKey]);
} catch (e) {
if (e.code === 'DEVICE_NOT_FOUND') {
console.warn(`${trackType} device not found:`, e);
} else {
throw e;
}
}
}));
// //
if (localTracks.length > 0) { if (localTracks.length > 0) {
await this.agoraClient.publish(localTracks); await this.agoraClient.publish(localTracks);
} }
// //
this.meetingShow = true; this.meetingShow = true;
} catch (error) { } catch (error) {
console.error(error) console.error(error)
$A.modalError({ $A.modalError({
language: false, language: false,
content: getErrorMessage(error.code, getLanguage()) || this.$L("会议组件加载失败!"), content: getErrorMessage(error.code, getLanguage()) || this.$L("会议组件加载失败!"),
onOk: async _ => { onOk: this.onBeforeClose
this.onBeforeClose()
resolve()
}
}); });
} }
} catch (e) { } } catch (e) { }
@ -633,9 +647,17 @@ export default {
async openAudio() { async openAudio() {
if (this.audioLoad || this.localUser.audioTrack) return; if (this.audioLoad || this.localUser.audioTrack) return;
this.audioLoad = true; this.audioLoad = true;
this.localUser.audioTrack = await AgoraRTC.createMicrophoneAudioTrack() try {
await this.agoraClient.publish([this.localUser.audioTrack]); this.localUser.audioTrack = await AgoraRTC.createMicrophoneAudioTrack()
this.audioLoad = false; await this.agoraClient.publish([this.localUser.audioTrack]);
} catch (e) {
$A.modalError({
language: false,
content: getErrorMessage(e.code, getLanguage()) || this.$L("开启麦克风失败!"),
});
} finally {
this.audioLoad = false;
}
}, },
async closeAudio() { async closeAudio() {
@ -651,9 +673,17 @@ export default {
async openVideo() { async openVideo() {
if (this.videoLoad || this.localUser.videoTrack) return; if (this.videoLoad || this.localUser.videoTrack) return;
this.videoLoad = true; this.videoLoad = true;
this.localUser.videoTrack = await AgoraRTC.createCameraVideoTrack() try {
await this.agoraClient.publish([this.localUser.videoTrack]); this.localUser.videoTrack = await AgoraRTC.createCameraVideoTrack()
this.videoLoad = false; await this.agoraClient.publish([this.localUser.videoTrack]);
} catch (e) {
$A.modalError({
language: false,
content: getErrorMessage(e.code, getLanguage()) || this.$L("开启摄像头失败!"),
});
} finally {
this.videoLoad = false;
}
}, },
async closeVideo() { async closeVideo() {