@byteplus/veplayer 2.11.2 → 2.12.0-rc.0

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.
@@ -659,6 +659,22 @@
659
659
  .xgplayer-pc.xgplayer-is-error .xgplayer-start {
660
660
  display: none;
661
661
  }
662
+ .xgplayer-mobile.xgplayer-mobile-mini-window video,
663
+ .xgplayer-mobile.xgplayer-mobile-mini-window xg-video {
664
+ position: fixed;
665
+ top: 0;
666
+ left: 0;
667
+ z-index: 9999;
668
+ /* stylelint-disable-next-line declaration-no-important */
669
+ width: 100vw !important;
670
+ /* stylelint-disable-next-line declaration-no-important */
671
+ height: 100vh !important;
672
+ }
673
+ .xgplayer-mobile.xgplayer-mobile-mini-window .xgplayer-start {
674
+ position: fixed;
675
+ /* stylelint-disable-next-line declaration-no-important */
676
+ z-index: 10000 !important;
677
+ }
662
678
  .xgplayer-mobile .xgplayer-progress .xgplayer-progress-played {
663
679
  background: #3469ff;
664
680
  }
@@ -701,15 +717,15 @@
701
717
  display: none;
702
718
  }
703
719
  .veplayer-logo {
704
- display: none;
705
720
  position: absolute;
706
- visibility: visible;
721
+ top: 20px;
722
+ right: 20px;
723
+ z-index: 10;
724
+ display: none;
707
725
  width: 70px;
708
726
  height: 20px;
709
- right: 20px;
710
- top: 20px;
727
+ visibility: visible;
711
728
  opacity: 1;
712
- z-index: 10;
713
729
  }
714
730
  .veplayer-logo svg {
715
731
  width: 100%;
@@ -14149,6 +14149,373 @@ class CustomMedia {
14149
14149
  replaceAttributes(this._el, this._videoAttributes);
14150
14150
  }
14151
14151
  }
