mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-08 11:26:56 +08:00
fix hub load
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { useAccount } from '@/api/account'
|
||||
import DanmakuClient, { AuthInfo, RoomAuthInfo } from '@/data/DanmakuClient'
|
||||
import { defineStore } from 'pinia'
|
||||
import { computed, ref } from 'vue'
|
||||
@@ -18,6 +19,7 @@ export const useDanmakuClient = defineStore('DanmakuClient', () => {
|
||||
() => status.value === 'running' || status.value === 'listening'
|
||||
)
|
||||
const authInfo = ref<RoomAuthInfo>()
|
||||
const accountInfo = useAccount()
|
||||
|
||||
let existOtherClient = false
|
||||
let isInitializing = false
|
||||
@@ -75,7 +77,7 @@ export const useDanmakuClient = defineStore('DanmakuClient', () => {
|
||||
async (lock) => {
|
||||
if (lock) {
|
||||
status.value = 'initializing'
|
||||
bc = new BroadcastChannel('vtsuru.danmaku')
|
||||
bc = new BroadcastChannel('vtsuru.danmaku.' + accountInfo.value?.id)
|
||||
bc.onmessage = (event) => {
|
||||
const message: BCMessage = event.data as BCMessage
|
||||
const data = message.data ? JSON.parse(message.data) : {}
|
||||
@@ -83,7 +85,7 @@ export const useDanmakuClient = defineStore('DanmakuClient', () => {
|
||||
case 'check-client':
|
||||
sendBCMessage('response-client-status', {
|
||||
status: status.value,
|
||||
auth: authInfo.value
|
||||
auth: authInfo.value,
|
||||
})
|
||||
break
|
||||
case 'response-client-status':
|
||||
|
||||
@@ -9,7 +9,9 @@ export const useWebRTC = defineStore('WebRTC', () => {
|
||||
const accountInfo = useAccount()
|
||||
let isInitializing = false
|
||||
|
||||
function Init(type: 'master' | 'slave'): MasterRTCClient | SlaveRTCClient | undefined {
|
||||
function Init(
|
||||
type: 'master' | 'slave'
|
||||
): MasterRTCClient | SlaveRTCClient | undefined {
|
||||
if (isInitializing) {
|
||||
return
|
||||
}
|
||||
@@ -30,7 +32,7 @@ export const useWebRTC = defineStore('WebRTC', () => {
|
||||
accountInfo.value.id.toString(),
|
||||
accountInfo.value.token
|
||||
)
|
||||
masterClient.value.Init()
|
||||
await masterClient.value.Init()
|
||||
return masterClient
|
||||
}
|
||||
} else {
|
||||
@@ -41,7 +43,7 @@ export const useWebRTC = defineStore('WebRTC', () => {
|
||||
accountInfo.value.id?.toString(),
|
||||
accountInfo.value.token
|
||||
)
|
||||
slaveClient.value.Init()
|
||||
await slaveClient.value.Init()
|
||||
return slaveClient
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,14 +13,16 @@ export const useVTsuruHub = defineStore('VTsuruHub', () => {
|
||||
const signalRClient = ref<signalR.HubConnection>()
|
||||
const isInited = ref(false)
|
||||
const isIniting = ref(false)
|
||||
let token = ''
|
||||
const accountInfo = useAccount()
|
||||
|
||||
async function connectSignalR() {
|
||||
if (isIniting.value) return
|
||||
isIniting.value = true
|
||||
while (!accountInfo.value.id || accountInfo.value.id < 1)
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000))
|
||||
//console.log('[Components-Event] 正在连接到 VTsuru 服务器...')
|
||||
const connection = new HubConnectionBuilder()
|
||||
.withUrl(BASE_HUB_URL + 'main?token=' + token, {
|
||||
.withUrl(BASE_HUB_URL + 'main?token=' + accountInfo.value.token, {
|
||||
skipNegotiation: true,
|
||||
transport: HttpTransportType.WebSockets,
|
||||
logger: LogLevel.Error
|
||||
@@ -91,9 +93,8 @@ export const useVTsuruHub = defineStore('VTsuruHub', () => {
|
||||
signalRClient.value?.onreconnected(listener)
|
||||
}
|
||||
|
||||
function Init(_token: string) {
|
||||
token = _token
|
||||
if (!isInited.value) {
|
||||
function Init() {
|
||||
if (!isInited.value && !isIniting.value) {
|
||||
connectSignalR()
|
||||
}
|
||||
return useVTsuruHub()
|
||||
|
||||
Reference in New Issue
Block a user