ckplayer-plus 1.0.2 → 1.0.5

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/dist/react.js CHANGED
@@ -207,7 +207,7 @@ var require_ckplayer = __commonJS({
207
207
  cdnFallback: true
208
208
  // getPath 失败时是否回退到 jsDelivr(内网可设 false,并配置 pluginPath)
209
209
  };
210
- var ckplayerPlusDefaultCdn = "https://cdn.jsdelivr.net/npm/ckplayer-plus@1.0.2/dist/";
210
+ var ckplayerPlusDefaultCdn = "https://cdn.jsdelivr.net/npm/ckplayer-plus@1.0.5/dist/";
211
211
  function ckplayerEmbed(videoObj) {
212
212
  var rightMenu = [
213
213
  {
@@ -370,26 +370,34 @@ var require_ckplayer = __commonJS({
370
370
  } else {
371
371
  return embed(obj2);
372
372
  }
373
+ }, isUnreliablePluginBase = function(base2) {
374
+ if (!base2 || valType(base2) != "string") {
375
+ return true;
376
+ }
377
+ return /\/(?:assets|\.vite\/deps|_next\/static|chunks?)\/?$/i.test(base2);
373
378
  }, resolveAssetPath = function(folder, file) {
374
- var base = "";
379
+ var base2 = "";
375
380
  if (vars && vars["pluginPath"]) {
376
- base = vars["pluginPath"];
381
+ base2 = vars["pluginPath"];
377
382
  } else if (typeof window !== "undefined" && window.ckplayerBasePath) {
378
- base = window.ckplayerBasePath;
383
+ base2 = window.ckplayerBasePath;
384
+ }
385
+ if (base2 && isUnreliablePluginBase(base2)) {
386
+ base2 = "";
379
387
  }
380
- if (base) {
381
- if (base.slice(-1) !== "/") {
382
- base += "/";
388
+ if (base2) {
389
+ if (base2.slice(-1) !== "/") {
390
+ base2 += "/";
383
391
  }
384
- return base + folder + "/" + file;
392
+ return base2 + folder + "/" + file;
385
393
  }
386
394
  var fromScript = getPath(folder) + file;
387
- if (fromScript && fromScript.indexOf(folder + "/") > -1 && fromScript.indexOf("undefined") === -1) {
395
+ if (fromScript && fromScript.indexOf(folder + "/") > -1 && fromScript.indexOf("undefined") === -1 && !isUnreliablePluginBase(getPath())) {
388
396
  return fromScript;
389
397
  }
390
398
  var allowCdn = !vars || vars["cdnFallback"] !== false;
391
399
  var cdn = typeof window !== "undefined" && window.ckplayerPlusCdn ? window.ckplayerPlusCdn : ckplayerPlusDefaultCdn;
392
- if (!allowCdn || !cdn || cdn.indexOf("1.0.2") > -1) {
400
+ if (!allowCdn || !cdn || cdn.indexOf("1.0.5") > -1) {
393
401
  return folder + "/" + file;
394
402
  }
395
403
  if (cdn.slice(-1) !== "/") {
@@ -5780,7 +5788,7 @@ var require_ckplayer = __commonJS({
5780
5788
  }
5781
5789
  varsTime += time;
5782
5790
  return language["lookBack"] + date("H:i:s", varsTime);
5783
- }, loadJs = function(file, callback2) {
5791
+ }, loadJs = function(file, callback2, isRetry) {
5784
5792
  var fn2 = function() {
5785
5793
  };
5786
5794
  if (!isUndefined(callback2)) {
@@ -5815,19 +5823,37 @@ var require_ckplayer = __commonJS({
5815
5823
  ;
5816
5824
  }, 10);
5817
5825
  };
5818
- var w3c = function() {
5819
- if (valType(fn2) == "function") {
5820
- fn2();
5826
+ var removeScript = function() {
5827
+ try {
5828
+ if (script.parentNode) {
5829
+ script.parentNode.removeChild(script);
5830
+ }
5831
+ } catch (event2) {
5821
5832
  }
5833
+ };
5834
+ var w3c = function() {
5822
5835
  removeListener(script, "load", w3c);
5823
5836
  removeListener(script, "error", w3cError);
5837
+ doReady();
5824
5838
  };
5825
5839
  var w3cError = function() {
5826
- if (valType(fn2) == "function") {
5827
- fn2();
5828
- }
5829
5840
  removeListener(script, "load", w3c);
5830
5841
  removeListener(script, "error", w3cError);
5842
+ removeScript();
5843
+ if (!isRetry && (!vars || vars["cdnFallback"] !== false)) {
5844
+ var cdn = typeof window !== "undefined" && window.ckplayerPlusCdn ? window.ckplayerPlusCdn : ckplayerPlusDefaultCdn;
5845
+ var m2 = String(file).match(/\/(hls\.js|flv\.js|mpegts\.js|language)\/([^/?#]+)(?:[?#].*)?$/i);
5846
+ if (cdn && cdn.indexOf("1.0.5") === -1 && m2) {
5847
+ if (cdn.slice(-1) !== "/") {
5848
+ cdn += "/";
5849
+ }
5850
+ var retryUrl = cdn + m2[1] + "/" + m2[2];
5851
+ if (retryUrl !== file) {
5852
+ loadJs(retryUrl, callback2, true);
5853
+ return;
5854
+ }
5855
+ }
5856
+ }
5831
5857
  };
5832
5858
  try {
5833
5859
  addListener(script, "load", w3c);
@@ -6053,14 +6079,19 @@ var require_ckplayer = __commonJS({
6053
6079
  }
6054
6080
  function getPath(siz) {
6055
6081
  if (typeof window !== "undefined" && window.ckplayerBasePath) {
6056
- var base = window.ckplayerBasePath;
6057
- if (base.slice(-1) !== "/") {
6058
- base += "/";
6082
+ var base2 = window.ckplayerBasePath;
6083
+ if (/\/(?:assets|\.vite\/deps|_next\/static|chunks?)\/?$/i.test(base2)) {
6084
+ base2 = "";
6059
6085
  }
6060
- if (!isUndefined(siz)) {
6061
- return base + siz + "/";
6086
+ if (base2) {
6087
+ if (base2.slice(-1) !== "/") {
6088
+ base2 += "/";
6089
+ }
6090
+ if (!isUndefined(siz)) {
6091
+ return base2 + siz + "/";
6092
+ }
6093
+ return base2;
6062
6094
  }
6063
- return base;
6064
6095
  }
6065
6096
  var scriptList = document.scripts || [], thisPath = scriptList.length ? scriptList[scriptList.length - 1].src : "";
6066
6097
  for (var i2 = 0; i2 < scriptList.length; i2++) {
@@ -6574,13 +6605,17 @@ var import_ckplayer = __toESM(require_ckplayer());
6574
6605
  var import_meta = {};
6575
6606
  try {
6576
6607
  if (typeof window !== "undefined" && !window.ckplayerBasePath) {
6577
- window.ckplayerBasePath = new URL("./", import_meta.url).href;
6608
+ base = new URL("./", import_meta.url).href;
6609
+ if (/\/dist\/$/i.test(base) || /\/ckplayer-plus(?:@[^/]+)?\/(?:dist\/)?$/i.test(base) || /\/node_modules\/ckplayer-plus\/(?:dist\/)?$/i.test(base)) {
6610
+ window.ckplayerBasePath = base;
6611
+ }
6578
6612
  }
6579
6613
  } catch (e) {
6580
6614
  }
6615
+ var base;
6581
6616
  var index_default = import_ckplayer.default;
6582
6617
 
6583
- // src/react/CkPlayer.js
6618
+ // src/shared.js
6584
6619
  var EVENT_MAP = {
6585
6620
  play: "onPlay",
6586
6621
  pause: "onPause",
@@ -6596,6 +6631,34 @@ var EVENT_MAP = {
6596
6631
  function createUid() {
6597
6632
  return "ckp-" + Math.random().toString(36).slice(2, 10);
6598
6633
  }
6634
+ function buildPlayerConfig(input) {
6635
+ var opts = input.options || {};
6636
+ var config = {
6637
+ container: input.container,
6638
+ video: input.video,
6639
+ poster: input.poster || "",
6640
+ autoplay: !!input.autoplay,
6641
+ live: input.live != null ? input.live : false,
6642
+ plug: input.plug || "",
6643
+ autoPlug: input.autoPlug !== false,
6644
+ volume: input.volume != null ? input.volume : 0.8,
6645
+ cookie: opts.cookie || input.cookie || createUid()
6646
+ };
6647
+ if (input.pluginPath) {
6648
+ config.pluginPath = input.pluginPath;
6649
+ }
6650
+ for (var key in opts) {
6651
+ if (Object.prototype.hasOwnProperty.call(opts, key) && key !== "container") {
6652
+ config[key] = opts[key];
6653
+ }
6654
+ }
6655
+ if (typeof config.loaded === "string") {
6656
+ delete config.loaded;
6657
+ }
6658
+ return config;
6659
+ }
6660
+
6661
+ // src/react/CkPlayer.js
6599
6662
  var CkPlayer = forwardRef(function CkPlayer2(props, ref) {
6600
6663
  var containerRef = useRef(null);
6601
6664
  var playerRef = useRef(null);
@@ -6610,47 +6673,30 @@ var CkPlayer = forwardRef(function CkPlayer2(props, ref) {
6610
6673
  var autoPlug = props.autoPlug;
6611
6674
  var volume = props.volume;
6612
6675
  var pluginPath = props.pluginPath;
6613
- var options = props.options;
6614
6676
  var width = props.width != null ? props.width : "100%";
6615
6677
  var height = props.height != null ? props.height : "400px";
6616
6678
  var className = props.className || "";
6617
6679
  var style = props.style;
6618
6680
  useEffect(function() {
6619
- var cancelled = false;
6620
6681
  var el = containerRef.current;
6621
6682
  if (typeof window === "undefined" || !el) {
6622
6683
  return void 0;
6623
6684
  }
6624
- var opts = propsRef.current && propsRef.current.options || {};
6625
- var config = {
6685
+ var current = propsRef.current || {};
6686
+ var config = buildPlayerConfig({
6626
6687
  container: el,
6627
- video: propsRef.current.video,
6628
- poster: propsRef.current.poster || "",
6629
- autoplay: !!propsRef.current.autoplay,
6630
- live: propsRef.current.live != null ? propsRef.current.live : false,
6631
- plug: propsRef.current.plug || "",
6632
- autoPlug: propsRef.current.autoPlug !== false,
6633
- volume: propsRef.current.volume != null ? propsRef.current.volume : 0.8,
6634
- cookie: opts.cookie || instanceIdRef.current
6635
- };
6636
- if (propsRef.current.pluginPath) {
6637
- config.pluginPath = propsRef.current.pluginPath;
6638
- }
6639
- Object.keys(opts).forEach(function(key) {
6640
- if (key !== "container") {
6641
- config[key] = opts[key];
6642
- }
6688
+ video: current.video,
6689
+ poster: current.poster,
6690
+ autoplay: current.autoplay,
6691
+ live: current.live,
6692
+ plug: current.plug,
6693
+ autoPlug: current.autoPlug,
6694
+ volume: current.volume,
6695
+ pluginPath: current.pluginPath,
6696
+ options: current.options,
6697
+ cookie: instanceIdRef.current
6643
6698
  });
6644
- if (typeof config.loaded === "string") {
6645
- delete config.loaded;
6646
- }
6647
6699
  var player2 = new index_default(config);
6648
- if (cancelled) {
6649
- if (player2 && typeof player2.remove === "function") {
6650
- player2.remove();
6651
- }
6652
- return void 0;
6653
- }
6654
6700
  playerRef.current = player2;
6655
6701
  Object.keys(EVENT_MAP).forEach(function(name) {
6656
6702
  if (typeof player2[name] === "function") {
@@ -6666,7 +6712,6 @@ var CkPlayer = forwardRef(function CkPlayer2(props, ref) {
6666
6712
  propsRef.current.onReady(player2);
6667
6713
  }
6668
6714
  return function cleanup() {
6669
- cancelled = true;
6670
6715
  if (playerRef.current && typeof playerRef.current.remove === "function") {
6671
6716
  try {
6672
6717
  playerRef.current.remove();
@@ -6675,7 +6720,12 @@ var CkPlayer = forwardRef(function CkPlayer2(props, ref) {
6675
6720
  }
6676
6721
  playerRef.current = null;
6677
6722
  };
6678
- }, [video2, poster, autoplay, live, plug, autoPlug, volume, pluginPath]);
6723
+ }, [video2, poster, autoplay, live, plug, autoPlug, pluginPath]);
6724
+ useEffect(function() {
6725
+ if (playerRef.current && typeof volume === "number" && typeof playerRef.current.volume === "function") {
6726
+ playerRef.current.volume(volume);
6727
+ }
6728
+ }, [volume]);
6679
6729
  useImperativeHandle(ref, function() {
6680
6730
  return {
6681
6731
  play: function() {