14152
+ var Web2NativeMessageEvent = /* @__PURE__ */ ((Web2NativeMessageEvent2) => {
14153
+ Web2NativeMessageEvent2[Web2NativeMessageEvent2["INIT_FINISH"] = 10001] = "INIT_FINISH";
14154
+ Web2NativeMessageEvent2[Web2NativeMessageEvent2["CREATE_PLAYER"] = 11e3] = "CREATE_PLAYER";
14155
+ Web2NativeMessageEvent2[Web2NativeMessageEvent2["DESTROY_PLAYER"] = 11001] = "DESTROY_PLAYER";
14156
+ Web2NativeMessageEvent2[Web2NativeMessageEvent2["OPEN_FULLSCREEN"] = 11002] = "OPEN_FULLSCREEN";
14157
+ Web2NativeMessageEvent2[Web2NativeMessageEvent2["EXIT_FULLSCREEN"] = 11003] = "EXIT_FULLSCREEN";
14158
+ Web2NativeMessageEvent2[Web2NativeMessageEvent2["LIVE_ROOM_STATE_CHANGE"] = 11004] = "LIVE_ROOM_STATE_CHANGE";
14159
+ Web2NativeMessageEvent2[Web2NativeMessageEvent2["PLAYER_STATE_CHANGE"] = 11005] = "PLAYER_STATE_CHANGE";
14160
+ Web2NativeMessageEvent2[Web2NativeMessageEvent2["MEDIA_LOAD_FINISH"] = 11006] = "MEDIA_LOAD_FINISH";
14161
+ Web2NativeMessageEvent2[Web2NativeMessageEvent2["OPEN_MINI_WINDOW"] = 11007] = "OPEN_MINI_WINDOW";
14162
+ Web2NativeMessageEvent2[Web2NativeMessageEvent2["CLOSE_MINI_WINDOW"] = 11008] = "CLOSE_MINI_WINDOW";
14163
+ Web2NativeMessageEvent2[Web2NativeMessageEvent2["OPEN_WAKE_LOCK"] = 11009] = "OPEN_WAKE_LOCK";
14164
+ Web2NativeMessageEvent2[Web2NativeMessageEvent2["EXIT_WAKE_LOCK"] = 110010] = "EXIT_WAKE_LOCK";
14165
+ Web2NativeMessageEvent2[Web2NativeMessageEvent2["PUSH_WEB_DATA_INFO"] = 110011] = "PUSH_WEB_DATA_INFO";
14166
+ return Web2NativeMessageEvent2;
14167
+ })(Web2NativeMessageEvent || {});
14168
+ var Native2WebMessageEvent = /* @__PURE__ */ ((Native2WebMessageEvent2) => {
14169
+ Native2WebMessageEvent2[Native2WebMessageEvent2["ENTER_MINI_WINDOW"] = 21e3] = "ENTER_MINI_WINDOW";
14170
+ Native2WebMessageEvent2[Native2WebMessageEvent2["EXIT_MINI_WINDOW"] = 21001] = "EXIT_MINI_WINDOW";
14171
+ Native2WebMessageEvent2[Native2WebMessageEvent2["PAUSE"] = 21002] = "PAUSE";
14172
+ Native2WebMessageEvent2[Native2WebMessageEvent2["START_PLAY"] = 21003] = "START_PLAY";
14173
+ Native2WebMessageEvent2[Native2WebMessageEvent2["PLAY"] = 21004] = "PLAY";
14174
+ Native2WebMessageEvent2[Native2WebMessageEvent2["WEBVIEW_CONFIG"] = 21005] = "WEBVIEW_CONFIG";
14175
+ Native2WebMessageEvent2[Native2WebMessageEvent2["GET_WEB_DATA_INFO"] = 21006] = "GET_WEB_DATA_INFO";
14176
+ Native2WebMessageEvent2[Native2WebMessageEvent2["ENTER_FULLSCREEN"] = 21007] = "ENTER_FULLSCREEN";
14177
+ Native2WebMessageEvent2[Native2WebMessageEvent2["EXIT_FULLSCREEN"] = 21008] = "EXIT_FULLSCREEN";
14178
+ return Native2WebMessageEvent2;
14179
+ })(Native2WebMessageEvent || {});
14180
+ class ByteLiveJsBridge {
14181
+ constructor(data) {
14182
+ __publicField(this, "_emitter", new EventEmitter());
14183
+ __publicField(this, "isInIOS", false);
14184
+ __publicField(this, "jsBridgeName", "ByteLiveJsBridge");
14185
+ __publicField(this, "jsBridge", null);
14186
+ __publicField(this, "data", {
14187
+ room: {},
14188
+ player: {}
14189
+ });
14190
+ // eslint-disable-next-line @typescript-eslint/member-ordering
14191
+ __publicField(this, "nativeConfig", {});
14192
+ if (data == null ? void 0 : data.name) {
14193
+ this.jsBridgeName = data.name;
14194
+ }
14195
+ this.init();
14196
+ }
14197
+ init() {
14198
+ this.initVariables();
14199
+ if (!this.jsBridge) {
14200
+ this.mountGlobal();
14201
+ }
14202
+ this.callToNative(Web2NativeMessageEvent.INIT_FINISH, {});
14203
+ }
14204
+ getJsBridge() {
14205
+ const jsBridge = Reflect.get(window, this.jsBridgeName);
14206
+ if (jsBridge) {
14207
+ this.jsBridge = jsBridge;
14208
+ }
14209
+ return this.jsBridge;
14210
+ }
14211
+ setJsBridge(jsBridge) {
14212
+ Reflect.set(window, this.jsBridgeName, jsBridge);
14213
+ Reflect.set(window, "VeCloudJsBridge", jsBridge);
14214
+ console.log("设置到 window 上");
14215
+ this.jsBridge = jsBridge;
14216
+ }
14217
+ initVariables() {
14218
+ this.isInIOS = Boolean(sniffer.os.isIos);
14219
+ }
14220
+ mountGlobal() {
14221
+ const JsBridge = this.getJsBridge();
14222
+ console.log("从 window 上获取到的 jsBridge", JsBridge);
14223
+ if (JsBridge) {
14224
+ JsBridge.nativeCallBack = (data) => {
14225
+ console.log("收到native发来消息", data);
14226
+ this.handelEventCallBack(data);
14227
+ };
14228
+ this.jsBridge = JsBridge;
14229
+ } else {
14230
+ const JsBridge2 = {
14231
+ nativeCallBack: (data) => {
14232
+ console.log("收到native发来消息", data);
14233
+ this.handelEventCallBack(data);
14234
+ }
14235
+ // invokeNative: (data: IMessage) => {
14236
+ // console.log('发送给native', data);
14237
+ // },
14238
+ };
14239
+ this.setJsBridge(JsBridge2);
14240
+ }
14241
+ this.bindWebDataInfo();
14242
+ this.bindGetNativeConfig();
14243
+ }
14244
+ on(action, func) {
14245
+ this._emitter.on(action, func);
14246
+ }
14247
+ handelEventCallBack(data) {
14248
+ const { eventKey, info } = data ?? {};
14249
+ if (!eventKey || !Native2WebMessageEvent[eventKey]) {
14250
+ console.log("Native2Web未匹配到对应事件", eventKey);
14251
+ return;
14252
+ }
14253
+ this._emitter.emit(Native2WebMessageEvent[eventKey], info);
14254
+ }
14255
+ invokeNative(data) {
14256
+ var _a, _b, _c;
14257
+ console.log("发送给native", data);
14258
+ if (this.isInIOS) {
14259
+ (_c = (_b = (_a = window == null ? void 0 : window.webkit) == null ? void 0 : _a.messageHandlers) == null ? void 0 : _b.invokeNative) == null ? void 0 : _c.postMessage(data);
14260
+ }
14261
+ const JsBridge = this.jsBridge || Reflect.get(window, this.jsBridgeName);
14262
+ console.log(
14263
+ "JsBridge",
14264
+ this.jsBridge,
14265
+ Reflect.get(window, this.jsBridgeName)
14266
+ );
14267
+ if (JsBridge.invokeNative) {
14268
+ JsBridge.invokeNative(JSON.stringify(data));
14269
+ } else {
14270
+ console.log("未找到对应invokeNative方法");
14271
+ }
14272
+ }
14273
+ bindWebDataInfo() {
14274
+ this.on("GET_WEB_DATA_INFO", () => {
14275
+ this.callToNative(Web2NativeMessageEvent.PUSH_WEB_DATA_INFO, {
14276
+ ...this.data
14277
+ });
14278
+ });
14279
+ }
14280
+ bindGetNativeConfig() {
14281
+ this.on("WEBVIEW_CONFIG", (data) => {
14282
+ this.nativeConfig = {
14283
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
14284
+ // @ts-ignore
14285
+ ...this.nativeConfig,
14286
+ ...data
14287
+ };
14288
+ });
14289
+ }
14290
+ callToNative(eventKey, info) {
14291
+ if (!eventKey || !Web2NativeMessageEvent[eventKey]) {
14292
+ console.log("Web2Native未匹配到对应事件", eventKey);
14293
+ return;
14294
+ }
14295
+ this.invokeNative({ eventKey, info });
14296
+ }
14297
+ callToNativeCreatePlayer(data) {
14298
+ this.data.room = {
14299
+ ...this.data.room,
14300
+ isPortrait: data.isPortrait
14301
+ };
14302
+ this.callToNative(Web2NativeMessageEvent.CREATE_PLAYER, data);
14303
+ }
14304
+ callToNativeDestroyPlayer() {
14305
+ this.callToNative(Web2NativeMessageEvent.DESTROY_PLAYER, {});
14306
+ }
14307
+ callToNativeOpenFullScreen() {
14308
+ this.data.player = {
14309
+ ...this.data.player,
14310
+ fullscreen: true
14311
+ };
14312
+ this.callToNative(Web2NativeMessageEvent.OPEN_FULLSCREEN, {});
14313
+ }
14314
+ callToNativeExitFullScreen() {
14315
+ this.data.player = {
14316
+ ...this.data.player,
14317
+ fullscreen: false
14318
+ };
14319
+ this.callToNative(Web2NativeMessageEvent.EXIT_FULLSCREEN, {});
14320
+ }
14321
+ callToNativeLiveRoomStateChange(data) {
14322
+ this.data.room = {
14323
+ ...this.data.room,
14324
+ status: data.status
14325
+ };
14326
+ this.callToNative(Web2NativeMessageEvent.LIVE_ROOM_STATE_CHANGE, data);
14327
+ }
14328
+ callToNativePlayerStateChange(data) {
14329
+ this.data.player = {
14330
+ ...this.data.player,
14331
+ created: data.created,
14332
+ paused: data.paused
14333
+ };
14334
+ this.callToNative(Web2NativeMessageEvent.PLAYER_STATE_CHANGE, data);
14335
+ }
14336
+ callToNativeMediaLoadFinish(data) {
14337
+ this.data.player = {
14338
+ ...this.data.player,
14339
+ videoWidth: data.videoWidth,
14340
+ videoHeight: data.videoHeight
14341
+ };
14342
+ this.callToNative(Web2NativeMessageEvent.MEDIA_LOAD_FINISH, data);
14343
+ }
14344
+ callToNativeOpenMiniWindow() {
14345
+ this.data.player = {
14346
+ ...this.data.player,
14347
+ mini: true
14348
+ };
14349
+ this.callToNative(Web2NativeMessageEvent.OPEN_MINI_WINDOW, {});
14350
+ }
14351
+ callToNativeCloseMiniWindow() {
14352
+ this.data.player = {
14353
+ ...this.data.player,
14354
+ mini: false
14355
+ };
14356
+ console.log("通知Native关闭小窗", /* @__PURE__ */ new Date());
14357
+ this.callToNative(Web2NativeMessageEvent.CLOSE_MINI_WINDOW, {});
14358
+ }
14359
+ callToNativeOpenWakeLock() {
14360
+ this.callToNative(Web2NativeMessageEvent.OPEN_WAKE_LOCK, {});
14361
+ }
14362
+ callToNativeExitWakeLock() {
14363
+ this.callToNative(Web2NativeMessageEvent.EXIT_WAKE_LOCK, {});
14364
+ }
14365
+ }
14366
+ let InnerJsBridge;
14367
+ const getJsbInstance = () => {
14368
+ if (InnerJsBridge)
14369
+ return InnerJsBridge;
14370
+ InnerJsBridge = new ByteLiveJsBridge();
14371
+ return InnerJsBridge;
14372
+ };
14373
+ var InnerJsBridge$1 = getJsbInstance();
14374
+ const bindPlayerEventsCallJSB = (player) => {
14375
+ const isPortrait = true;
14376
+ const isLive = true;
14377
+ if (!InnerJsBridge$1) {
14378
+ return;
14379
+ }
14380
+ if (!sniffer.os.isPc) {
14381
+ bindMiniWindowEvents(player);
14382
+ }
14383
+ InnerJsBridge$1.callToNativeCreatePlayer({
14384
+ isLive,
14385
+ isPortrait
14386
+ });
14387
+ InnerJsBridge$1.callToNativePlayerStateChange({
14388
+ created: true,
14389
+ paused: false
14390
+ });
14391
+ player.on(Events.PLAY, () => {
14392
+ InnerJsBridge$1 == null ? void 0 : InnerJsBridge$1.callToNativePlayerStateChange({
14393
+ created: true,
14394
+ paused: false
14395
+ });
14396
+ });
14397
+ player.on(Events.PAUSE, () => {
14398
+ InnerJsBridge$1 == null ? void 0 : InnerJsBridge$1.callToNativePlayerStateChange({
14399
+ created: true,
14400
+ paused: true
14401
+ });
14402
+ });
14403
+ player.on(Events.ERROR, () => {
14404
+ existMiniWindow();
14405
+ });
14406
+ player.on(Events.LOADED_DATA, () => {
14407
+ getVideoSizeWithRetry(player, isPortrait).then(
14408
+ ({ videoWidth, videoHeight }) => {
14409
+ InnerJsBridge$1 == null ? void 0 : InnerJsBridge$1.callToNativeMediaLoadFinish({
14410
+ isPortrait: videoHeight > videoWidth,
14411
+ videoWidth,
14412
+ videoHeight
14413
+ });
14414
+ }
14415
+ );
14416
+ });
14417
+ };
14418
+ const destroyPlayerEventsCallJSB = () => {
14419
+ if (InnerJsBridge$1) {
14420
+ InnerJsBridge$1.callToNativeDestroyPlayer();
14421
+ InnerJsBridge$1.callToNativePlayerStateChange({
14422
+ created: false,
14423
+ paused: true
14424
+ });
14425
+ }
14426
+ existMiniWindow();
14427
+ };
14428
+ const bindMiniWindowEvents = (player) => {
14429
+ if (!InnerJsBridge$1) {
14430
+ return;
14431
+ }
14432
+ const handleMiniWindowChange = (state) => {
14433
+ if (!player || !player.root) {
14434
+ return;
14435
+ }
14436
+ if (state) {
14437
+ player.addClass("xgplayer-mobile-mini-window");
14438
+ } else {
14439
+ player.removeClass("xgplayer-mobile-mini-window");
14440
+ }
14441
+ };
14442
+ InnerJsBridge$1.on("WEBVIEW_CONFIG", (data) => {
14443
+ console.log("WEBVIEW_CONFIG", data);
14444
+ if (data == null ? void 0 : data.keepPlayWhenPageHide) {
14445
+ player.unRegisterPlugin("PageChangePlugin");
14446
+ }
14447
+ });
14448
+ InnerJsBridge$1.on("ENTER_MINI_WINDOW", () => {
14449
+ handleMiniWindowChange(true);
14450
+ });
14451
+ InnerJsBridge$1.on("EXIT_MINI_WINDOW", () => {
14452
+ console.log("切回小窗播放器处于暂停: ", player.paused, /* @__PURE__ */ new Date());
14453
+ if (player.paused) {
14454
+ player.play();
14455
+ }
14456
+ handleMiniWindowChange(false);
14457
+ });
14458
+ InnerJsBridge$1.on("PAUSE", () => {
14459
+ if (!player) {
14460
+ return;
14461
+ }
14462
+ player.pause();
14463
+ });
14464
+ InnerJsBridge$1.on("START_PLAY", () => {
14465
+ handleMiniWindowChange(false);
14466
+ if (!player) {
14467
+ return;
14468
+ }
14469
+ player.play();
14470
+ });
14471
+ InnerJsBridge$1.on("PLAY", () => {
14472
+ if (!player) {
14473
+ return;
14474
+ }
14475
+ player.play();
14476
+ });
14477
+ InnerJsBridge$1.on("ENTER_FULLSCREEN", () => {
14478
+ var _a;
14479
+ if (!(player == null ? void 0 : player.fullscreen)) {
14480
+ (_a = player.getPlugin("fullscreen")) == null ? void 0 : _a.toggleFullScreen();
14481
+ }
14482
+ });
14483
+ InnerJsBridge$1.on("EXIT_FULLSCREEN", () => {
14484
+ var _a;
14485
+ if (player == null ? void 0 : player.fullscreen) {
14486
+ (_a = player.getPlugin("fullscreen")) == null ? void 0 : _a.toggleFullScreen();
14487
+ }
14488
+ });
14489
+ };
14490
+ const existMiniWindow = () => {
14491
+ InnerJsBridge$1 && (InnerJsBridge$1 == null ? void 0 : InnerJsBridge$1.callToNativeCloseMiniWindow());
14492
+ };
14493
+ const getVideoSizeWithRetry = (player, isPortrait) => {
14494
+ const retryGetVideoSize = (retryCount = 0) => {
14495
+ return new Promise((resolve) => {
14496
+ let { videoWidth, videoHeight } = player.video;
14497
+ if (videoWidth > 0 && videoHeight > 0) {
14498
+ resolve({ videoWidth, videoHeight });
14499
+ return;
14500
+ }
14501
+ if (retryCount < 15) {
14502
+ setTimeout(() => {
14503
+ retryGetVideoSize(retryCount + 1).then(resolve);
14504
+ }, 500);
14505
+ return;
14506
+ }
14507
+ if (isPortrait) {
14508
+ videoWidth = 1080;
14509
+ videoHeight = 1920;
14510
+ } else {
14511
+ videoWidth = 1920;
14512
+ videoHeight = 1080;
14513
+ }
14514
+ resolve({ videoWidth, videoHeight });
14515
+ });
14516
+ };
14517
+ return retryGetVideoSize();
14518
+ };
14152
14519
  const { POSITIONS: XGPosition } = Plugin;
