@bddh/starling-realtime-client 1.0.0-beta.5 → 1.0.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.
@@ -66,7 +66,6 @@ export interface RtcCallback {
66
66
  onDigitalHumanCallback: (data: CallbackMsgType) => void;
67
67
  }
68
68
  interface BrtcClientType {
69
- brtcParams: any;
70
69
  videoWrapperId: string;
71
70
  bizConfig: BizConfig;
72
71
  closeLog?: boolean;
@@ -78,7 +77,6 @@ interface BrtcClientType {
78
77
  declare class BrtcClient {
79
78
  client?: BRtcInstance;
80
79
  isRtcVideoOn: boolean;
81
- private readonly brtcParams?;
82
80
  private rtcConnection;
83
81
  private readonly rtcConfig?;
84
82
  private readonly bizConfig?;
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"),s=require("./interface.js");exports.default=class{client;isRtcVideoOn=!1;brtcParams;rtcConnection;rtcConfig;bizConfig;rtcCallback;restarting=!1;timeoutEvent;reopenTimer;restartCount=0;closeLog=!0;haveVideoOn=!1;rtcStateCallback=null;constructor(t){const{brtcParams:o,rtcConnection:i,rtcConfig:n,closeLog:s=!0,rtcCallback:c}=t;this.brtcParams=o,this.rtcConnection=i,this.rtcConfig=n,this.rtcCallback=c,this.closeLog=s,this.timeoutEvent=new e.TimeoutController(6e4,(()=>{if(!this.rtcConnection)return!this.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");this.timeoutEvent.clear(),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:c,token:r,roomName:a,userId:l}=this.rtcConnection,{onRemotedata:d,onLocalStream:h,onRemoteVideoComing:m,onLocalVideoPublished:u,onLocalVideoPublishing:C,onRemoteVideoOn:b,onRemoteVideoOff:g,onRemoteVideoLoading:L,onSuccess:R,onError:f,onLocalVideoConnected:y,onRemoteVideoConnected:v,onRemoteMediaState:E,onPlayingError:S,onDigitalHumanCallback:V}=this.rtcCallback||{};this.timeoutEvent.start(),this.rtcStateCallback=t=>{const{body:e,action:o}=t;V&&V({status:s.statusEnum.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:o,body:e}})},this.client=new t({roomName:a,token:r,userId:l,appId:c,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?.(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&&(console.log("promise",e),e.catch((()=>{t.muted=!0,t.play().catch((e=>{!this.closeLog&&console.info("videoElement play error",e),S?.(t),V&&V({status:s.statusEnum.DH_LIB_ERROR,content:{type:s.errorTypeEnum.LOCAL_VIDEO_ERROR}})})),V&&V({status:s.statusEnum.DH_LIB_STATUS,content:{type:s.errorTypeEnum.LOCAL_VIDEO_MUTED}})})))}!this.closeLog&&console.info("remoteVideoConnected",t,o,this.restartCount),this.rtcStateCallback?.({action:"remoteVideoConnected",body:{id:t,connected:o,restartCount:this.restartCount}}),n(v)&&v(t,o)},onRemoteVideoOn:t=>{this.haveVideoOn=!0,!this.closeLog&&console.info("remotevideoon by id: ",t),this.timeoutEvent.clear();const e=document.querySelector("#starlingRtcContainer")?.lastChild;e&&(e.style.display="none"),this.rtcStateCallback?.({action:"remotevideoon",body:t}),V&&V({status:s.statusEnum.DH_LIB_OPEN}),n(b)&&b(t)},onRemoteMediaState:(t,e,o)=>{!this.closeLog&&console.info("remoteMediaState",t,e,o),this.rtcStateCallback?.({action:"remoteMediaState",body:{id:t,medium:e,connected:o}}),n(E)&&E(t,e,o)},onLocalVideoConnected:t=>{!this.closeLog&&console.info("localVideoConnected",t),this.rtcStateCallback?.({action:"localVideoConnected",body:{connected:t}}),n(y)&&y(t)},onRemotedata:t=>{if(this.rtcConfig?.usingdatachannel){const e=o.parse(t);!this.closeLog&&console.info("RTC - receive:",e),n(d)&&d(e)}},onLocalStream:(t,e)=>{!this.closeLog&&console.info("rtc - onlocalstream by name: "+e),this.rtcStateCallback?.({action:"onlocalstream",body:{stream:t,name:e}}),n(h)&&h(t,e)},onLocalVideoPublished:()=>{!this.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),this.rtcStateCallback?.({action:"localvideopublished_ok",body:!0}),n(u)&&u()},onLocalVideoPublishing:()=>{!this.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),this.rtcStateCallback?.({action:"localvideopublishing",body:!0}),n(C)&&C()},onRemoteVideoComing:t=>{!this.closeLog&&console.info("remotevideocoming",t),this.rtcStateCallback?.({action:"remotevideocoming",body:t}),n(m)&&m(t)},onRemoteVideoLoading:t=>{!this.closeLog&&console.info("remotevideoloading by id: ",t),this.rtcStateCallback?.({action:"remotevideoloading",body:t}),n(L)&&L(t)},onRemoteVideoOff:t=>{!this.closeLog&&console.info("remotevideooff: ",t),this.isRtcVideoOn=!1,this.rtcStateCallback?.({action:"remotevideooff",body:t}),V&&V({status:s.statusEnum.DH_LIB_CLOSE}),n(g)&&g(t),this.timeoutEvent.start()},onSuccess:()=>{!this.closeLog&&console.info("rtc - success"),this.rtcStateCallback?.({action:"success",body:!0}),n(R)&&R()},onError:t=>{this.isRtcVideoOn=!1,!this.closeLog&&console.error("rtc - error:",t),this.rtcStateCallback?.({action:"error",body:t}),V&&V({status:s.statusEnum.DH_LIB_ERROR,content:{type:s.errorTypeEnum.RTC_ERROR}}),n(f)&&f(t),(t.includes("Lost connection to the server")||t.includes("Is the server down"))&&this.restartRtc?.(e)}}})}};closeRtc=()=>{this.timeoutEvent.clear(),clearTimeout(this.reopenTimer),this.client?.destroy(),this.restarting=!1};restartRtc=t=>{!this.restarting&&this.bizConfig?.autoReConnect&&(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("@bddh/starling-brtc"),e=require("@bddh/starling-timeout-controller"),o=require("@bddh/starling-json"),i=require("lodash/isEmpty"),n=require("lodash/isFunction"),s=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:s}=t;this.rtcConnection=o,this.rtcConfig=i,this.rtcCallback=s,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.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:c,token:r,roomName:a,userId:l}=this.rtcConnection,{onRemotedata:d,onLocalStream:h,onRemoteVideoComing:u,onLocalVideoPublished:m,onLocalVideoPublishing:C,onRemoteVideoOn:g,onRemoteVideoOff:b,onRemoteVideoLoading:L,onSuccess:R,onError:f,onLocalVideoConnected:y,onRemoteVideoConnected:v,onRemoteMediaState:E,onPlayingError:S,onDigitalHumanCallback:V}=this.rtcCallback||{};this.timeoutEvent.start(),this.rtcStateCallback=t=>{const{body:e,action:o}=t;V&&V({status:s.statusEnum.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:o,body:e}})},this.client=new t({roomName:a,token:r,userId:l,appId:c,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?.(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),S?.(t),V&&V({status:s.statusEnum.DH_LIB_ERROR,content:{type:s.errorTypeEnum.LOCAL_VIDEO_ERROR}})})),V&&V({status:s.statusEnum.DH_LIB_STATUS,content:{type:s.errorTypeEnum.LOCAL_VIDEO_MUTED}})}))}!this.closeLog&&console.info("remoteVideoConnected",t,o,this.restartCount),this.rtcStateCallback?.({action:"remoteVideoConnected",body:{id:t,connected:o,restartCount:this.restartCount}}),n(v)&&v(t,o)},onRemoteVideoOn:t=>{this.haveVideoOn=!0,!this.closeLog&&console.info("remotevideoon by id: ",t),this.timeoutEvent.clear();const e=document.querySelector("#starlingRtcContainer")?.lastChild;e&&(e.style.display="none"),this.rtcStateCallback?.({action:"remotevideoon",body:t}),V&&V({status:s.statusEnum.DH_LIB_OPEN}),n(g)&&g(t)},onRemoteMediaState:(t,e,o)=>{!this.closeLog&&console.info("remoteMediaState",t,e,o),this.rtcStateCallback?.({action:"remoteMediaState",body:{id:t,medium:e,connected:o}}),n(E)&&E(t,e,o)},onLocalVideoConnected:t=>{!this.closeLog&&console.info("localVideoConnected",t),this.rtcStateCallback?.({action:"localVideoConnected",body:{connected:t}}),n(y)&&y(t)},onRemotedata:t=>{if(this.rtcConfig?.usingdatachannel){const e=o.parse(t);!this.closeLog&&console.info("RTC - receive:",e),n(d)&&d(e)}},onLocalStream:(t,e)=>{!this.closeLog&&console.info("rtc - onlocalstream by name: "+e),this.rtcStateCallback?.({action:"onlocalstream",body:{stream:t,name:e}}),n(h)&&h(t,e)},onLocalVideoPublished:()=>{!this.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),this.rtcStateCallback?.({action:"localvideopublished_ok",body:!0}),n(m)&&m()},onLocalVideoPublishing:()=>{!this.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),this.rtcStateCallback?.({action:"localvideopublishing",body:!0}),n(C)&&C()},onRemoteVideoComing:t=>{!this.closeLog&&console.info("remotevideocoming",t),this.rtcStateCallback?.({action:"remotevideocoming",body:t}),n(u)&&u(t)},onRemoteVideoLoading:t=>{!this.closeLog&&console.info("remotevideoloading by id: ",t),this.rtcStateCallback?.({action:"remotevideoloading",body:t}),n(L)&&L(t)},onRemoteVideoOff:t=>{!this.closeLog&&console.info("remotevideooff: ",t),this.isRtcVideoOn=!1,this.rtcStateCallback?.({action:"remotevideooff",body:t}),V&&V({status:s.statusEnum.DH_LIB_CLOSE}),n(b)&&b(t),this.timeoutEvent.start()},onSuccess:()=>{!this.closeLog&&console.info("rtc - success"),this.rtcStateCallback?.({action:"success",body:!0}),n(R)&&R()},onError:t=>{this.isRtcVideoOn=!1,!this.closeLog&&console.error("rtc - error:",t),this.rtcStateCallback?.({action:"error",body:t}),V&&V({status:s.statusEnum.DH_LIB_ERROR,content:{type:s.errorTypeEnum.RTC_ERROR}}),n(f)&&f(t),(t.includes("Lost connection to the server")||t.includes("Is the server down"))&&this.restartRtc?.(e)}}})}};closeRtc=()=>{this.timeoutEvent.clear(),clearTimeout(this.reopenTimer),this.client?.destroy(),this.restarting=!1};restartRtc=t=>{!this.restarting&&this.bizConfig?.autoReConnect&&(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))}};
package/cjs/Client.d.ts CHANGED
@@ -24,13 +24,14 @@ export default class DhRealtimeHuman {
24
24
  createServer: (sessionId?: string) => void;
25
25
  checkHumanInstansce: () => void;
26
26
  sendMessage: (message: DHServerInterface, listener: RenderCallback | null) => Promise<void> | undefined;
27
+ interrupt: () => Promise<void>;
27
28
  textRender: (renderData: {
28
29
  requestId: string;
29
30
  body: string;
30
31
  onCallbackMsg: RenderCallback;
31
32
  }) => void;
32
33
  textStreamRender: (renderData: {
33
- requestId: string;
34
+ requestId?: string;
34
35
  body: string;
35
36
  onCallbackMsg: RenderCallback;
36
37
  }) => void;
@@ -39,6 +40,7 @@ export default class DhRealtimeHuman {
39
40
  onCallbackMsg: RenderCallback;
40
41
  }) => void;
