ezuikit-js 0.4.1-beta.0 → 0.4.3

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.
@@ -33,9 +33,9 @@
33
33
  var playr = new EZUIKit.EZUIKitPlayer({
34
34
  id: 'video-container', // 视频容器ID
35
35
  accessToken: 'at.740rax9017850gps4kxruugu30cr9gqy-6ezmv0q5bp-0k6u4f4-pgu1gtspi',
36
- url: 'ezopen://open.ys7.com/C78957921/1.live',
37
- template: 'simple', // simple - 极简版;standard-标准版;security - 安防版(预览回放);voice-语音版; theme-可配置主题;
38
- //themeId: "89d071ff92f941118d7920f9ca347190",
36
+ url: 'ezopen://open.ys7.com/C78957921/1.rec',
37
+ //template: 'simple', // simple - 极简版;standard-标准版;security - 安防版(预览回放);voice-语音版; theme-可配置主题;
38
+ themeId: "mobileRec",
39
39
  autoplay: true,
40
40
  // audio: 1, // 是否默认开启声音 0 - 关闭 1 - 开启
41
41
  plugin: ['talk'], // 加载插件,talk-对讲
@@ -45,8 +45,8 @@
45
45
  handleTalkSuccess: () => console.log("对讲成功回调"),
46
46
  handleTalkError: (data) = function(){console.log("对讲失败",data)},
47
47
  decoderVersion: "v3.4",
48
- width: 600,
49
- height:400,
48
+ width: 375,
49
+ height:210,
50
50
  });
