mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-08 11:26:56 +08:00
fix: no voice in speech page; custom personal page redirect notworking. feat: sync sroll bar between question display page an obs component
This commit is contained in:
@@ -1,55 +1,68 @@
|
||||
import { useAccount } from '@/api/account'
|
||||
import { MasterRTCClient, SlaveRTCClient } from '@/data/RTCClient'
|
||||
import {
|
||||
BaseRTCClient,
|
||||
MasterRTCClient,
|
||||
SlaveRTCClient
|
||||
} from '@/data/RTCClient'
|
||||
import { nonFunctionArgSeparator } from 'html2canvas/dist/types/css/syntax/parser'
|
||||
import { acceptHMRUpdate, defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
export const useWebRTC = defineStore('WebRTC', () => {
|
||||
const masterClient = ref<MasterRTCClient>()
|
||||
const slaveClient = ref<SlaveRTCClient>()
|
||||
const client = ref<BaseRTCClient>()
|
||||
const accountInfo = useAccount()
|
||||
let isInitializing = false
|
||||
|
||||
function Init(
|
||||
type: 'master' | 'slave'
|
||||
): MasterRTCClient | SlaveRTCClient | undefined {
|
||||
function on(event: string, callback: (...args: any[]) => void) {
|
||||
client.value?.on(event, callback)
|
||||
}
|
||||
|
||||
function off(event: string, callback: (...args: any[]) => void) {
|
||||
client.value?.off(event, callback)
|
||||
}
|
||||
|
||||
function send(event: string, data: any) {
|
||||
client.value?.send(event, data)
|
||||
}
|
||||
|
||||
async function Init(type: 'master' | 'slave') {
|
||||
if (isInitializing) {
|
||||
return
|
||||
return useWebRTC()
|
||||
}
|
||||
try {
|
||||
isInitializing = true
|
||||
navigator.locks.request(
|
||||
await navigator.locks.request(
|
||||
'rtcClientInit',
|
||||
{
|
||||
ifAvailable: true
|
||||
},
|
||||
async (lock) => {
|
||||
if (lock) {
|
||||
if (type == 'master') {
|
||||
if (masterClient.value) {
|
||||
return masterClient
|
||||
} else {
|
||||
masterClient.value = new MasterRTCClient(
|
||||
accountInfo.value.id.toString(),
|
||||
accountInfo.value.token
|
||||
)
|
||||
await masterClient.value.Init()
|
||||
return masterClient
|
||||
}
|
||||
} else {
|
||||
if (slaveClient.value) {
|
||||
return slaveClient
|
||||
} else {
|
||||
slaveClient.value = new SlaveRTCClient(
|
||||
accountInfo.value.id?.toString(),
|
||||
accountInfo.value.token
|
||||
)
|
||||
await slaveClient.value.Init()
|
||||
return slaveClient
|
||||
}
|
||||
while (!accountInfo.value.id) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 500))
|
||||
}
|
||||
if (client.value) {
|
||||
return client.value
|
||||
}
|
||||
if (type == 'master') {
|
||||
client.value = new MasterRTCClient(
|
||||
accountInfo.value.id.toString(),
|
||||
accountInfo.value.token
|
||||
)
|
||||
} else {
|
||||
client.value = new SlaveRTCClient(
|
||||
accountInfo.value.id?.toString(),
|
||||
accountInfo.value.token
|
||||
)
|
||||
}
|
||||
await client.value.Init()
|
||||
return useWebRTC()
|
||||
} else {
|
||||
return useWebRTC()
|
||||
}
|
||||
}
|
||||
)
|
||||
return useWebRTC()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
throw e
|
||||
@@ -59,7 +72,10 @@ export const useWebRTC = defineStore('WebRTC', () => {
|
||||
}
|
||||
|
||||
return {
|
||||
Init
|
||||
Init,
|
||||
send,
|
||||
on,
|
||||
off
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user