@bddh/starling-realtime-client 1.0.9 → 1.0.11

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/cjs/BrtcClient.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./_virtual/_rollupPluginBabelHelpers.js"),e=require("@bddh/starling-brtc"),o=require("@bddh/starling-timeout-controller"),n=require("@bddh/starling-json"),c=require("lodash/isEmpty"),r=require("lodash/isFunction"),i=require("./interface.js"),a=t.createClass((function a(l){var s=this;t.classCallCheck(this,a),t.defineProperty(this,"client",void 0),t.defineProperty(this,"isRtcVideoOn",!1),t.defineProperty(this,"rtcConnection",void 0),t.defineProperty(this,"rtcConfig",void 0),t.defineProperty(this,"bizConfig",void 0),t.defineProperty(this,"rtcCallback",void 0),t.defineProperty(this,"restarting",!1),t.defineProperty(this,"timeoutEvent",void 0),t.defineProperty(this,"reopenTimer",void 0),t.defineProperty(this,"restartCount",0),t.defineProperty(this,"closeLog",!0),t.defineProperty(this,"haveVideoOn",!1),t.defineProperty(this,"rtcStateCallback",null),t.defineProperty(this,"openRtc",(function(t){if(s.restarting)!s.closeLog&&console.warn("rtc restarting");else if(t&&(s.rtcConnection=t),s.rtcConnection&&!c(s.rtcConnection)){var o=s.rtcConnection,a=o.server,l=o.appId,d=o.token,u=o.roomName,C=o.userId,f=s.rtcCallback||{},m=f.onRemotedata,b=f.onLocalStream,g=f.onRemoteVideoComing,y=f.onLocalVideoPublished,v=f.onLocalVideoPublishing,R=f.onRemoteVideoOn,h=f.onRemoteVideoOff,L=f.onRemoteVideoLoading,p=f.onSuccess,S=f.onError,k=f.onLocalVideoConnected,E=f.onRemoteVideoConnected,V=f.onRemoteMediaState,P=f.onPlayingError,_=f.onDigitalHumanCallback;s.timeoutEvent.start(),s.rtcStateCallback=function(t){var e=t.body,o=t.action;_&&_({status:i.statusEnum.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:o,body:e}})},s.client=new e({roomName:u,token:d,userId:C,appId:l,server:a,rtcConfig:s.rtcConfig,callback:{onRemoteVideoConnected:function(e,o){if(!o&&!s.haveVideoOn)var n=setTimeout((function(){s.restartCount<3?(s.restartCount=++s.restartCount,s.restartRtc&&s.restartRtc(t)):(s.restartCount=0,s.closeRtc()),clearTimeout(n)}),500);if(o){var c=document.getElementById("remotevideo500");c.muted=!1;var a=c.play();void 0!==a&&a.catch((function(){c.muted=!0,c.play().catch((function(t){!s.closeLog&&console.info("videoElement play error",t),P&&P(c),_&&_({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.LOCAL_VIDEO_ERROR}})})),_&&_({status:i.statusEnum.DH_LIB_STATUS,content:{type:i.errorTypeEnum.LOCAL_VIDEO_MUTED}})}))}!s.closeLog&&console.info("remoteVideoConnected",e,o,s.restartCount),s.rtcStateCallback&&s.rtcStateCallback({action:"remoteVideoConnected",body:{id:e,connected:o,restartCount:s.restartCount}}),r(E)&&E(e,o)},onRemoteVideoOn:function(t){s.haveVideoOn=!0,!s.closeLog&&console.info("remotevideoon by id: ",t),s.timeoutEvent.clear();var e=document.querySelector("#starlingRtcContainer"),o=e&&e.lastChild;o&&(o.style.display="none"),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideoon",body:t}),_&&_({status:i.statusEnum.DH_LIB_OPEN}),r(R)&&R(t)},onRemoteMediaState:function(t,e,o){!s.closeLog&&console.info("remoteMediaState",t,e,o),s.rtcStateCallback&&s.rtcStateCallback({action:"remoteMediaState",body:{id:t,medium:e,connected:o}}),r(V)&&V(t,e,o)},onLocalVideoConnected:function(t){!s.closeLog&&console.info("localVideoConnected",t),s.rtcStateCallback&&s.rtcStateCallback({action:"localVideoConnected",body:{connected:t}}),r(k)&&k(t)},onRemotedata:function(t){if(s.rtcConfig&&s.rtcConfig.usingdatachannel){var e=n.parse(t);!s.closeLog&&console.info("RTC - receive:",e),r(m)&&m(e)}},onLocalStream:function(t,e){!s.closeLog&&console.info("rtc - onlocalstream by name: "+e),s.rtcStateCallback&&s.rtcStateCallback({action:"onlocalstream",body:{stream:t,name:e}}),r(b)&&b(t,e)},onLocalVideoPublished:function(){!s.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),s.rtcStateCallback&&s.rtcStateCallback({action:"localvideopublished_ok",body:!0}),r(y)&&y()},onLocalVideoPublishing:function(){!s.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),s.rtcStateCallback&&s.rtcStateCallback({action:"localvideopublishing",body:!0}),r(v)&&v()},onRemoteVideoComing:function(t){!s.closeLog&&console.info("remotevideocoming",t),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideocoming",body:t}),r(g)&&g(t)},onRemoteVideoLoading:function(t){!s.closeLog&&console.info("remotevideoloading by id: ",t),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideoloading",body:t}),r(L)&&L(t)},onRemoteVideoOff:function(t){!s.closeLog&&console.info("remotevideooff: ",t),s.isRtcVideoOn=!1,s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideooff",body:t}),_&&_({status:i.statusEnum.DH_LIB_CLOSE}),r(h)&&h(t),s.timeoutEvent.start()},onSuccess:function(){!s.closeLog&&console.info("rtc - success"),s.rtcStateCallback&&s.rtcStateCallback({action:"success",body:!0}),r(p)&&p()},onError:function(e){s.isRtcVideoOn=!1,!s.closeLog&&console.error("rtc - error:",e),s.rtcStateCallback&&s.rtcStateCallback({action:"error",body:e}),_&&_({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.RTC_ERROR}}),r(S)&&S(e),(e.includes("Lost connection to the server")||e.includes("Is the server down"))&&s.restartRtc&&s.restartRtc(t)}}})}})),t.defineProperty(this,"closeRtc",(function(){s.timeoutEvent.clear(),clearTimeout(s.reopenTimer),s.client&&s.client.destroy(),s.restarting=!1})),t.defineProperty(this,"restartRtc",(function(t){!s.restarting&&s.bizConfig&&s.bizConfig.autoReConnect&&(s.rtcStateCallback&&s.rtcStateCallback({action:"restartRtc",body:t}),s.restarting=!0,s.closeRtc(),s.reopenTimer=setTimeout((function(){!s.closeLog&&console.error("拉流失败,开始重启"),s.restarting=!1,s.openRtc(t)}),2e3))}));var d=l.rtcConnection,u=l.rtcConfig,C=l.closeLog,f=void 0===C||C,m=l.rtcCallback;this.rtcConnection=d,this.rtcConfig=u,this.rtcCallback=m,this.closeLog=f,this.timeoutEvent=new o.TimeoutController(6e4,(function(){if(!s.rtcConnection)return!s.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");s.timeoutEvent.clear(),s.restartRtc&&s.restartRtc(s.rtcConnection)}))}));exports.default=a;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),t=require("@bddh/starling-brtc"),o=require("@bddh/starling-timeout-controller"),n=require("@bddh/starling-json"),c=require("lodash/isEmpty"),r=require("lodash/isFunction"),i=require("./interface.js"),a=e.createClass((function a(l){var s=this;e.classCallCheck(this,a),e.defineProperty(this,"client",void 0),e.defineProperty(this,"isRtcVideoOn",!1),e.defineProperty(this,"rtcConnection",void 0),e.defineProperty(this,"rtcConfig",void 0),e.defineProperty(this,"bizConfig",void 0),e.defineProperty(this,"rtcCallback",void 0),e.defineProperty(this,"restarting",!1),e.defineProperty(this,"timeoutEvent",void 0),e.defineProperty(this,"reopenTimer",void 0),e.defineProperty(this,"restartCount",0),e.defineProperty(this,"closeLog",!0),e.defineProperty(this,"haveVideoOn",!1),e.defineProperty(this,"rtcStateCallback",null),e.defineProperty(this,"openRtc",(function(e){if(s.restarting)!s.closeLog&&console.warn("rtc restarting");else if(e&&(s.rtcConnection=e),s.rtcConnection&&!c(s.rtcConnection)){var o=s.rtcConnection,a=o.server,l=o.appId,d=o.token,u=o.roomName,C=o.userId,m=s.rtcCallback||{},f=m.onRemotedata,b=m.onLocalStream,g=m.onRemoteVideoComing,y=m.onLocalVideoPublished,v=m.onLocalVideoPublishing,R=m.onRemoteVideoOn,h=m.onRemoteVideoOff,p=m.onRemoteVideoLoading,L=m.onSuccess,S=m.onError,k=m.onLocalVideoConnected,E=m.onRemoteVideoConnected,V=m.onRemoteMediaState,P=m.onPlayingError,_=m.onDigitalHumanCallback;s.timeoutEvent.start(),s.rtcStateCallback=function(e){var t=e.body,o=e.action;_&&_({status:i.statusEnum.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:o,body:t}})},s.client=new t({roomName:u,token:d,userId:C,appId:l,server:a,rtcConfig:s.rtcConfig,callback:{onRemoteVideoConnected:function(t,o){if(!o&&!s.haveVideoOn)var n=setTimeout((function(){s.restartCount<3?(s.restartCount=++s.restartCount,s.restartRtc&&s.restartRtc(e)):(s.restartCount=0,s.closeRtc()),clearTimeout(n)}),500);if(o){var c=document.getElementById("remotevideo500");c.muted=!1;var a=c.play();void 0!==a&&a.catch((function(){c.muted=!0,c.play().catch((function(e){!s.closeLog&&console.info("videoElement play error",e),P&&P(c),_&&_({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.LOCAL_VIDEO_ERROR}})})),_&&_({status:i.statusEnum.DH_LIB_STATUS,content:{type:i.errorTypeEnum.LOCAL_VIDEO_MUTED}})}))}!s.closeLog&&console.info("remoteVideoConnected",t,o,s.restartCount),s.rtcStateCallback&&s.rtcStateCallback({action:"remoteVideoConnected",body:{id:t,connected:o,restartCount:s.restartCount}}),r(E)&&E(t,o)},onRemoteVideoOn:function(e){s.haveVideoOn=!0,!s.closeLog&&console.info("remotevideoon by id: ",e),s.timeoutEvent.clear();var t=document.querySelector("#starlingRtcContainer"),o=t&&t.lastChild;o&&(o.style.display="none"),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideoon",body:e}),_&&_({status:i.statusEnum.DH_LIB_OPEN}),r(R)&&R(e)},onRemoteMediaState:function(e,t,o){!s.closeLog&&console.info("remoteMediaState",e,t,o),s.rtcStateCallback&&s.rtcStateCallback({action:"remoteMediaState",body:{id:e,medium:t,connected:o}}),r(V)&&V(e,t,o)},onLocalVideoConnected:function(e){!s.closeLog&&console.info("localVideoConnected",e),s.rtcStateCallback&&s.rtcStateCallback({action:"localVideoConnected",body:{connected:e}}),r(k)&&k(e)},onRemotedata:function(e){if(s.rtcConfig&&s.rtcConfig.usingdatachannel){var t=n.parse(e);!s.closeLog&&console.info("RTC - receive:",t),r(f)&&f(t)}},onLocalStream:function(e,t){!s.closeLog&&console.info("rtc - onlocalstream by name: "+t),s.rtcStateCallback&&s.rtcStateCallback({action:"onlocalstream",body:{stream:e,name:t}}),r(b)&&b(e,t)},onLocalVideoPublished:function(){!s.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),s.rtcStateCallback&&s.rtcStateCallback({action:"localvideopublished_ok",body:!0}),r(y)&&y()},onLocalVideoPublishing:function(){!s.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),s.rtcStateCallback&&s.rtcStateCallback({action:"localvideopublishing",body:!0}),r(v)&&v()},onRemoteVideoComing:function(e){!s.closeLog&&console.info("remotevideocoming",e),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideocoming",body:e}),r(g)&&g(e)},onRemoteVideoLoading:function(e){!s.closeLog&&console.info("remotevideoloading by id: ",e),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideoloading",body:e}),r(p)&&p(e)},onRemoteVideoOff:function(e){var t=document.getElementById("remotevideo500");t&&t.pause(),!s.closeLog&&console.info("remotevideooff: ",e),s.isRtcVideoOn=!1,s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideooff",body:e}),_&&_({status:i.statusEnum.DH_LIB_CLOSE}),r(h)&&h(e),s.timeoutEvent.start()},onSuccess:function(){!s.closeLog&&console.info("rtc - success"),s.rtcStateCallback&&s.rtcStateCallback({action:"success",body:!0}),r(L)&&L()},onError:function(t){s.isRtcVideoOn=!1,!s.closeLog&&console.error("rtc - error:",t),s.rtcStateCallback&&s.rtcStateCallback({action:"error",body:t}),_&&_({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.RTC_ERROR}}),r(S)&&S(t),(t.includes("Lost connection to the server")||t.includes("Is the server down"))&&s.restartRtc&&s.restartRtc(e)}}})}})),e.defineProperty(this,"closeRtc",(function(){s.timeoutEvent.clear(),clearTimeout(s.reopenTimer),s.client&&s.client.destroy(),s.restarting=!1})),e.defineProperty(this,"restartRtc",(function(e){!s.restarting&&s.bizConfig&&s.bizConfig.autoReConnect&&(s.rtcStateCallback&&s.rtcStateCallback({action:"restartRtc",body:e}),s.restarting=!0,s.closeRtc(),s.reopenTimer=setTimeout((function(){!s.closeLog&&console.error("拉流失败,开始重启"),s.restarting=!1,s.openRtc(e)}),2e3))}));var d=l.rtcConnection,u=l.rtcConfig,C=l.closeLog,m=void 0===C||C,f=l.rtcCallback;this.rtcConnection=d,this.rtcConfig=u,this.rtcCallback=f,this.closeLog=m,this.timeoutEvent=new o.TimeoutController(6e4,(function(){if(!s.rtcConnection)return!s.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");s.timeoutEvent.clear(),s.restartRtc&&s.restartRtc(s.rtcConnection)}))}));exports.default=a;
package/cjs/DomControl.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e="starling-cutout-canvas",t="cloud-brtc-player-wrapper",n="remotevideo500";exports.DEFAULT_CANVAS_ID=e,exports.HUMAN_WRAPPER_ID=t,exports.RTC_VIDEO_ID=n,exports.appendRtcDomStyle=function(){var e=document.createElement("style");e.appendChild(document.createTextNode('\n [id^="videoremote1-"] {\n display: none !important;\n }\n \n video#remotevideo500 {\n width: auto !important;\n height: auto !important;\n max-width: 100% !important;\n max-height: 100% !important;\n }\n\n .cloud-brtc-player-wrapper {\n width: inherit !important;\n background-size: cover;\n height: inherit;\n display: flex;\n justify-content: center;\n }\n\n #starling-cutout-canvas {\n object-fit: cover;\n }\n ')),document.head.appendChild(e)},exports.checkIsHuawei=function(){var e=navigator.userAgent||navigator.vendor;return/huawei/i.test(e)||/honor/i.test(e)},exports.createHumanDom=function(i){var o=i.id,r=void 0===o?n:o,a=i.autoChromaKey,d=void 0!==a&&a,u=i.autoplay,c=void 0===u||u;if(document.getElementById(r))return console.error('DOM with id "'.concat(r,'" already exists.')),null;var p=document.createElement("div");p.className=t,p.id=t,p.style.position="relative";var s=document.createElement("video");s.id=r,s.width=0,s.height=0,s.setAttribute("width","100%"),s.setAttribute("height","100%"),s.setAttribute("data-playing","true"),s.setAttribute("playsinline","");var l=document.createElement("canvas");return l.id=e,Object.assign(l.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:d?"block":"none"}),c&&s.setAttribute("autoplay",""),d&&(s.style.visibility="hidden"),p.appendChild(s),p.appendChild(l),{playerWrapper:p,video:s}},exports.muteHumanVideo=function(e){var t=document.getElementById(n);return t&&(t.muted=e),t},exports.playHumanVideo=function(e){var t=document.getElementById(n);try{if(t)return e?t.play():t.pause()}catch(e){console.info(e)}},exports.removeHumanDom=function(){var e=document.getElementById(t);e&&e.parentNode&&e.parentNode.removeChild(e)};
1
+ "use strict";var t="starling-cutout-canvas",e="cloud-brtc-player-wrapper",n="remotevideo500";exports.DEFAULT_CANVAS_ID=t,exports.HUMAN_WRAPPER_ID=e,exports.RTC_VIDEO_ID=n,exports.appendRtcDomStyle=function(){var t=document.createElement("style");t.appendChild(document.createTextNode('\n [id^="videoremote1-"] {\n display: none !important;\n }\n \n video#remotevideo500 {\n width: auto !important;\n height: auto !important;\n max-width: 100% !important;\n max-height: 100% !important;\n width: 100% !important;\n height: 100% !important;\n object-fit: cover;\n }\n\n .cloud-brtc-player-wrapper {\n width: inherit !important;\n background-size: cover;\n height: inherit;\n display: flex;\n justify-content: center;\n }\n\n #starling-cutout-canvas {\n object-fit: cover;\n }\n ')),document.head.appendChild(t)},exports.checkIsHuawei=function(){var t=navigator.userAgent||navigator.vendor;return/huawei/i.test(t)||/honor/i.test(t)},exports.createHumanDom=function(i){var o=i.autoChromaKey,r=void 0!==o&&o,a=i.autoplay,d=void 0===a||a;if(document.getElementById(n))return console.error('DOM with id "'.concat(n,'" already exists.')),null;var u=document.createElement("div");u.className=e,u.id=e,u.style.position="relative";var c=document.createElement("video");c.id=n,c.width=0,c.height=0,c.setAttribute("width","100%"),c.setAttribute("height","100%"),c.setAttribute("data-playing","true"),c.setAttribute("playsinline","");var p=document.createElement("canvas");return p.id=t,Object.assign(p.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:r?"block":"none"}),d&&c.setAttribute("autoplay",""),r&&(c.style.visibility="hidden"),u.appendChild(c),u.appendChild(p),{playerWrapper:u,video:c}},exports.muteHumanVideo=function(t){var e=document.getElementById(n);return e&&(e.muted=t),e},exports.playHumanVideo=function(t){var e=document.getElementById(n);try{if(e)return t?e.play():e.pause()}catch(t){console.info(t)}},exports.removeHumanDom=function(){var t=document.getElementById(e);t&&t.parentNode&&t.parentNode.removeChild(t)};
package/es/BrtcClient.js CHANGED
@@ -1 +1 @@
1
- import{createClass as t,classCallCheck as o,defineProperty as e}from"./_virtual/_rollupPluginBabelHelpers.js";import n from"@bddh/starling-brtc";import{TimeoutController as c}from"@bddh/starling-timeout-controller";import i from"@bddh/starling-json";import a from"lodash/isEmpty";import r from"lodash/isFunction";import{statusEnum as l,errorTypeEnum as s}from"./interface.js";var d=t((function t(d){var m=this;o(this,t),e(this,"client",void 0),e(this,"isRtcVideoOn",!1),e(this,"rtcConnection",void 0),e(this,"rtcConfig",void 0),e(this,"bizConfig",void 0),e(this,"rtcCallback",void 0),e(this,"restarting",!1),e(this,"timeoutEvent",void 0),e(this,"reopenTimer",void 0),e(this,"restartCount",0),e(this,"closeLog",!0),e(this,"haveVideoOn",!1),e(this,"rtcStateCallback",null),e(this,"openRtc",(function(t){if(m.restarting)!m.closeLog&&console.warn("rtc restarting");else if(t&&(m.rtcConnection=t),m.rtcConnection&&!a(m.rtcConnection)){var o=m.rtcConnection,e=o.server,c=o.appId,d=o.token,u=o.roomName,C=o.userId,f=m.rtcCallback||{},b=f.onRemotedata,g=f.onLocalStream,v=f.onRemoteVideoComing,R=f.onLocalVideoPublished,h=f.onLocalVideoPublishing,L=f.onRemoteVideoOn,S=f.onRemoteVideoOff,k=f.onRemoteVideoLoading,y=f.onSuccess,p=f.onError,V=f.onLocalVideoConnected,E=f.onRemoteVideoConnected,_=f.onRemoteMediaState,O=f.onPlayingError,I=f.onDigitalHumanCallback;m.timeoutEvent.start(),m.rtcStateCallback=function(t){var o=t.body,e=t.action;I&&I({status:l.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:e,body:o}})},m.client=new n({roomName:u,token:d,userId:C,appId:c,server:e,rtcConfig:m.rtcConfig,callback:{onRemoteVideoConnected:function(o,e){if(!e&&!m.haveVideoOn)var n=setTimeout((function(){m.restartCount<3?(m.restartCount=++m.restartCount,m.restartRtc&&m.restartRtc(t)):(m.restartCount=0,m.closeRtc()),clearTimeout(n)}),500);if(e){var c=document.getElementById("remotevideo500");c.muted=!1;var i=c.play();void 0!==i&&i.catch((function(){c.muted=!0,c.play().catch((function(t){!m.closeLog&&console.info("videoElement play error",t),O&&O(c),I&&I({status:l.DH_LIB_ERROR,content:{type:s.LOCAL_VIDEO_ERROR}})})),I&&I({status:l.DH_LIB_STATUS,content:{type:s.LOCAL_VIDEO_MUTED}})}))}!m.closeLog&&console.info("remoteVideoConnected",o,e,m.restartCount),m.rtcStateCallback&&m.rtcStateCallback({action:"remoteVideoConnected",body:{id:o,connected:e,restartCount:m.restartCount}}),r(E)&&E(o,e)},onRemoteVideoOn:function(t){m.haveVideoOn=!0,!m.closeLog&&console.info("remotevideoon by id: ",t),m.timeoutEvent.clear();var o=document.querySelector("#starlingRtcContainer"),e=o&&o.lastChild;e&&(e.style.display="none"),m.rtcStateCallback&&m.rtcStateCallback({action:"remotevideoon",body:t}),I&&I({status:l.DH_LIB_OPEN}),r(L)&&L(t)},onRemoteMediaState:function(t,o,e){!m.closeLog&&console.info("remoteMediaState",t,o,e),m.rtcStateCallback&&m.rtcStateCallback({action:"remoteMediaState",body:{id:t,medium:o,connected:e}}),r(_)&&_(t,o,e)},onLocalVideoConnected:function(t){!m.closeLog&&console.info("localVideoConnected",t),m.rtcStateCallback&&m.rtcStateCallback({action:"localVideoConnected",body:{connected:t}}),r(V)&&V(t)},onRemotedata:function(t){if(m.rtcConfig&&m.rtcConfig.usingdatachannel){var o=i.parse(t);!m.closeLog&&console.info("RTC - receive:",o),r(b)&&b(o)}},onLocalStream:function(t,o){!m.closeLog&&console.info("rtc - onlocalstream by name: "+o),m.rtcStateCallback&&m.rtcStateCallback({action:"onlocalstream",body:{stream:t,name:o}}),r(g)&&g(t,o)},onLocalVideoPublished:function(){!m.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),m.rtcStateCallback&&m.rtcStateCallback({action:"localvideopublished_ok",body:!0}),r(R)&&R()},onLocalVideoPublishing:function(){!m.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),m.rtcStateCallback&&m.rtcStateCallback({action:"localvideopublishing",body:!0}),r(h)&&h()},onRemoteVideoComing:function(t){!m.closeLog&&console.info("remotevideocoming",t),m.rtcStateCallback&&m.rtcStateCallback({action:"remotevideocoming",body:t}),r(v)&&v(t)},onRemoteVideoLoading:function(t){!m.closeLog&&console.info("remotevideoloading by id: ",t),m.rtcStateCallback&&m.rtcStateCallback({action:"remotevideoloading",body:t}),r(k)&&k(t)},onRemoteVideoOff:function(t){!m.closeLog&&console.info("remotevideooff: ",t),m.isRtcVideoOn=!1,m.rtcStateCallback&&m.rtcStateCallback({action:"remotevideooff",body:t}),I&&I({status:l.DH_LIB_CLOSE}),r(S)&&S(t),m.timeoutEvent.start()},onSuccess:function(){!m.closeLog&&console.info("rtc - success"),m.rtcStateCallback&&m.rtcStateCallback({action:"success",body:!0}),r(y)&&y()},onError:function(o){m.isRtcVideoOn=!1,!m.closeLog&&console.error("rtc - error:",o),m.rtcStateCallback&&m.rtcStateCallback({action:"error",body:o}),I&&I({status:l.DH_LIB_ERROR,content:{type:s.RTC_ERROR}}),r(p)&&p(o),(o.includes("Lost connection to the server")||o.includes("Is the server down"))&&m.restartRtc&&m.restartRtc(t)}}})}})),e(this,"closeRtc",(function(){m.timeoutEvent.clear(),clearTimeout(m.reopenTimer),m.client&&m.client.destroy(),m.restarting=!1})),e(this,"restartRtc",(function(t){!m.restarting&&m.bizConfig&&m.bizConfig.autoReConnect&&(m.rtcStateCallback&&m.rtcStateCallback({action:"restartRtc",body:t}),m.restarting=!0,m.closeRtc(),m.reopenTimer=setTimeout((function(){!m.closeLog&&console.error("拉流失败,开始重启"),m.restarting=!1,m.openRtc(t)}),2e3))}));var u=d.rtcConnection,C=d.rtcConfig,f=d.closeLog,b=void 0===f||f,g=d.rtcCallback;this.rtcConnection=u,this.rtcConfig=C,this.rtcCallback=g,this.closeLog=b,this.timeoutEvent=new c(6e4,(function(){if(!m.rtcConnection)return!m.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");m.timeoutEvent.clear(),m.restartRtc&&m.restartRtc(m.rtcConnection)}))}));export{d as default};
1
+ import{createClass as t,classCallCheck as o,defineProperty as e}from"./_virtual/_rollupPluginBabelHelpers.js";import n from"@bddh/starling-brtc";import{TimeoutController as c}from"@bddh/starling-timeout-controller";import a from"@bddh/starling-json";import i from"lodash/isEmpty";import r from"lodash/isFunction";import{statusEnum as l,errorTypeEnum as s}from"./interface.js";var d=t((function t(d){var m=this;o(this,t),e(this,"client",void 0),e(this,"isRtcVideoOn",!1),e(this,"rtcConnection",void 0),e(this,"rtcConfig",void 0),e(this,"bizConfig",void 0),e(this,"rtcCallback",void 0),e(this,"restarting",!1),e(this,"timeoutEvent",void 0),e(this,"reopenTimer",void 0),e(this,"restartCount",0),e(this,"closeLog",!0),e(this,"haveVideoOn",!1),e(this,"rtcStateCallback",null),e(this,"openRtc",(function(t){if(m.restarting)!m.closeLog&&console.warn("rtc restarting");else if(t&&(m.rtcConnection=t),m.rtcConnection&&!i(m.rtcConnection)){var o=m.rtcConnection,e=o.server,c=o.appId,d=o.token,u=o.roomName,C=o.userId,f=m.rtcCallback||{},b=f.onRemotedata,g=f.onLocalStream,v=f.onRemoteVideoComing,R=f.onLocalVideoPublished,h=f.onLocalVideoPublishing,L=f.onRemoteVideoOn,S=f.onRemoteVideoOff,k=f.onRemoteVideoLoading,y=f.onSuccess,p=f.onError,V=f.onLocalVideoConnected,E=f.onRemoteVideoConnected,_=f.onRemoteMediaState,O=f.onPlayingError,I=f.onDigitalHumanCallback;m.timeoutEvent.start(),m.rtcStateCallback=function(t){var o=t.body,e=t.action;I&&I({status:l.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:e,body:o}})},m.client=new n({roomName:u,token:d,userId:C,appId:c,server:e,rtcConfig:m.rtcConfig,callback:{onRemoteVideoConnected:function(o,e){if(!e&&!m.haveVideoOn)var n=setTimeout((function(){m.restartCount<3?(m.restartCount=++m.restartCount,m.restartRtc&&m.restartRtc(t)):(m.restartCount=0,m.closeRtc()),clearTimeout(n)}),500);if(e){var c=document.getElementById("remotevideo500");c.muted=!1;var a=c.play();void 0!==a&&a.catch((function(){c.muted=!0,c.play().catch((function(t){!m.closeLog&&console.info("videoElement play error",t),O&&O(c),I&&I({status:l.DH_LIB_ERROR,content:{type:s.LOCAL_VIDEO_ERROR}})})),I&&I({status:l.DH_LIB_STATUS,content:{type:s.LOCAL_VIDEO_MUTED}})}))}!m.closeLog&&console.info("remoteVideoConnected",o,e,m.restartCount),m.rtcStateCallback&&m.rtcStateCallback({action:"remoteVideoConnected",body:{id:o,connected:e,restartCount:m.restartCount}}),r(E)&&E(o,e)},onRemoteVideoOn:function(t){m.haveVideoOn=!0,!m.closeLog&&console.info("remotevideoon by id: ",t),m.timeoutEvent.clear();var o=document.querySelector("#starlingRtcContainer"),e=o&&o.lastChild;e&&(e.style.display="none"),m.rtcStateCallback&&m.rtcStateCallback({action:"remotevideoon",body:t}),I&&I({status:l.DH_LIB_OPEN}),r(L)&&L(t)},onRemoteMediaState:function(t,o,e){!m.closeLog&&console.info("remoteMediaState",t,o,e),m.rtcStateCallback&&m.rtcStateCallback({action:"remoteMediaState",body:{id:t,medium:o,connected:e}}),r(_)&&_(t,o,e)},onLocalVideoConnected:function(t){!m.closeLog&&console.info("localVideoConnected",t),m.rtcStateCallback&&m.rtcStateCallback({action:"localVideoConnected",body:{connected:t}}),r(V)&&V(t)},onRemotedata:function(t){if(m.rtcConfig&&m.rtcConfig.usingdatachannel){var o=a.parse(t);!m.closeLog&&console.info("RTC - receive:",o),r(b)&&b(o)}},onLocalStream:function(t,o){!m.closeLog&&console.info("rtc - onlocalstream by name: "+o),m.rtcStateCallback&&m.rtcStateCallback({action:"onlocalstream",body:{stream:t,name:o}}),r(g)&&g(t,o)},onLocalVideoPublished:function(){!m.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),m.rtcStateCallback&&m.rtcStateCallback({action:"localvideopublished_ok",body:!0}),r(R)&&R()},onLocalVideoPublishing:function(){!m.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),m.rtcStateCallback&&m.rtcStateCallback({action:"localvideopublishing",body:!0}),r(h)&&h()},onRemoteVideoComing:function(t){!m.closeLog&&console.info("remotevideocoming",t),m.rtcStateCallback&&m.rtcStateCallback({action:"remotevideocoming",body:t}),r(v)&&v(t)},onRemoteVideoLoading:function(t){!m.closeLog&&console.info("remotevideoloading by id: ",t),m.rtcStateCallback&&m.rtcStateCallback({action:"remotevideoloading",body:t}),r(k)&&k(t)},onRemoteVideoOff:function(t){var o=document.getElementById("remotevideo500");o&&o.pause(),!m.closeLog&&console.info("remotevideooff: ",t),m.isRtcVideoOn=!1,m.rtcStateCallback&&m.rtcStateCallback({action:"remotevideooff",body:t}),I&&I({status:l.DH_LIB_CLOSE}),r(S)&&S(t),m.timeoutEvent.start()},onSuccess:function(){!m.closeLog&&console.info("rtc - success"),m.rtcStateCallback&&m.rtcStateCallback({action:"success",body:!0}),r(y)&&y()},onError:function(o){m.isRtcVideoOn=!1,!m.closeLog&&console.error("rtc - error:",o),m.rtcStateCallback&&m.rtcStateCallback({action:"error",body:o}),I&&I({status:l.DH_LIB_ERROR,content:{type:s.RTC_ERROR}}),r(p)&&p(o),(o.includes("Lost connection to the server")||o.includes("Is the server down"))&&m.restartRtc&&m.restartRtc(t)}}})}})),e(this,"closeRtc",(function(){m.timeoutEvent.clear(),clearTimeout(m.reopenTimer),m.client&&m.client.destroy(),m.restarting=!1})),e(this,"restartRtc",(function(t){!m.restarting&&m.bizConfig&&m.bizConfig.autoReConnect&&(m.rtcStateCallback&&m.rtcStateCallback({action:"restartRtc",body:t}),m.restarting=!0,m.closeRtc(),m.reopenTimer=setTimeout((function(){!m.closeLog&&console.error("拉流失败,开始重启"),m.restarting=!1,m.openRtc(t)}),2e3))}));var u=d.rtcConnection,C=d.rtcConfig,f=d.closeLog,b=void 0===f||f,g=d.rtcCallback;this.rtcConnection=u,this.rtcConfig=C,this.rtcCallback=g,this.closeLog=b,this.timeoutEvent=new c(6e4,(function(){if(!m.rtcConnection)return!m.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");m.timeoutEvent.clear(),m.restartRtc&&m.restartRtc(m.rtcConnection)}))}));export{d as default};
package/es/DomControl.js CHANGED
@@ -1 +1 @@
1
- var t="starling-cutout-canvas",e="cloud-brtc-player-wrapper",n="remotevideo500";function i(i){var a=i.id,o=void 0===a?n:a,r=i.autoChromaKey,d=void 0!==r&&r,u=i.autoplay,c=void 0===u||u;if(document.getElementById(o))return console.error('DOM with id "'.concat(o,'" already exists.')),null;var l=document.createElement("div");l.className=e,l.id=e,l.style.position="relative";var p=document.createElement("video");p.id=o,p.width=0,p.height=0,p.setAttribute("width","100%"),p.setAttribute("height","100%"),p.setAttribute("data-playing","true"),p.setAttribute("playsinline","");var s=document.createElement("canvas");return s.id=t,Object.assign(s.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:d?"block":"none"}),c&&p.setAttribute("autoplay",""),d&&(p.style.visibility="hidden"),l.appendChild(p),l.appendChild(s),{playerWrapper:l,video:p}}function a(){var t=document.getElementById(e);t&&t.parentNode&&t.parentNode.removeChild(t)}function o(t){var e=document.getElementById(n);return e&&(e.muted=t),e}function r(t){var e=document.getElementById(n);try{if(e)return t?e.play():e.pause()}catch(t){console.info(t)}}function d(){var t=navigator.userAgent||navigator.vendor;return/huawei/i.test(t)||/honor/i.test(t)}function u(){var t=document.createElement("style");t.appendChild(document.createTextNode('\n [id^="videoremote1-"] {\n display: none !important;\n }\n \n video#remotevideo500 {\n width: auto !important;\n height: auto !important;\n max-width: 100% !important;\n max-height: 100% !important;\n }\n\n .cloud-brtc-player-wrapper {\n width: inherit !important;\n background-size: cover;\n height: inherit;\n display: flex;\n justify-content: center;\n }\n\n #starling-cutout-canvas {\n object-fit: cover;\n }\n ')),document.head.appendChild(t)}export{t as DEFAULT_CANVAS_ID,e as HUMAN_WRAPPER_ID,n as RTC_VIDEO_ID,u as appendRtcDomStyle,d as checkIsHuawei,i as createHumanDom,o as muteHumanVideo,r as playHumanVideo,a as removeHumanDom};
1
+ var t="starling-cutout-canvas",e="cloud-brtc-player-wrapper",n="remotevideo500";function i(i){var a=i.autoChromaKey,o=void 0!==a&&a,r=i.autoplay,d=void 0===r||r;if(document.getElementById(n))return console.error('DOM with id "'.concat(n,'" already exists.')),null;var c=document.createElement("div");c.className=e,c.id=e,c.style.position="relative";var u=document.createElement("video");u.id=n,u.width=0,u.height=0,u.setAttribute("width","100%"),u.setAttribute("height","100%"),u.setAttribute("data-playing","true"),u.setAttribute("playsinline","");var l=document.createElement("canvas");return l.id=t,Object.assign(l.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:o?"block":"none"}),d&&u.setAttribute("autoplay",""),o&&(u.style.visibility="hidden"),c.appendChild(u),c.appendChild(l),{playerWrapper:c,video:u}}function a(){var t=document.getElementById(e);t&&t.parentNode&&t.parentNode.removeChild(t)}function o(t){var e=document.getElementById(n);return e&&(e.muted=t),e}function r(t){var e=document.getElementById(n);try{if(e)return t?e.play():e.pause()}catch(t){console.info(t)}}function d(){var t=navigator.userAgent||navigator.vendor;return/huawei/i.test(t)||/honor/i.test(t)}function c(){var t=document.createElement("style");t.appendChild(document.createTextNode('\n [id^="videoremote1-"] {\n display: none !important;\n }\n \n video#remotevideo500 {\n width: auto !important;\n height: auto !important;\n max-width: 100% !important;\n max-height: 100% !important;\n width: 100% !important;\n height: 100% !important;\n object-fit: cover;\n }\n\n .cloud-brtc-player-wrapper {\n width: inherit !important;\n background-size: cover;\n height: inherit;\n display: flex;\n justify-content: center;\n }\n\n #starling-cutout-canvas {\n object-fit: cover;\n }\n ')),document.head.appendChild(t)}export{t as DEFAULT_CANVAS_ID,e as HUMAN_WRAPPER_ID,n as RTC_VIDEO_ID,c as appendRtcDomStyle,d as checkIsHuawei,i as createHumanDom,o as muteHumanVideo,r as playHumanVideo,a as removeHumanDom};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bddh/starling-realtime-client",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "keywords": [
5
5
  "react",
6
6
  "indexDB"
@@ -44,5 +44,5 @@
44
44
  "lodash": "^4.17.21",
45
45
  "uuid": "^9.0.0"
46
46
  },
47
- "gitHead": "d688dfc3e88d91657047342c30f89d2de81efee5"
47
+ "gitHead": "1fb3029720c63874413631a26bb84d4a50071148"
48
48
  }