|
|
@ -33,6 +33,7 @@ export function useMonitorLive({ getDockId, ui, getLivePlayer }) { |
|
|
const live = reactive({ |
|
|
const live = reactive({ |
|
|
session: null, |
|
|
session: null, |
|
|
dockId: '', |
|
|
dockId: '', |
|
|
|
|
|
opening: false, |
|
|
playUrl: '', |
|
|
playUrl: '', |
|
|
playUrlExpiresAt: 0, |
|
|
playUrlExpiresAt: 0, |
|
|
heartbeatTimer: null, |
|
|
heartbeatTimer: null, |
|
|
@ -42,7 +43,10 @@ export function useMonitorLive({ getDockId, ui, getLivePlayer }) { |
|
|
phasePollStartedAt: 0, |
|
|
phasePollStartedAt: 0, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
let playURLRequest = null |
|
|
|
|
|
|
|
|
const livePhaseText = computed(() => { |
|
|
const livePhaseText = computed(() => { |
|
|
|
|
|
if (live.opening && !live.session) return '打开中' |
|
|
if (!live.session) return '待机' |
|
|
if (!live.session) return '待机' |
|
|
const phase = live.session.phase |
|
|
const phase = live.session.phase |
|
|
if (phase === 'streaming') return live.playUrl.startsWith('fake://') ? '模拟直播' : '直播中' |
|
|
if (phase === 'streaming') return live.playUrl.startsWith('fake://') ? '模拟直播' : '直播中' |
|
|
@ -66,8 +70,10 @@ export function useMonitorLive({ getDockId, ui, getLivePlayer }) { |
|
|
|
|
|
|
|
|
function resetLocal() { |
|
|
function resetLocal() { |
|
|
clearTimers() |
|
|
clearTimers() |
|
|
|
|
|
playURLRequest = null |
|
|
live.session = null |
|
|
live.session = null |
|
|
live.dockId = '' |
|
|
live.dockId = '' |
|
|
|
|
|
live.opening = false |
|
|
live.playUrl = '' |
|
|
live.playUrl = '' |
|
|
live.playUrlExpiresAt = 0 |
|
|
live.playUrlExpiresAt = 0 |
|
|
live.playRetryCount = 0 |
|
|
live.playRetryCount = 0 |
|
|
@ -84,6 +90,7 @@ export function useMonitorLive({ getDockId, ui, getLivePlayer }) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function toggleLive() { |
|
|
function toggleLive() { |
|
|
|
|
|
if (live.opening) return |
|
|
if (live.session) closeLive() |
|
|
if (live.session) closeLive() |
|
|
else openLive() |
|
|
else openLive() |
|
|
} |
|
|
} |
|
|
@ -98,8 +105,11 @@ export function useMonitorLive({ getDockId, ui, getLivePlayer }) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function openLive() { |
|
|
async function openLive() { |
|
|
|
|
|
if (live.opening || live.session) return |
|
|
const dockId = getDockId?.() |
|
|
const dockId = getDockId?.() |
|
|
if (!dockId) return |
|
|
if (!dockId) return |
|
|
|
|
|
|
|
|
|
|
|
live.opening = true |
|
|
try { |
|
|
try { |
|
|
const result = await joinLive(dockId) |
|
|
const result = await joinLive(dockId) |
|
|
live.session = result.session |
|
|
live.session = result.session |
|
|
@ -119,6 +129,8 @@ export function useMonitorLive({ getDockId, ui, getLivePlayer }) { |
|
|
} |
|
|
} |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
ui.toast(e.message || '打开直播失败') |
|
|
ui.toast(e.message || '打开直播失败') |
|
|
|
|
|
} finally { |
|
|
|
|
|
live.opening = false |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -166,7 +178,7 @@ export function useMonitorLive({ getDockId, ui, getLivePlayer }) { |
|
|
|
|
|
|
|
|
// 成功返回 true;失败抛错,由调用方决定是否 onPlayError(避免互相递归)
|
|
|
// 成功返回 true;失败抛错,由调用方决定是否 onPlayError(避免互相递归)
|
|
|
// fromRetry: 播放错误触发的刷新不重置重试计数,避免无限重建
|
|
|
// fromRetry: 播放错误触发的刷新不重置重试计数,避免无限重建
|
|
|
async function refreshPlayURL({ fromRetry = false } = {}) { |
|
|
|
|
|
|
|
|
async function refreshPlayURLOnce({ fromRetry = false } = {}) { |
|
|
if (!live.dockId || !live.session?.id) return false |
|
|
if (!live.dockId || !live.session?.id) return false |
|
|
const sessionId = live.session.id |
|
|
const sessionId = live.session.id |
|
|
const play = await getLivePlayURL(live.dockId, sessionId) |
|
|
const play = await getLivePlayURL(live.dockId, sessionId) |
|
|
@ -179,6 +191,14 @@ export function useMonitorLive({ getDockId, ui, getLivePlayer }) { |
|
|
return true |
|
|
return true |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function refreshPlayURL(options = {}) { |
|
|
|
|
|
if (playURLRequest) return playURLRequest |
|
|
|
|
|
playURLRequest = refreshPlayURLOnce(options).finally(() => { |
|
|
|
|
|
playURLRequest = null |
|
|
|
|
|
}) |
|
|
|
|
|
return playURLRequest |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function schedulePlayRefresh() { |
|
|
function schedulePlayRefresh() { |
|
|
window.clearTimeout(live.playRefreshTimer) |
|
|
window.clearTimeout(live.playRefreshTimer) |
|
|
if (!live.playUrl || live.playUrl.startsWith('fake://') || !live.playUrlExpiresAt) return |
|
|
if (!live.playUrl || live.playUrl.startsWith('fake://') || !live.playUrlExpiresAt) return |
|
|
@ -268,7 +288,7 @@ export function useMonitorLive({ getDockId, ui, getLivePlayer }) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function stopLiveStream() { |
|
|
async function stopLiveStream() { |
|
|
if (!live.session || !live.dockId) return |
|
|
|
|
|
|
|
|
if (!live.session || !live.dockId || live.opening) return |
|
|
const dockId = live.dockId |
|
|
const dockId = live.dockId |
|
|
const session = live.session |
|
|
const session = live.session |
|
|
const ok = await ui.confirm( |
|
|
const ok = await ui.confirm( |
|
|
|