|
|
@ -39,19 +39,12 @@ |
|
|
伪代码(两页各自落地,字段名可本地化): |
|
|
伪代码(两页各自落地,字段名可本地化): |
|
|
|
|
|
|
|
|
```js |
|
|
```js |
|
|
|
|
|
const PLAY_URL_FRESH_MS = 30_000 |
|
|
|
|
|
|
|
|
let playUrlPromise = null |
|
|
let playUrlPromise = null |
|
|
let playUrlSessionId = '' |
|
|
let playUrlSessionId = '' |
|
|
|
|
|
|
|
|
async function ensurePlayUrl(sessionId, { force = false } = {}) { |
|
|
async function ensurePlayUrl(sessionId, { force = false } = {}) { |
|
|
if ( |
|
|
|
|
|
!force && |
|
|
|
|
|
activeSessionId === sessionId && |
|
|
|
|
|
playUrl && |
|
|
|
|
|
playUrlExpiresAt * 1000 - Date.now() > 30_000 |
|
|
|
|
|
) { |
|
|
|
|
|
return { playUrl, expiresAt: playUrlExpiresAt } // 或直接 true / 沿用现有写入形态 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
if ( |
|
|
!force && |
|
|
!force && |
|
|
activeSessionId === sessionId && |
|
|
activeSessionId === sessionId && |
|
|
@ -68,7 +61,8 @@ async function ensurePlayUrl(sessionId, { force = false } = {}) { |
|
|
playUrlSessionId = sessionId |
|
|
playUrlSessionId = sessionId |
|
|
playUrlPromise = getLivePlayURL(dockId, sessionId) |
|
|
playUrlPromise = getLivePlayURL(dockId, sessionId) |
|
|
.then((play) => { |
|
|
.then((play) => { |
|
|
if (activeSessionId !== sessionId) return play // 调用方仍须再校验后再写入本地状态 |
|
|
|
|
|
|
|
|
// 回写前调用方仍须再校验 session;此处仅作提示性守卫 |
|
|
|
|
|
if (activeSessionId !== sessionId) return play |
|
|
return play |
|
|
return play |
|
|
}) |
|
|
}) |
|
|
.finally(() => { |
|
|
.finally(() => { |
|
|
@ -76,10 +70,10 @@ async function ensurePlayUrl(sessionId, { force = false } = {}) { |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
return playUrlPromise |
|
|
return playUrlPromise |
|
|
常量:`PLAY_URL_FRESH_MS = 30_000`(与现有临期续期 lead 对齐)。**写入** `playUrl` / `expiresAt` / `schedulePlayRefresh` 由调用方在 ensure resolve 且 session 仍匹配后执行(Monitor 可把写入收进 ensure 内部,但必须含二次 session 校验)。 |
|
|
|
|
|
|
|
|
} |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
常量:`PLAY_URL_FRESH_MS = 30_000`(与现有临期续期 lead 对齐)。 |
|
|
|
|
|
|
|
|
常量:`PLAY_URL_FRESH_MS = 30_000`(与现有临期续期 lead 对齐)。**写入** `playUrl` / `expiresAt` / `schedulePlayRefresh` 由调用方在 ensure resolve 且 session 仍匹配后执行(Monitor 可把写入收进 ensure 内部,但必须含二次 session 校验)。 |
|
|
|
|
|
|
|
|
### 4.2 Monitor:`useMonitorLive.js` |
|
|
### 4.2 Monitor:`useMonitorLive.js` |
|
|
|
|
|
|
|
|
|