@bddh/starling-realtime-client 1.0.8-beta.1 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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"),i=require("@bddh/starling-json"),n=require("lodash/isEmpty"),s=require("lodash/isFunction"),r=require("./interface.js");exports.default=class{constructor(c){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",(t=>{if(this.restarting)!this.closeLog&&console.warn("rtc restarting");else if(t&&(this.rtcConnection=t),this.rtcConnection&&!n(this.rtcConnection)){const{server:o,appId:n,token:c,roomName:a,userId:l}=this.rtcConnection,{onRemotedata:d,onLocalStream:h,onRemoteVideoComing:u,onLocalVideoPublished:C,onLocalVideoPublishing:m,onRemoteVideoOn:b,onRemoteVideoOff:g,onRemoteVideoLoading:f,onSuccess:y,onError:R,onLocalVideoConnected:L,onRemoteVideoConnected:p,onRemoteMediaState:S,onPlayingError:v,onDigitalHumanCallback:k}=this.rtcCallback||{};this.timeoutEvent.start(),this.rtcStateCallback=t=>{const{body:e,action:o}=t;k&&k({status:r.statusEnum.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:o,body:e}})},this.client=new e({roomName:a,token:c,userId:l,appId:n,server:o,rtcConfig:this.rtcConfig,callback:{onRemoteVideoConnected:(e,o)=>{if(!o&&!this.haveVideoOn){let e=setTimeout((()=>{this.restartCount<3?(this.restartCount=++this.restartCount,this.restartRtc&&this.restartRtc(t)):(this.restartCount=0,this.closeRtc()),clearTimeout(e)}),500)}if(o){const t=document.getElementById("remotevideo500");t.muted=!1;let e=t.play();void 0!==e&&e.catch((()=>{t.muted=!0,t.play().catch((e=>{!this.closeLog&&console.info("videoElement play error",e),v&&v(t),k&&k({status:r.statusEnum.DH_LIB_ERROR,content:{type:r.errorTypeEnum.LOCAL_VIDEO_ERROR}})})),k&&k({status:r.statusEnum.DH_LIB_STATUS,content:{type:r.errorTypeEnum.LOCAL_VIDEO_MUTED}})}))}!this.closeLog&&console.info("remoteVideoConnected",e,o,this.restartCount),this.rtcStateCallback&&this.rtcStateCallback({action:"remoteVideoConnected",body:{id:e,connected:o,restartCount:this.restartCount}}),s(p)&&p(e,o)},onRemoteVideoOn:t=>{this.haveVideoOn=!0,!this.closeLog&&console.info("remotevideoon by id: ",t),this.timeoutEvent.clear();const e=document.querySelector("#starlingRtcContainer"),o=e&&e.lastChild;o&&(o.style.display="none"),this.rtcStateCallback&&this.rtcStateCallback({action:"remotevideoon",body:t}),k&&k({status:r.statusEnum.DH_LIB_OPEN}),s(b)&&b(t)},onRemoteMediaState:(t,e,o)=>{!this.closeLog&&console.info("remoteMediaState",t,e,o),this.rtcStateCallback&&this.rtcStateCallback({action:"remoteMediaState",body:{id:t,medium:e,connected:o}}),s(S)&&S(t,e,o)},onLocalVideoConnected:t=>{!this.closeLog&&console.info("localVideoConnected",t),this.rtcStateCallback&&this.rtcStateCallback({action:"localVideoConnected",body:{connected:t}}),s(L)&&L(t)},onRemotedata:t=>{if(this.rtcConfig&&this.rtcConfig.usingdatachannel){const e=i.parse(t);!this.closeLog&&console.info("RTC - receive:",e),s(d)&&d(e)}},onLocalStream:(t,e)=>{!this.closeLog&&console.info("rtc - onlocalstream by name: "+e),this.rtcStateCallback&&this.rtcStateCallback({action:"onlocalstream",body:{stream:t,name:e}}),s(h)&&h(t,e)},onLocalVideoPublished:()=>{!this.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),this.rtcStateCallback&&this.rtcStateCallback({action:"localvideopublished_ok",body:!0}),s(C)&&C()},onLocalVideoPublishing:()=>{!this.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),this.rtcStateCallback&&this.rtcStateCallback({action:"localvideopublishing",body:!0}),s(m)&&m()},onRemoteVideoComing:t=>{!this.closeLog&&console.info("remotevideocoming",t),this.rtcStateCallback&&this.rtcStateCallback({action:"remotevideocoming",body:t}),s(u)&&u(t)},onRemoteVideoLoading:t=>{!this.closeLog&&console.info("remotevideoloading by id: ",t),this.rtcStateCallback&&this.rtcStateCallback({action:"remotevideoloading",body:t}),s(f)&&f(t)},onRemoteVideoOff:t=>{!this.closeLog&&console.info("remotevideooff: ",t),this.isRtcVideoOn=!1,this.rtcStateCallback&&this.rtcStateCallback({action:"remotevideooff",body:t}),k&&k({status:r.statusEnum.DH_LIB_CLOSE}),s(g)&&g(t),this.timeoutEvent.start()},onSuccess:()=>{!this.closeLog&&console.info("rtc - success"),this.rtcStateCallback&&this.rtcStateCallback({action:"success",body:!0}),s(y)&&y()},onError:e=>{this.isRtcVideoOn=!1,!this.closeLog&&console.error("rtc - error:",e),this.rtcStateCallback&&this.rtcStateCallback({action:"error",body:e}),k&&k({status:r.statusEnum.DH_LIB_ERROR,content:{type:r.errorTypeEnum.RTC_ERROR}}),s(R)&&R(e),(e.includes("Lost connection to the server")||e.includes("Is the server down"))&&this.restartRtc&&this.restartRtc(t)}}})}})),t.defineProperty(this,"closeRtc",(()=>{this.timeoutEvent.clear(),clearTimeout(this.reopenTimer),this.client&&this.client.destroy(),this.restarting=!1})),t.defineProperty(this,"restartRtc",(t=>{!this.restarting&&this.bizConfig&&this.bizConfig.autoReConnect&&(this.rtcStateCallback&&this.rtcStateCallback({action:"restartRtc",body:t}),this.restarting=!0,this.closeRtc(),this.reopenTimer=setTimeout((()=>{!this.closeLog&&console.error("拉流失败,开始重启"),this.restarting=!1,this.openRtc(t)}),2e3))}));const{rtcConnection:a,rtcConfig:l,closeLog:d=!0,rtcCallback:h}=c;this.rtcConnection=a,this.rtcConfig=l,this.rtcCallback=h,this.closeLog=d,this.timeoutEvent=new o.TimeoutController(6e4,(()=>{if(!this.rtcConnection)return!this.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");this.timeoutEvent.clear(),this.restartRtc&&this.restartRtc(this.rtcConnection)}))}};
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;
package/cjs/Client.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),t=require("@bddh/starling-json"),r=require("lodash/isEmpty"),i=require("lodash/omit"),s=require("lodash/pick"),n=require("uuid"),a=require("./interface.js"),o=require("./Server.js"),d=require("./BrtcClient.js"),c=require("./DomControl.js"),h=require("./Cutout.js");exports.default=class{constructor(u){e.defineProperty(this,"token",void 0),e.defineProperty(this,"appKey",void 0),e.defineProperty(this,"appId",void 0),e.defineProperty(this,"connectParams",void 0),e.defineProperty(this,"onDigitalHumanCallback",void 0),e.defineProperty(this,"dhServer",void 0),e.defineProperty(this,"rtcServer",void 0),e.defineProperty(this,"rtcConnectParams",void 0),e.defineProperty(this,"cutoutInstance",void 0),e.defineProperty(this,"isHuawei",c.checkIsHuawei()),e.defineProperty(this,"rtcServerUrl",void 0),e.defineProperty(this,"onRemoteVideoComing",(e=>{this.rtcConnectParams&&this.rtcConnectParams.feedId&&e===+this.rtcConnectParams.feedId&&this.rtcServer&&this.rtcServer.client&&this.rtcServer.client.subscribeStreaming("remotevideo500",+this.rtcConnectParams.feedId)})),e.defineProperty(this,"onRemoteVideoOn",(()=>{setTimeout((async()=>{const e=document.getElementById(c.RTC_VIDEO_ID);if(await(this.cutoutInstance&&this.cutoutInstance.updateSource(c.RTC_VIDEO_ID)),e){e.setAttribute("data-playing","true");const{videoWidth:t,videoHeight:r}=e,i=document.getElementById(c.DEFAULT_CANVAS_ID),s=i.getContext("2d");i&&s&&(i.width=t,i.height=r,s.drawImage(e,0,0,t,r))}}),100)})),e.defineProperty(this,"connectListener",(e=>{const{code:r,body:i,message:s}=e;if(0===r&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:a.statusEnum.DH_LIB_WS_SUCCESS,content:e}),0===r){const e=t.parse(i),{rtcServerUrl:r,appId:s,clientToken:n,roomName:a,clientId:o,feedId:d,chargeId:c}=e;s&&a&&(this.rtcConnectParams={server:this.rtcServerUrl||r,appId:s,token:n,roomName:a,userId:o,feedId:d,chargeId:c},this.rtcServer&&this.rtcServer.openRtc(this.rtcConnectParams))}else this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:a.statusEnum.DH_LIB_ERROR,content:{type:a.errorTypeEnum.CONNECT_ERROR,msg:{code:r,errMsg:s}}})})),e.defineProperty(this,"createServer",(e=>{this.dhServer&&this.dhServer.createSocket({token:this.token,appKey:this.appKey,appId:this.appId,...e?{sessionId:e}:{},...s(this.connectParams,a.CONNECT_MAIN_KEY),parameters:i(this.connectParams,a.CONNECT_MAIN_KEY),onConnect:this.connectListener,onDigitalHumanCallback:this.onDigitalHumanCallback})})),e.defineProperty(this,"checkHumanInstansce",(()=>{this.dhServer||console.warn("请先初始化数字人示例")})),e.defineProperty(this,"sendMessage",((e,t)=>this.dhServer&&this.dhServer.sendMessage(e,t))),e.defineProperty(this,"interrupt",(async()=>new Promise((e=>{this.dhServer&&this.dhServer.sendMessage({requestId:n.v4(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(()=>e()))})))),e.defineProperty(this,"textRender",(e=>{const{requestId:t,body:r,onCallbackMsg:i}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:t||n.v4(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},i)})),e.defineProperty(this,"textStreamRender",(e=>{const{requestId:r,body:i,onCallbackMsg:s}=e,{first:a}=t.parse(i);this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:r||n.v4(),action:"TEXT_STREAM_RENDER",body:i,clientTs:(new Date).getTime()},a?s:null)})),e.defineProperty(this,"audioRender",(e=>{const{body:t,onCallbackMsg:r}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:n.v4(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},r)})),e.defineProperty(this,"audioStreamRender",(e=>{const{requestId:t,body:r,onCallbackMsg:i}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:t||n.v4(),action:"AUDIO_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},i)})),e.defineProperty(this,"destory",(async()=>{await(this.dhServer&&this.dhServer.closeSocket()),this.rtcServer&&this.rtcServer.closeRtc(),c.removeHumanDom(),this.dhServer=null,this.rtcServer=null})),e.defineProperty(this,"pauseHuman",(()=>c.playHumanVideo(!1))),e.defineProperty(this,"playHuman",(()=>c.playHumanVideo(!0))),e.defineProperty(this,"muteHuman",(()=>c.muteHumanVideo(!0))),e.defineProperty(this,"unMuteHuman",(()=>{const e=c.muteHumanVideo(!1);try{return this.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));const{wrapperId:l,token:m,appKey:p,appId:y,connectParams:v,renderParams:I,rtcConnectParams:g,brtcParams:S,wsUrl:C,rtcServerUrl:f,onDigitalHumanCallback:P}=u;this.token=m,this.appKey=p,this.appId=y,this.rtcServerUrl=f,this.connectParams={autoChromaKey:I.autoChromaKey,...v};const{fullStatus:D,closeLog:b}=I;this.onDigitalHumanCallback=e=>{const{status:t}=e;t!==a.statusEnum.DH_LIB_FULL_STATUS?P&&P(e):D&&P&&P(e)},this.dhServer=new o.default(C||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration");const{playerWrapper:E}=c.createHumanDom({autoChromaKey:!!I.autoChromaKey})||{},H=document.getElementById(l);H||console.error("dom with wrapperId is not find"),E&&H&&H.appendChild(E),c.appendRtcDomStyle(),this.rtcServer=new d.default({closeLog:b,videoWrapperId:c.RTC_VIDEO_ID,rtcConfig:{remotevideoviewid:l,showvideobps:!1,usingvideo:!1,usingaudio:!1,aspublisher:!1,usingdatachannel:!0,autoplaymuted:!1,...S},bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new h.default({sourceId:c.RTC_VIDEO_ID}),r(g)||(this.rtcConnectParams=g,this.rtcServer.openRtc(g))}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),r=require("@bddh/starling-json"),t=require("lodash/isEmpty"),n=require("lodash/omit"),a=require("lodash/pick"),o=require("uuid"),i=require("./interface.js"),s=require("./Server.js"),c=require("./BrtcClient.js"),d=require("./DomControl.js"),u=require("./Cutout.js"),l=e.createClass((function l(p){var m=this;e.classCallCheck(this,l),e.defineProperty(this,"token",void 0),e.defineProperty(this,"appKey",void 0),e.defineProperty(this,"appId",void 0),e.defineProperty(this,"connectParams",void 0),e.defineProperty(this,"onDigitalHumanCallback",void 0),e.defineProperty(this,"dhServer",void 0),e.defineProperty(this,"rtcServer",void 0),e.defineProperty(this,"rtcConnectParams",void 0),e.defineProperty(this,"cutoutInstance",void 0),e.defineProperty(this,"isHuawei",d.checkIsHuawei()),e.defineProperty(this,"rtcServerUrl",void 0),e.defineProperty(this,"onRemoteVideoComing",(function(e){m.rtcConnectParams&&m.rtcConnectParams.feedId&&e===+m.rtcConnectParams.feedId&&m.rtcServer&&m.rtcServer.client&&m.rtcServer.client.subscribeStreaming("remotevideo500",+m.rtcConnectParams.feedId)})),e.defineProperty(this,"onRemoteVideoOn",(function(){setTimeout(e.asyncToGenerator(e.regeneratorRuntime().mark((function r(){var t,n,a,o,i;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=document.getElementById(d.RTC_VIDEO_ID),e.next=3,m.cutoutInstance&&m.cutoutInstance.updateSource(d.RTC_VIDEO_ID);case 3:t&&(t.setAttribute("data-playing","true"),n=t.videoWidth,a=t.videoHeight,o=document.getElementById(d.DEFAULT_CANVAS_ID),i=o.getContext("2d"),o&&i&&(o.width=n,o.height=a,i.drawImage(t,0,0,n,a)));case 4:case"end":return e.stop()}}),r)}))),100)})),e.defineProperty(this,"connectListener",(function(e){var t=e.code,n=e.body,a=e.message;if(0===t&&m.onDigitalHumanCallback&&m.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_WS_SUCCESS,content:e}),0===t){var o=r.parse(n),s=o.rtcServerUrl,c=o.appId,d=o.clientToken,u=o.roomName,l=o.clientId,p=o.feedId,h=o.chargeId;c&&u&&(m.rtcConnectParams={server:m.rtcServerUrl||s,appId:c,token:d,roomName:u,userId:l,feedId:p,chargeId:h},m.rtcServer&&m.rtcServer.openRtc(m.rtcConnectParams))}else m.onDigitalHumanCallback&&m.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:t,errMsg:a}}})})),e.defineProperty(this,"createServer",(function(r){m.dhServer&&m.dhServer.createSocket(e.objectSpread2(e.objectSpread2(e.objectSpread2({token:m.token,appKey:m.appKey,appId:m.appId},r?{sessionId:r}:{}),a(m.connectParams,i.CONNECT_MAIN_KEY)),{},{parameters:n(m.connectParams,i.CONNECT_MAIN_KEY),onConnect:m.connectListener,onDigitalHumanCallback:m.onDigitalHumanCallback}))})),e.defineProperty(this,"checkHumanInstansce",(function(){m.dhServer||console.warn("请先初始化数字人示例")})),e.defineProperty(this,"sendMessage",(function(e,r){return m.dhServer&&m.dhServer.sendMessage(e,r)})),e.defineProperty(this,"interrupt",e.asyncToGenerator(e.regeneratorRuntime().mark((function r(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){m.dhServer&&m.dhServer.sendMessage({requestId:o.v4(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(function(){return e()}))})));case 1:case"end":return e.stop()}}),r)})))),e.defineProperty(this,"textRender",(function(e){var r=e.requestId,t=e.body,n=e.onCallbackMsg;m.checkHumanInstansce(),m.dhServer&&m.dhServer.sendMessage({requestId:r||o.v4(),action:"TEXT_RENDER",body:t,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"textStreamRender",(function(e){var t=e.requestId,n=e.body,a=e.onCallbackMsg,i=r.parse(n).first;m.checkHumanInstansce(),m.dhServer&&m.dhServer.sendMessage({requestId:t||o.v4(),action:"TEXT_STREAM_RENDER",body:n,clientTs:(new Date).getTime()},i?a:null)})),e.defineProperty(this,"audioRender",(function(e){var r=e.body,t=e.onCallbackMsg;m.checkHumanInstansce(),m.dhServer&&m.dhServer.sendMessage({requestId:o.v4(),action:"AUDIO_RENDER",body:r,clientTs:(new Date).getTime()},t)})),e.defineProperty(this,"audioStreamRender",(function(e){var r=e.requestId,t=e.body,n=e.onCallbackMsg;m.checkHumanInstansce(),m.dhServer&&m.dhServer.sendMessage({requestId:r||o.v4(),action:"AUDIO_STREAM_RENDER",body:t,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"destory",e.asyncToGenerator(e.regeneratorRuntime().mark((function r(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,m.dhServer&&m.dhServer.closeSocket();case 2:m.rtcServer&&m.rtcServer.closeRtc(),d.removeHumanDom(),m.dhServer=null,m.rtcServer=null;case 6:case"end":return e.stop()}}),r)})))),e.defineProperty(this,"pauseHuman",(function(){return d.playHumanVideo(!1)})),e.defineProperty(this,"playHuman",(function(){return d.playHumanVideo(!0)})),e.defineProperty(this,"muteHuman",(function(){return d.muteHumanVideo(!0)})),e.defineProperty(this,"unMuteHuman",(function(){var e=d.muteHumanVideo(!1);try{return m.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));var h=p.wrapperId,v=p.token,f=p.appKey,y=p.appId,g=p.connectParams,S=p.renderParams,I=p.rtcConnectParams,C=p.brtcParams,P=p.wsUrl,b=p.rtcServerUrl,D=p.onDigitalHumanCallback;this.token=v,this.appKey=f,this.appId=y,this.rtcServerUrl=b,this.connectParams=e.objectSpread2({autoChromaKey:S.autoChromaKey},g);var R=S.fullStatus,k=S.closeLog;this.onDigitalHumanCallback=function(e){e.status!==i.statusEnum.DH_LIB_FULL_STATUS?D&&D(e):R&&D&&D(e)},this.dhServer=new s.default(P||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration");var E=(d.createHumanDom({autoChromaKey:!!S.autoChromaKey})||{}).playerWrapper,H=document.getElementById(h);H||console.error("dom with wrapperId is not find"),E&&H&&H.appendChild(E),d.appendRtcDomStyle(),this.rtcServer=new c.default({closeLog:k,videoWrapperId:d.RTC_VIDEO_ID,rtcConfig:e.objectSpread2({remotevideoviewid:h,showvideobps:!1,usingvideo:!1,usingaudio:!1,aspublisher:!1,usingdatachannel:!0,autoplaymuted:!1},C),bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new u.default({sourceId:d.RTC_VIDEO_ID}),t(I)||(this.rtcConnectParams=I,this.rtcServer.openRtc(I))}));exports.default=l;
package/cjs/Cutout.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./_virtual/_rollupPluginBabelHelpers.js"),e=require("@bddh/starling-cutout/es/Seriously");const s={version:2,chromaKey:{screen:[53,186,123],similarity:90,edgeShrink:3,smoothness:80,spill:100,opacity:1,contrast:0,brightness:0,gamma:0}};exports.DEFAULT_EFFECTS=s,exports.default=class{constructor(r){t.defineProperty(this,"cutoutInstance",void 0);const{effects:o,sourceId:u}=r;this.cutoutInstance=new e("starling-cutout-canvas",u||"starling-cutout-video",o&&o.chromaKey||s.chromaKey,o&&o.version||s.version)}setOptions(t){t&&this.cutoutInstance&&this.cutoutInstance.setOptions(t)}destroy(){return this.cutoutInstance.destroy()}updateSource(t){return this.cutoutInstance.updateSource(t)}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./_virtual/_rollupPluginBabelHelpers.js"),e=require("@bddh/starling-cutout/es/Seriously"),s={version:2,chromaKey:{screen:[53,186,123],similarity:90,edgeShrink:3,smoothness:80,spill:100,opacity:1,contrast:0,brightness:0,gamma:0}},r=function(){function r(u){t.classCallCheck(this,r),t.defineProperty(this,"cutoutInstance",void 0);var n=u.effects,o=u.sourceId;this.cutoutInstance=new e("starling-cutout-canvas",o||"starling-cutout-video",n&&n.chromaKey||s.chromaKey,n&&n.version||s.version)}return t.createClass(r,[{key:"setOptions",value:function(t){t&&this.cutoutInstance&&this.cutoutInstance.setOptions(t)}},{key:"destroy",value:function(){return this.cutoutInstance.destroy()}},{key:"updateSource",value:function(t){return this.cutoutInstance.updateSource(t)}}]),r}();exports.DEFAULT_EFFECTS=s,exports.default=r;
package/cjs/DomControl.js CHANGED
@@ -1 +1 @@
1
- "use strict";const 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(){const 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)},exports.checkIsHuawei=function(){const t=navigator.userAgent||navigator.vendor;return/huawei/i.test(t)||/honor/i.test(t)},exports.createHumanDom=function(o){const{id:i=n,autoChromaKey:r=!1,autoplay:a=!0}=o;if(document.getElementById(i))return console.error(`DOM with id "${i}" already exists.`),null;const d=document.createElement("div");d.className=e,d.id=e,d.style.position="relative";const c=document.createElement("video");c.id=i,c.width=0,c.height=0,c.setAttribute("width","100%"),c.setAttribute("height","100%"),c.setAttribute("data-playing","true"),c.setAttribute("playsinline","");const 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:r?"block":"none"}),a&&c.setAttribute("autoplay",""),r&&(c.style.visibility="hidden"),d.appendChild(c),d.appendChild(s),{playerWrapper:d,video:c}},exports.muteHumanVideo=function(t){const e=document.getElementById(n);return e&&(e.muted=t),e},exports.playHumanVideo=function(t){const e=document.getElementById(n);try{if(e)return t?e.play():e.pause()}catch(t){console.info(t)}},exports.removeHumanDom=function(){const t=document.getElementById(e);t&&t.parentNode&&t.parentNode.removeChild(t)};
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)};
package/cjs/Server.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),t=require("uuid"),s=require("@bddh/starling-web-socket/es/create-web-socket"),r=require("lodash/pick"),o=require("lodash/omit"),n=require("./interface.js");exports.default=class{constructor(i){e.defineProperty(this,"dhServerSocket",null),e.defineProperty(this,"socketClosingPromise",null),e.defineProperty(this,"url",void 0),e.defineProperty(this,"firstConnect",!0),e.defineProperty(this,"connectParams",null),e.defineProperty(this,"createSocket",(async e=>{this.connectParams=e;const{token:r,sessionId:o,onConnect:i,onDigitalHumanCallback:c}=e;return this.socketClosingPromise&&await this.socketClosingPromise,this.dhServerSocket&&await this.closeSocket(),new Promise(((e,a)=>{const h=s.createWebSocket(this.url,{reopen:!0,keepAlive:"heartbeat",combine:(e,t)=>e&&t&&e.requestId===t.requestId,onOpen:()=>{if(this.dhServerSocket=h,o&&this.firstConnect)return h.request({action:"RE_CONNECT",requestId:t.v4(),body:JSON.stringify({token:r,sessionId:o})}).on(((t,s)=>{i(t),0!==t.code&&(s(),this.handleConnect()),e(h)})),void(this.firstConnect=!1);this.handleConnect()},onClose:()=>{this.dhServerSocket=null,this.socketClosingPromise=null},onError:e=>{a(e)}});h.onReadyStateChange((e=>{0===e&&c&&c({status:n.statusEnum.DH_LIB_INIT}),c&&c({status:n.statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:n.WS_STATUS_MAP[e]}})})),h.onMessage((e=>{const{action:t}=e;[n.errorTypeEnum.TIMEOUT_EXIT,n.errorTypeEnum.DISCONNECT_ALERT].includes(t)&&c&&c({status:n.statusEnum.DH_LIB_STATUS,content:{type:t}})})),h.open()}))})),e.defineProperty(this,"closeSocket",(async()=>{this.dhServerSocket&&(this.socketClosingPromise=this.dhServerSocket.close(),await this.socketClosingPromise,this.dhServerSocket=null)})),e.defineProperty(this,"handleConnect",(async()=>{if(!this.connectParams)return;const{appId:e,appKey:s,token:i,parameters:c,onConnect:a}=this.connectParams;(e||s||i)&&this.dhServerSocket&&this.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:t.v4(),body:JSON.stringify({token:i,appId:e,appKey:s,...r(this.connectParams,n.CONNECT_MAIN_KEY),parameters:{...o(c,["parameters"]),...c&&c.parameters?c.parameters:{}}})}).on(((e,t)=>{a(e),0!==e.code&&t()}))})),this.url=i}async sendMessage(e,t){try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(e).on((e=>{t&&t(e)}))}catch(s){t&&t({code:-11,body:null,action:"RENDER_ERROR",requestId:e.requestId,message:JSON.stringify(s)})}}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),r=require("uuid"),t=require("@bddh/starling-web-socket/es/create-web-socket"),n=require("lodash/pick"),o=require("lodash/omit"),s=require("./interface.js"),a=function(a){function c(a){var i,u=this;e.classCallCheck(this,c),e.defineProperty(this,"dhServerSocket",null),e.defineProperty(this,"socketClosingPromise",null),e.defineProperty(this,"url",void 0),e.defineProperty(this,"firstConnect",!0),e.defineProperty(this,"connectParams",null),e.defineProperty(this,"createSocket",(function(n){return(i=i||e.asyncToGenerator(e.regeneratorRuntime().mark((function n(o){var a,c,i,d;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(u.connectParams=o,a=o.token,c=o.sessionId,i=o.onConnect,d=o.onDigitalHumanCallback,!u.socketClosingPromise){e.next=5;break}return e.next=5,u.socketClosingPromise;case 5:if(!u.dhServerSocket){e.next=8;break}return e.next=8,u.closeSocket();case 8:return e.abrupt("return",new Promise((function(e,n){var o=t.createWebSocket(u.url,{reopen:!0,keepAlive:"heartbeat",combine:function(e,r){return e&&r&&e.requestId===r.requestId},onOpen:function(){if(u.dhServerSocket=o,c&&u.firstConnect)return o.request({action:"RE_CONNECT",requestId:r.v4(),body:JSON.stringify({token:a,sessionId:c})}).on((function(r,t){i(r),0!==r.code&&(t(),u.handleConnect()),e(o)})),void(u.firstConnect=!1);u.handleConnect()},onClose:function(){u.dhServerSocket=null,u.socketClosingPromise=null},onError:function(e){n(e)}});o.onReadyStateChange((function(e){0===e&&d&&d({status:s.statusEnum.DH_LIB_INIT}),d&&d({status:s.statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:s.WS_STATUS_MAP[e]}})})),o.onMessage((function(e){var r=e.action;[s.errorTypeEnum.TIMEOUT_EXIT,s.errorTypeEnum.DISCONNECT_ALERT].includes(r)&&d&&d({status:s.statusEnum.DH_LIB_STATUS,content:{type:r}})})),o.open()})));case 9:case"end":return e.stop()}}),n)})))).apply(this,arguments)})),e.defineProperty(this,"closeSocket",e.asyncToGenerator(e.regeneratorRuntime().mark((function r(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(u.dhServerSocket){e.next=2;break}return e.abrupt("return");case 2:return u.socketClosingPromise=u.dhServerSocket.close(),e.next=5,u.socketClosingPromise;case 5:u.dhServerSocket=null;case 6:case"end":return e.stop()}}),r)})))),e.defineProperty(this,"handleConnect",e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){var a,c,i,d,p,l;return e.regeneratorRuntime().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(u.connectParams){t.next=2;break}return t.abrupt("return");case 2:if(a=u.connectParams,c=a.appId,i=a.appKey,d=a.token,p=a.parameters,l=a.onConnect,c||i||d){t.next=5;break}return t.abrupt("return");case 5:u.dhServerSocket&&u.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:r.v4(),body:JSON.stringify(e.objectSpread2(e.objectSpread2({token:d,appId:c,appKey:i},n(u.connectParams,s.CONNECT_MAIN_KEY)),{},{parameters:e.objectSpread2(e.objectSpread2({},o(p,["parameters"])),p&&p.parameters?p.parameters:{})}))}).on((function(e,r){l(e),0!==e.code&&r()}));case 6:case"end":return t.stop()}}),t)})))),this.url=a}return e.createClass(c,[{key:"sendMessage",value:function(r,t){return(a=a||e.asyncToGenerator(e.regeneratorRuntime().mark((function r(t,n){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(t).on((function(e){n&&n(e)}))}catch(e){n&&n({code:-11,body:null,action:"RENDER_ERROR",requestId:t.requestId,message:JSON.stringify(e)})}case 1:case"end":return e.stop()}}),r,this)})))).apply(this,arguments)}}]),c}();exports.default=a;
@@ -1 +1 @@
1
- "use strict";function r(r,e){if("object"!=typeof r||null===r)return r;var t=r[Symbol.toPrimitive];if(void 0!==t){var i=t.call(r,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(r)}function e(e){var t=r(e,"string");return"symbol"==typeof t?t:String(t)}exports.defineProperty=function(r,t,i){return(t=e(t))in r?Object.defineProperty(r,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):r[t]=i,r},exports.toPrimitive=r,exports.toPropertyKey=e;
1
+ "use strict";function t(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function r(){r=function(){return e};var t,e={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",f=a.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=r&&r.prototype instanceof m?r:m,a=Object.create(o.prototype),c=new N(n||[]);return i(a,"_invoke",{value:_(t,e,c)}),a}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}e.wrap=s;var p="suspendedStart",y="suspendedYield",v="executing",g="completed",d={};function m(){}function w(){}function b(){}var O={};l(O,c,(function(){return this}));var x=Object.getPrototypeOf,j=x&&x(x(T([])));j&&j!==n&&o.call(j,c)&&(O=j);var L=b.prototype=m.prototype=Object.create(O);function E(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function P(t,r){function e(n,i,a,c){var u=h(t[n],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==typeof l&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function _(r,e,n){var o=p;return function(i,a){if(o===v)throw new Error("Generator is already running");if(o===g){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=S(c,n);if(u){if(u===d)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var f=h(r,e,n);if("normal"===f.type){if(o=n.done?g:y,f.arg===d)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(o=g,n.method="throw",n.arg=f.arg)}}}function S(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,S(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var i=h(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,d;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,d):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function k(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function G(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function T(r){if(r||""===r){var e=r[c];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return w.prototype=b,i(L,"constructor",{value:b,configurable:!0}),i(b,"constructor",{value:w,configurable:!0}),w.displayName=l(b,f,"GeneratorFunction"),e.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===w||"GeneratorFunction"===(r.displayName||r.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,l(t,f,"GeneratorFunction")),t.prototype=Object.create(L),t},e.awrap=function(t){return{__await:t}},E(P.prototype),l(P.prototype,u,(function(){return this})),e.AsyncIterator=P,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new P(s(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},E(L),l(L,f,"Generator"),l(L,c,(function(){return this})),l(L,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=T,N.prototype={constructor:N,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(G),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=o.call(a,"catchLoc"),f=o.call(a,"finallyLoc");if(u&&f){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!f)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),d},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),G(e),d}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;G(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:T(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),d}},e}function e(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function n(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,a(n.key),n)}}function o(t,r,e){return(r=a(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function i(t,r){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}function a(t){var r=i(t,"string");return"symbol"==typeof r?r:String(r)}exports.asyncToGenerator=function(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function c(t){e(a,o,i,c,u,"next",t)}function u(t){e(a,o,i,c,u,"throw",t)}c(void 0)}))}},exports.classCallCheck=function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")},exports.createClass=function(t,r,e){return r&&n(t.prototype,r),e&&n(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t},exports.defineProperty=o,exports.objectSpread2=function(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?t(Object(n),!0).forEach((function(t){o(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))}))}return r},exports.regeneratorRuntime=r,exports.toPrimitive=i,exports.toPropertyKey=a;
package/es/BrtcClient.js CHANGED
@@ -1 +1 @@
1
- import{defineProperty as t}from"./_virtual/_rollupPluginBabelHelpers.js";import o from"@bddh/starling-brtc";import{TimeoutController as e}from"@bddh/starling-timeout-controller";import i from"@bddh/starling-json";import s from"lodash/isEmpty";import c from"lodash/isFunction";import{statusEnum as n,errorTypeEnum as a}from"./interface.js";class r{constructor(r){t(this,"client",void 0),t(this,"isRtcVideoOn",!1),t(this,"rtcConnection",void 0),t(this,"rtcConfig",void 0),t(this,"bizConfig",void 0),t(this,"rtcCallback",void 0),t(this,"restarting",!1),t(this,"timeoutEvent",void 0),t(this,"reopenTimer",void 0),t(this,"restartCount",0),t(this,"closeLog",!0),t(this,"haveVideoOn",!1),t(this,"rtcStateCallback",null),t(this,"openRtc",(t=>{if(this.restarting)!this.closeLog&&console.warn("rtc restarting");else if(t&&(this.rtcConnection=t),this.rtcConnection&&!s(this.rtcConnection)){const{server:e,appId:s,token:r,roomName:l,userId:h}=this.rtcConnection,{onRemotedata:d,onLocalStream:m,onRemoteVideoComing:C,onLocalVideoPublished:b,onLocalVideoPublishing:u,onRemoteVideoOn:g,onRemoteVideoOff:f,onRemoteVideoLoading:R,onSuccess:L,onError:S,onLocalVideoConnected:k,onRemoteVideoConnected:v,onRemoteMediaState:y,onPlayingError:p,onDigitalHumanCallback:V}=this.rtcCallback||{};this.timeoutEvent.start(),this.rtcStateCallback=t=>{const{body:o,action:e}=t;V&&V({status:n.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:e,body:o}})},this.client=new o({roomName:l,token:r,userId:h,appId:s,server:e,rtcConfig:this.rtcConfig,callback:{onRemoteVideoConnected:(o,e)=>{if(!e&&!this.haveVideoOn){let o=setTimeout((()=>{this.restartCount<3?(this.restartCount=++this.restartCount,this.restartRtc&&this.restartRtc(t)):(this.restartCount=0,this.closeRtc()),clearTimeout(o)}),500)}if(e){const t=document.getElementById("remotevideo500");t.muted=!1;let o=t.play();void 0!==o&&o.catch((()=>{t.muted=!0,t.play().catch((o=>{!this.closeLog&&console.info("videoElement play error",o),p&&p(t),V&&V({status:n.DH_LIB_ERROR,content:{type:a.LOCAL_VIDEO_ERROR}})})),V&&V({status:n.DH_LIB_STATUS,content:{type:a.LOCAL_VIDEO_MUTED}})}))}!this.closeLog&&console.info("remoteVideoConnected",o,e,this.restartCount),this.rtcStateCallback&&this.rtcStateCallback({action:"remoteVideoConnected",body:{id:o,connected:e,restartCount:this.restartCount}}),c(v)&&v(o,e)},onRemoteVideoOn:t=>{this.haveVideoOn=!0,!this.closeLog&&console.info("remotevideoon by id: ",t),this.timeoutEvent.clear();const o=document.querySelector("#starlingRtcContainer"),e=o&&o.lastChild;e&&(e.style.display="none"),this.rtcStateCallback&&this.rtcStateCallback({action:"remotevideoon",body:t}),V&&V({status:n.DH_LIB_OPEN}),c(g)&&g(t)},onRemoteMediaState:(t,o,e)=>{!this.closeLog&&console.info("remoteMediaState",t,o,e),this.rtcStateCallback&&this.rtcStateCallback({action:"remoteMediaState",body:{id:t,medium:o,connected:e}}),c(y)&&y(t,o,e)},onLocalVideoConnected:t=>{!this.closeLog&&console.info("localVideoConnected",t),this.rtcStateCallback&&this.rtcStateCallback({action:"localVideoConnected",body:{connected:t}}),c(k)&&k(t)},onRemotedata:t=>{if(this.rtcConfig&&this.rtcConfig.usingdatachannel){const o=i.parse(t);!this.closeLog&&console.info("RTC - receive:",o),c(d)&&d(o)}},onLocalStream:(t,o)=>{!this.closeLog&&console.info("rtc - onlocalstream by name: "+o),this.rtcStateCallback&&this.rtcStateCallback({action:"onlocalstream",body:{stream:t,name:o}}),c(m)&&m(t,o)},onLocalVideoPublished:()=>{!this.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),this.rtcStateCallback&&this.rtcStateCallback({action:"localvideopublished_ok",body:!0}),c(b)&&b()},onLocalVideoPublishing:()=>{!this.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),this.rtcStateCallback&&this.rtcStateCallback({action:"localvideopublishing",body:!0}),c(u)&&u()},onRemoteVideoComing:t=>{!this.closeLog&&console.info("remotevideocoming",t),this.rtcStateCallback&&this.rtcStateCallback({action:"remotevideocoming",body:t}),c(C)&&C(t)},onRemoteVideoLoading:t=>{!this.closeLog&&console.info("remotevideoloading by id: ",t),this.rtcStateCallback&&this.rtcStateCallback({action:"remotevideoloading",body:t}),c(R)&&R(t)},onRemoteVideoOff:t=>{!this.closeLog&&console.info("remotevideooff: ",t),this.isRtcVideoOn=!1,this.rtcStateCallback&&this.rtcStateCallback({action:"remotevideooff",body:t}),V&&V({status:n.DH_LIB_CLOSE}),c(f)&&f(t),this.timeoutEvent.start()},onSuccess:()=>{!this.closeLog&&console.info("rtc - success"),this.rtcStateCallback&&this.rtcStateCallback({action:"success",body:!0}),c(L)&&L()},onError:o=>{this.isRtcVideoOn=!1,!this.closeLog&&console.error("rtc - error:",o),this.rtcStateCallback&&this.rtcStateCallback({action:"error",body:o}),V&&V({status:n.DH_LIB_ERROR,content:{type:a.RTC_ERROR}}),c(S)&&S(o),(o.includes("Lost connection to the server")||o.includes("Is the server down"))&&this.restartRtc&&this.restartRtc(t)}}})}})),t(this,"closeRtc",(()=>{this.timeoutEvent.clear(),clearTimeout(this.reopenTimer),this.client&&this.client.destroy(),this.restarting=!1})),t(this,"restartRtc",(t=>{!this.restarting&&this.bizConfig&&this.bizConfig.autoReConnect&&(this.rtcStateCallback&&this.rtcStateCallback({action:"restartRtc",body:t}),this.restarting=!0,this.closeRtc(),this.reopenTimer=setTimeout((()=>{!this.closeLog&&console.error("拉流失败,开始重启"),this.restarting=!1,this.openRtc(t)}),2e3))}));const{rtcConnection:l,rtcConfig:h,closeLog:d=!0,rtcCallback:m}=r;this.rtcConnection=l,this.rtcConfig=h,this.rtcCallback=m,this.closeLog=d,this.timeoutEvent=new e(6e4,(()=>{if(!this.rtcConnection)return!this.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");this.timeoutEvent.clear(),this.restartRtc&&this.restartRtc(this.rtcConnection)}))}}export{r 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 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};
package/es/Client.js CHANGED
@@ -1 +1 @@
1
- import{defineProperty as e}from"./_virtual/_rollupPluginBabelHelpers.js";import t from"@bddh/starling-json";import s from"lodash/isEmpty";import r from"lodash/omit";import i from"lodash/pick";import{v4 as a}from"uuid";import{statusEnum as n,errorTypeEnum as o,CONNECT_MAIN_KEY as c}from"./interface.js";import h from"./Server.js";import d from"./BrtcClient.js";import{createHumanDom as m,appendRtcDomStyle as l,RTC_VIDEO_ID as u,checkIsHuawei as p,DEFAULT_CANVAS_ID as v,removeHumanDom as g,playHumanVideo as S,muteHumanVideo as I}from"./DomControl.js";import C from"./Cutout.js";class b{constructor(b){e(this,"token",void 0),e(this,"appKey",void 0),e(this,"appId",void 0),e(this,"connectParams",void 0),e(this,"onDigitalHumanCallback",void 0),e(this,"dhServer",void 0),e(this,"rtcServer",void 0),e(this,"rtcConnectParams",void 0),e(this,"cutoutInstance",void 0),e(this,"isHuawei",p()),e(this,"rtcServerUrl",void 0),e(this,"onRemoteVideoComing",(e=>{this.rtcConnectParams&&this.rtcConnectParams.feedId&&e===+this.rtcConnectParams.feedId&&this.rtcServer&&this.rtcServer.client&&this.rtcServer.client.subscribeStreaming("remotevideo500",+this.rtcConnectParams.feedId)})),e(this,"onRemoteVideoOn",(()=>{setTimeout((async()=>{const e=document.getElementById(u);if(await(this.cutoutInstance&&this.cutoutInstance.updateSource(u)),e){e.setAttribute("data-playing","true");const{videoWidth:t,videoHeight:s}=e,r=document.getElementById(v),i=r.getContext("2d");r&&i&&(r.width=t,r.height=s,i.drawImage(e,0,0,t,s))}}),100)})),e(this,"connectListener",(e=>{const{code:s,body:r,message:i}=e;if(0===s&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:n.DH_LIB_WS_SUCCESS,content:e}),0===s){const e=t.parse(r),{rtcServerUrl:s,appId:i,clientToken:a,roomName:n,clientId:o,feedId:c,chargeId:h}=e;i&&n&&(this.rtcConnectParams={server:this.rtcServerUrl||s,appId:i,token:a,roomName:n,userId:o,feedId:c,chargeId:h},this.rtcServer&&this.rtcServer.openRtc(this.rtcConnectParams))}else this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:n.DH_LIB_ERROR,content:{type:o.CONNECT_ERROR,msg:{code:s,errMsg:i}}})})),e(this,"createServer",(e=>{this.dhServer&&this.dhServer.createSocket({token:this.token,appKey:this.appKey,appId:this.appId,...e?{sessionId:e}:{},...i(this.connectParams,c),parameters:r(this.connectParams,c),onConnect:this.connectListener,onDigitalHumanCallback:this.onDigitalHumanCallback})})),e(this,"checkHumanInstansce",(()=>{this.dhServer||console.warn("请先初始化数字人示例")})),e(this,"sendMessage",((e,t)=>this.dhServer&&this.dhServer.sendMessage(e,t))),e(this,"interrupt",(async()=>new Promise((e=>{this.dhServer&&this.dhServer.sendMessage({requestId:a(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(()=>e()))})))),e(this,"textRender",(e=>{const{requestId:t,body:s,onCallbackMsg:r}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:t||a(),action:"TEXT_RENDER",body:s,clientTs:(new Date).getTime()},r)})),e(this,"textStreamRender",(e=>{const{requestId:s,body:r,onCallbackMsg:i}=e,{first:n}=t.parse(r);this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:s||a(),action:"TEXT_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},n?i:null)})),e(this,"audioRender",(e=>{const{body:t,onCallbackMsg:s}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:a(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},s)})),e(this,"audioStreamRender",(e=>{const{requestId:t,body:s,onCallbackMsg:r}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:t||a(),action:"AUDIO_STREAM_RENDER",body:s,clientTs:(new Date).getTime()},r)})),e(this,"destory",(async()=>{await(this.dhServer&&this.dhServer.closeSocket()),this.rtcServer&&this.rtcServer.closeRtc(),g(),this.dhServer=null,this.rtcServer=null})),e(this,"pauseHuman",(()=>S(!1))),e(this,"playHuman",(()=>S(!0))),e(this,"muteHuman",(()=>I(!0))),e(this,"unMuteHuman",(()=>{const e=I(!1);try{return this.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));const{wrapperId:y,token:k,appKey:R,appId:f,connectParams:D,renderParams:H,rtcConnectParams:w,brtcParams:E,wsUrl:T,rtcServerUrl:P,onDigitalHumanCallback:_}=b;this.token=k,this.appKey=R,this.appId=f,this.rtcServerUrl=P,this.connectParams={autoChromaKey:H.autoChromaKey,...D};const{fullStatus:M,closeLog:U}=H;this.onDigitalHumanCallback=e=>{const{status:t}=e;t!==n.DH_LIB_FULL_STATUS?_&&_(e):M&&_&&_(e)},this.dhServer=new h(T||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration");const{playerWrapper:K}=m({autoChromaKey:!!H.autoChromaKey})||{},L=document.getElementById(y);L||console.error("dom with wrapperId is not find"),K&&L&&L.appendChild(K),l(),this.rtcServer=new d({closeLog:U,videoWrapperId:u,rtcConfig:{remotevideoviewid:y,showvideobps:!1,usingvideo:!1,usingaudio:!1,aspublisher:!1,usingdatachannel:!0,autoplaymuted:!1,...E},bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new C({sourceId:u}),s(w)||(this.rtcConnectParams=w,this.rtcServer.openRtc(w))}}export{b as default};
1
+ import{createClass as e,classCallCheck as t,defineProperty as r,objectSpread2 as n,asyncToGenerator as a,regeneratorRuntime as o}from"./_virtual/_rollupPluginBabelHelpers.js";import s from"@bddh/starling-json";import i from"lodash/isEmpty";import c from"lodash/omit";import d from"lodash/pick";import{v4 as u}from"uuid";import{statusEnum as m,errorTypeEnum as l,CONNECT_MAIN_KEY as h}from"./interface.js";import p from"./Server.js";import v from"./BrtcClient.js";import{createHumanDom as g,appendRtcDomStyle as S,RTC_VIDEO_ID as f,checkIsHuawei as C,playHumanVideo as I,muteHumanVideo as b,removeHumanDom as k,DEFAULT_CANVAS_ID as y}from"./DomControl.js";import R from"./Cutout.js";var w=e((function e(w){var D=this;t(this,e),r(this,"token",void 0),r(this,"appKey",void 0),r(this,"appId",void 0),r(this,"connectParams",void 0),r(this,"onDigitalHumanCallback",void 0),r(this,"dhServer",void 0),r(this,"rtcServer",void 0),r(this,"rtcConnectParams",void 0),r(this,"cutoutInstance",void 0),r(this,"isHuawei",C()),r(this,"rtcServerUrl",void 0),r(this,"onRemoteVideoComing",(function(e){D.rtcConnectParams&&D.rtcConnectParams.feedId&&e===+D.rtcConnectParams.feedId&&D.rtcServer&&D.rtcServer.client&&D.rtcServer.client.subscribeStreaming("remotevideo500",+D.rtcConnectParams.feedId)})),r(this,"onRemoteVideoOn",(function(){setTimeout(a(o().mark((function e(){var t,r,n,a,s;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=document.getElementById(f),e.next=3,D.cutoutInstance&&D.cutoutInstance.updateSource(f);case 3:t&&(t.setAttribute("data-playing","true"),r=t.videoWidth,n=t.videoHeight,a=document.getElementById(y),s=a.getContext("2d"),a&&s&&(a.width=r,a.height=n,s.drawImage(t,0,0,r,n)));case 4:case"end":return e.stop()}}),e)}))),100)})),r(this,"connectListener",(function(e){var t=e.code,r=e.body,n=e.message;if(0===t&&D.onDigitalHumanCallback&&D.onDigitalHumanCallback({status:m.DH_LIB_WS_SUCCESS,content:e}),0===t){var a=s.parse(r),o=a.rtcServerUrl,i=a.appId,c=a.clientToken,d=a.roomName,u=a.clientId,h=a.feedId,p=a.chargeId;i&&d&&(D.rtcConnectParams={server:D.rtcServerUrl||o,appId:i,token:c,roomName:d,userId:u,feedId:h,chargeId:p},D.rtcServer&&D.rtcServer.openRtc(D.rtcConnectParams))}else D.onDigitalHumanCallback&&D.onDigitalHumanCallback({status:m.DH_LIB_ERROR,content:{type:l.CONNECT_ERROR,msg:{code:t,errMsg:n}}})})),r(this,"createServer",(function(e){D.dhServer&&D.dhServer.createSocket(n(n(n({token:D.token,appKey:D.appKey,appId:D.appId},e?{sessionId:e}:{}),d(D.connectParams,h)),{},{parameters:c(D.connectParams,h),onConnect:D.connectListener,onDigitalHumanCallback:D.onDigitalHumanCallback}))})),r(this,"checkHumanInstansce",(function(){D.dhServer||console.warn("请先初始化数字人示例")})),r(this,"sendMessage",(function(e,t){return D.dhServer&&D.dhServer.sendMessage(e,t)})),r(this,"interrupt",a(o().mark((function e(){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){D.dhServer&&D.dhServer.sendMessage({requestId:u(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(function(){return e()}))})));case 1:case"end":return e.stop()}}),e)})))),r(this,"textRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;D.checkHumanInstansce(),D.dhServer&&D.dhServer.sendMessage({requestId:t||u(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},n)})),r(this,"textStreamRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg,a=s.parse(r).first;D.checkHumanInstansce(),D.dhServer&&D.dhServer.sendMessage({requestId:t||u(),action:"TEXT_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},a?n:null)})),r(this,"audioRender",(function(e){var t=e.body,r=e.onCallbackMsg;D.checkHumanInstansce(),D.dhServer&&D.dhServer.sendMessage({requestId:u(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},r)})),r(this,"audioStreamRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;D.checkHumanInstansce(),D.dhServer&&D.dhServer.sendMessage({requestId:t||u(),action:"AUDIO_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},n)})),r(this,"destory",a(o().mark((function e(){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,D.dhServer&&D.dhServer.closeSocket();case 2:D.rtcServer&&D.rtcServer.closeRtc(),k(),D.dhServer=null,D.rtcServer=null;case 6:case"end":return e.stop()}}),e)})))),r(this,"pauseHuman",(function(){return I(!1)})),r(this,"playHuman",(function(){return I(!0)})),r(this,"muteHuman",(function(){return b(!0)})),r(this,"unMuteHuman",(function(){var e=b(!1);try{return D.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));var H=w.wrapperId,T=w.token,E=w.appKey,P=w.appId,_=w.connectParams,M=w.renderParams,U=w.rtcConnectParams,x=w.brtcParams,K=w.wsUrl,L=w.rtcServerUrl,N=w.onDigitalHumanCallback;this.token=T,this.appKey=E,this.appId=P,this.rtcServerUrl=L,this.connectParams=n({autoChromaKey:M.autoChromaKey},_);var j=M.fullStatus,q=M.closeLog;this.onDigitalHumanCallback=function(e){e.status!==m.DH_LIB_FULL_STATUS?N&&N(e):j&&N&&N(e)},this.dhServer=new p(K||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration");var B=(g({autoChromaKey:!!M.autoChromaKey})||{}).playerWrapper,A=document.getElementById(H);A||console.error("dom with wrapperId is not find"),B&&A&&A.appendChild(B),S(),this.rtcServer=new v({closeLog:q,videoWrapperId:f,rtcConfig:n({remotevideoviewid:H,showvideobps:!1,usingvideo:!1,usingaudio:!1,aspublisher:!1,usingdatachannel:!0,autoplaymuted:!1},x),bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new R({sourceId:f}),i(U)||(this.rtcConnectParams=U,this.rtcServer.openRtc(U))}));export{w as default};
package/es/Cutout.js CHANGED
@@ -1 +1 @@
1
- import{defineProperty as t}from"./_virtual/_rollupPluginBabelHelpers.js";import s from"@bddh/starling-cutout/es/Seriously";const e={version:2,chromaKey:{screen:[53,186,123],similarity:90,edgeShrink:3,smoothness:80,spill:100,opacity:1,contrast:0,brightness:0,gamma:0}};class o{constructor(o){t(this,"cutoutInstance",void 0);const{effects:r,sourceId:n}=o;this.cutoutInstance=new s("starling-cutout-canvas",n||"starling-cutout-video",r&&r.chromaKey||e.chromaKey,r&&r.version||e.version)}setOptions(t){t&&this.cutoutInstance&&this.cutoutInstance.setOptions(t)}destroy(){return this.cutoutInstance.destroy()}updateSource(t){return this.cutoutInstance.updateSource(t)}}export{e as DEFAULT_EFFECTS,o as default};
1
+ import{createClass as t,classCallCheck as e,defineProperty as s}from"./_virtual/_rollupPluginBabelHelpers.js";import n from"@bddh/starling-cutout/es/Seriously";var o={version:2,chromaKey:{screen:[53,186,123],similarity:90,edgeShrink:3,smoothness:80,spill:100,opacity:1,contrast:0,brightness:0,gamma:0}},r=function(){function r(t){e(this,r),s(this,"cutoutInstance",void 0);var u=t.effects,a=t.sourceId;this.cutoutInstance=new n("starling-cutout-canvas",a||"starling-cutout-video",u&&u.chromaKey||o.chromaKey,u&&u.version||o.version)}return t(r,[{key:"setOptions",value:function(t){t&&this.cutoutInstance&&this.cutoutInstance.setOptions(t)}},{key:"destroy",value:function(){return this.cutoutInstance.destroy()}},{key:"updateSource",value:function(t){return this.cutoutInstance.updateSource(t)}}]),r}();export{o as DEFAULT_EFFECTS,r as default};
package/es/DomControl.js CHANGED
@@ -1 +1 @@
1
- const t="starling-cutout-canvas",e="cloud-brtc-player-wrapper",n="remotevideo500";function i(i){const{id:o=n,autoChromaKey:a=!1,autoplay:r=!0}=i;if(document.getElementById(o))return console.error(`DOM with id "${o}" already exists.`),null;const d=document.createElement("div");d.className=e,d.id=e,d.style.position="relative";const c=document.createElement("video");c.id=o,c.width=0,c.height=0,c.setAttribute("width","100%"),c.setAttribute("height","100%"),c.setAttribute("data-playing","true"),c.setAttribute("playsinline","");const 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:a?"block":"none"}),r&&c.setAttribute("autoplay",""),a&&(c.style.visibility="hidden"),d.appendChild(c),d.appendChild(s),{playerWrapper:d,video:c}}function o(){const t=document.getElementById(e);t&&t.parentNode&&t.parentNode.removeChild(t)}function a(t){const e=document.getElementById(n);return e&&(e.muted=t),e}function r(t){const e=document.getElementById(n);try{if(e)return t?e.play():e.pause()}catch(t){console.info(t)}}function d(){const t=navigator.userAgent||navigator.vendor;return/huawei/i.test(t)||/honor/i.test(t)}function c(){const 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,c as appendRtcDomStyle,d as checkIsHuawei,i as createHumanDom,a as muteHumanVideo,r as playHumanVideo,o as removeHumanDom};
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};
package/es/Server.js CHANGED
@@ -1 +1 @@
1
- import{defineProperty as e}from"./_virtual/_rollupPluginBabelHelpers.js";import{v4 as t}from"uuid";import{createWebSocket as s}from"@bddh/starling-web-socket/es/create-web-socket";import o from"lodash/pick";import r from"lodash/omit";import{statusEnum as n,WS_STATUS_MAP as i,errorTypeEnum as c,CONNECT_MAIN_KEY as a}from"./interface.js";class h{constructor(h){e(this,"dhServerSocket",null),e(this,"socketClosingPromise",null),e(this,"url",void 0),e(this,"firstConnect",!0),e(this,"connectParams",null),e(this,"createSocket",(async e=>{this.connectParams=e;const{token:o,sessionId:r,onConnect:a,onDigitalHumanCallback:h}=e;return this.socketClosingPromise&&await this.socketClosingPromise,this.dhServerSocket&&await this.closeSocket(),new Promise(((e,l)=>{const d=s(this.url,{reopen:!0,keepAlive:"heartbeat",combine:(e,t)=>e&&t&&e.requestId===t.requestId,onOpen:()=>{if(this.dhServerSocket=d,r&&this.firstConnect)return d.request({action:"RE_CONNECT",requestId:t(),body:JSON.stringify({token:o,sessionId:r})}).on(((t,s)=>{a(t),0!==t.code&&(s(),this.handleConnect()),e(d)})),void(this.firstConnect=!1);this.handleConnect()},onClose:()=>{this.dhServerSocket=null,this.socketClosingPromise=null},onError:e=>{l(e)}});d.onReadyStateChange((e=>{0===e&&h&&h({status:n.DH_LIB_INIT}),h&&h({status:n.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:i[e]}})})),d.onMessage((e=>{const{action:t}=e;[c.TIMEOUT_EXIT,c.DISCONNECT_ALERT].includes(t)&&h&&h({status:n.DH_LIB_STATUS,content:{type:t}})})),d.open()}))})),e(this,"closeSocket",(async()=>{this.dhServerSocket&&(this.socketClosingPromise=this.dhServerSocket.close(),await this.socketClosingPromise,this.dhServerSocket=null)})),e(this,"handleConnect",(async()=>{if(!this.connectParams)return;const{appId:e,appKey:s,token:n,parameters:i,onConnect:c}=this.connectParams;(e||s||n)&&this.dhServerSocket&&this.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:t(),body:JSON.stringify({token:n,appId:e,appKey:s,...o(this.connectParams,a),parameters:{...r(i,["parameters"]),...i&&i.parameters?i.parameters:{}}})}).on(((e,t)=>{c(e),0!==e.code&&t()}))})),this.url=h}async sendMessage(e,t){try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(e).on((e=>{t&&t(e)}))}catch(s){t&&t({code:-11,body:null,action:"RENDER_ERROR",requestId:e.requestId,message:JSON.stringify(s)})}}}export{h as default};
1
+ import{createClass as e,asyncToGenerator as t,classCallCheck as r,defineProperty as n,regeneratorRuntime as o,objectSpread2 as s}from"./_virtual/_rollupPluginBabelHelpers.js";import{v4 as a}from"uuid";import{createWebSocket as c}from"@bddh/starling-web-socket/es/create-web-socket";import i from"lodash/pick";import u from"lodash/omit";import{errorTypeEnum as l,CONNECT_MAIN_KEY as p,statusEnum as d,WS_STATUS_MAP as f}from"./interface.js";var h=function(h){function k(e){var h,m=this;r(this,k),n(this,"dhServerSocket",null),n(this,"socketClosingPromise",null),n(this,"url",void 0),n(this,"firstConnect",!0),n(this,"connectParams",null),n(this,"createSocket",(function(e){return(h=h||t(o().mark((function e(t){var r,n,s,i;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(m.connectParams=t,r=t.token,n=t.sessionId,s=t.onConnect,i=t.onDigitalHumanCallback,!m.socketClosingPromise){e.next=5;break}return e.next=5,m.socketClosingPromise;case 5:if(!m.dhServerSocket){e.next=8;break}return e.next=8,m.closeSocket();case 8:return e.abrupt("return",new Promise((function(e,t){var o=c(m.url,{reopen:!0,keepAlive:"heartbeat",combine:function(e,t){return e&&t&&e.requestId===t.requestId},onOpen:function(){if(m.dhServerSocket=o,n&&m.firstConnect)return o.request({action:"RE_CONNECT",requestId:a(),body:JSON.stringify({token:r,sessionId:n})}).on((function(t,r){s(t),0!==t.code&&(r(),m.handleConnect()),e(o)})),void(m.firstConnect=!1);m.handleConnect()},onClose:function(){m.dhServerSocket=null,m.socketClosingPromise=null},onError:function(e){t(e)}});o.onReadyStateChange((function(e){0===e&&i&&i({status:d.DH_LIB_INIT}),i&&i({status:d.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:f[e]}})})),o.onMessage((function(e){var t=e.action;[l.TIMEOUT_EXIT,l.DISCONNECT_ALERT].includes(t)&&i&&i({status:d.DH_LIB_STATUS,content:{type:t}})})),o.open()})));case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)})),n(this,"closeSocket",t(o().mark((function e(){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(m.dhServerSocket){e.next=2;break}return e.abrupt("return");case 2:return m.socketClosingPromise=m.dhServerSocket.close(),e.next=5,m.socketClosingPromise;case 5:m.dhServerSocket=null;case 6:case"end":return e.stop()}}),e)})))),n(this,"handleConnect",t(o().mark((function e(){var t,r,n,c,l,d;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(m.connectParams){e.next=2;break}return e.abrupt("return");case 2:if(t=m.connectParams,r=t.appId,n=t.appKey,c=t.token,l=t.parameters,d=t.onConnect,r||n||c){e.next=5;break}return e.abrupt("return");case 5:m.dhServerSocket&&m.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:a(),body:JSON.stringify(s(s({token:c,appId:r,appKey:n},i(m.connectParams,p)),{},{parameters:s(s({},u(l,["parameters"])),l&&l.parameters?l.parameters:{})}))}).on((function(e,t){d(e),0!==e.code&&t()}));case 6:case"end":return e.stop()}}),e)})))),this.url=e}return e(k,[{key:"sendMessage",value:function(e,r){return(h=h||t(o().mark((function e(t,r){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(t).on((function(e){r&&r(e)}))}catch(e){r&&r({code:-11,body:null,action:"RENDER_ERROR",requestId:t.requestId,message:JSON.stringify(e)})}case 1:case"end":return e.stop()}}),e,this)})))).apply(this,arguments)}}]),k}();export{h as default};
@@ -1 +1 @@
1
- function r(r,e,i){return(e=t(e))in r?Object.defineProperty(r,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):r[e]=i,r}function e(r,e){if("object"!=typeof r||null===r)return r;var t=r[Symbol.toPrimitive];if(void 0!==t){var i=t.call(r,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(r)}function t(r){var t=e(r,"string");return"symbol"==typeof t?t:String(t)}export{r as defineProperty,e as toPrimitive,t as toPropertyKey};
1
+ function t(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function r(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?t(Object(n),!0).forEach((function(t){u(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))}))}return r}function e(){e=function(){return r};var t,r={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",f=a.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=r&&r.prototype instanceof m?r:m,a=Object.create(o.prototype),c=new N(n||[]);return i(a,"_invoke",{value:_(t,e,c)}),a}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=s;var p="suspendedStart",y="suspendedYield",v="executing",g="completed",d={};function m(){}function w(){}function b(){}var O={};l(O,c,(function(){return this}));var j=Object.getPrototypeOf,L=j&&j(j(T([])));L&&L!==n&&o.call(L,c)&&(O=L);var E=b.prototype=m.prototype=Object.create(O);function x(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function P(t,r){function e(n,i,a,c){var u=h(t[n],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==typeof l&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function _(r,e,n){var o=p;return function(i,a){if(o===v)throw new Error("Generator is already running");if(o===g){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=S(c,n);if(u){if(u===d)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var f=h(r,e,n);if("normal"===f.type){if(o=n.done?g:y,f.arg===d)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(o=g,n.method="throw",n.arg=f.arg)}}}function S(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,S(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var i=h(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,d;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,d):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function k(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function G(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function T(r){if(r||""===r){var e=r[c];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return w.prototype=b,i(E,"constructor",{value:b,configurable:!0}),i(b,"constructor",{value:w,configurable:!0}),w.displayName=l(b,f,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===w||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,l(t,f,"GeneratorFunction")),t.prototype=Object.create(E),t},r.awrap=function(t){return{__await:t}},x(P.prototype),l(P.prototype,u,(function(){return this})),r.AsyncIterator=P,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new P(s(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(E),l(E,f,"Generator"),l(E,c,(function(){return this})),l(E,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=T,N.prototype={constructor:N,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(G),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=o.call(a,"catchLoc"),f=o.call(a,"finallyLoc");if(u&&f){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!f)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),d},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),G(e),d}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;G(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:T(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),d}},r}function n(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function o(t){return function(){var r=this,e=arguments;return new Promise((function(o,i){var a=t.apply(r,e);function c(t){n(a,o,i,c,u,"next",t)}function u(t){n(a,o,i,c,u,"throw",t)}c(void 0)}))}}function i(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function a(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,l(n.key),n)}}function c(t,r,e){return r&&a(t.prototype,r),e&&a(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function u(t,r,e){return(r=l(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function f(t,r){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}function l(t){var r=f(t,"string");return"symbol"==typeof r?r:String(r)}export{o as asyncToGenerator,i as classCallCheck,c as createClass,u as defineProperty,r as objectSpread2,e as regeneratorRuntime,f as toPrimitive,l as toPropertyKey};
package/es/interface.js CHANGED
@@ -1 +1 @@
1
- const _=["projectId","characterConfigId","configVersion","selectors","figureName"];var I,E;!function(_){_.DH_LIB_INIT="DH_LIB_INIT",_.DH_LIB_WS_SUCCESS="DH_LIB_WS_SUCCESS",_.DH_LIB_OPEN="DH_LIB_OPEN",_.DH_LIB_STATUS="DH_LIB_STATUS",_.DH_LIB_CLOSE="DH_LIB_CLOSE",_.DH_LIB_ERROR="DH_LIB_ERROR",_.DH_LIB_WARNING="DH_LIB_WARNING",_.DH_LIB_FULL_STATUS="DH_LIB_FULL_STATUS"}(I||(I={})),function(_){_.CONNECT_ERROR="CONNECT_ERROR",_.DISCONNECT_ALERT="DISCONNECT_ALERT",_.TIMEOUT_EXIT="TIMEOUT_EXIT",_.LOCAL_VIDEO_MUTED="LOCAL_VIDEO_MUTED",_.LOCAL_VIDEO_ERROR="LOCAL_VIDEO_ERROR",_.RTC_ERROR="RTC_ERROR"}(E||(E={}));const L={"-1":"UNINSTANTIATED",0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"};export{_ as CONNECT_MAIN_KEY,L as WS_STATUS_MAP,E as errorTypeEnum,I as statusEnum};
1
+ var _,I,E=["projectId","characterConfigId","configVersion","selectors","figureName"];!function(_){_.DH_LIB_INIT="DH_LIB_INIT",_.DH_LIB_WS_SUCCESS="DH_LIB_WS_SUCCESS",_.DH_LIB_OPEN="DH_LIB_OPEN",_.DH_LIB_STATUS="DH_LIB_STATUS",_.DH_LIB_CLOSE="DH_LIB_CLOSE",_.DH_LIB_ERROR="DH_LIB_ERROR",_.DH_LIB_WARNING="DH_LIB_WARNING",_.DH_LIB_FULL_STATUS="DH_LIB_FULL_STATUS"}(_||(_={})),function(_){_.CONNECT_ERROR="CONNECT_ERROR",_.DISCONNECT_ALERT="DISCONNECT_ALERT",_.TIMEOUT_EXIT="TIMEOUT_EXIT",_.LOCAL_VIDEO_MUTED="LOCAL_VIDEO_MUTED",_.LOCAL_VIDEO_ERROR="LOCAL_VIDEO_ERROR",_.RTC_ERROR="RTC_ERROR"}(I||(I={}));var L={"-1":"UNINSTANTIATED",0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"};export{E as CONNECT_MAIN_KEY,L as WS_STATUS_MAP,I as errorTypeEnum,_ as statusEnum};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bddh/starling-realtime-client",
3
- "version": "1.0.8-beta.1",
3
+ "version": "1.0.9",
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": "1cee540024b051ebda341ee1bc2d9cb46bcac526"
47
+ "gitHead": "d688dfc3e88d91657047342c30f89d2de81efee5"
48
48
  }