41
42
  audioStreamRender: (renderData: {
43
+ requestId?: string;
42
44
  body: string;
43
45
  onCallbackMsg: RenderCallback;
44
46
  }) => void;
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"),a=require("uuid"),n=require("./interface.js"),s=require("./Server.js"),r=require("./BrtcClient.js"),o=require("./DomControl.js"),i=require("./Cutout.js");exports.default=class{token;appKey;appId;connectParams;renderParams;onDigitalHumanCallback;dhServer;rtcServer;rtcConnectParams;cutoutInstance;isHuawei=o.checkIsHuawei();constructor(e){const{wrapperId:a,token:c,appKey:d,appId:u,connectParams:m,renderParams:l,rtcConnectParams:h,onDigitalHumanCallback:p}=e;this.token=c,this.appKey=d,this.appId=u,this.connectParams=m,this.renderParams=l;const{fullStatus:I,closeLog:g}=l;this.onDigitalHumanCallback=e=>{const{status:t}=e;t!==n.statusEnum.DH_LIB_FULL_STATUS?p&&p(e):I&&p&&p(e)},this.dhServer=new s.default("wss://persona.baidu.com:8850/cloud/digital-human-demonstration");const{playerWrapper:C}=o.createHumanDom({autoChromaKey:!!l.autoChromaKey})||{},v=document.getElementById(a);v||console.error("dom with wrapperId is not find"),C&&v?.appendChild(C),this.rtcServer=new r.default({closeLog:g,brtcParams:{},videoWrapperId:o.RTC_VIDEO_ID,rtcConfig:{remotevideoviewid:a,showvideobps:!1,usingvideo:!1,usingaudio:!1,aspublisher:!1,usingdatachannel:!0,autoplaymuted:!1},bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new i.default({sourceId:o.RTC_VIDEO_ID}),t(h)||(this.rtcConnectParams=h,this.rtcServer.openRtc(h))}onRemoteVideoComing=e=>{this.rtcConnectParams&&this.rtcConnectParams.feedId&&e===+this.rtcConnectParams.feedId&&this.rtcServer?.client?.subscribeStreaming("remotevideo500",+this.rtcConnectParams.feedId)};onRemoteVideoOn=()=>{setTimeout((async()=>{const e=document.getElementById(o.RTC_VIDEO_ID);if(await(this.cutoutInstance?.updateSource?.(o.RTC_VIDEO_ID)),e){e.setAttribute?.("data-playing","true");const{videoWidth:t,videoHeight:a}=e,n=document.getElementById(o.DEFAULT_CANVAS_ID),s=n.getContext("2d");n&&s&&(n.width=t,n.height=a,s.drawImage(e,0,0,t,a))}}),100)};connectListener=t=>{const{code:a,body:n}=t;if(0===a){const t=e.parse(n),{rtcServerUrl:a,appId:s,clientToken:r,roomName:o,clientId:i,feedId:c,chargeId:d}=t;this.rtcConnectParams={server:a,appId:s,token:r,roomName:o,userId:i,feedId:c,chargeId:d},s&&o&&this.rtcServer?.openRtc(this.rtcConnectParams)}};createServer=e=>{this.dhServer?.createSocket({token:this.token,appKey:this.appKey,appId:this.appId,...e?{sessionId:e}:{},parameters:this.connectParams,onConnect:this.connectListener,onDigitalHumanCallback:this.onDigitalHumanCallback})};checkHumanInstansce=()=>{this.dhServer||console.warn("请先初始化数字人示例")};sendMessage=(e,t)=>this.dhServer?.sendMessage(e,t);textRender=e=>{const{requestId:t,body:n,onCallbackMsg:s}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:t||a.v4(),action:"TEXT_RENDER",body:n,clientTs:(new Date).getTime()},s)};textStreamRender=t=>{const{requestId:n,body:s,onCallbackMsg:r}=t,{first:o}=e.parse(s);this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:n||a.v4(),action:"TEXT_STREAM_RENDER",body:s,clientTs:(new Date).getTime()},o?r:null)};audioRender=e=>{const{body:t,onCallbackMsg:n}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:a.v4(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},n)};audioStreamRender=e=>{const{body:t,onCallbackMsg:n}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:a.v4(),action:"AUDIO_STREAM_RENDER",body:t,clientTs:(new Date).getTime()},n)};destory=async()=>{await(this.dhServer?.closeSocket()),this.rtcServer?.closeRtc(),o.removeHumanDom(),this.dhServer=null,this.rtcServer=null};pauseHuman=()=>o.playHumanVideo(!1);playHuman=()=>o.playHumanVideo(!0);muteHuman=()=>o.muteHumanVideo(!0);unMuteHuman=()=>{const e=o.muteHumanVideo(!1);if(!this.isHuawei)return e.paused&&e.play();e.pause(),e.play()}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@bddh/starling-json"),t=require("lodash/isEmpty"),a=require("lodash/omit"),n=require("lodash/pick"),s=require("uuid"),r=require("./interface.js"),o=require("./Server.js"),i=require("./BrtcClient.js"),c=require("./DomControl.js"),d=require("./Cutout.js");exports.default=class{token;appKey;appId;connectParams;renderParams;onDigitalHumanCallback;dhServer;rtcServer;rtcConnectParams;cutoutInstance;isHuawei=c.checkIsHuawei();constructor(e){const{wrapperId:a,token:n,appKey:s,appId:u,connectParams:m,renderParams:l,rtcConnectParams:h,brtcParams:p,onDigitalHumanCallback:I}=e;this.token=n,this.appKey=s,this.appId=u,this.connectParams=m,this.renderParams=l;const{fullStatus:g,closeLog:C}=l;this.onDigitalHumanCallback=e=>{const{status:t}=e;t!==r.statusEnum.DH_LIB_FULL_STATUS?I&&I(e):g&&I&&I(e)},this.dhServer=new o.default("wss://persona.baidu.com:8850/cloud/digital-human-demonstration");const{playerWrapper:v}=c.createHumanDom({autoChromaKey:!!l.autoChromaKey})||{},y=document.getElementById(a);y||console.error("dom with wrapperId is not find"),v&&y?.appendChild(v),this.rtcServer=new i.default({closeLog:C,videoWrapperId:c.RTC_VIDEO_ID,rtcConfig:{remotevideoviewid:a,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(h)||(this.rtcConnectParams=h,this.rtcServer.openRtc(h))}onRemoteVideoComing=e=>{this.rtcConnectParams&&this.rtcConnectParams.feedId&&e===+this.rtcConnectParams.feedId&&this.rtcServer?.client?.subscribeStreaming("remotevideo500",+this.rtcConnectParams.feedId)};onRemoteVideoOn=()=>{setTimeout((async()=>{const e=document.getElementById(c.RTC_VIDEO_ID);if(await(this.cutoutInstance?.updateSource?.(c.RTC_VIDEO_ID)),e){e.setAttribute?.("data-playing","true");const{videoWidth:t,videoHeight:a}=e,n=document.getElementById(c.DEFAULT_CANVAS_ID),s=n.getContext("2d");n&&s&&(n.width=t,n.height=a,s.drawImage(e,0,0,t,a))}}),100)};connectListener=t=>{const{code:a,body:n}=t;if(0===a){const t=e.parse(n),{rtcServerUrl:a,appId:s,clientToken:r,roomName:o,clientId:i,feedId:c,chargeId:d}=t;this.rtcConnectParams={server:a,appId:s,token:r,roomName:o,userId:i,feedId:c,chargeId:d},s&&o&&this.rtcServer?.openRtc(this.rtcConnectParams)}};createServer=e=>{this.dhServer?.createSocket({token:this.token,appKey:this.appKey,appId:this.appId,...e?{sessionId:e}:{},...n(this.connectParams,r.CONNECT_MAIN_KEY),parameters:a(this.connectParams,r.CONNECT_MAIN_KEY),onConnect:this.connectListener,onDigitalHumanCallback:this.onDigitalHumanCallback})};checkHumanInstansce=()=>{this.dhServer||console.warn("请先初始化数字人示例")};sendMessage=(e,t)=>this.dhServer?.sendMessage(e,t);interrupt=async()=>new Promise((e=>{this.dhServer?.sendMessage({requestId:s.v4(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(()=>e()))}));textRender=e=>{const{requestId:t,body:a,onCallbackMsg:n}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:t||s.v4(),action:"TEXT_RENDER",body:a,clientTs:(new Date).getTime()},n)};textStreamRender=t=>{const{requestId:a,body:n,onCallbackMsg:r}=t,{first:o}=e.parse(n);this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:a||s.v4(),action:"TEXT_STREAM_RENDER",body:n,clientTs:(new Date).getTime()},o?r:null)};audioRender=e=>{const{body:t,onCallbackMsg:a}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:s.v4(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},a)};audioStreamRender=e=>{const{requestId:t,body:a,onCallbackMsg:n}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:t||s.v4(),action:"AUDIO_STREAM_RENDER",body:a,clientTs:(new Date).getTime()},n)};destory=async()=>{await(this.dhServer?.closeSocket()),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.log(e)}}};
package/cjs/DomControl.js CHANGED
@@ -1 +1 @@
1
- "use strict";const 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.checkIsHuawei=function(){const e=navigator.userAgent||navigator.vendor;return/huawei/i.test(e)||/honor/i.test(e)},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=t,s.id=t,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=e,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(e){const t=document.getElementById(n);return t&&(t.muted=e),t},exports.playHumanVideo=function(e){const t=document.getElementById(n);if(t)return e?t.play():t.pause()},exports.removeHumanDom=function(){const e=document.getElementById(t);e&&e.parentNode&&e.parentNode.removeChild(e)};
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)};
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("./interface.js");exports.default=class{dhServerSocket=null;socketClosingPromise=null;url;firstConnect=!0;connectParams=null;constructor(e){this.url=e}createSocket=async n=>{this.connectParams=n;const{token:o,sessionId:r,onConnect:c,onDigitalHumanCallback:i}=n;return this.socketClosingPromise&&await this.socketClosingPromise,this.dhServerSocket&&await this.closeSocket(),new Promise(((n,a)=>{const u=t.createWebSocket(this.url,{reopen:!0,keepAlive:"heartbeat",combine:(e,t)=>e?.requestId===t?.requestId,onOpen:()=>{if(this.dhServerSocket=u,r&&this.firstConnect)return u.request({action:"RE_CONNECT",requestId:e.v4(),body:JSON.stringify({token:o,sessionId:r})}).on(((e,t)=>{c(e),0!==e.code&&(t(),this.handleConnect()),n(u)})),void(this.firstConnect=!1);this.handleConnect()},onClose:()=>{this.dhServerSocket=null,this.socketClosingPromise=null},onError:e=>{a(e)}});u.onReadyStateChange((e=>{-1===e&&i&&i({status:s.statusEnum.DH_LIB_INIT}),i&&i({status:s.statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:s.WS_STATUS_MAP[e]}})})),u.onMessage((e=>{const{action:t}=e;[s.errorTypeEnum.TIMEOUT_EXIT,s.errorTypeEnum.DISCONNECT_ALERT].includes(t)&&i&&i({status:s.statusEnum.DH_LIB_STATUS,content:{type:t}})})),u.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:s,token:n,parameters:o,onConnect:r}=this.connectParams;(t||s||n)&&this.dhServerSocket?.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:e.v4(),body:JSON.stringify({token:n,appId:t,appKey:s,parameters:o})}).on(((e,t)=>{r(e),0!==e.code&&t()}))};async sendMessage(e,t){try{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("uuid"),t=require("@bddh/starling-web-socket/es/create-web-socket"),s=require("lodash/pick"),n=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:o,sessionId:r,onConnect:c,onDigitalHumanCallback:i}=s;return this.socketClosingPromise&&await this.socketClosingPromise,this.dhServerSocket&&await this.closeSocket(),new Promise(((s,a)=>{const u=t.createWebSocket(this.url,{reopen:!0,keepAlive:"heartbeat",combine:(e,t)=>e?.requestId===t?.requestId,onOpen:()=>{if(this.dhServerSocket=u,r&&this.firstConnect)return u.request({action:"RE_CONNECT",requestId:e.v4(),body:JSON.stringify({token:o,sessionId:r})}).on(((e,t)=>{c(e),0!==e.code&&(t(),this.handleConnect()),s(u)})),void(this.firstConnect=!1);this.handleConnect()},onClose:()=>{this.dhServerSocket=null,this.socketClosingPromise=null},onError:e=>{a(e)}});u.onReadyStateChange((e=>{-1===e&&i&&i({status:n.statusEnum.DH_LIB_INIT}),i&&i({status:n.statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:n.WS_STATUS_MAP[e]}})})),u.onMessage((e=>{const{action:t}=e;[n.errorTypeEnum.TIMEOUT_EXIT,n.errorTypeEnum.DISCONNECT_ALERT].includes(t)&&i&&i({status:n.statusEnum.DH_LIB_STATUS,content:{type:t}})})),u.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:o,token:r,parameters:c,onConnect:i}=this.connectParams;(t||o||r)&&this.dhServerSocket?.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:e.v4(),body:JSON.stringify({token:r,appId:t,appKey:o,...s(this.connectParams,n.CONNECT_MAIN_KEY),parameters:{...c,...c?.extraParameters&&c?.extraParameters||{}}})}).on(((e,t)=>{i(e),0!==e.code&&t()}))};async sendMessage(e,t){try{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)})}}};
package/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./Client.js"),r=require("./interface.js");exports.default=e.default,exports.WS_STATUS_MAP=r.WS_STATUS_MAP,Object.defineProperty(exports,"errorTypeEnum",{enumerable:!0,get:function(){return r.errorTypeEnum}}),Object.defineProperty(exports,"statusEnum",{enumerable:!0,get:function(){return r.statusEnum}});
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./Client.js"),r=require("./interface.js");exports.default=e.default,exports.CONNECT_MAIN_KEY=r.CONNECT_MAIN_KEY,exports.WS_STATUS_MAP=r.WS_STATUS_MAP,Object.defineProperty(exports,"errorTypeEnum",{enumerable:!0,get:function(){return r.errorTypeEnum}}),Object.defineProperty(exports,"statusEnum",{enumerable:!0,get:function(){return r.statusEnum}});
@@ -23,7 +23,20 @@ export interface ConnectParamsType {
23
23
  inactiveDisconnectSec?: number;
24
24
  preAlertSec?: number;
25
25
  x264BitRate?: number;
26
+ backgroundImageUrl?: string;
27
+ projectId?: string;
28
+ characterConfigId?: string;
29
+ selectors?: any;
30
+ figureName?: string;
31
+ configVersion?: string;
32
+ extraInfo?: any;
33
+ roomName?: string;
34
+ paintSubtitleOnPicture?: boolean;
35
+ h5Embedded?: boolean;
36
+ paintWidgetOnPicture?: boolean;
37
+ extraParameters?: any;
26
38
  }
