comein-player-web 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/dist/index.css +7 -4
- package/dist/index.esm.js +84 -7
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,6 @@ import 'comein-player-web/dist/index.css';
|
|
|
17
17
|
const player = await createWebPlayer('#comein-player-web', {
|
|
18
18
|
roadshowId: 'ROADSHOW_ID',
|
|
19
19
|
userInfo: 'URL 编码后的 userInfo',
|
|
20
|
-
page: 'room',
|
|
21
20
|
locale: 'zh-cn',
|
|
22
21
|
isBuild: false,
|
|
23
22
|
hideWebFullscreen: true,
|
|
@@ -27,4 +26,4 @@ const player = await createWebPlayer('#comein-player-web', {
|
|
|
27
26
|
player.destroy();
|
|
28
27
|
```
|
|
29
28
|
|
|
30
|
-
`roadshowId`、`userInfo
|
|
29
|
+
`roadshowId`、`userInfo` 为必填参数。`hideWebFullscreen` 和 `hideFullscreen` 为可选参数,不传时使用 SDK 默认值。`page` 不需要业务侧传入,SDK 会固定按播放器房间入口初始化,底层根据路演状态处理预告、直播、回放展示。`userInfo` 只从初始化参数读取,SDK 不会从页面 URL 或浏览器缓存中自动补取。
|
package/dist/index.css
CHANGED
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
display: flex;
|
|
59
59
|
align-items: center;
|
|
60
60
|
justify-content: center;
|
|
61
|
+
background: #000;
|
|
61
62
|
overflow: hidden;
|
|
62
63
|
color: #fff;
|
|
63
64
|
font-family: "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
|
|
@@ -138,10 +139,11 @@
|
|
|
138
139
|
|
|
139
140
|
.comein-web-sdk-roadshow-preview-controls {
|
|
140
141
|
position: absolute;
|
|
141
|
-
right:
|
|
142
|
+
right: 16px;
|
|
142
143
|
bottom: 16px;
|
|
143
144
|
z-index: 2;
|
|
144
145
|
display: flex;
|
|
146
|
+
max-width: calc(100% - 32px);
|
|
145
147
|
gap: 20px;
|
|
146
148
|
align-items: center;
|
|
147
149
|
}
|
|
@@ -169,9 +171,10 @@
|
|
|
169
171
|
|
|
170
172
|
.comein-web-sdk-roadshow-preview-control::after {
|
|
171
173
|
position: absolute;
|
|
172
|
-
right:
|
|
174
|
+
right: 0;
|
|
173
175
|
bottom: calc(100% + 8px);
|
|
174
|
-
|
|
176
|
+
box-sizing: border-box;
|
|
177
|
+
max-width: min(240px, calc(100vw - 48px));
|
|
175
178
|
padding: 5px 8px;
|
|
176
179
|
overflow: hidden;
|
|
177
180
|
border-radius: 4px;
|
|
@@ -181,8 +184,8 @@
|
|
|
181
184
|
font: 12px/18px "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
|
|
182
185
|
opacity: 0;
|
|
183
186
|
pointer-events: none;
|
|
187
|
+
text-align: center;
|
|
184
188
|
text-overflow: ellipsis;
|
|
185
|
-
transform: translateX(50%);
|
|
186
189
|
transition: opacity 0.15s ease;
|
|
187
190
|
white-space: nowrap;
|
|
188
191
|
}
|
package/dist/index.esm.js
CHANGED
|
@@ -416,6 +416,7 @@ async function loadPlayerClass() {
|
|
|
416
416
|
}
|
|
417
417
|
|
|
418
418
|
const ROADSHOW_PREVIEW_END_HIDE_DELAY = 300;
|
|
419
|
+
const ROADSHOW_LIVE_WATCH_INTERVAL = 300;
|
|
419
420
|
|
|
420
421
|
function assertContainer(el) {
|
|
421
422
|
const isSelector = typeof el === 'string' && el.trim();
|
|
@@ -676,8 +677,14 @@ function shouldShowRoadshowPreviewOverlay(payload, player, state = {}) {
|
|
|
676
677
|
);
|
|
677
678
|
}
|
|
678
679
|
|
|
679
|
-
function shouldShowInteractionPanels(hasJoinSuccess, player) {
|
|
680
|
-
return
|
|
680
|
+
function shouldShowInteractionPanels(hasJoinSuccess, player, state = {}) {
|
|
681
|
+
return (
|
|
682
|
+
hasJoinSuccess === true &&
|
|
683
|
+
player?.isLive === true &&
|
|
684
|
+
state.isAccessWaitingRoom !== true &&
|
|
685
|
+
!isRoadshowEndStatus(player?.status) &&
|
|
686
|
+
state.hasLiveEnded !== true
|
|
687
|
+
);
|
|
681
688
|
}
|
|
682
689
|
|
|
683
690
|
const ROADSHOW_PREVIEW_LABELS = {
|
|
@@ -1150,6 +1157,38 @@ async function createWebPlayer(el, options = {}, dependencies = {}) {
|
|
|
1150
1157
|
let liveWatchTimer = null;
|
|
1151
1158
|
let interactionVisible = false;
|
|
1152
1159
|
let previewCountdownEnded = false;
|
|
1160
|
+
let lastLiveStatus;
|
|
1161
|
+
let hasLiveEnded = false;
|
|
1162
|
+
let currentRoadshowData;
|
|
1163
|
+
let lastLiveStateLogKey = '';
|
|
1164
|
+
const debugLog = (label, data) => {
|
|
1165
|
+
// 调试直播状态时可临时打开:
|
|
1166
|
+
// globalThis.console?.log?.(`[COMEIN_WEB_SDK_LIVE_STATE] ${label}`, data);
|
|
1167
|
+
};
|
|
1168
|
+
const resolveIsAccessWaitingRoom = () =>
|
|
1169
|
+
player.isAccessWaitingRoom === true || currentRoadshowData?.isAccessWaitingRoom === true;
|
|
1170
|
+
const logLiveState = (reason, action, extra = {}) => {
|
|
1171
|
+
const snapshot = {
|
|
1172
|
+
reason,
|
|
1173
|
+
action,
|
|
1174
|
+
hasJoinSuccess,
|
|
1175
|
+
playerStatus: player.status,
|
|
1176
|
+
roadshowDataStatus: currentRoadshowData?.status,
|
|
1177
|
+
isLive: player.isLive,
|
|
1178
|
+
liveStatus: player.liveStatus,
|
|
1179
|
+
playerIsAccessWaitingRoom: player.isAccessWaitingRoom,
|
|
1180
|
+
roadshowDataIsAccessWaitingRoom: currentRoadshowData?.isAccessWaitingRoom,
|
|
1181
|
+
isAccessWaitingRoom: resolveIsAccessWaitingRoom(),
|
|
1182
|
+
hasLiveEnded,
|
|
1183
|
+
interactionVisible,
|
|
1184
|
+
previewCountdownEnded,
|
|
1185
|
+
...extra,
|
|
1186
|
+
};
|
|
1187
|
+
const logKey = JSON.stringify(snapshot);
|
|
1188
|
+
if (logKey === lastLiveStateLogKey) return;
|
|
1189
|
+
lastLiveStateLogKey = logKey;
|
|
1190
|
+
debugLog('判断互动/预告状态', snapshot);
|
|
1191
|
+
};
|
|
1153
1192
|
const destroyPreviewOverlay = () => {
|
|
1154
1193
|
previewOverlay?.destroy?.();
|
|
1155
1194
|
previewOverlay = undefined;
|
|
@@ -1173,34 +1212,57 @@ async function createWebPlayer(el, options = {}, dependencies = {}) {
|
|
|
1173
1212
|
setInteractionVisible(false);
|
|
1174
1213
|
layout.destroyPanels?.();
|
|
1175
1214
|
};
|
|
1176
|
-
const updateLiveState = () => {
|
|
1215
|
+
const updateLiveState = (reason = 'watch') => {
|
|
1177
1216
|
const currentIsLive = player.isLive;
|
|
1217
|
+
const currentLiveStatus = player.liveStatus;
|
|
1178
1218
|
const isEndStatus = isRoadshowEndStatus(player.status);
|
|
1219
|
+
const isAccessWaitingRoom = resolveIsAccessWaitingRoom();
|
|
1220
|
+
|
|
1221
|
+
// 底层直播结束时可能保持 isLive=true,只通过 liveStatus true -> false 表示真实直播结束。
|
|
1222
|
+
if (lastLiveStatus === true && currentLiveStatus === false) {
|
|
1223
|
+
hasLiveEnded = true;
|
|
1224
|
+
}
|
|
1225
|
+
if (currentLiveStatus === true) {
|
|
1226
|
+
hasLiveEnded = false;
|
|
1227
|
+
}
|
|
1228
|
+
lastLiveStatus = currentLiveStatus;
|
|
1179
1229
|
|
|
1180
1230
|
if (isEndStatus) {
|
|
1231
|
+
logLiveState(reason, 'hide-interaction:end-status', { isEndStatus });
|
|
1181
1232
|
destroyPreviewOverlay();
|
|
1182
1233
|
hideAndDestroyInteraction();
|
|
1183
1234
|
stopLiveWatch();
|
|
1184
1235
|
return;
|
|
1185
1236
|
}
|
|
1186
1237
|
|
|
1187
|
-
if (
|
|
1238
|
+
if (currentIsLive === true) {
|
|
1188
1239
|
destroyPreviewOverlay();
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
if (shouldShowInteractionPanels(hasJoinSuccess, player, { hasLiveEnded, isAccessWaitingRoom })) {
|
|
1189
1243
|
const mounted = layout.mountPanels?.(player);
|
|
1190
1244
|
setInteractionVisible(mounted === true);
|
|
1191
|
-
|
|
1245
|
+
logLiveState(reason, mounted === true ? 'show-interaction' : 'hide-interaction:mount-failed', {
|
|
1246
|
+
isEndStatus,
|
|
1247
|
+
mounted,
|
|
1248
|
+
});
|
|
1192
1249
|
return;
|
|
1193
1250
|
}
|
|
1194
1251
|
|
|
1252
|
+
logLiveState(reason, 'hide-interaction:condition-false', { isEndStatus });
|
|
1195
1253
|
hideAndDestroyInteraction();
|
|
1196
1254
|
};
|
|
1197
1255
|
const startLiveWatch = () => {
|
|
1198
1256
|
stopLiveWatch();
|
|
1199
|
-
liveWatchTimer = setIntervalRef(updateLiveState,
|
|
1257
|
+
liveWatchTimer = setIntervalRef(updateLiveState, ROADSHOW_LIVE_WATCH_INTERVAL);
|
|
1200
1258
|
};
|
|
1201
1259
|
const resetSessionState = () => {
|
|
1202
1260
|
hasJoinSuccess = false;
|
|
1203
1261
|
previewCountdownEnded = false;
|
|
1262
|
+
lastLiveStatus = undefined;
|
|
1263
|
+
hasLiveEnded = false;
|
|
1264
|
+
currentRoadshowData = undefined;
|
|
1265
|
+
lastLiveStateLogKey = '';
|
|
1204
1266
|
destroyPreviewOverlay();
|
|
1205
1267
|
hideAndDestroyInteraction();
|
|
1206
1268
|
stopLiveWatch();
|
|
@@ -1212,6 +1274,15 @@ async function createWebPlayer(el, options = {}, dependencies = {}) {
|
|
|
1212
1274
|
const joinSuccessHandler = (payload, roadshowAuth) => {
|
|
1213
1275
|
hasJoinSuccess = true;
|
|
1214
1276
|
const previewPayload = getRoadshowPreviewPayload(payload, player, roadshowAuth);
|
|
1277
|
+
currentRoadshowData = previewPayload.roadshowData;
|
|
1278
|
+
debugLog('onJoinSuccess roadshowData', {
|
|
1279
|
+
roadshowData: currentRoadshowData,
|
|
1280
|
+
roadshowAuth: previewPayload.roadshowAuth,
|
|
1281
|
+
playerStatus: player.status,
|
|
1282
|
+
isLive: player.isLive,
|
|
1283
|
+
liveStatus: player.liveStatus,
|
|
1284
|
+
playerIsAccessWaitingRoom: player.isAccessWaitingRoom,
|
|
1285
|
+
});
|
|
1215
1286
|
if (shouldShowRoadshowPreviewOverlay(previewPayload, player, { previewCountdownEnded })) {
|
|
1216
1287
|
destroyPreviewOverlay();
|
|
1217
1288
|
previewOverlay = createRoadshowPreviewOverlay(layout.getOverlayHost?.() || layout.overlayHost, player, previewPayload, {
|
|
@@ -1232,7 +1303,7 @@ async function createWebPlayer(el, options = {}, dependencies = {}) {
|
|
|
1232
1303
|
} else {
|
|
1233
1304
|
destroyPreviewOverlay();
|
|
1234
1305
|
}
|
|
1235
|
-
updateLiveState();
|
|
1306
|
+
updateLiveState('onJoinSuccess');
|
|
1236
1307
|
startLiveWatch();
|
|
1237
1308
|
};
|
|
1238
1309
|
player.on('onLogout', logoutHandler);
|
|
@@ -1240,12 +1311,18 @@ async function createWebPlayer(el, options = {}, dependencies = {}) {
|
|
|
1240
1311
|
player.on('onJoinError', resetSessionState);
|
|
1241
1312
|
player.on('onError', resetSessionState);
|
|
1242
1313
|
player.on('onExitRoom', resetSessionState);
|
|
1314
|
+
const playerStateHandler = () => {
|
|
1315
|
+
updateLiveState('player-play-event');
|
|
1316
|
+
};
|
|
1317
|
+
const playerEventHandlers = { play: playerStateHandler };
|
|
1318
|
+
player.addListener?.(playerEventHandlers);
|
|
1243
1319
|
cleanupCallbacks.push(() => {
|
|
1244
1320
|
player.off?.('onLogout', logoutHandler);
|
|
1245
1321
|
player.off?.('onJoinSuccess', joinSuccessHandler);
|
|
1246
1322
|
player.off?.('onJoinError', resetSessionState);
|
|
1247
1323
|
player.off?.('onError', resetSessionState);
|
|
1248
1324
|
player.off?.('onExitRoom', resetSessionState);
|
|
1325
|
+
player.removeListener?.(playerEventHandlers);
|
|
1249
1326
|
resetSessionState();
|
|
1250
1327
|
});
|
|
1251
1328
|
}
|