视频连线

This commit is contained in:
duoaohui
2026-05-25 21:45:36 +08:00
parent 079ee16a95
commit 771e6d0d8e

View File

@@ -154,6 +154,7 @@ const userStore = useUserStore()
const rawCode = ref('') const rawCode = ref('')
const callId = ref('') const callId = ref('')
const cloudLawApiBase = ref('') const cloudLawApiBase = ref('')
const cloudLawToken = ref('')
const callMode = ref('video') const callMode = ref('video')
const joining = ref(false) const joining = ref(false)
const joinError = ref('') const joinError = ref('')
@@ -382,6 +383,20 @@ const requestCloudLawCommands = (url) => {
}) })
} }
const notifyCloudLawEnd = () => {
if (!callId.value || !cloudLawApiBase.value) return Promise.resolve()
return new Promise(resolve => {
uni.request({
url: resolveCloudLawApiUrl(`/api/applet/voiceConnection/${encodeURIComponent(callId.value)}/end`),
method: 'POST',
data: {},
header: cloudLawToken.value ? { 'Content-Type': 'application/json', token: `Bearer ${cloudLawToken.value}` } : { 'Content-Type': 'application/json' },
timeout: 5000,
complete: resolve
})
})
}
const pollCommandsOnce = async () => { const pollCommandsOnce = async () => {
if (!callId.value || !meetingStore.isInMeeting || leaving.value || ended.value || commandPolling) return if (!callId.value || !meetingStore.isInMeeting || leaving.value || ended.value || commandPolling) return
commandPolling = true commandPolling = true
@@ -687,6 +702,7 @@ const hangup = async () => {
leaving.value = true leaving.value = true
stopCommandPolling() stopCommandPolling()
try { try {
await notifyCloudLawEnd()
// 云律视频咨询:发起人(小程序端用户)在 CreateRoomForInternal 时被加成 host // 云律视频咨询:发起人(小程序端用户)在 CreateRoomForInternal 时被加成 host
// 用户挂机 = 咨询结束,无条件 endMeeting 让律师 iframe 收到 room.ended 自动退出。 // 用户挂机 = 咨询结束,无条件 endMeeting 让律师 iframe 收到 room.ended 自动退出。
// 不依赖 meetingStore.isHosthost_id/userId 偶发类型不一致导致误判 false 只走 leave // 不依赖 meetingStore.isHosthost_id/userId 偶发类型不一致导致误判 false 只走 leave
@@ -712,6 +728,7 @@ onLoad(query => {
rawCode.value = query?.code || query?.roomCode || '' rawCode.value = query?.code || query?.roomCode || ''
callId.value = query?.callId || query?.call_id || '' callId.value = query?.callId || query?.call_id || ''
cloudLawApiBase.value = query?.cloudLawApiBase || query?.cloud_law_api_base || '' cloudLawApiBase.value = query?.cloudLawApiBase || query?.cloud_law_api_base || ''
cloudLawToken.value = query?.cloudLawToken || query?.cloud_law_token || ''
const mode = String(query?.mode || query?.callType || query?.type || '').toLowerCase() const mode = String(query?.mode || query?.callType || query?.type || '').toLowerCase()
callMode.value = mode === 'voice' || mode === 'audio' ? 'voice' : 'video' callMode.value = mode === 'voice' || mode === 'audio' ? 'voice' : 'video'
joinMeeting() joinMeeting()
@@ -752,6 +769,9 @@ onBeforeUnmount(() => {
onUnload(() => { onUnload(() => {
stopCommandPolling() stopCommandPolling()
if (!ended.value && callId.value) {
notifyCloudLawEnd().catch(() => {})
}
if (meetingStore.isInMeeting && meetingStore.localState !== MEETING_LOCAL_STATE_LEAVING) { if (meetingStore.isInMeeting && meetingStore.localState !== MEETING_LOCAL_STATE_LEAVING) {
meetingStore.leave().catch(() => {}) meetingStore.leave().catch(() => {})
} }