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

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("@bddh/starling-brtc"),e=require("@bddh/starling-timeout-controller"),o=require("@bddh/starling-json"),i=require("lodash/isEmpty"),n=require("lodash/isFunction"),c=require("./interface.js");exports.default=class{client;isRtcVideoOn=!1;rtcConnection;rtcConfig;bizConfig;rtcCallback;restarting=!1;timeoutEvent;reopenTimer;restartCount=0;closeLog=!0;haveVideoOn=!1;rtcStateCallback=null;constructor(t){const{rtcConnection:o,rtcConfig:i,closeLog:n=!0,rtcCallback:c}=t;this.rtcConnection=o,this.rtcConfig=i,this.rtcCallback=c,this.closeLog=n,this.timeoutEvent=new e.TimeoutController(6e4,(()=>{if(!this.rtcConnection)return!this.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");this.timeoutEvent.clear(),this.restartRtc&&this.restartRtc(this.rtcConnection)}))}openRtc=e=>{if(this.restarting)!this.closeLog&&console.warn("rtc restarting");else if(e&&(this.rtcConnection=e),this.rtcConnection&&!i(this.rtcConnection)){const{server:i,appId:s,token:a,roomName:r,userId:l}=this.rtcConnection,{onRemotedata:h,onLocalStream:d,onRemoteVideoComing:u,onLocalVideoPublished:C,onLocalVideoPublishing:m,onRemoteVideoOn:b,onRemoteVideoOff:g,onRemoteVideoLoading:R,onSuccess:L,onError:S,onLocalVideoConnected:f,onRemoteVideoConnected:k,onRemoteMediaState:y,onPlayingError:v,onDigitalHumanCallback:E}=this.rtcCallback||{};this.timeoutEvent.start(),this.rtcStateCallback=t=>{const{body:e,action:o}=t;E&&E({status:c.statusEnum.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:o,body:e}})},this.client=new t({roomName:r,token:a,userId:l,appId:s,server:i,rtcConfig:this.rtcConfig,callback:{onRemoteVideoConnected:(t,o)=>{if(!o&&!this.haveVideoOn){let t=setTimeout((()=>{this.restartCount<3?(this.restartCount=++this.restartCount,this.restartRtc&&this.restartRtc(e)):(this.restartCount=0,this.closeRtc()),clearTimeout(t)}),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),E&&E({status:c.statusEnum.DH_LIB_ERROR,content:{type:c.errorTypeEnum.LOCAL_VIDEO_ERROR}})})),E&&E({status:c.statusEnum.DH_LIB_STATUS,content:{type:c.errorTypeEnum.LOCAL_VIDEO_MUTED}})}))}!this.closeLog&&console.info("remoteVideoConnected",t,o,this.restartCount),this.rtcStateCallback&&this.rtcStateCallback({action:"remoteVideoConnected",body:{id:t,connected:o,restartCount:this.restartCount}}),n(k)&&k(t,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}),E&&E({status:c.statusEnum.DH_LIB_OPEN}),n(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}}),n(y)&&y(t,e,o)},onLocalVideoConnected:t=>{!this.closeLog&&console.info("localVideoConnected",t),this.rtcStateCallback&&this.rtcStateCallback({action:"localVideoConnected",body:{connected:t}}),n(f)&&f(t)},onRemotedata:t=>{if(this.rtcConfig&&this.rtcConfig.usingdatachannel){const e=o.parse(t);!this.closeLog&&console.info("RTC - receive:",e),n(h)&&h(e)}},onLocalStream:(t,e)=>{!this.closeLog&&console.info("rtc - onlocalstream by name: "+e),this.rtcStateCallback&&this.rtcStateCallback({action:"onlocalstream",body:{stream:t,name:e}}),n(d)&&d(t,e)},onLocalVideoPublished:()=>{!this.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),this.rtcStateCallback&&this.rtcStateCallback({action:"localvideopublished_ok",body:!0}),n(C)&&C()},onLocalVideoPublishing:()=>{!this.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),this.rtcStateCallback&&this.rtcStateCallback({action:"localvideopublishing",body:!0}),n(m)&&m()},onRemoteVideoComing:t=>{!this.closeLog&&console.info("remotevideocoming",t),this.rtcStateCallback&&this.rtcStateCallback({action:"remotevideocoming",body:t}),n(u)&&u(t)},onRemoteVideoLoading:t=>{!this.closeLog&&console.info("remotevideoloading by id: ",t),this.rtcStateCallback&&this.rtcStateCallback({action:"remotevideoloading",body:t}),n(R)&&R(t)},onRemoteVideoOff:t=>{!this.closeLog&&console.info("remotevideooff: ",t),this.isRtcVideoOn=!1,this.rtcStateCallback&&this.rtcStateCallback({action:"remotevideooff",body:t}),E&&E({status:c.statusEnum.DH_LIB_CLOSE}),n(g)&&g(t),this.timeoutEvent.start()},onSuccess:()=>{!this.closeLog&&console.info("rtc - success"),this.rtcStateCallback&&this.rtcStateCallback({action:"success",body:!0}),n(L)&&L()},onError:t=>{this.isRtcVideoOn=!1,!this.closeLog&&console.error("rtc - error:",t),this.rtcStateCallback&&this.rtcStateCallback({action:"error",body:t}),E&&E({status:c.statusEnum.DH_LIB_ERROR,content:{type:c.errorTypeEnum.RTC_ERROR}}),n(S)&&S(t),(t.includes("Lost connection to the server")||t.includes("Is the server down"))&&this.restartRtc&&this.restartRtc(e)}}})}};closeRtc=()=>{this.timeoutEvent.clear(),clearTimeout(this.reopenTimer),this.client&&this.client.destroy(),this.restarting=!1};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))}};
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)}))}};
package/cjs/Client.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@bddh/starling-json"),t=require("lodash/isEmpty"),r=require("lodash/omit"),s=require("lodash/pick"),a=require("uuid"),n=require("./interface.js"),i=require("./Server.js"),o=require("./BrtcClient.js"),c=require("./DomControl.js"),d=require("./Cutout.js");exports.default=class{token;appKey;appId;connectParams;onDigitalHumanCallback;dhServer;rtcServer;rtcConnectParams;cutoutInstance;isHuawei=c.checkIsHuawei();rtcServerUrl;constructor(e){const{wrapperId:r,token:s,appKey:a,appId:u,connectParams:h,renderParams:l,rtcConnectParams:m,brtcParams:p,wsUrl:I,rtcServerUrl:v,onDigitalHumanCallback:g}=e;this.token=s,this.appKey=a,this.appId=u,this.rtcServerUrl=v,this.connectParams={autoChromaKey:l.autoChromaKey,...h};const{fullStatus:S,closeLog:C}=l;this.onDigitalHumanCallback=e=>{const{status:t}=e;t!==n.statusEnum.DH_LIB_FULL_STATUS?g&&g(e):S&&g&&g(e)},this.dhServer=new i.default(I||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration");const{playerWrapper:y}=c.createHumanDom({autoChromaKey:!!l.autoChromaKey})||{},D=document.getElementById(r);D||console.error("dom with wrapperId is not find"),y&&D&&D.appendChild(y),this.rtcServer=new o.default({closeLog:C,videoWrapperId:c.RTC_VIDEO_ID,rtcConfig:{remotevideoviewid:r,showvideobps:!1,usingvideo:!1,usingaudio:!1,aspublisher:!1,usingdatachannel:!0,autoplaymuted:!1,...p},bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new d.default({sourceId:c.RTC_VIDEO_ID}),t(m)||(this.rtcConnectParams=m,this.rtcServer.openRtc(m))}onRemoteVideoComing=e=>{this.rtcConnectParams&&this.rtcConnectParams.feedId&&e===+this.rtcConnectParams.feedId&&this.rtcServer&&this.rtcServer.client&&this.rtcServer.client.subscribeStreaming("remotevideo500",+this.rtcConnectParams.feedId)};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,s=document.getElementById(c.DEFAULT_CANVAS_ID),a=s.getContext("2d");s&&a&&(s.width=t,s.height=r,a.drawImage(e,0,0,t,r))}}),100)};connectListener=t=>{const{code:r,body:s,message:a}=t;if(0===r&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:n.statusEnum.DH_LIB_WS_SUCCESS,content:t}),0===r){const t=e.parse(s),{rtcServerUrl:r,appId:a,clientToken:n,roomName:i,clientId:o,feedId:c,chargeId:d}=t;a&&i&&(this.rtcConnectParams={server:this.rtcServerUrl||r,appId:a,token:n,roomName:i,userId:o,feedId:c,chargeId:d},this.rtcServer&&this.rtcServer.openRtc(this.rtcConnectParams))}else this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:n.statusEnum.DH_LIB_ERROR,content:{type:n.errorTypeEnum.CONNECT_ERROR,msg:{code:r,errMsg:a}}})};createServer=e=>{this.dhServer&&this.dhServer.createSocket({token:this.token,appKey:this.appKey,appId:this.appId,...e?{sessionId:e}:{},...s(this.connectParams,n.CONNECT_MAIN_KEY),parameters:r(this.connectParams,n.CONNECT_MAIN_KEY),onConnect:this.connectListener,onDigitalHumanCallback:this.onDigitalHumanCallback})};checkHumanInstansce=()=>{this.dhServer||console.warn("请先初始化数字人示例")};sendMessage=(e,t)=>this.dhServer&&this.dhServer.sendMessage(e,t);interrupt=async()=>new Promise((e=>{this.dhServer&&this.dhServer.sendMessage({requestId:a.v4(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(()=>e()))}));textRender=e=>{const{requestId:t,body:r,onCallbackMsg:s}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:t||a.v4(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},s)};textStreamRender=t=>{const{requestId:r,body:s,onCallbackMsg:n}=t,{first:i}=e.parse(s);this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:r||a.v4(),action:"TEXT_STREAM_RENDER",body:s,clientTs:(new Date).getTime()},i?n:null)};audioRender=e=>{const{body:t,onCallbackMsg:r}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:a.v4(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},r)};audioStreamRender=e=>{const{requestId:t,body:r,onCallbackMsg:s}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:t||a.v4(),action:"AUDIO_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},s)};destory=async()=>{await(this.dhServer&&this.dhServer.closeSocket()),this.rtcServer&&this.rtcServer.closeRtc(),c.removeHumanDom(),this.dhServer=null,this.rtcServer=null};pauseHuman=()=>c.playHumanVideo(!1);playHuman=()=>c.playHumanVideo(!0);muteHuman=()=>c.muteHumanVideo(!0);unMuteHuman=()=>{const e=c.muteHumanVideo(!1);try{return this.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}};
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))}};
package/cjs/Cutout.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@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}};exports.DEFAULT_EFFECTS=e,exports.default=class{cutoutInstance;constructor(s){const{effects:o,sourceId:r}=s;this.cutoutInstance=new t("starling-cutout-canvas",r||"starling-cutout-video",o&&o.chromaKey||e.chromaKey,o&&o.version||e.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");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)}};
@@ -19,4 +19,5 @@ export declare function removeHumanDom(): void;
19
19
  export declare function muteHumanVideo(muted: boolean): HTMLVideoElement;
20
20
  export declare function playHumanVideo(play: boolean): void | Promise<void>;
21
21
  export declare function checkIsHuawei(): boolean;
22
+ export declare function appendRtcDomStyle(): void;
22
23
  export {};
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.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 s=document.createElement("div");s.className=e,s.id=e,s.style.position="relative";const u=document.createElement("video");u.id=i,u.width=0,u.height=0,u.setAttribute("width","100%"),u.setAttribute("height","100%"),u.setAttribute("data-playing","true"),u.setAttribute("playsinline","");const d=document.createElement("canvas");return d.id=t,Object.assign(d.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:r?"block":"none"}),a&&u.setAttribute("autoplay",""),r&&(u.style.visibility="hidden"),s.appendChild(u),s.appendChild(d),{playerWrapper:s,video:u}},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";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)};
package/cjs/Server.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("uuid"),t=require("@bddh/starling-web-socket/es/create-web-socket"),s=require("lodash/pick"),r=require("lodash/omit"),o=require("./interface.js");exports.default=class{dhServerSocket=null;socketClosingPromise=null;url;firstConnect=!0;connectParams=null;constructor(e){this.url=e}createSocket=async s=>{this.connectParams=s;const{token:r,sessionId:n,onConnect:i,onDigitalHumanCallback:c}=s;return this.socketClosingPromise&&await this.socketClosingPromise,this.dhServerSocket&&await this.closeSocket(),new Promise(((s,a)=>{const h=t.createWebSocket(this.url,{reopen:!0,keepAlive:"heartbeat",combine:(e,t)=>e&&e.requestId===t&&t.requestId,onOpen:()=>{if(this.dhServerSocket=h,n&&this.firstConnect)return h.request({action:"RE_CONNECT",requestId:e.v4(),body:JSON.stringify({token:r,sessionId:n})}).on(((e,t)=>{i(e),0!==e.code&&(t(),this.handleConnect()),s(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:o.statusEnum.DH_LIB_INIT}),c&&c({status:o.statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:o.WS_STATUS_MAP[e]}})})),h.onMessage((e=>{const{action:t}=e;[o.errorTypeEnum.TIMEOUT_EXIT,o.errorTypeEnum.DISCONNECT_ALERT].includes(t)&&c&&c({status:o.statusEnum.DH_LIB_STATUS,content:{type:t}})})),h.open()}))};closeSocket=async()=>{this.dhServerSocket&&(this.socketClosingPromise=this.dhServerSocket.close(),await this.socketClosingPromise,this.dhServerSocket=null)};handleConnect=async()=>{if(!this.connectParams)return;const{appId:t,appKey:n,token:i,parameters:c,onConnect:a}=this.connectParams;(t||n||i)&&this.dhServerSocket&&this.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:e.v4(),body:JSON.stringify({token:i,appId:t,appKey:n,...s(this.connectParams,o.CONNECT_MAIN_KEY),parameters:{...r(c,["parameters"]),...c&&c.parameters?c.parameters:{}}})}).on(((e,t)=>{a(e),0!==e.code&&t()}))};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"),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)})}}};
@@ -0,0 +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;
package/es/BrtcClient.js CHANGED
@@ -1 +1 @@
1
- import t from"@bddh/starling-brtc";import{TimeoutController as o}from"@bddh/starling-timeout-controller";import e from"@bddh/starling-json";import i from"lodash/isEmpty";import c from"lodash/isFunction";import{statusEnum as n,errorTypeEnum as s}from"./interface.js";class a{client;isRtcVideoOn=!1;rtcConnection;rtcConfig;bizConfig;rtcCallback;restarting=!1;timeoutEvent;reopenTimer;restartCount=0;closeLog=!0;haveVideoOn=!1;rtcStateCallback=null;constructor(t){const{rtcConnection:e,rtcConfig:i,closeLog:c=!0,rtcCallback:n}=t;this.rtcConnection=e,this.rtcConfig=i,this.rtcCallback=n,this.closeLog=c,this.timeoutEvent=new o(6e4,(()=>{if(!this.rtcConnection)return!this.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");this.timeoutEvent.clear(),this.restartRtc&&this.restartRtc(this.rtcConnection)}))}openRtc=o=>{if(this.restarting)!this.closeLog&&console.warn("rtc restarting");else if(o&&(this.rtcConnection=o),this.rtcConnection&&!i(this.rtcConnection)){const{server:i,appId:a,token:r,roomName:l,userId:h}=this.rtcConnection,{onRemotedata:d,onLocalStream:m,onRemoteVideoComing:C,onLocalVideoPublished:b,onLocalVideoPublishing:g,onRemoteVideoOn:u,onRemoteVideoOff:R,onRemoteVideoLoading:f,onSuccess:L,onError:S,onLocalVideoConnected:k,onRemoteVideoConnected:y,onRemoteMediaState:V,onPlayingError:v,onDigitalHumanCallback:p}=this.rtcCallback||{};this.timeoutEvent.start(),this.rtcStateCallback=t=>{const{body:o,action:e}=t;p&&p({status:n.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:e,body:o}})},this.client=new t({roomName:l,token:r,userId:h,appId:a,server:i,rtcConfig:this.rtcConfig,callback:{onRemoteVideoConnected:(t,e)=>{if(!e&&!this.haveVideoOn){let t=setTimeout((()=>{this.restartCount<3?(this.restartCount=++this.restartCount,this.restartRtc&&this.restartRtc(o)):(this.restartCount=0,this.closeRtc()),clearTimeout(t)}),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),v&&v(t),p&&p({status:n.DH_LIB_ERROR,content:{type:s.LOCAL_VIDEO_ERROR}})})),p&&p({status:n.DH_LIB_STATUS,content:{type:s.LOCAL_VIDEO_MUTED}})}))}!this.closeLog&&console.info("remoteVideoConnected",t,e,this.restartCount),this.rtcStateCallback&&this.rtcStateCallback({action:"remoteVideoConnected",body:{id:t,connected:e,restartCount:this.restartCount}}),c(y)&&y(t,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}),p&&p({status:n.DH_LIB_OPEN}),c(u)&&u(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(V)&&V(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=e.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(g)&&g()},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(f)&&f(t)},onRemoteVideoOff:t=>{!this.closeLog&&console.info("remotevideooff: ",t),this.isRtcVideoOn=!1,this.rtcStateCallback&&this.rtcStateCallback({action:"remotevideooff",body:t}),p&&p({status:n.DH_LIB_CLOSE}),c(R)&&R(t),this.timeoutEvent.start()},onSuccess:()=>{!this.closeLog&&console.info("rtc - success"),this.rtcStateCallback&&this.rtcStateCallback({action:"success",body:!0}),c(L)&&L()},onError:t=>{this.isRtcVideoOn=!1,!this.closeLog&&console.error("rtc - error:",t),this.rtcStateCallback&&this.rtcStateCallback({action:"error",body:t}),p&&p({status:n.DH_LIB_ERROR,content:{type:s.RTC_ERROR}}),c(S)&&S(t),(t.includes("Lost connection to the server")||t.includes("Is the server down"))&&this.restartRtc&&this.restartRtc(o)}}})}};closeRtc=()=>{this.timeoutEvent.clear(),clearTimeout(this.reopenTimer),this.client&&this.client.destroy(),this.restarting=!1};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))}}export{a as default};
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};
package/es/Client.js CHANGED
@@ -1 +1 @@
1
- import e from"@bddh/starling-json";import t from"lodash/isEmpty";import r from"lodash/omit";import s from"lodash/pick";import{v4 as a}from"uuid";import{statusEnum as n,errorTypeEnum as o,CONNECT_MAIN_KEY as i}from"./interface.js";import c from"./Server.js";import d from"./BrtcClient.js";import{checkIsHuawei as h,createHumanDom as m,RTC_VIDEO_ID as l,DEFAULT_CANVAS_ID as u,removeHumanDom as p,playHumanVideo as g,muteHumanVideo as S}from"./DomControl.js";import v from"./Cutout.js";class I{token;appKey;appId;connectParams;onDigitalHumanCallback;dhServer;rtcServer;rtcConnectParams;cutoutInstance;isHuawei=h();rtcServerUrl;constructor(e){const{wrapperId:r,token:s,appKey:a,appId:o,connectParams:i,renderParams:h,rtcConnectParams:u,brtcParams:p,wsUrl:g,rtcServerUrl:S,onDigitalHumanCallback:I}=e;this.token=s,this.appKey=a,this.appId=o,this.rtcServerUrl=S,this.connectParams={autoChromaKey:h.autoChromaKey,...i};const{fullStatus:C,closeLog:b}=h;this.onDigitalHumanCallback=e=>{const{status:t}=e;t!==n.DH_LIB_FULL_STATUS?I&&I(e):C&&I&&I(e)},this.dhServer=new c(g||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration");const{playerWrapper:y}=m({autoChromaKey:!!h.autoChromaKey})||{},k=document.getElementById(r);k||console.error("dom with wrapperId is not find"),y&&k&&k.appendChild(y),this.rtcServer=new d({closeLog:b,videoWrapperId:l,rtcConfig:{remotevideoviewid:r,showvideobps:!1,usingvideo:!1,usingaudio:!1,aspublisher:!1,usingdatachannel:!0,autoplaymuted:!1,...p},bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new v({sourceId:l}),t(u)||(this.rtcConnectParams=u,this.rtcServer.openRtc(u))}onRemoteVideoComing=e=>{this.rtcConnectParams&&this.rtcConnectParams.feedId&&e===+this.rtcConnectParams.feedId&&this.rtcServer&&this.rtcServer.client&&this.rtcServer.client.subscribeStreaming("remotevideo500",+this.rtcConnectParams.feedId)};onRemoteVideoOn=()=>{setTimeout((async()=>{const e=document.getElementById(l);if(await(this.cutoutInstance&&this.cutoutInstance.updateSource(l)),e){e.setAttribute("data-playing","true");const{videoWidth:t,videoHeight:r}=e,s=document.getElementById(u),a=s.getContext("2d");s&&a&&(s.width=t,s.height=r,a.drawImage(e,0,0,t,r))}}),100)};connectListener=t=>{const{code:r,body:s,message:a}=t;if(0===r&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:n.DH_LIB_WS_SUCCESS,content:t}),0===r){const t=e.parse(s),{rtcServerUrl:r,appId:a,clientToken:n,roomName:o,clientId:i,feedId:c,chargeId:d}=t;a&&o&&(this.rtcConnectParams={server:this.rtcServerUrl||r,appId:a,token:n,roomName:o,userId:i,feedId:c,chargeId:d},this.rtcServer&&this.rtcServer.openRtc(this.rtcConnectParams))}else this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:n.DH_LIB_ERROR,content:{type:o.CONNECT_ERROR,msg:{code:r,errMsg:a}}})};createServer=e=>{this.dhServer&&this.dhServer.createSocket({token:this.token,appKey:this.appKey,appId:this.appId,...e?{sessionId:e}:{},...s(this.connectParams,i),parameters:r(this.connectParams,i),onConnect:this.connectListener,onDigitalHumanCallback:this.onDigitalHumanCallback})};checkHumanInstansce=()=>{this.dhServer||console.warn("请先初始化数字人示例")};sendMessage=(e,t)=>this.dhServer&&this.dhServer.sendMessage(e,t);interrupt=async()=>new Promise((e=>{this.dhServer&&this.dhServer.sendMessage({requestId:a(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(()=>e()))}));textRender=e=>{const{requestId:t,body:r,onCallbackMsg:s}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:t||a(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},s)};textStreamRender=t=>{const{requestId:r,body:s,onCallbackMsg:n}=t,{first:o}=e.parse(s);this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:r||a(),action:"TEXT_STREAM_RENDER",body:s,clientTs:(new Date).getTime()},o?n:null)};audioRender=e=>{const{body:t,onCallbackMsg:r}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:a(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},r)};audioStreamRender=e=>{const{requestId:t,body:r,onCallbackMsg:s}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:t||a(),action:"AUDIO_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},s)};destory=async()=>{await(this.dhServer&&this.dhServer.closeSocket()),this.rtcServer&&this.rtcServer.closeRtc(),p(),this.dhServer=null,this.rtcServer=null};pauseHuman=()=>g(!1);playHuman=()=>g(!0);muteHuman=()=>S(!0);unMuteHuman=()=>{const e=S(!1);try{return this.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}}export{I as default};
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};
package/es/Cutout.js CHANGED
@@ -1 +1 @@
1
- import t from"@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}};class e{cutoutInstance;constructor(e){const{effects:o,sourceId:n}=e;this.cutoutInstance=new t("starling-cutout-canvas",n||"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)}}export{s as DEFAULT_EFFECTS,e as default};
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};
@@ -19,4 +19,5 @@ export declare function removeHumanDom(): void;
19
19
  export declare function muteHumanVideo(muted: boolean): HTMLVideoElement;