39
+ export declare const CONNECT_MAIN_KEY: string[];
27
40
  export interface RenderParamsType {
28
41
  chromaEffects?: object;
29
42
  autoChromaKey?: boolean;
@@ -83,5 +96,6 @@ export interface DhRealtimeHumanType {
83
96
  connectParams: ConnectParamsType;
84
97
  renderParams: RenderParamsType;
85
98
  rtcConnectParams?: RtcConnectionType;
99
+ brtcParams?: any;
86
100
  onDigitalHumanCallback: (data: CallbackMsgType) => void;
87
101
  }
package/cjs/interface.js CHANGED
@@ -1 +1 @@
1
- "use strict";var _,E;exports.statusEnum=void 0,(_=exports.statusEnum||(exports.statusEnum={})).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",exports.errorTypeEnum=void 0,(E=exports.errorTypeEnum||(exports.errorTypeEnum={})).CONNECT_ERROR="CONNECT_ERROR",E.DISCONNECT_ALERT="DISCONNECT_ALERT",E.TIMEOUT_EXIT="TIMEOUT_EXIT",E.LOCAL_VIDEO_MUTED="LOCAL_VIDEO_MUTED",E.LOCAL_VIDEO_ERROR="LOCAL_VIDEO_ERROR",E.RTC_ERROR="RTC_ERROR";exports.WS_STATUS_MAP={"-1":"UNINSTANTIATED",0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"};
1
+ "use strict";var _,E;exports.statusEnum=void 0,(_=exports.statusEnum||(exports.statusEnum={})).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",exports.errorTypeEnum=void 0,(E=exports.errorTypeEnum||(exports.errorTypeEnum={})).CONNECT_ERROR="CONNECT_ERROR",E.DISCONNECT_ALERT="DISCONNECT_ALERT",E.TIMEOUT_EXIT="TIMEOUT_EXIT",E.LOCAL_VIDEO_MUTED="LOCAL_VIDEO_MUTED",E.LOCAL_VIDEO_ERROR="LOCAL_VIDEO_ERROR",E.RTC_ERROR="RTC_ERROR";exports.CONNECT_MAIN_KEY=["projectId","characterConfigId","configVersion","selectors","figureName"],exports.WS_STATUS_MAP={"-1":"UNINSTANTIATED",0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"};
@@ -66,7 +66,6 @@ export interface RtcCallback {
66
66
  onDigitalHumanCallback: (data: CallbackMsgType) => void;
67
67
  }
