mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-08 11:26:56 +08:00
progessing on client
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { useAccount } from '@/api/account'
|
||||
import DanmakuClient, { AuthInfo, RoomAuthInfo } from '@/data/DanmakuClient'
|
||||
import OpenLiveClient, {
|
||||
AuthInfo,
|
||||
RoomAuthInfo
|
||||
} from '@/data/DanmakuClients/OpenLiveClient'
|
||||
import { defineStore } from 'pinia'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
@@ -9,7 +12,7 @@ export interface BCMessage {
|
||||
}
|
||||
|
||||
export const useDanmakuClient = defineStore('DanmakuClient', () => {
|
||||
const danmakuClient = ref<DanmakuClient>(new DanmakuClient(null))
|
||||
const danmakuClient = ref<OpenLiveClient>(new OpenLiveClient())
|
||||
let bc: BroadcastChannel
|
||||
const isOwnedDanmakuClient = ref(false)
|
||||
const status = ref<'waiting' | 'initializing' | 'listening' | 'running'>(
|
||||
@@ -77,8 +80,10 @@ export const useDanmakuClient = defineStore('DanmakuClient', () => {
|
||||
async (lock) => {
|
||||
if (lock) {
|
||||
status.value = 'initializing'
|
||||
bc = new BroadcastChannel('vtsuru.danmaku.' + accountInfo.value?.id)
|
||||
console.log('[DanmakuClient] 创建 BroadcastChannel: ' + bc.name)
|
||||
bc = new BroadcastChannel(
|
||||
'vtsuru.danmaku.open-live' + accountInfo.value?.id
|
||||
)
|
||||
console.log('[DanmakuClient] 创建 BroadcastChannel: ' + bc.name)
|
||||
bc.onmessage = (event) => {
|
||||
const message: BCMessage = event.data as BCMessage
|
||||
const data = message.data ? JSON.parse(message.data) : {}
|
||||
@@ -86,7 +91,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':
|
||||
@@ -178,7 +183,7 @@ export const useDanmakuClient = defineStore('DanmakuClient', () => {
|
||||
const events = danmakuClient.value.events
|
||||
const eventsAsModel = danmakuClient.value.eventsAsModel
|
||||
|
||||
danmakuClient.value = new DanmakuClient(auth || null)
|
||||
danmakuClient.value = new OpenLiveClient(auth)
|
||||
|
||||
danmakuClient.value.events = events
|
||||
danmakuClient.value.eventsAsModel = eventsAsModel
|
||||
@@ -192,7 +197,7 @@ export const useDanmakuClient = defineStore('DanmakuClient', () => {
|
||||
status: 'running',
|
||||
auth: authInfo.value
|
||||
})
|
||||
danmakuClient.value.onEvent('all', (data) => {
|
||||
danmakuClient.value.on('all', (data) => {
|
||||
sendBCMessage('on-danmaku', data)
|
||||
})
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user