@bddh/starling-realtime-client 1.0.7 → 1.0.8
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/Client.js +1 -1
- package/cjs/DomControl.d.ts +1 -0
- package/cjs/DomControl.js +1 -1
- package/cjs/Server.js +1 -1
- package/es/Client.js +1 -1
- package/es/DomControl.d.ts +1 -0
- package/es/DomControl.js +1 -1
- package/es/Server.js +1 -1
- package/package.json +2 -2
package/cjs/Client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@bddh/starling-json"),t=require("lodash/isEmpty"),r=require("lodash/omit"),s=require("lodash/pick"),a=require("uuid"),n=require("./interface.js"),i=require("./Server.js"),o=require("./BrtcClient.js"),c=require("./DomControl.js"),d=require("./Cutout.js");exports.default=class{token;appKey;appId;connectParams;onDigitalHumanCallback;dhServer;rtcServer;rtcConnectParams;cutoutInstance;isHuawei=c.checkIsHuawei();rtcServerUrl;constructor(e){const{wrapperId:r,token:s,appKey:a,appId:u,connectParams:h,renderParams:l,rtcConnectParams:m,brtcParams:p,wsUrl:I,rtcServerUrl:v,onDigitalHumanCallback:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@bddh/starling-json"),t=require("lodash/isEmpty"),r=require("lodash/omit"),s=require("lodash/pick"),a=require("uuid"),n=require("./interface.js"),i=require("./Server.js"),o=require("./BrtcClient.js"),c=require("./DomControl.js"),d=require("./Cutout.js");exports.default=class{token;appKey;appId;connectParams;onDigitalHumanCallback;dhServer;rtcServer;rtcConnectParams;cutoutInstance;isHuawei=c.checkIsHuawei();rtcServerUrl;constructor(e){const{wrapperId:r,token:s,appKey:a,appId:u,connectParams:h,renderParams:l,rtcConnectParams:m,brtcParams:p,wsUrl:I,rtcServerUrl:v,onDigitalHumanCallback:S}=e;this.token=s,this.appKey=a,this.appId=u,this.rtcServerUrl=v,this.connectParams={autoChromaKey:l.autoChromaKey,...h};const{fullStatus:g,closeLog:C}=l;this.onDigitalHumanCallback=e=>{const{status:t}=e;t!==n.statusEnum.DH_LIB_FULL_STATUS?S&&S(e):g&&S&&S(e)},this.dhServer=new i.default(I||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration");const{playerWrapper:y}=c.createHumanDom({autoChromaKey:!!l.autoChromaKey})||{},D=document.getElementById(r);D||console.error("dom with wrapperId is not find"),y&&D&&D.appendChild(y),c.appendRtcDomStyle(r),this.rtcServer=new o.default({closeLog:C,videoWrapperId:c.RTC_VIDEO_ID,rtcConfig:{remotevideoviewid:r,showvideobps:!1,usingvideo:!1,usingaudio:!1,aspublisher:!1,usingdatachannel:!0,autoplaymuted:!1,...p},bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new d.default({sourceId:c.RTC_VIDEO_ID}),t(m)||(this.rtcConnectParams=m,this.rtcServer.openRtc(m))}onRemoteVideoComing=e=>{this.rtcConnectParams&&this.rtcConnectParams.feedId&&e===+this.rtcConnectParams.feedId&&this.rtcServer&&this.rtcServer.client&&this.rtcServer.client.subscribeStreaming("remotevideo500",+this.rtcConnectParams.feedId)};onRemoteVideoOn=()=>{setTimeout((async()=>{const e=document.getElementById(c.RTC_VIDEO_ID);if(await(this.cutoutInstance&&this.cutoutInstance.updateSource(c.RTC_VIDEO_ID)),e){e.setAttribute("data-playing","true");const{videoWidth:t,videoHeight:r}=e,s=document.getElementById(c.DEFAULT_CANVAS_ID),a=s.getContext("2d");s&&a&&(s.width=t,s.height=r,a.drawImage(e,0,0,t,r))}}),100)};connectListener=t=>{const{code:r,body:s,message:a}=t;if(0===r&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:n.statusEnum.DH_LIB_WS_SUCCESS,content:t}),0===r){const t=e.parse(s),{rtcServerUrl:r,appId:a,clientToken:n,roomName:i,clientId:o,feedId:c,chargeId:d}=t;a&&i&&(this.rtcConnectParams={server:this.rtcServerUrl||r,appId:a,token:n,roomName:i,userId:o,feedId:c,chargeId:d},this.rtcServer&&this.rtcServer.openRtc(this.rtcConnectParams))}else this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:n.statusEnum.DH_LIB_ERROR,content:{type:n.errorTypeEnum.CONNECT_ERROR,msg:{code:r,errMsg:a}}})};createServer=e=>{this.dhServer&&this.dhServer.createSocket({token:this.token,appKey:this.appKey,appId:this.appId,...e?{sessionId:e}:{},...s(this.connectParams,n.CONNECT_MAIN_KEY),parameters:r(this.connectParams,n.CONNECT_MAIN_KEY),onConnect:this.connectListener,onDigitalHumanCallback:this.onDigitalHumanCallback})};checkHumanInstansce=()=>{this.dhServer||console.warn("请先初始化数字人示例")};sendMessage=(e,t)=>this.dhServer&&this.dhServer.sendMessage(e,t);interrupt=async()=>new Promise((e=>{this.dhServer&&this.dhServer.sendMessage({requestId:a.v4(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(()=>e()))}));textRender=e=>{const{requestId:t,body:r,onCallbackMsg:s}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:t||a.v4(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},s)};textStreamRender=t=>{const{requestId:r,body:s,onCallbackMsg:n}=t,{first:i}=e.parse(s);this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:r||a.v4(),action:"TEXT_STREAM_RENDER",body:s,clientTs:(new Date).getTime()},i?n:null)};audioRender=e=>{const{body:t,onCallbackMsg:r}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:a.v4(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},r)};audioStreamRender=e=>{const{requestId:t,body:r,onCallbackMsg:s}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:t||a.v4(),action:"AUDIO_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},s)};destory=async()=>{await(this.dhServer&&this.dhServer.closeSocket()),this.rtcServer&&this.rtcServer.closeRtc(),c.removeHumanDom(),this.dhServer=null,this.rtcServer=null};pauseHuman=()=>c.playHumanVideo(!1);playHuman=()=>c.playHumanVideo(!0);muteHuman=()=>c.muteHumanVideo(!0);unMuteHuman=()=>{const e=c.muteHumanVideo(!1);try{return this.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}};
|
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(id: string): 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(t){const e=`\n #${t} div:last-of-type {\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 `,n=document.createElement("style");n.appendChild(document.createTextNode(e)),document.head.appendChild(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 d=document.createElement("div");d.className=e,d.id=e,d.style.position="relative";const s=document.createElement("video");s.id=i,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}},exports.muteHumanVideo=function(t){const e=document.getElementById(n);return e&&(e.muted=t),e},exports.playHumanVideo=function(t){const e=document.getElementById(n);try{if(e)return t?e.play():e.pause()}catch(t){console.info(t)}},exports.removeHumanDom=function(){const t=document.getElementById(e);t&&t.parentNode&&t.parentNode.removeChild(t)};
|
package/cjs/Server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("uuid"),t=require("@bddh/starling-web-socket/es/create-web-socket"),s=require("lodash/pick"),r=require("lodash/omit"),o=require("./interface.js");exports.default=class{dhServerSocket=null;socketClosingPromise=null;url;firstConnect=!0;connectParams=null;constructor(e){this.url=e}createSocket=async s=>{this.connectParams=s;const{token:r,sessionId:n,onConnect:i,onDigitalHumanCallback:c}=s;return this.socketClosingPromise&&await this.socketClosingPromise,this.dhServerSocket&&await this.closeSocket(),new Promise(((s,a)=>{const h=t.createWebSocket(this.url,{reopen:!0,keepAlive:"heartbeat",combine:(e,t)=>e&&e.requestId===t
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("uuid"),t=require("@bddh/starling-web-socket/es/create-web-socket"),s=require("lodash/pick"),r=require("lodash/omit"),o=require("./interface.js");exports.default=class{dhServerSocket=null;socketClosingPromise=null;url;firstConnect=!0;connectParams=null;constructor(e){this.url=e}createSocket=async s=>{this.connectParams=s;const{token:r,sessionId:n,onConnect:i,onDigitalHumanCallback:c}=s;return this.socketClosingPromise&&await this.socketClosingPromise,this.dhServerSocket&&await this.closeSocket(),new Promise(((s,a)=>{const h=t.createWebSocket(this.url,{reopen:!0,keepAlive:"heartbeat",combine:(e,t)=>e&&t&&e.requestId===t.requestId,onOpen:()=>{if(this.dhServerSocket=h,n&&this.firstConnect)return h.request({action:"RE_CONNECT",requestId:e.v4(),body:JSON.stringify({token:r,sessionId:n})}).on(((e,t)=>{i(e),0!==e.code&&(t(),this.handleConnect()),s(h)})),void(this.firstConnect=!1);this.handleConnect()},onClose:()=>{this.dhServerSocket=null,this.socketClosingPromise=null},onError:e=>{a(e)}});h.onReadyStateChange((e=>{0===e&&c&&c({status:o.statusEnum.DH_LIB_INIT}),c&&c({status:o.statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:o.WS_STATUS_MAP[e]}})})),h.onMessage((e=>{const{action:t}=e;[o.errorTypeEnum.TIMEOUT_EXIT,o.errorTypeEnum.DISCONNECT_ALERT].includes(t)&&c&&c({status:o.statusEnum.DH_LIB_STATUS,content:{type:t}})})),h.open()}))};closeSocket=async()=>{this.dhServerSocket&&(this.socketClosingPromise=this.dhServerSocket.close(),await this.socketClosingPromise,this.dhServerSocket=null)};handleConnect=async()=>{if(!this.connectParams)return;const{appId:t,appKey:n,token:i,parameters:c,onConnect:a}=this.connectParams;(t||n||i)&&this.dhServerSocket&&this.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:e.v4(),body:JSON.stringify({token:i,appId:t,appKey:n,...s(this.connectParams,o.CONNECT_MAIN_KEY),parameters:{...r(c,["parameters"]),...c&&c.parameters?c.parameters:{}}})}).on(((e,t)=>{a(e),0!==e.code&&t()}))};async sendMessage(e,t){try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(e).on((e=>{t&&t(e)}))}catch(s){t&&t({code:-11,body:null,action:"RENDER_ERROR",requestId:e.requestId,message:JSON.stringify(s)})}}};
|
package/es/Client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@bddh/starling-json";import t from"lodash/isEmpty";import r from"lodash/omit";import s from"lodash/pick";import{v4 as a}from"uuid";import{statusEnum as n,errorTypeEnum as o,CONNECT_MAIN_KEY as i}from"./interface.js";import c from"./Server.js";import d from"./BrtcClient.js";import{checkIsHuawei as h,createHumanDom as m,
|
|
1
|
+
import e from"@bddh/starling-json";import t from"lodash/isEmpty";import r from"lodash/omit";import s from"lodash/pick";import{v4 as a}from"uuid";import{statusEnum as n,errorTypeEnum as o,CONNECT_MAIN_KEY as i}from"./interface.js";import c from"./Server.js";import d from"./BrtcClient.js";import{checkIsHuawei as h,createHumanDom as m,appendRtcDomStyle as l,RTC_VIDEO_ID as u,DEFAULT_CANVAS_ID as p,removeHumanDom as g,playHumanVideo as S,muteHumanVideo as v}from"./DomControl.js";import I from"./Cutout.js";class C{token;appKey;appId;connectParams;onDigitalHumanCallback;dhServer;rtcServer;rtcConnectParams;cutoutInstance;isHuawei=h();rtcServerUrl;constructor(e){const{wrapperId:r,token:s,appKey:a,appId:o,connectParams:i,renderParams:h,rtcConnectParams:p,brtcParams:g,wsUrl:S,rtcServerUrl:v,onDigitalHumanCallback:C}=e;this.token=s,this.appKey=a,this.appId=o,this.rtcServerUrl=v,this.connectParams={autoChromaKey:h.autoChromaKey,...i};const{fullStatus:b,closeLog:y}=h;this.onDigitalHumanCallback=e=>{const{status:t}=e;t!==n.DH_LIB_FULL_STATUS?C&&C(e):b&&C&&C(e)},this.dhServer=new c(S||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration");const{playerWrapper:k}=m({autoChromaKey:!!h.autoChromaKey})||{},R=document.getElementById(r);R||console.error("dom with wrapperId is not find"),k&&R&&R.appendChild(k),l(r),this.rtcServer=new d({closeLog:y,videoWrapperId:u,rtcConfig:{remotevideoviewid:r,showvideobps:!1,usingvideo:!1,usingaudio:!1,aspublisher:!1,usingdatachannel:!0,autoplaymuted:!1,...g},bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new I({sourceId:u}),t(p)||(this.rtcConnectParams=p,this.rtcServer.openRtc(p))}onRemoteVideoComing=e=>{this.rtcConnectParams&&this.rtcConnectParams.feedId&&e===+this.rtcConnectParams.feedId&&this.rtcServer&&this.rtcServer.client&&this.rtcServer.client.subscribeStreaming("remotevideo500",+this.rtcConnectParams.feedId)};onRemoteVideoOn=()=>{setTimeout((async()=>{const e=document.getElementById(u);if(await(this.cutoutInstance&&this.cutoutInstance.updateSource(u)),e){e.setAttribute("data-playing","true");const{videoWidth:t,videoHeight:r}=e,s=document.getElementById(p),a=s.getContext("2d");s&&a&&(s.width=t,s.height=r,a.drawImage(e,0,0,t,r))}}),100)};connectListener=t=>{const{code:r,body:s,message:a}=t;if(0===r&&this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:n.DH_LIB_WS_SUCCESS,content:t}),0===r){const t=e.parse(s),{rtcServerUrl:r,appId:a,clientToken:n,roomName:o,clientId:i,feedId:c,chargeId:d}=t;a&&o&&(this.rtcConnectParams={server:this.rtcServerUrl||r,appId:a,token:n,roomName:o,userId:i,feedId:c,chargeId:d},this.rtcServer&&this.rtcServer.openRtc(this.rtcConnectParams))}else this.onDigitalHumanCallback&&this.onDigitalHumanCallback({status:n.DH_LIB_ERROR,content:{type:o.CONNECT_ERROR,msg:{code:r,errMsg:a}}})};createServer=e=>{this.dhServer&&this.dhServer.createSocket({token:this.token,appKey:this.appKey,appId:this.appId,...e?{sessionId:e}:{},...s(this.connectParams,i),parameters:r(this.connectParams,i),onConnect:this.connectListener,onDigitalHumanCallback:this.onDigitalHumanCallback})};checkHumanInstansce=()=>{this.dhServer||console.warn("请先初始化数字人示例")};sendMessage=(e,t)=>this.dhServer&&this.dhServer.sendMessage(e,t);interrupt=async()=>new Promise((e=>{this.dhServer&&this.dhServer.sendMessage({requestId:a(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(()=>e()))}));textRender=e=>{const{requestId:t,body:r,onCallbackMsg:s}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:t||a(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},s)};textStreamRender=t=>{const{requestId:r,body:s,onCallbackMsg:n}=t,{first:o}=e.parse(s);this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:r||a(),action:"TEXT_STREAM_RENDER",body:s,clientTs:(new Date).getTime()},o?n:null)};audioRender=e=>{const{body:t,onCallbackMsg:r}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:a(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},r)};audioStreamRender=e=>{const{requestId:t,body:r,onCallbackMsg:s}=e;this.checkHumanInstansce(),this.dhServer&&this.dhServer.sendMessage({requestId:t||a(),action:"AUDIO_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},s)};destory=async()=>{await(this.dhServer&&this.dhServer.closeSocket()),this.rtcServer&&this.rtcServer.closeRtc(),g(),this.dhServer=null,this.rtcServer=null};pauseHuman=()=>S(!1);playHuman=()=>S(!0);muteHuman=()=>v(!0);unMuteHuman=()=>{const e=v(!1);try{return this.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}}export{C 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(id: string): 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(t){const e=`\n #${t} div:last-of-type {\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 `,n=document.createElement("style");n.appendChild(document.createTextNode(e)),document.head.appendChild(n)}export{t as DEFAULT_CANVAS_ID,e as HUMAN_WRAPPER_ID,n as RTC_VIDEO_ID,c as appendRtcDomStyle,d as checkIsHuawei,i as createHumanDom,a as muteHumanVideo,r as playHumanVideo,o as removeHumanDom};
|
package/es/Server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{v4 as e}from"uuid";import{createWebSocket as t}from"@bddh/starling-web-socket/es/create-web-socket";import s from"lodash/pick";import o from"lodash/omit";import{statusEnum as n,WS_STATUS_MAP as r,errorTypeEnum as i,CONNECT_MAIN_KEY as c}from"./interface.js";class a{dhServerSocket=null;socketClosingPromise=null;url;firstConnect=!0;connectParams=null;constructor(e){this.url=e}createSocket=async s=>{this.connectParams=s;const{token:o,sessionId:c,onConnect:a,onDigitalHumanCallback:h}=s;return this.socketClosingPromise&&await this.socketClosingPromise,this.dhServerSocket&&await this.closeSocket(),new Promise(((s,d)=>{const l=t(this.url,{reopen:!0,keepAlive:"heartbeat",combine:(e,t)=>e&&e.requestId===t
|
|
1
|
+
import{v4 as e}from"uuid";import{createWebSocket as t}from"@bddh/starling-web-socket/es/create-web-socket";import s from"lodash/pick";import o from"lodash/omit";import{statusEnum as n,WS_STATUS_MAP as r,errorTypeEnum as i,CONNECT_MAIN_KEY as c}from"./interface.js";class a{dhServerSocket=null;socketClosingPromise=null;url;firstConnect=!0;connectParams=null;constructor(e){this.url=e}createSocket=async s=>{this.connectParams=s;const{token:o,sessionId:c,onConnect:a,onDigitalHumanCallback:h}=s;return this.socketClosingPromise&&await this.socketClosingPromise,this.dhServerSocket&&await this.closeSocket(),new Promise(((s,d)=>{const l=t(this.url,{reopen:!0,keepAlive:"heartbeat",combine:(e,t)=>e&&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:o,sessionId:c})}).on(((e,t)=>{a(e),0!==e.code&&(t(),this.handleConnect()),s(l)})),void(this.firstConnect=!1);this.handleConnect()},onClose:()=>{this.dhServerSocket=null,this.socketClosingPromise=null},onError:e=>{d(e)}});l.onReadyStateChange((e=>{0===e&&h&&h({status:n.DH_LIB_INIT}),h&&h({status:n.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:r[e]}})})),l.onMessage((e=>{const{action:t}=e;[i.TIMEOUT_EXIT,i.DISCONNECT_ALERT].includes(t)&&h&&h({status:n.DH_LIB_STATUS,content:{type:t}})})),l.open()}))};closeSocket=async()=>{this.dhServerSocket&&(this.socketClosingPromise=this.dhServerSocket.close(),await this.socketClosingPromise,this.dhServerSocket=null)};handleConnect=async()=>{if(!this.connectParams)return;const{appId:t,appKey:n,token:r,parameters:i,onConnect:a}=this.connectParams;(t||n||r)&&this.dhServerSocket&&this.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:e(),body:JSON.stringify({token:r,appId:t,appKey:n,...s(this.connectParams,c),parameters:{...o(i,["parameters"]),...i&&i.parameters?i.parameters:{}}})}).on(((e,t)=>{a(e),0!==e.code&&t()}))};async sendMessage(e,t){try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(e).on((e=>{t&&t(e)}))}catch(s){t&&t({code:-11,body:null,action:"RENDER_ERROR",requestId:e.requestId,message:JSON.stringify(s)})}}}export{a as default};
|
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",
|
|
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": "2874dcc2d3166129722766fb56d3640cb4477d1c"
|
|
48
48
|
}
|