68
68
  interface BrtcClientType {
69
- brtcParams: any;
70
69
  videoWrapperId: string;
71
70
  bizConfig: BizConfig;
72
71
  closeLog?: boolean;
@@ -78,7 +77,6 @@ interface BrtcClientType {
78
77
  declare class BrtcClient {
79
78
  client?: BRtcInstance;
80
79
  isRtcVideoOn: boolean;
81
- private readonly brtcParams?;
82
80
  private rtcConnection;
83
81
  private readonly rtcConfig?;
84
82
  private readonly bizConfig?;
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 n from"lodash/isFunction";import{statusEnum as c,errorTypeEnum as s}from"./interface.js";class r{client;isRtcVideoOn=!1;brtcParams;rtcConnection;rtcConfig;bizConfig;rtcCallback;restarting=!1;timeoutEvent;reopenTimer;restartCount=0;closeLog=!0;haveVideoOn=!1;rtcStateCallback=null;constructor(t){const{brtcParams:e,rtcConnection:i,rtcConfig:n,closeLog:c=!0,rtcCallback:s}=t;this.brtcParams=e,this.rtcConnection=i,this.rtcConfig=n,this.rtcCallback=s,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.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:r,token:a,roomName:l,userId:d}=this.rtcConnection,{onRemotedata:h,onLocalStream:m,onRemoteVideoComing:C,onLocalVideoPublished:u,onLocalVideoPublishing:b,onRemoteVideoOn:g,onRemoteVideoOff:L,onRemoteVideoLoading:f,onSuccess:R,onError:y,onLocalVideoConnected:S,onRemoteVideoConnected:V,onRemoteMediaState:p,onPlayingError:v,onDigitalHumanCallback:k}=this.rtcCallback||{};this.timeoutEvent.start(),this.rtcStateCallback=t=>{const{body:o,action:e}=t;k&&k({status:c.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:e,body:o}})},this.client=new t({roomName:l,token:a,userId:d,appId:r,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?.(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&&(console.log("promise",o),o.catch((()=>{t.muted=!0,t.play().catch((o=>{!this.closeLog&&console.info("videoElement play error",o),v?.(t),k&&k({status:c.DH_LIB_ERROR,content:{type:s.LOCAL_VIDEO_ERROR}})})),k&&k({status:c.DH_LIB_STATUS,content:{type:s.LOCAL_VIDEO_MUTED}})})))}!this.closeLog&&console.info("remoteVideoConnected",t,e,this.restartCount),this.rtcStateCallback?.({action:"remoteVideoConnected",body:{id:t,connected:e,restartCount:this.restartCount}}),n(V)&&V(t,e)},onRemoteVideoOn:t=>{this.haveVideoOn=!0,!this.closeLog&&console.info("remotevideoon by id: ",t),this.timeoutEvent.clear();const o=document.querySelector("#starlingRtcContainer")?.lastChild;o&&(o.style.display="none"),this.rtcStateCallback?.({action:"remotevideoon",body:t}),k&&k({status:c.DH_LIB_OPEN}),n(g)&&g(t)},onRemoteMediaState:(t,o,e)=>{!this.closeLog&&console.info("remoteMediaState",t,o,e),this.rtcStateCallback?.({action:"remoteMediaState",body:{id:t,medium:o,connected:e}}),n(p)&&p(t,o,e)},onLocalVideoConnected:t=>{!this.closeLog&&console.info("localVideoConnected",t),this.rtcStateCallback?.({action:"localVideoConnected",body:{connected:t}}),n(S)&&S(t)},onRemotedata:t=>{if(this.rtcConfig?.usingdatachannel){const o=e.parse(t);!this.closeLog&&console.info("RTC - receive:",o),n(h)&&h(o)}},onLocalStream:(t,o)=>{!this.closeLog&&console.info("rtc - onlocalstream by name: "+o),this.rtcStateCallback?.({action:"onlocalstream",body:{stream:t,name:o}}),n(m)&&m(t,o)},onLocalVideoPublished:()=>{!this.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),this.rtcStateCallback?.({action:"localvideopublished_ok",body:!0}),n(u)&&u()},onLocalVideoPublishing:()=>{!this.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),this.rtcStateCallback?.({action:"localvideopublishing",body:!0}),n(b)&&b()},onRemoteVideoComing:t=>{!this.closeLog&&console.info("remotevideocoming",t),this.rtcStateCallback?.({action:"remotevideocoming",body:t}),n(C)&&C(t)},onRemoteVideoLoading:t=>{!this.closeLog&&console.info("remotevideoloading by id: ",t),this.rtcStateCallback?.({action:"remotevideoloading",body:t}),n(f)&&f(t)},onRemoteVideoOff:t=>{!this.closeLog&&console.info("remotevideooff: ",t),this.isRtcVideoOn=!1,this.rtcStateCallback?.({action:"remotevideooff",body:t}),k&&k({status:c.DH_LIB_CLOSE}),n(L)&&L(t),this.timeoutEvent.start()},onSuccess:()=>{!this.closeLog&&console.info("rtc - success"),this.rtcStateCallback?.({action:"success",body:!0}),n(R)&&R()},onError:t=>{this.isRtcVideoOn=!1,!this.closeLog&&console.error("rtc - error:",t),this.rtcStateCallback?.({action:"error",body:t}),k&&k({status:c.DH_LIB_ERROR,content:{type:s.RTC_ERROR}}),n(y)&&y(t),(t.includes("Lost connection to the server")||t.includes("Is the server down"))&&this.restartRtc?.(o)}}})}};closeRtc=()=>{this.timeoutEvent.clear(),clearTimeout(this.reopenTimer),this.client?.destroy(),this.restarting=!1};restartRtc=t=>{!this.restarting&&this.bizConfig?.autoReConnect&&(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{r as default};
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 n from"lodash/isFunction";import{statusEnum as c,errorTypeEnum as s}from"./interface.js";class r{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:n=!0,rtcCallback:c}=t;this.rtcConnection=e,this.rtcConfig=i,this.rtcCallback=c,this.closeLog=n,this.timeoutEvent=new o(6e4,(()=>{if(!this.rtcConnection)return!this.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");this.timeoutEvent.clear(),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:r,token:a,roomName:l,userId:d}=this.rtcConnection,{onRemotedata:h,onLocalStream:m,onRemoteVideoComing:C,onLocalVideoPublished:u,onLocalVideoPublishing:g,onRemoteVideoOn:b,onRemoteVideoOff:L,onRemoteVideoLoading:f,onSuccess:R,onError:y,onLocalVideoConnected:S,onRemoteVideoConnected:V,onRemoteMediaState:v,onPlayingError:p,onDigitalHumanCallback:k}=this.rtcCallback||{};this.timeoutEvent.start(),this.rtcStateCallback=t=>{const{body:o,action:e}=t;k&&k({status:c.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:e,body:o}})},this.client=new t({roomName:l,token:a,userId:d,appId:r,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?.(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),p?.(t),k&&k({status:c.DH_LIB_ERROR,content:{type:s.LOCAL_VIDEO_ERROR}})})),k&&k({status:c.DH_LIB_STATUS,content:{type:s.LOCAL_VIDEO_MUTED}})}))}!this.closeLog&&console.info("remoteVideoConnected",t,e,this.restartCount),this.rtcStateCallback?.({action:"remoteVideoConnected",body:{id:t,connected:e,restartCount:this.restartCount}}),n(V)&&V(t,e)},onRemoteVideoOn:t=>{this.haveVideoOn=!0,!this.closeLog&&console.info("remotevideoon by id: ",t),this.timeoutEvent.clear();const o=document.querySelector("#starlingRtcContainer")?.lastChild;o&&(o.style.display="none"),this.rtcStateCallback?.({action:"remotevideoon",body:t}),k&&k({status:c.DH_LIB_OPEN}),n(b)&&b(t)},onRemoteMediaState:(t,o,e)=>{!this.closeLog&&console.info("remoteMediaState",t,o,e),this.rtcStateCallback?.({action:"remoteMediaState",body:{id:t,medium:o,connected:e}}),n(v)&&v(t,o,e)},onLocalVideoConnected:t=>{!this.closeLog&&console.info("localVideoConnected",t),this.rtcStateCallback?.({action:"localVideoConnected",body:{connected:t}}),n(S)&&S(t)},onRemotedata:t=>{if(this.rtcConfig?.usingdatachannel){const o=e.parse(t);!this.closeLog&&console.info("RTC - receive:",o),n(h)&&h(o)}},onLocalStream:(t,o)=>{!this.closeLog&&console.info("rtc - onlocalstream by name: "+o),this.rtcStateCallback?.({action:"onlocalstream",body:{stream:t,name:o}}),n(m)&&m(t,o)},onLocalVideoPublished:()=>{!this.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),this.rtcStateCallback?.({action:"localvideopublished_ok",body:!0}),n(u)&&u()},onLocalVideoPublishing:()=>{!this.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),this.rtcStateCallback?.({action:"localvideopublishing",body:!0}),n(g)&&g()},onRemoteVideoComing:t=>{!this.closeLog&&console.info("remotevideocoming",t),this.rtcStateCallback?.({action:"remotevideocoming",body:t}),n(C)&&C(t)},onRemoteVideoLoading:t=>{!this.closeLog&&console.info("remotevideoloading by id: ",t),this.rtcStateCallback?.({action:"remotevideoloading",body:t}),n(f)&&f(t)},onRemoteVideoOff:t=>{!this.closeLog&&console.info("remotevideooff: ",t),this.isRtcVideoOn=!1,this.rtcStateCallback?.({action:"remotevideooff",body:t}),k&&k({status:c.DH_LIB_CLOSE}),n(L)&&L(t),this.timeoutEvent.start()},onSuccess:()=>{!this.closeLog&&console.info("rtc - success"),this.rtcStateCallback?.({action:"success",body:!0}),n(R)&&R()},onError:t=>{this.isRtcVideoOn=!1,!this.closeLog&&console.error("rtc - error:",t),this.rtcStateCallback?.({action:"error",body:t}),k&&k({status:c.DH_LIB_ERROR,content:{type:s.RTC_ERROR}}),n(y)&&y(t),(t.includes("Lost connection to the server")||t.includes("Is the server down"))&&this.restartRtc?.(o)}}})}};closeRtc=()=>{this.timeoutEvent.clear(),clearTimeout(this.reopenTimer),this.client?.destroy(),this.restarting=!1};restartRtc=t=>{!this.restarting&&this.bizConfig?.autoReConnect&&(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{r as default};
package/es/Client.d.ts CHANGED
@@ -24,13 +24,14 @@ export default class DhRealtimeHuman {
24
24
  createServer: (sessionId?: string) => void;
25
25
  checkHumanInstansce: () => void;
26
26
  sendMessage: (message: DHServerInterface, listener: RenderCallback | null) => Promise<void> | undefined;
27
+ interrupt: () => Promise<void>;
27
28
  textRender: (renderData: {
28
29
  requestId: string;
29
30
  body: string;
30
31
  onCallbackMsg: RenderCallback;
31
32
  }) => void;
32
33
  textStreamRender: (renderData: {
33
- requestId: string;
34
+ requestId?: string;
34
35
  body: string;
35
36
  onCallbackMsg: RenderCallback;
36
37
  }) => void;
@@ -39,6 +40,7 @@ export default class DhRealtimeHuman {
39
40
  onCallbackMsg: RenderCallback;
40
41
  }) => void;
41
42
  audioStreamRender: (renderData: {
43
+ requestId?: string;
42
44
  body: string;
43
45
  onCallbackMsg: RenderCallback;
44
46
  }) => void;
package/es/Client.js CHANGED
@@ -1 +1 @@
1
- import e from"@bddh/starling-json";import t from"lodash/isEmpty";import{v4 as a}from"uuid";import{statusEnum as n}from"./interface.js";import s from"./Server.js";import r from"./BrtcClient.js";import{checkIsHuawei as o,createHumanDom as i,RTC_VIDEO_ID as c,DEFAULT_CANVAS_ID as d,removeHumanDom as m,playHumanVideo as h,muteHumanVideo as u}from"./DomControl.js";import l from"./Cutout.js";class p{token;appKey;appId;connectParams;renderParams;onDigitalHumanCallback;dhServer;rtcServer;rtcConnectParams;cutoutInstance;isHuawei=o();constructor(e){const{wrapperId:a,token:o,appKey:d,appId:m,connectParams:h,renderParams:u,rtcConnectParams:p,onDigitalHumanCallback:g}=e;this.token=o,this.appKey=d,this.appId=m,this.connectParams=h,this.renderParams=u;const{fullStatus:I,closeLog:C}=u;this.onDigitalHumanCallback=e=>{const{status:t}=e;t!==n.DH_LIB_FULL_STATUS?g&&g(e):I&&g&&g(e)},this.dhServer=new s("wss://persona.baidu.com:8850/cloud/digital-human-demonstration");const{playerWrapper:S}=i({autoChromaKey:!!u.autoChromaKey})||{},b=document.getElementById(a);b||console.error("dom with wrapperId is not find"),S&&b?.appendChild(S),this.rtcServer=new r({closeLog:C,brtcParams:{},videoWrapperId:c,rtcConfig:{remotevideoviewid:a,showvideobps:!1,usingvideo:!1,usingaudio:!1,aspublisher:!1,usingdatachannel:!0,autoplaymuted:!1},bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new l({sourceId:c}),t(p)||(this.rtcConnectParams=p,this.rtcServer.openRtc(p))}onRemoteVideoComing=e=>{this.rtcConnectParams&&this.rtcConnectParams.feedId&&e===+this.rtcConnectParams.feedId&&this.rtcServer?.client?.subscribeStreaming("remotevideo500",+this.rtcConnectParams.feedId)};onRemoteVideoOn=()=>{setTimeout((async()=>{const e=document.getElementById(c);if(await(this.cutoutInstance?.updateSource?.(c)),e){e.setAttribute?.("data-playing","true");const{videoWidth:t,videoHeight:a}=e,n=document.getElementById(d),s=n.getContext("2d");n&&s&&(n.width=t,n.height=a,s.drawImage(e,0,0,t,a))}}),100)};connectListener=t=>{const{code:a,body:n}=t;if(0===a){const t=e.parse(n),{rtcServerUrl:a,appId:s,clientToken:r,roomName:o,clientId:i,feedId:c,chargeId:d}=t;this.rtcConnectParams={server:a,appId:s,token:r,roomName:o,userId:i,feedId:c,chargeId:d},s&&o&&this.rtcServer?.openRtc(this.rtcConnectParams)}};createServer=e=>{this.dhServer?.createSocket({token:this.token,appKey:this.appKey,appId:this.appId,...e?{sessionId:e}:{},parameters:this.connectParams,onConnect:this.connectListener,onDigitalHumanCallback:this.onDigitalHumanCallback})};checkHumanInstansce=()=>{this.dhServer||console.warn("请先初始化数字人示例")};sendMessage=(e,t)=>this.dhServer?.sendMessage(e,t);textRender=e=>{const{requestId:t,body:n,onCallbackMsg:s}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:t||a(),action:"TEXT_RENDER",body:n,clientTs:(new Date).getTime()},s)};textStreamRender=t=>{const{requestId:n,body:s,onCallbackMsg:r}=t,{first:o}=e.parse(s);this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:n||a(),action:"TEXT_STREAM_RENDER",body:s,clientTs:(new Date).getTime()},o?r:null)};audioRender=e=>{const{body:t,onCallbackMsg:n}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:a(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},n)};audioStreamRender=e=>{const{body:t,onCallbackMsg:n}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:a(),action:"AUDIO_STREAM_RENDER",body:t,clientTs:(new Date).getTime()},n)};destory=async()=>{await(this.dhServer?.closeSocket()),this.rtcServer?.closeRtc(),m(),this.dhServer=null,this.rtcServer=null};pauseHuman=()=>h(!1);playHuman=()=>h(!0);muteHuman=()=>u(!0);unMuteHuman=()=>{const e=u(!1);if(!this.isHuawei)return e.paused&&e.play();e.pause(),e.play()}}export{p as default};
1
+ import e from"@bddh/starling-json";import t from"lodash/isEmpty";import n from"lodash/omit";import s from"lodash/pick";import{v4 as a}from"uuid";import{statusEnum as r,CONNECT_MAIN_KEY as o}from"./interface.js";import i from"./Server.js";import c from"./BrtcClient.js";import{checkIsHuawei as d,createHumanDom as m,RTC_VIDEO_ID as h,DEFAULT_CANVAS_ID as u,removeHumanDom as l,playHumanVideo as p,muteHumanVideo as g}from"./DomControl.js";import I from"./Cutout.js";class C{token;appKey;appId;connectParams;renderParams;onDigitalHumanCallback;dhServer;rtcServer;rtcConnectParams;cutoutInstance;isHuawei=d();constructor(e){const{wrapperId:n,token:s,appKey:a,appId:o,connectParams:d,renderParams:u,rtcConnectParams:l,brtcParams:p,onDigitalHumanCallback:g}=e;this.token=s,this.appKey=a,this.appId=o,this.connectParams=d,this.renderParams=u;const{fullStatus:C,closeLog:S}=u;this.onDigitalHumanCallback=e=>{const{status:t}=e;t!==r.DH_LIB_FULL_STATUS?g&&g(e):C&&g&&g(e)},this.dhServer=new i("wss://persona.baidu.com:8850/cloud/digital-human-demonstration");const{playerWrapper:y}=m({autoChromaKey:!!u.autoChromaKey})||{},b=document.getElementById(n);b||console.error("dom with wrapperId is not find"),y&&b?.appendChild(y),this.rtcServer=new c({closeLog:S,videoWrapperId:h,rtcConfig:{remotevideoviewid:n,showvideobps:!1,usingvideo:!1,usingaudio:!1,aspublisher:!1,usingdatachannel:!0,autoplaymuted:!1,...p},bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new I({sourceId:h}),t(l)||(this.rtcConnectParams=l,this.rtcServer.openRtc(l))}onRemoteVideoComing=e=>{this.rtcConnectParams&&this.rtcConnectParams.feedId&&e===+this.rtcConnectParams.feedId&&this.rtcServer?.client?.subscribeStreaming("remotevideo500",+this.rtcConnectParams.feedId)};onRemoteVideoOn=()=>{setTimeout((async()=>{const e=document.getElementById(h);if(await(this.cutoutInstance?.updateSource?.(h)),e){e.setAttribute?.("data-playing","true");const{videoWidth:t,videoHeight:n}=e,s=document.getElementById(u),a=s.getContext("2d");s&&a&&(s.width=t,s.height=n,a.drawImage(e,0,0,t,n))}}),100)};connectListener=t=>{const{code:n,body:s}=t;if(0===n){const t=e.parse(s),{rtcServerUrl:n,appId:a,clientToken:r,roomName:o,clientId:i,feedId:c,chargeId:d}=t;this.rtcConnectParams={server:n,appId:a,token:r,roomName:o,userId:i,feedId:c,chargeId:d},a&&o&&this.rtcServer?.openRtc(this.rtcConnectParams)}};createServer=e=>{this.dhServer?.createSocket({token:this.token,appKey:this.appKey,appId:this.appId,...e?{sessionId:e}:{},...s(this.connectParams,o),parameters:n(this.connectParams,o),onConnect:this.connectListener,onDigitalHumanCallback:this.onDigitalHumanCallback})};checkHumanInstansce=()=>{this.dhServer||console.warn("请先初始化数字人示例")};sendMessage=(e,t)=>this.dhServer?.sendMessage(e,t);interrupt=async()=>new Promise((e=>{this.dhServer?.sendMessage({requestId:a(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(()=>e()))}));textRender=e=>{const{requestId:t,body:n,onCallbackMsg:s}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:t||a(),action:"TEXT_RENDER",body:n,clientTs:(new Date).getTime()},s)};textStreamRender=t=>{const{requestId:n,body:s,onCallbackMsg:r}=t,{first:o}=e.parse(s);this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:n||a(),action:"TEXT_STREAM_RENDER",body:s,clientTs:(new Date).getTime()},o?r:null)};audioRender=e=>{const{body:t,onCallbackMsg:n}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:a(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},n)};audioStreamRender=e=>{const{requestId:t,body:n,onCallbackMsg:s}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:t||a(),action:"AUDIO_STREAM_RENDER",body:n,clientTs:(new Date).getTime()},s)};destory=async()=>{await(this.dhServer?.closeSocket()),this.rtcServer?.closeRtc(),l(),this.dhServer=null,this.rtcServer=null};pauseHuman=()=>p(!1);playHuman=()=>p(!0);muteHuman=()=>g(!0);unMuteHuman=()=>{const e=g(!1);try{return this.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.log(e)}}}export{C 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: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 u=document.createElement("canvas");return u.id=t,Object.assign(u.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(u),{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);if(e)return t?e.play():e.pause()}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: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};
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{statusEnum as s,WS_STATUS_MAP as o,errorTypeEnum as n}from"./interface.js";class r{dhServerSocket=null;socketClosingPromise=null;url;firstConnect=!0;connectParams=null;constructor(e){this.url=e}createSocket=async r=>{this.connectParams=r;const{token:i,sessionId:c,onConnect:a,onDigitalHumanCallback:h}=r;return this.socketClosingPromise&&await this.socketClosingPromise,this.dhServerSocket&&await this.closeSocket(),new Promise(((r,d)=>{const l=t(this.url,{reopen:!0,keepAlive:"heartbeat",combine:(e,t)=>e?.requestId===t?.requestId,onOpen:()=>{if(this.dhServerSocket=l,c&&this.firstConnect)return l.request({action:"RE_CONNECT",requestId:e(),body:JSON.stringify({token:i,sessionId:c})}).on(((e,t)=>{a(e),0!==e.code&&(t(),this.handleConnect()),r(l)})),void(this.firstConnect=!1);this.handleConnect()},onClose:()=>{this.dhServerSocket=null,this.socketClosingPromise=null},onError:e=>{d(e)}});l.onReadyStateChange((e=>{-1===e&&h&&h({status:s.DH_LIB_INIT}),h&&h({status:s.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:o[e]}})})),l.onMessage((e=>{const{action:t}=e;[n.TIMEOUT_EXIT,n.DISCONNECT_ALERT].includes(t)&&h&&h({status:s.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:s,token:o,parameters:n,onConnect:r}=this.connectParams;(t||s||o)&&this.dhServerSocket?.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:e(),body:JSON.stringify({token:o,appId:t,appKey:s,parameters:n})}).on(((e,t)=>{r(e),0!==e.code&&t()}))};async sendMessage(e,t){try{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{r as default};
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{statusEnum as o,WS_STATUS_MAP as n,errorTypeEnum as r,CONNECT_MAIN_KEY as i}from"./interface.js";class c{dhServerSocket=null;socketClosingPromise=null;url;firstConnect=!0;connectParams=null;constructor(e){this.url=e}createSocket=async s=>{this.connectParams=s;const{token:i,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?.requestId===t?.requestId,onOpen:()=>{if(this.dhServerSocket=l,c&&this.firstConnect)return l.request({action:"RE_CONNECT",requestId:e(),body:JSON.stringify({token:i,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=>{-1===e&&h&&h({status:o.DH_LIB_INIT}),h&&h({status:o.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:n[e]}})})),l.onMessage((e=>{const{action:t}=e;[r.TIMEOUT_EXIT,r.DISCONNECT_ALERT].includes(t)&&h&&h({status:o.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:o,token:n,parameters:r,onConnect:c}=this.connectParams;(t||o||n)&&this.dhServerSocket?.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:e(),body:JSON.stringify({token:n,appId:t,appKey:o,...s(this.connectParams,i),parameters:{...r,...r?.extraParameters&&r?.extraParameters||{}}})}).on(((e,t)=>{c(e),0!==e.code&&t()}))};async sendMessage(e,t){try{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{c as default};
package/es/index.js CHANGED
@@ -1 +1 @@
1
- import r from"./Client.js";export{WS_STATUS_MAP,errorTypeEnum,statusEnum}from"./interface.js";export{r as default};
1
+ import r from"./Client.js";export{CONNECT_MAIN_KEY,WS_STATUS_MAP,errorTypeEnum,statusEnum}from"./interface.js";export{r as default};
package/es/interface.d.ts CHANGED
@@ -23,7 +23,20 @@ export interface ConnectParamsType {
23
23
  inactiveDisconnectSec?: number;
24
24
  preAlertSec?: number;
25
25
  x264BitRate?: number;
26
+ backgroundImageUrl?: string;
27
+ projectId?: string;
28
+ characterConfigId?: string;
29
+ selectors?: any;
30
+ figureName?: string;
31
+ configVersion?: string;
32
+ extraInfo?: any;
33
+ roomName?: string;
34
+ paintSubtitleOnPicture?: boolean;
35
+ h5Embedded?: boolean;
36
+ paintWidgetOnPicture?: boolean;
37
+ extraParameters?: any;
26
38
  }
39
+ export declare const CONNECT_MAIN_KEY: string[];
27
40
  export interface RenderParamsType {
28
41
  chromaEffects?: object;
29
42
  autoChromaKey?: boolean;
@@ -83,5 +96,6 @@ export interface DhRealtimeHumanType {
83
96
  connectParams: ConnectParamsType;
84
97
  renderParams: RenderParamsType;
85
98
  rtcConnectParams?: RtcConnectionType;
99
+ brtcParams?: any;
86
100
  onDigitalHumanCallback: (data: CallbackMsgType) => void;
87
101
  }
package/es/interface.js CHANGED
@@ -1 +1 @@
1
- var _,I;!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={}));const E={"-1":"UNINSTANTIATED",0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"};export{E as WS_STATUS_MAP,I as errorTypeEnum,_ as statusEnum};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bddh/starling-realtime-client",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.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": "3a8eee0324683be3f0048c667a9efefa366af4de"
47
+ "gitHead": "42091abddc93acf43e0b3ac796ae6c7a185f5b43"
48
48
  }