@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 +1 -1
- package/cjs/Client.js +1 -1
- package/cjs/Cutout.js +1 -1
- package/cjs/DomControl.d.ts +1 -0
- package/cjs/DomControl.js +1 -1
- package/cjs/Server.js +1 -1
- package/cjs/_virtual/_rollupPluginBabelHelpers.js +1 -0
- package/es/BrtcClient.js +1 -1
- package/es/Client.js +1 -1
- package/es/Cutout.js +1 -1
- package/es/DomControl.d.ts +1 -0
- package/es/DomControl.js +1 -1
- package/es/Server.js +1 -1
- package/es/_virtual/_rollupPluginBabelHelpers.js +1 -0
- package/package.json +2 -2
package/cjs/BrtcClient.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@bddh/starling-brtc"),
|
|
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"),
|
|
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
|
|
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)}};
|
package/cjs/DomControl.d.ts
CHANGED
|
@@ -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
|
|
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("
|
|
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
|
|
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
|
|
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
|
|
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};
|
package/es/DomControl.d.ts
CHANGED
|
@@ -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:
|
|
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{
|
|
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.
|
|
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": "
|
|
47
|
+
"gitHead": "1cee540024b051ebda341ee1bc2d9cb46bcac526"
|
|
48
48
|
}
|