20
20
  export declare function playHumanVideo(play: boolean): void | Promise<void>;
21
21
  export declare function checkIsHuawei(): boolean;
22
+ export declare function appendRtcDomStyle(): void;
22
23
  export {};
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:r=!1,autoplay:a=!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 s=document.createElement("video");s.id=o,s.width=0,s.height=0,s.setAttribute("width","100%"),s.setAttribute("height","100%"),s.setAttribute("data-playing","true"),s.setAttribute("playsinline","");const c=document.createElement("canvas");return c.id=t,Object.assign(c.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:r?"block":"none"}),a&&s.setAttribute("autoplay",""),r&&(s.style.visibility="hidden"),d.appendChild(s),d.appendChild(c),{playerWrapper:d,video:s}}function o(){const t=document.getElementById(e);t&&t.parentNode&&t.parentNode.removeChild(t)}function r(t){const e=document.getElementById(n);return e&&(e.muted=t),e}function a(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)}export{t as DEFAULT_CANVAS_ID,e as HUMAN_WRAPPER_ID,n as RTC_VIDEO_ID,d as checkIsHuawei,i as createHumanDom,r as muteHumanVideo,a as playHumanVideo,o as removeHumanDom};
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};
package/es/Server.js CHANGED
@@ -1 +1 @@
1
- import{v4 as e}from"uuid";import{createWebSocket as t}from"@bddh/starling-web-socket/es/create-web-socket";import s from"lodash/pick";import o from"lodash/omit";import{statusEnum as n,WS_STATUS_MAP as r,errorTypeEnum as i,CONNECT_MAIN_KEY as c}from"./interface.js";class a{dhServerSocket=null;socketClosingPromise=null;url;firstConnect=!0;connectParams=null;constructor(e){this.url=e}createSocket=async s=>{this.connectParams=s;const{token:o,sessionId:c,onConnect:a,onDigitalHumanCallback:h}=s;return this.socketClosingPromise&&await this.socketClosingPromise,this.dhServerSocket&&await this.closeSocket(),new Promise(((s,d)=>{const l=t(this.url,{reopen:!0,keepAlive:"heartbeat",combine:(e,t)=>e&&e.requestId===t&&t.requestId,onOpen:()=>{if(this.dhServerSocket=l,c&&this.firstConnect)return l.request({action:"RE_CONNECT",requestId:e(),body:JSON.stringify({token:o,sessionId:c})}).on(((e,t)=>{a(e),0!==e.code&&(t(),this.handleConnect()),s(l)})),void(this.firstConnect=!1);this.handleConnect()},onClose:()=>{this.dhServerSocket=null,this.socketClosingPromise=null},onError:e=>{d(e)}});l.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:r[e]}})})),l.onMessage((e=>{const{action:t}=e;[i.TIMEOUT_EXIT,i.DISCONNECT_ALERT].includes(t)&&h&&h({status:n.DH_LIB_STATUS,content:{type:t}})})),l.open()}))};closeSocket=async()=>{this.dhServerSocket&&(this.socketClosingPromise=this.dhServerSocket.close(),await this.socketClosingPromise,this.dhServerSocket=null)};handleConnect=async()=>{if(!this.connectParams)return;const{appId:t,appKey:n,token:r,parameters:i,onConnect:a}=this.connectParams;(t||n||r)&&this.dhServerSocket&&this.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:e(),body:JSON.stringify({token:r,appId:t,appKey:n,...s(this.connectParams,c),parameters:{...o(i,["parameters"]),...i&&i.parameters?i.parameters:{}}})}).on(((e,t)=>{a(e),0!==e.code&&t()}))};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{a as default};
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};
@@ -0,0 +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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bddh/starling-realtime-client",
3
- "version": "1.0.7",
3
+ "version": "1.0.8-beta.1",
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": "13384790efae052fbe644f33c3d6ae1089951784"
47
+ "gitHead": "1cee540024b051ebda341ee1bc2d9cb46bcac526"
48
48
  }