14153
14520
  const POSITIONS = {
14154
14521
  ...XGPosition,
@@ -14263,6 +14630,7 @@ class VePlayerBase {
14263
14630
  this.emit(Events.PLAYER_CREATE_FINISH, this._player);
14264
14631
  this._errorCallback = (err) => this._handleFallback(err);
14265
14632
  this._player.on(ERROR, this._errorCallback);
14633
+ bindPlayerEventsCallJSB(this._player);
14266
14634
  }
14267
14635
  /** {zh}
14268
14636
  * @brief 获取视频的就绪状态,其状态枚举值、枚举名称和说明如下:
@@ -14428,7 +14796,7 @@ class VePlayerBase {
14428
14796
  * @brief Retrieve the player SDK version number.
14429
14797
  */
14430
14798
  get playerVersion() {
14431
- return "2.11.2";
14799
+ return "2.12.0-rc.0";
14432
14800
  }
14433
14801
  /** {zh}
14434
14802
  * @brief 获取当前播放视频的清晰度唯一标识(definition)。
@@ -14933,6 +15301,7 @@ class VePlayerBase {
14933
15301
  */
14934
15302
  destroy() {
14935
15303
  var _a;
15304
+ destroyPlayerEventsCallJSB();
14936
15305
  this._player.off(ERROR, this._errorCallback);
14937
15306
  this._player.destroy();
14938
15307
  (_a = this._customMedia) == null ? void 0 : _a.destroy();