51
51
  function fullScreen(){
52
52
  var playPromise = playr.fullScreen();
package/ezuikit.js CHANGED
@@ -317,8 +317,9 @@ class FLV {
317
317
  function insertAfter(newElement, targetElement) { var parent = targetElement.parentNode; if (parent.lastChild == targetElement) { parent.appendChild(newElement); } else { parent.insertBefore(newElement, targetElement.nextSibling); } }
318
318
 
319
319
  class Status {
320
- constructor(id) {
320
+ constructor(jSPlugin,id) {
321
321
  this.id = id;
322
+ this.jSPlugin = jSPlugin;
322
323
  }
323
324
  toString() {
324
325
  return `${this.coreX}-${this.coreY}`;
@@ -340,6 +341,10 @@ class Status {
340
341
  var loadingContainerDOM = document.createElement('div');
341
342
  loadingContainerDOM.setAttribute('id', `${id}-loading-id-0`);
342
343
  var style = 'position:absolute;outline:none;pointer-events:none;';
344
+ console.log("this.jSPlugin",this.jSPlugin);
345
+ if(typeof this.jSPlugin.poster === 'string') {
346
+ style += `background: url(${this.jSPlugin.poster}) no-repeat;background-size: cover;`;
347
+ }
343
348
  style += 'width: 100%;';
344
349
  style += 'height: 100%;';
345
350
  style += 'top:' + offsetTop + ';';
@@ -400,6 +405,14 @@ class Status {
400
405
  for (var i = elements.length - 1; i >= 0; i--) {
401
406
  elements[i].parentNode.removeChild(elements[i]);
402
407
  }
408
+ if(document.getElementById(`${this.id}-loading-id-0`)) {
409
+ document.getElementById(`${this.id}-loading-id-0`).style.background = 'none';
410
+ }
411
+ }
412
+ setPoster(pic) {
413
+ if(document.getElementById(`${this.id}-loading-id-0`)) {
414
+ document.getElementById(`${this.id}-loading-id-0`).style.backgroundImage = `url(${pic})`;
415
+ }
403
416
  }
404
417
  loadingEnd() {
405
418
  var loadingItemContainerDOM = document.getElementById(`${this.id}-loading-item-0`);
@@ -410,6 +423,7 @@ class Status {
410
423
  loadingContainerDOM.parentNode.removeChild(loadingContainerDOM);
411
424
  }
412
425
  }
426
+ document.getElementById(`${this.id}-loading-item-0`).style.background = 'none';
413
427
  }
414
428
  }
415
429
 
@@ -23789,6 +23803,9 @@ var TimeLine$1 = function (jsPlugin) {
23789
23803
  class Rec {
23790
23804
  constructor(jSPlugin) {
23791
23805
  this.jSPlugin = jSPlugin;
23806
+ if(!document.getElementById(`${this.jSPlugin.id}-audioControls`)) {
23807
+ return false;
23808
+ }
23792
23809
  this.currentTimeWidth = 1; //回放时间轴尺度 1~4
23793
23810
  this.timer = null;
23794
23811
  this.date = new Date();
@@ -23909,10 +23926,10 @@ C11.4,16.3,11,16.6,10.6,16.6z" />
23909
23926
  });
23910
23927
  this.syncTimeLine();
23911
23928
  // 加载日期选择器
23912
- addCss("https://open.ys7.com/assets/ezuikit_theme/css/datepicker.min.css");
23913
- addJs("https://open.ys7.com/assets/ezuikit_v2.6.4/js/jquery.min.js", () => {
23914
- addJs("https://open.ys7.com/assets/ezuikit_theme/js/datepicker.js", () => {
23915
- addJs("https://open.ys7.com/assets/ezuikit_theme/js/datepicker.zh-CN.js", () => {
23929
+ addCss(`${this.jSPlugin.staticPath}/rec/datepicker.min.css`);
23930
+ addJs(`${this.jSPlugin.staticPath}/rec/jquery.min.js`, () => {
23931
+ addJs(`${this.jSPlugin.staticPath}/rec/datepicker.js`, () => {
23932
+ addJs(`${this.jSPlugin.staticPath}/rec/datepicker.zh-CN.js`, () => {
23916
23933
  // 日期选择:
23917
23934
  $(`#${this.jSPlugin.id}-datepicker`).datepicker({
23918
23935
  autoShow: false,
@@ -25216,9 +25233,9 @@ class Talk {
25216
25233
  audioRightDOM.setAttribute("controls", true);
25217
25234
  audioRight.appendChild(audioRightDOM);
25218
25235
 
25219
- addJs("https://open.ys7.com/assets/ezuikit_v2.6.4/npm/js/adapeter.js", () => {
25220
- addJs("https://open.ys7.com/assets/ezuikit_v2.6.4/npm/js/janus.js", () => {
25221
- addJs("https://open.ys7.com/assets/ezuikit_v4.0/js/tts-v4.js", () => {
25236
+ addJs(`${this.jSPlugin.staticPath}/talk/adapeter.js`, () => {
25237
+ addJs(`${this.jSPlugin.staticPath}/talk/janus.js`, () => {
25238
+ addJs(`${this.jSPlugin.staticPath}/talk/tts-v4.js`, () => {
25222
25239
  // 临时处理
25223
25240
  window.EZUIKit["handleTalkError"] = {
25224
25241
  handleTalkError: (err)=>{
@@ -26067,69 +26084,6 @@ class Theme {
26067
26084
  PC端 & 直播 =》 pcLive
26068
26085
  PC端 & 回放地址 => pcRec
26069
26086
  */
26070
- // switch (matchEzopenUrl(jSPlugin.url).type) {
26071
- // case 'live':
26072
- // this.themeData = pcLiveData.data;
26073
- // if (this.isMobile) {
26074
- // this.themeData = mobileLiveData.data;
26075
- // }
26076
- // break;
26077
- // case 'rec':
26078
- // case 'cloud.rec':
26079
- // this.themeData = pcRecData.data;
26080
- // if (this.isMobile) {
26081
- // this.themeData = mobileRecData.data;
26082
- // }
26083
- // break;
26084
- // default:
26085
- // break;
26086
- // }
26087
- // const videoId = jSPlugin.id;
26088
- // this.header = defaultTheme.header;
26089
- // this.footer = defaultTheme.footer;
26090
- // if (!document.getElementById(`${this.jSPlugin.id}-headControl`)) {
26091
- // const headerContainer = document.createElement('div');
26092
- // headerContainer.setAttribute('id', `${this.jSPlugin.id}-headControl`);
26093
- // headerContainer.setAttribute('class', 'head-message');
26094
- // headerContainer.innerHTML = `<div id='${this.jSPlugin.id}}-headControl-left' style='display:flex'></div><div id='${this.jSPlugin.id}}-headControl-right' style='display:flex'></div>`;
26095
- // var headerStyle = {
26096
- // height: "48px",
26097
- // "line-height": "48px",
26098
- // display: "flex",
26099
- // "justify-content": "space-between",
26100
- // top: 0,
26101
- // "z-index": 1,
26102
- // background: "#000000",
26103
- // color: "#FFFFFF",
26104
- // width: "100%"
26105
- // };
26106
- // headerContainer.style = styleToString(headerStyle);
26107
- // document.getElementById(`${videoId}-wrap`).insertBefore(headerContainer, document.getElementById(videoId));
26108
- // }
26109
- // if (!document.getElementById(`${this.jSPlugin.id}-ez-iframe-footer-container`)) {
26110
- // const footerContainer = document.createElement('div');
26111
- // footerContainer.setAttribute('id', `${this.jSPlugin.id}-ez-iframe-footer-container`);
26112
- // footerContainer.setAttribute('class', 'ez-iframe-footer-container');
26113
- // var footerStyle = {
26114
- // "min-height": "48px",
26115
- // "max-height": "96px",
26116
- // "position": "relative",
26117
- // "margin-top": "-48px",
26118
- // display: "flex",
26119
- // "flex-wrap": "wrap",
26120
- // "justify-content": "space-between",
26121
- // top: 0,
26122
- // "z-index": 1,
26123
- // color: "#FFFFFF",
26124
- // width: "100%"
26125
- // };
26126
- // footerContainer.style = styleToString(footerStyle);
26127
- // footerContainer.innerHTML = `<div id="${this.jSPlugin.id}-audioControls" style='display:flex;justify-content: space-between;height: 48px;width:100%;'><div id='${this.jSPlugin.id}-audioControls-left' style='display:flex'></div><div id='${this.jSPlugin.id}-audioControls-right' style='display:flex'></div></div>`;
26128
- // insertAfter(footerContainer, document.getElementById(videoId));
26129
- // }
26130
- // if (!this.jSPlugin.inited) {
26131
- // this.initThemeData();
26132
- // }
26133
26087
  if (this.jSPlugin.themeId) {
26134
26088
  switch (this.jSPlugin.themeId) {
26135
26089
  case 'pcLive':
@@ -26175,11 +26129,9 @@ class Theme {
26175
26129
  this.Ptz = new Ptz(jSPlugin);
26176
26130
  }
26177
26131
  }
26178
- //设备信息
26179
- this.getDeviceInfo();
26180
26132
  }
26181
26133
  fetchThemeData(themeId) {
26182
- const url = `https://open.ys7.com/jssdk/ezopen/template/getDetail?accessToken=${this.jSPlugin.accessToken}&id=${themeId}`;
26134
+ const url = `${this.jSPlugin.env.domain}/jssdk/ezopen/template/getDetail?accessToken=${this.jSPlugin.accessToken}&id=${themeId}`;
26183
26135
  fetch(url, {
26184
26136
  method: 'GET'
26185
26137
  })
@@ -26351,9 +26303,16 @@ class Theme {
26351
26303
  }
26352
26304
  break;
26353
26305
  case 'hd':
26354
- if (document.getElementById(`${this.jSPlugin.id}-hd`)) {
26355
- document.getElementById(`${this.jSPlugin.id}-hd`).className = options[item] ? 'active' : '';
26356
- document.getElementById(`${this.jSPlugin.id}-hd-content`).childNodes[1].childNodes[0].style.fill = options[item] ? activeColor : color;
26306
+ if (options[item]) {
26307
+ if(document.getElementById(`${this.jSPlugin.id}-hd`)) {
26308
+ document.getElementById(`${this.jSPlugin.id}-hd-content`).children[1].children[0].style = "display:block";
26309
+ document.getElementById(`${this.jSPlugin.id}-hd-content`).children[1].children[1].style = "display:none";
26310
+ }
26311
+ } else {
26312
+ if(document.getElementById(`${this.jSPlugin.id}-hd`)) {
26313
+ document.getElementById(`${this.jSPlugin.id}-hd-content`).children[1].children[1].style = "display:block";
26314
+ document.getElementById(`${this.jSPlugin.id}-hd-content`).children[1].children[0].style = "display:none";
26315
+ }
26357
26316
  }
26358
26317
  break;
26359
26318
  case 'cloudRec':
@@ -26807,8 +26766,7 @@ class Theme {
26807
26766
  btnItem.onclick = (e) => {
26808
26767
  const { hd } = this.decoderState.state;
26809
26768
  // 选择清晰度选项时才触发事件
26810
- console.log(`选择画面清晰度-${e.target.innerHTML}`);
26811
- if (hd && e.target.id === 'select-sd') {
26769
+ if (hd && e.target.id === `${this.jSPlugin.id}-select-sd`) {
26812
26770
  //decoder.changePlayUrl({ hd: false });
26813
26771
  console.log("切换到标清");
26814
26772
  this.jSPlugin.changePlayUrl({ hd: false });
@@ -27019,6 +26977,8 @@ class Theme {
27019
26977
  window.addEventListener(item, (data) => fullscreenchange());
27020
26978
  });
27021
26979
  this.inited = true;
26980
+ //设备信息
26981
+ this.getDeviceInfo();
27022
26982
  }
27023
26983
  getDeviceInfo() {
27024
26984
  const deviceAPISuccess = (data) => {
@@ -28639,46 +28599,100 @@ var EZUIKitV3$1 = EZUIKitV3;
28639
28599
 
28640
28600
  /* eslint-disable valid-jsdoc */
28641
28601
 
28602
+ // iframe模板 - 兼容旧版本
28603
+ const matchTemplate = (templateName, params) => {
28604
+ const IFRAMETEMPLATE = ['simple', 'standard', 'security', 'vioce', 'theme'];
28605
+ const LOCALTEMPLATE = ['pcLive', 'pcRec', 'mobileLive', 'mobileRec', 'noData'];
28606
+ if (typeof templateName === 'undefined') {
28607
+ return {
28608
+ templateType: 'local',
28609
+ templateId: ''
28610
+ }
28611
+ } if (typeof templateName === 'string') {
28612
+
28613
+ if (templateName.length === 32) {
28614
+ return {
28615
+ templateType: 'remote',
28616
+ templateId: templateName
28617
+ }
28618
+ } else if (IFRAMETEMPLATE.indexOf(templateName) !== -1) {
28619
+ // 精简版且不使用头部,底部,仅播放视频,建议使用按需加载避免iframe内存额外消耗
28620
+ if (templateName === 'simple' && typeof params.header === 'undefined' && typeof params.footer === 'undefined') {
28621
+ return {
28622
+ templateType: 'local',
28623
+ templateId: ''
28624
+ }
28625
+ }
28626
+ return {
28627
+ templateType: 'iframe',
28628
+ templateId: templateName
28629
+ }
28630
+ } else if (LOCALTEMPLATE.indexOf(templateName) !== -1) {
28631
+ return {
28632
+ templateType: 'local',
28633
+ templateId: templateName
28634
+ }
28635
+ }
28636
+ }
28637
+ };
28638
+
28642
28639
  class EZUIKitPlayer {
28643
28640
  constructor(params) {
28644
28641
  const { autoplay = true } = params;
28645
28642
  this.params = params;
28646
- // 精简版且不使用头部,底部,仅播放视频,建议使用按需加载避免iframe内存额外消耗
28647
- if (this.params.template && this.params.template === 'simple' && typeof this.params.header === 'undefined' && typeof this.params.footer === 'undefined') {
28648
- this.params.themeId = "";
28649
- delete this.params.template;
28650
- }
28651
- window.EZUIKit[params.id] = {state: {
28652
- EZUIKitPlayer: {
28653
- init: window.EZUIKit[params.id] && window.EZUIKit[params.id].state && window.EZUIKit[params.id].state.EZUIKitPlayer.init || false,
28654
- themeInit: window.EZUIKit[params.id] && window.EZUIKit[params.id].state && window.EZUIKit[params.id].state.EZUIKitPlayer.themeInit || false,
28655
- talkInit: window.EZUIKit[params.id] && window.EZUIKit[params.id].state && window.EZUIKit[params.id].state.EZUIKitPlayer.talkInit || false
28656
- }}
28643
+ window.EZUIKit[params.id] = {
28644
+ state: {
28645
+ EZUIKitPlayer: {
28646
+ init: window.EZUIKit[params.id] && window.EZUIKit[params.id].state && window.EZUIKit[params.id].state.EZUIKitPlayer.init || false,
28647
+ themeInit: window.EZUIKit[params.id] && window.EZUIKit[params.id].state && window.EZUIKit[params.id].state.EZUIKitPlayer.themeInit || false,
28648
+ talkInit: window.EZUIKit[params.id] && window.EZUIKit[params.id].state && window.EZUIKit[params.id].state.EZUIKitPlayer.talkInit || false
28649
+ }
28650
+ }
28657
28651
  };
28658
- if (!(typeof this.params.template === 'string')) {
28652
+ if (matchTemplate(this.params.template, params).templateType !== 'iframe') {
28659
28653
  this.id = params.id;
28660
28654
  this.width = params.width;
28661
28655
  this.height = params.height;
28662
28656
  this.url = params.url;
28663
28657
  this.accessToken = params.accessToken;
28664
- this.themeId = params.themeId;
28658
+ this.themeId = matchTemplate(params.template, params).templateId;
28665
28659
  this.id = params.id;
28666
28660
  this.audio = params.audio;
28667
- addJs("https://open.ys7.com/assets/ezuikit_v4.0/js/AudioRenderer.js", () => {
28668
- addJs("https://open.ys7.com/assets/ezuikit_v4.0/js/SuperRender_10.js", () => {
28669
- addJs("https://test11open.ys7.com/assets/ezuikit_v4.0/js/jsPlugin-4.0.1.min.js", () => {
28670
- var initEZUIKitPlayerPromise = this.initEZUIKitPlayer(params);
28671
- initEZUIKitPlayerPromise.then((data) => {
28672
- console.log("初始化成功", data);
28673
- window.EZUIKit[params.id].state.EZUIKitPlayer.init = true;
28674
- if (document.getElementById(`${params.id}canvas_draw0`)) {
28675
- document.getElementById(`${params.id}canvas_draw0`).style.border = "none";
28676
- }
28677
- if (autoplay) {
28678
- //next version 此处可采用promise.all将播放接口部分同步到初始化阶段。
28679
- this.play();
28680
- }
28681
- });
28661
+ this.poster = params.poster;
28662
+ this.speed = 1;
28663
+ this.staticPath = "https://open.ys7.com/assets/ezuikit_v4.0";
28664
+ if (typeof params.staticPath === 'string') {
28665
+ this.staticPath = params.staticPath;
28666
+ }
28667
+ addJs(`${this.staticPath}/js/AudioRenderer.js`, () => {
28668
+ addJs(`${this.staticPath}/js/SuperRender_10.js`, () => {
28669
+ addJs(`${this.staticPath}/js/jsPlugin-4.0.2.min.js`, () => {
28670
+ if (autoplay) {
28671
+ var initEZUIKitPlayerPromise = this.initEZUIKitPlayer(params);
28672
+ var getRealUrlPromise = this._getRealUrlPromise(params.accessToken, params.url);
28673
+ Promise.all([initEZUIKitPlayerPromise, getRealUrlPromise]).then(values => {
28674
+ console.log("values", values);
28675
+ if (values[1]) {
28676
+ this._pluginPlay(values[1],
28677
+ () => { console.log("自动播放成功"); },
28678
+ () => { console.log("自动播放失败"); },
28679
+ );
28680
+ }
28681
+ window.EZUIKit[params.id].state.EZUIKitPlayer.init = true;
28682
+ if (document.getElementById(`${params.id}canvas_draw0`)) {
28683
+ document.getElementById(`${params.id}canvas_draw0`).style.border = "none";
28684
+ }
28685
+ });
28686
+ } else {
28687
+ var initEZUIKitPlayerPromise = this.initEZUIKitPlayer(params);
28688
+ initEZUIKitPlayerPromise.then((data) => {
28689
+ console.log("初始化成功", data);
28690
+ window.EZUIKit[params.id].state.EZUIKitPlayer.init = true;
28691
+ if (document.getElementById(`${params.id}canvas_draw0`)) {
28692
+ document.getElementById(`${params.id}canvas_draw0`).style.border = "none";
28693
+ }
28694
+ });
28695
+ }
28682
28696
  });
28683
28697
  });
28684
28698
  });
@@ -28691,7 +28705,7 @@ class EZUIKitPlayer {
28691
28705
  }
28692
28706
  }
28693
28707
  initEZUIKitPlayer(params) {
28694
- const { id, themeId, width = 600, height = 400 } = params;
28708
+ const { id, width = 600, height = 400 } = params;
28695
28709
  if (!document.getElementById(`${id}-wrap`)) {
28696
28710
  document.getElementById(id).style = `display:inline-block;width:${width}px;height:${height}px;`;
28697
28711
  var wapDom = document.createElement("div");
@@ -28710,6 +28724,7 @@ class EZUIKitPlayer {
28710
28724
  iMaxSplit: 1,
28711
28725
  iCurrentSplit: 1,
28712
28726
  szBasePath: "",
28727
+ staticPath: params.staticPath,
28713
28728
  oStyle: {
28714
28729
  border: "none",
28715
28730
  background: "#000000"
@@ -28757,7 +28772,7 @@ class EZUIKitPlayer {
28757
28772
  }
28758
28773
  };
28759
28774
  // 增加视频容器
28760
- var pluginStatus = new Status(id);
28775
+ var pluginStatus = new Status(this, id);
28761
28776
  pluginStatus.loadingStart(id);
28762
28777
  pluginStatus.loadingSetText({ text: '初始化播放器完成' });
28763
28778
  this.env = {
@@ -28768,7 +28783,7 @@ class EZUIKitPlayer {
28768
28783
  }
28769
28784
  this.errorHander = new Code();
28770
28785
  this.jSPlugin = jSPlugin;
28771
- if (themeId && !window.EZUIKit[params.id].state.EZUIKitPlayer.themeInit) {
28786
+ if (this.themeId && !window.EZUIKit[params.id].state.EZUIKitPlayer.themeInit) {
28772
28787
  this.Theme = new Theme(this, id);
28773
28788
  window.EZUIKit[params.id].state.EZUIKitPlayer.themeInit = true;
28774
28789
  }
@@ -29082,64 +29097,136 @@ class EZUIKitPlayer {
29082
29097
  return new Date(date.replace(/-/g, '/')).getTime();
29083
29098
  }
29084
29099
  }
29085
- play() {
29100
+ _pluginPlay(data, successCallback, errorCallback) {
29101
+ console.log("get real url result ===", data);
29102
+ function getPlayParams(url) {
29103
+ var websocketConnectUrl = url.split('?')[0].replace('/live', '').replace('/playback', '');
29104
+ var websocketStreamingParam = (url.indexOf('/live') === -1 ? (url.indexOf('cloudplayback') !== -1 ? '/cloudplayback?' : '/playback?') : '/live?') + url.split('?')[1];
29105
+ if (websocketStreamingParam.indexOf('/playback') !== -1) {
29106
+ websocketStreamingParam = websocketStreamingParam.replace("stream=2", 'stream=1');
29107
+ }
29108
+ // 本地回放仅支持主码流
29109
+ return {
29110
+ websocketConnectUrl: websocketConnectUrl,
29111
+ websocketStreamingParam: websocketStreamingParam
29112
+ };
29113
+ }
29114
+ var wsUrl = getPlayParams(data).websocketConnectUrl;
29115
+ if (this.env && this.env.wsUrl) {
29116
+ wsUrl = this.env.wsUrl;
29117
+ }
29118
+ var wsParams = {
29119
+ playURL: getPlayParams(data).websocketStreamingParam
29120
+ };
29121
+
29122
+ this.jSPlugin.JS_Play(wsUrl, wsParams, 0).then(() => {
29123
+ console.log("播放成功");
29124
+ this.pluginStatus.loadingClear();
29125
+ if (this.Theme) {
29126
+ this.Theme.setDecoderState({ play: true });
29127
+ }
29128
+ if (this.audio) {
29129
+ setTimeout(() => {
29130
+ this.openSound();
29131
+ }, 500);
29132
+ }
29133
+ if (typeof this.params.handleSuccess === 'function') {
29134
+ this.params.handleSuccess({
29135
+ retcode: 0,
29136
+ id: this.params.id,
29137
+ type: "handleSuccess"
29138
+ });
29139
+ }
29140
+ successCallback();
29141
+ }, (err) => {
29142
+ var errorInfo = this.errorHander.matchErrorInfo(err.oError.errorCode);
29143
+ var msg = errorInfo ? errorInfo.description : '播放失败,请检查设备及客户端网络';
29144
+ this.pluginStatus.loadingSetText({
29145
+ text: msg,
29146
+ color: 'red'
29147
+ });
29148
+ if (typeof this.params.handleError === 'function') {
29149
+ this.params.handleError({
29150
+ retcode: err.oError.errorCode,
29151
+ msg: msg,
29152
+ id: this.params.id,
29153
+ type: "handleError"
29154
+ });
29155
+ }
29156
+ successCallback(errorCallback);
29157
+ });
29158
+ }
29159
+ play(options) {
29160
+ if(typeof options.url === 'string') {
29161
+ this.url = options.url;
29162
+ }
29163
+ if(typeof options.accessToken === 'string') {
29164
+ this.accessToken = options.accessToken;
29165
+ }
29166
+ if(this.Theme && (typeof options.url === 'string' || typeof options.accessToken === 'string')) {
29167
+ this.Theme.getDeviceInfo();
29168
+ }
29086
29169
  const promise = new Promise((resolve, reject) => {
29087
29170
  this._getRealUrlPromise(this.accessToken, this.url)
29088
29171
  .then((data) => {
29089
- console.log("get real url result ===", data);
29090
- function getPlayParams(url) {
29091
- var websocketConnectUrl = url.split('?')[0].replace('/live', '').replace('/playback', '');
29092
- var websocketStreamingParam = (url.indexOf('/live') === -1 ? (url.indexOf('cloudplayback') !== -1 ? '/cloudplayback?' : '/playback?') : '/live?') + url.split('?')[1];
29093
- if (websocketStreamingParam.indexOf('/playback') !== -1) {
29094
- websocketStreamingParam = websocketStreamingParam.replace("stream=2", 'stream=1');
29095
- }
29096
- // 本地回放仅支持主码流
29097
- return {
29098
- websocketConnectUrl: websocketConnectUrl,
29099
- websocketStreamingParam: websocketStreamingParam
29100
- };
29101
- }
29102
- var wsUrl = getPlayParams(data).websocketConnectUrl;
29103
- var wsParams = {
29104
- playURL: getPlayParams(data).websocketStreamingParam
29105
- };
29106
-
29107
- this.jSPlugin.JS_Play(wsUrl, wsParams, 0).then(() => {
29108
- console.log("播放成功");
29109
- this.pluginStatus.loadingClear();
29110
- if (this.Theme) {
29111
- this.Theme.setDecoderState({ play: true });
29112
- }
29113
- if (this.audio) {
29114
- setTimeout(() => {
29115
- this.openSound();
29116
- }, 500);
29117
- }
29118
- if (typeof this.params.handleSuccess === 'function') {
29119
- this.params.handleSuccess({
29120
- retcode: 0,
29121
- id: this.params.id,
29122
- type: "handleSuccess"
29123
- });
29124
- }
29125
- resolve(true);
29126
- }, (err) => {
29127
- var errorInfo = this.errorHander.matchErrorInfo(err.oError.errorCode);
29128
- var msg = errorInfo ? errorInfo.description : '播放失败,请检查设备及客户端网络';
29129
- this.pluginStatus.loadingSetText({
29130
- text: msg,
29131
- color: 'red'
29132
- });
29133
- if (typeof this.params.handleError === 'function') {
29134
- this.params.handleError({
29135
- retcode: err.oError.errorCode,
29136
- msg: msg,
29137
- id: this.params.id,
29138
- type: "handleError"
29139
- });
29140
- }
29141
- reject(false);
29142
- });
29172
+ this._pluginPlay(data, () => resolve(true), () => reject(false));
29173
+ // console.log("get real url result ===", data);
29174
+ // function getPlayParams(url) {
29175
+ // var websocketConnectUrl = url.split('?')[0].replace('/live', '').replace('/playback', '');
29176
+ // var websocketStreamingParam = (url.indexOf('/live') === -1 ? (url.indexOf('cloudplayback') !== -1 ? '/cloudplayback?' : '/playback?') : '/live?') + url.split('?')[1];
29177
+ // if (websocketStreamingParam.indexOf('/playback') !== -1) {
29178
+ // websocketStreamingParam = websocketStreamingParam.replace("stream=2", 'stream=1');
29179
+ // }
29180
+ // // 本地回放仅支持主码流
29181
+ // return {
29182
+ // websocketConnectUrl: websocketConnectUrl,
29183
+ // websocketStreamingParam: websocketStreamingParam
29184
+ // };
29185
+ // }
29186
+ // var wsUrl = getPlayParams(data).websocketConnectUrl;
29187
+ // if(this.env && this.env.wsUrl) {
29188
+ // wsUrl = this.env.wsUrl;
29189
+ // }
29190
+ // var wsParams = {
29191
+ // playURL: getPlayParams(data).websocketStreamingParam
29192
+ // };
29193
+
29194
+ // this.jSPlugin.JS_Play(wsUrl, wsParams, 0).then(() => {
29195
+ // console.log("播放成功");
29196
+ // this.pluginStatus.loadingClear();
29197
+ // if (this.Theme) {
29198
+ // this.Theme.setDecoderState({ play: true });
29199
+ // }
29200
+ // if (this.audio) {
29201
+ // setTimeout(() => {
29202
+ // this.openSound();
29203
+ // }, 500);
29204
+ // }
29205
+ // if (typeof this.params.handleSuccess === 'function') {
29206
+ // this.params.handleSuccess({
29207
+ // retcode: 0,
29208
+ // id: this.params.id,
29209
+ // type: "handleSuccess"
29210
+ // });
29211
+ // }
29212
+ // resolve(true);
29213
+ // }, (err) => {
29214
+ // var errorInfo = this.errorHander.matchErrorInfo(err.oError.errorCode);
29215
+ // var msg = errorInfo ? errorInfo.description : '播放失败,请检查设备及客户端网络';
29216
+ // this.pluginStatus.loadingSetText({
29217
+ // text: msg,
29218
+ // color: 'red'
29219
+ // });
29220
+ // if (typeof this.params.handleError === 'function') {
29221
+ // this.params.handleError({
29222
+ // retcode: err.oError.errorCode,
29223
+ // msg: msg,
29224
+ // id: this.params.id,
29225
+ // type: "handleError"
29226
+ // });
29227
+ // }
29228
+ // reject(false);
29229
+ // });
29143
29230
  })
29144
29231
  .catch((err) => {
29145
29232
  var msg = err.msg ? err.msg : '播放失败,请检查设备及客户端网络';
@@ -29255,28 +29342,45 @@ class EZUIKitPlayer {
29255
29342
  return promise;
29256
29343
  }
29257
29344
  getOSDTime() {
29258
- var promise = new Promise((resolve,reject) => {
29345
+ var promise = new Promise((resolve, reject) => {
29259
29346
  this.jSPlugin.JS_GetOSDTime(0)
29260
- .then((data)=>{
29347
+ .then((data) => {
29261
29348
  resolve({
29262
29349
  code: 0,
29263
29350
  retcode: 0,
29264
29351
  data: data
29265
29352
  });
29353
+ // 兼容旧版本callback
29354
+ if (typeof this.params.getOSDTimeCallBack === 'function') {
29355
+ this.params.getOSDTimeCallBack({ id: this.id, type: 'getOSDTime', code: 0, data: data});
29356
+ }
29266
29357
  })
29267
- .catch(err=>{
29358
+ .catch(err => {
29268
29359
  reject({
29269
29360
  code: -1,
29270
29361
  retcode: -1,
29271
29362
  data: err
29272
29363
  });
29364
+ // 兼容旧版本callback
29365
+ if (typeof this.params.getOSDTimeCallBack === 'function') {
29366
+ this.params.getOSDTimeCallBack({ id: this.id, type: 'getOSDTime', code: -1,data: -1 });
29367
+ }
29273
29368
  });
29274
29369
  });
29275
29370
  return promise;
29276
29371
  }
29277
29372
  capturePicture(name, callback = false) {
29278
- var capturePictureRT = this.jSPlugin.JS_CapturePicture(0, name, "JPEG", callback);
29373
+ var capturePictureRT = this.jSPlugin.JS_CapturePicture(0, name, "JPEG", callback, !!callback);
29279
29374
  if (isPromise(capturePictureRT)) {
29375
+ // 兼容旧版本callback
29376
+ if (typeof this.params.capturePictureCallBack === 'function') {
29377
+ capturePictureRT.then(() => {
29378
+ this.params.capturePictureCallBack({ id: this.id, type: 'capturePicture', code: 0 });
29379
+ })
29380
+ .catch(() => {
29381
+ this.params.capturePictureCallBack({ id: this.id, type: 'capturePicture', code: -1 });
29382
+ });
29383
+ }
29280
29384
  return capturePictureRT;
29281
29385
  }
29282
29386
  return new Promise(function (resolve) {
@@ -29286,6 +29390,15 @@ class EZUIKitPlayer {
29286
29390
  startSave(name) {
29287
29391
  var startSaveRT = this.jSPlugin.JS_StartSave(0, name);
29288
29392
  if (isPromise(startSaveRT)) {
29393
+ // 兼容旧版本callback
29394
+ if (typeof this.params.startSaveCallBack === 'function') {
29395
+ startSaveRT.then(() => {
29396
+ this.params.startSaveCallBack({ id: this.id, type: 'startSave', code: 0 });
29397
+ })
29398
+ .catch(() => {
29399
+ this.params.startSaveCallBack({ id: this.id, type: 'startSave', code: -1 });
29400
+ });
29401
+ }
29289
29402
  return startSaveRT;
29290
29403
  }
29291
29404
  if (this.Theme) {
@@ -29298,6 +29411,15 @@ class EZUIKitPlayer {
29298
29411
  stopSave() {
29299
29412
  var stopSaveRT = this.jSPlugin.JS_StopSave(0);
29300
29413
  if (isPromise(stopSaveRT)) {
29414
+ // 兼容旧版本callback
29415
+ if (typeof this.params.startSaveCallBack === 'function') {
29416
+ stopSaveRT.then(() => {
29417
+ this.params.stopSaveCallBack({ id: this.id, type: 'stopSave', code: 0 });
29418
+ })
29419
+ .catch(() => {
29420
+ this.params.stopSaveCallBack({ id: this.id, type: 'stopSave', code: -1 });
29421
+ });
29422
+ }
29301
29423
  return stopSaveRT;
29302
29424
  }
29303
29425
  if (this.Theme) {
@@ -29316,6 +29438,10 @@ class EZUIKitPlayer {
29316
29438
  if (this.Theme) {
29317
29439
  this.Theme.setDecoderState({ sound: true });
29318
29440
  }
29441
+ // 兼容旧版本callback
29442
+ if (typeof this.params.openSoundCallBack === 'function') {
29443
+ this.params.openSoundCallBack({ id: this.id, type: 'openSound', code: openSoundRT });
29444
+ }
29319
29445
  return new Promise(function (resolve) {
29320
29446
  resolve(openSoundRT);
29321
29447
  });
@@ -29328,6 +29454,10 @@ class EZUIKitPlayer {
29328
29454
  if (this.Theme) {
29329
29455
  this.Theme.setDecoderState({ sound: false });
29330
29456
  }
29457
+ // 兼容旧版本callback
29458
+ if (typeof this.params.closeSoundCallBack === 'function') {
29459
+ this.params.closeSoundCallBack({ id: this.id, type: 'closeSound', code: closeSoundRT });
29460
+ }
29331
29461
  return new Promise(function (resolve) {
29332
29462
  resolve(closeSoundRT);
29333
29463
  });
@@ -29350,17 +29480,87 @@ class EZUIKitPlayer {
29350
29480
  resolve(closeZoomRT);
29351
29481
  });
29352
29482
  }
29483
+ setPoster(url) {
29484
+ this.pluginStatus.setPoster(url);
29485
+ }
29353
29486
  reSize(width, height) {
29354
29487
  this.width = width;
29355
29488
  this.height = height;
29356
- document.getElementById(`${this.id}-wrap`).style.width = `${width}px;position:relative;`;
29489
+ document.getElementById(`${this.id}-wrap`).style = `width:${width}px;position:relative;`;
29357
29490
  this.jSPlugin.JS_Resize(width, height);
29358
29491
  }
29492
+ fast() {
29493
+ var speed = this.speed;
29494
+ if (speed === 1) {
29495
+ speed = 2;
29496
+ } else if (speed === 2) {
29497
+ speed = 4;
29498
+ } else {
29499
+ if (typeof this.params.handleError === 'function') {
29500
+ this.params.handleError({
29501
+ msg: "播放速度最大为4倍速度",
29502
+ retcode: 1003,
29503
+ id: this.id,
29504
+ type: "handleError"
29505
+ });
29506
+ }
29507
+ }
29508
+ var fastRT = this.jSPlugin.JS_Fast(0);
29509
+ if (isPromise(fastRT)) {
29510
+ this.speed = speed;
29511
+ return fastRT;
29512
+ }
29513
+ return new Promise(function (resolve) {
29514
+ this.speed = speed;
29515
+ resolve(fastRT);
29516
+ });
29517
+ }
29518
+ slow() {
29519
+ var speed = this.speed;
29520
+ if (speed === 4) {
29521
+ speed = 2;
29522
+ } else if (speed === 2) {
29523
+ speed = 1;
29524
+ } else {
29525
+ if (typeof this.params.handleError === 'function') {
29526
+ this.params.handleError({
29527
+ msg: "播放速度最小为1倍速度",
29528
+ retcode: 1003,
29529
+ id: this.id,
29530
+ type: "handleError"
29531
+ });
29532
+ }
29533
+ }
29534
+ var slowRT = this.jSPlugin.JS_Slow(0);
29535
+ console.log("slowRT", slowRT);
29536
+ if (isPromise(slowRT)) {
29537
+ this.speed = speed;
29538
+ return slowRT;
29539
+ }
29540
+ return new Promise(function (resolve) {
29541
+ this.speed = speed;
29542
+ resolve(slowRT);
29543
+ });
29544
+ }
29545
+ seek(startTime, endTime) {
29546
+ var seekRT = this.jSPlugin.JS_Seek(0, startTime, endTime);
29547
+ console.log("seekRT", seekRT);
29548
+ if (isPromise(seekRT)) {
29549
+ return seekRT;
29550
+ }
29551
+ return new Promise(function (resolve) {
29552
+ resolve(seekRT);
29553
+ });
29554
+ }
29359
29555
  fullScreen() {
29360
29556
  var promise = requestFullScreenPromise(document.getElementById(`${this.id}`));
29361
29557
  promise.then((data) => {
29362
29558
  console.log("全屏promise", window.screen.availWidth);
29363
29559
  this.jSPlugin.JS_Resize(window.screen.availWidth, window.screen.availHeight);
29560
+ // 兼容旧版本callback
29561
+ if (typeof this.params.fullScreenCallBack === 'function') {
29562
+ this.params.fullScreenCallBack({ id: this.id, type: 'fullScreen', code: 0 });
29563
+ }
29364
29564
  });
29365
29565
  // 监听全屏事件触发
29366
29566
  const fullscreenchange = () => {
@@ -29368,6 +29568,10 @@ class EZUIKitPlayer {
29368
29568
  if (!isFullScreen) {
29369
29569
  this.jSPlugin.JS_Resize(this.width, this.height);
29370
29570
  }
29571
+ // 兼容旧版本callback
29572
+ if (typeof this.params.fullScreenChangeCallBack === 'function') {
29573
+ this.params.fullScreenChangeCallBack({ id: this.id, type: 'fullScreen', code: isFullScreen });
29574
+ }
29371
29575
  };
29372
29576
  ['fullscreenchange', 'webkitfullscreenchange', 'mozfullscreenchange'].forEach((item) => {
29373
29577
  window.addEventListener(item, (data) => fullscreenchange());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ezuikit-js",
3
- "version": "0.4.1-beta.0",
3
+ "version": "0.4.3",
4
4
  "description": "ezuikit javascript for npm",
5
5
  "main": "ezuikit.js",
6
6
  "scripts": {