@bddh/starling-realtime-client 2.0.4 → 2.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bddh/starling-realtime-client",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "keywords": [
5
5
  "react",
6
6
  "indexDB"
@@ -24,7 +24,7 @@
24
24
  "scripts": {
25
25
  "build": "rm -rf cjs es && rollup -c --bundleConfigAsCjs",
26
26
  "test": "npx jest --passWithNoTests",
27
- "deploy": "npm publish --registry=https://registry.npmjs.org --access public"
27
+ "deploy": "npm run build & npm publish --registry=https://registry.npmjs.org --access public"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "@bddh/starling-brtc": "^1.0.2",
@@ -1,97 +0,0 @@
1
- /**
2
- * @file lib/Brtc
3
- * @description brtc拉流相关
4
- * @author zhangyue49
5
- */
6
- import type { BRtcInstance } from '@bddh/starling-brtc';
7
- import { ChromaEffectOptions } from '@bddh/starling-cutout/es/interface';
8
- import { CallbackMsgType } from './interface';
9
- export interface RtcConnectionType {
10
- server: string;
11
- appId: string;
12
- token: string;
13
- roomName: string;
14
- userId: string;
15
- feedId?: number;
16
- chargeId?: number;
17
- }
18
- interface RtcConfig {
19
- [x: string]: any;
20
- videoprofile?: Record<string, any>;
21
- mediaserverip?: string;
22
- displayname?: string;
23
- remotevideoviewid?: string;
24
- localvideoviewid?: string;
25
- bitrate?: number;
26
- showvideobps?: boolean;
27
- usingvideo?: boolean;
28
- usingaudio?: boolean;
29
- aspublisher?: boolean;
30
- usingdatachannel?: boolean;
31
- autoplaymuted?: boolean;
32
- autosubscribe?: boolean;
33
- uploadVideoResolution?: {
34
- width: number;
35
- height: number;
36
- };
37
- uploadVideoBitrate?: number;
38
- }
39
- export interface BizConfig {
40
- autoCheck?: boolean;
41
- isCrash?: boolean;
42
- showMessage?: boolean;
43
- autoReConnect?: boolean;
44
- autoStart?: boolean;
45
- showLocalVideo?: boolean;
46
- welcomeContent?: string;
47
- autoChromaKey?: boolean;
48
- chromaEffects?: ChromaEffectOptions;
49
- }
50
- export interface RtcCallback {
51
- [x: string]: any;
52
- onLocalStream?: (stream: MediaStream, name: string) => void;
53
- onLocalVideoPublished?: () => void;
54
- onRemoteVideoComing?: (id: number) => void;
55
- onRemoteVideoOn?: (id: number) => void;
56
- onRemoteVideoOff?: (id: number) => void;
57
- onRemoteVideoLoading?: (id: number) => void;
58
- onSuccess?: () => void;
59
- onError?: (error: string) => void;
60
- onRemoteVideoConnected?: (id: number, on: boolean) => void;
61
- onRemoteMediaState?: (id: number, medium: MediaStream, on: boolean) => void;
62
- onLocalVideoConnected?: (on: boolean) => void;
63
- onPlayingError: (element: HTMLVideoElement) => void;
64
- onRemotedata: (data: any) => void;
65
- onLocalVideoPublishing: () => void;
66
- onDigitalHumanCallback: (data: CallbackMsgType) => void;
67
- }
68
- interface BrtcClientType {
69
- videoWrapperId: string;
70
- bizConfig: BizConfig;
71
- closeLog?: boolean;
72
- rtcConnection?: RtcConnectionType;
73
- preConnectInfo?: RtcConnectionType;
74
- rtcConfig?: RtcConfig;
75
- rtcCallback?: Partial<RtcCallback>;
76
- }
77
- declare class BrtcClient {
78
- client?: BRtcInstance;
79
- isRtcVideoOn: boolean;
80
- private rtcConnection;
81
- private readonly rtcConfig?;
82
- private readonly bizConfig?;
83
- private readonly rtcCallback?;
84
- private restarting;
85
- private readonly timeoutEvent;
86
- private reopenTimer;
87
- private restartCount;
88
- private readonly closeLog;
89
- private haveVideoOn;
90
- private rtcStateCallback;
91
- constructor(props: BrtcClientType);
92
- openRtc: (rtcConnection: RtcConnectionType) => void;
93
- closeRtc: () => void;
94
- restartRtc: (rtcConnection: RtcConnectionType) => void;
95
- muteMicphone(mute: boolean): void;
96
- }
97
- export default BrtcClient;
package/cjs/BrtcClient.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),t=require("@bddh/starling-brtc"),o=require("@bddh/starling-timeout-controller"),n=require("@bddh/starling-json"),c=require("lodash/isEmpty"),i=require("lodash/isFunction"),r=require("./interface.js"),a=function(){function a(l){var s=this;e.classCallCheck(this,a),e.defineProperty(this,"client",void 0),e.defineProperty(this,"isRtcVideoOn",!1),e.defineProperty(this,"rtcConnection",void 0),e.defineProperty(this,"rtcConfig",void 0),e.defineProperty(this,"bizConfig",void 0),e.defineProperty(this,"rtcCallback",void 0),e.defineProperty(this,"restarting",!1),e.defineProperty(this,"timeoutEvent",void 0),e.defineProperty(this,"reopenTimer",void 0),e.defineProperty(this,"restartCount",0),e.defineProperty(this,"closeLog",!0),e.defineProperty(this,"haveVideoOn",!1),e.defineProperty(this,"rtcStateCallback",null),e.defineProperty(this,"openRtc",(function(e){if(s.restarting)!s.closeLog&&console.warn("rtc restarting");else if(e&&(s.rtcConnection=e),s.rtcConnection&&!c(s.rtcConnection)){var o=s.rtcConnection,a=o.server,l=o.appId,d=o.token,u=o.roomName,m=o.userId,C=s.rtcCallback||{},f=C.onRemotedata,b=C.onLocalStream,g=C.onRemoteVideoComing,y=C.onLocalVideoPublished,h=C.onLocalVideoPublishing,v=C.onRemoteVideoOn,p=C.onRemoteVideoOff,R=C.onRemoteVideoLoading,L=C.onSuccess,S=C.onError,k=C.onLocalVideoConnected,E=C.onRemoteVideoConnected,V=C.onRemoteMediaState,P=C.onPlayingError,_=C.onDigitalHumanCallback;s.timeoutEvent.start(),s.rtcStateCallback=function(e){var t=e.body,o=e.action;_&&_({status:r.statusEnum.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:o,body:t}})},s.client=new t({roomName:u,token:d,userId:m,appId:l,server:a,rtcConfig:s.rtcConfig,callback:{onRemoteVideoConnected:function(t,o){if(!o&&!s.haveVideoOn)var n=setTimeout((function(){s.restartCount<3?(s.restartCount=++s.restartCount,s.restartRtc&&s.restartRtc(e)):(s.restartCount=0,s.closeRtc()),clearTimeout(n)}),500);if(o){var c=document.getElementById("remotevideo500");c.muted=!1;var a=c.play();void 0!==a&&a.catch((function(){c.muted=!0,c.play().catch((function(e){!s.closeLog&&console.info("videoElement play error",e),P&&P(c),_&&_({status:r.statusEnum.DH_LIB_ERROR,content:{type:r.errorTypeEnum.LOCAL_VIDEO_ERROR}})})),_&&_({status:r.statusEnum.DH_LIB_STATUS,content:{type:r.errorTypeEnum.LOCAL_VIDEO_MUTED}})}))}!s.closeLog&&console.info("remoteVideoConnected",t,o,s.restartCount),s.rtcStateCallback&&s.rtcStateCallback({action:"remoteVideoConnected",body:{id:t,connected:o,restartCount:s.restartCount}}),i(E)&&E(t,o)},onRemoteVideoOn:function(e){s.haveVideoOn=!0,!s.closeLog&&console.info("remotevideoon by id: ",e),s.timeoutEvent.clear();var t=document.querySelector("#starlingRtcContainer"),o=t&&t.lastChild;o&&(o.style.display="none"),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideoon",body:e}),_&&_({status:r.statusEnum.DH_LIB_OPEN}),i(v)&&v(e)},onRemoteMediaState:function(e,t,o){!s.closeLog&&console.info("remoteMediaState",e,t,o),s.rtcStateCallback&&s.rtcStateCallback({action:"remoteMediaState",body:{id:e,medium:t,connected:o}}),i(V)&&V(e,t,o)},onLocalVideoConnected:function(e){!s.closeLog&&console.info("localVideoConnected",e),s.rtcStateCallback&&s.rtcStateCallback({action:"localVideoConnected",body:{connected:e}}),i(k)&&k(e)},onRemotedata:function(e){if(s.rtcConfig&&s.rtcConfig.usingdatachannel){var t=n.parse(e);!s.closeLog&&console.info("RTC - receive:",t),i(f)&&f(t)}},onLocalStream:function(e,t){!s.closeLog&&console.info("rtc - onlocalstream by name: "+t),s.rtcStateCallback&&s.rtcStateCallback({action:"onlocalstream",body:{stream:e,name:t}}),i(b)&&b(e,t)},onLocalVideoPublished:function(){!s.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),s.rtcStateCallback&&s.rtcStateCallback({action:"localvideopublished_ok",body:!0}),i(y)&&y()},onLocalVideoPublishing:function(){!s.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),s.rtcStateCallback&&s.rtcStateCallback({action:"localvideopublishing",body:!0}),i(h)&&h()},onRemoteVideoComing:function(e){!s.closeLog&&console.info("remotevideocoming",e),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideocoming",body:e}),i(g)&&g(e)},onRemoteVideoLoading:function(e){!s.closeLog&&console.info("remotevideoloading by id: ",e),s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideoloading",body:e}),i(R)&&R(e)},onRemoteVideoOff:function(e){var t=document.getElementById("remotevideo500");t&&t.pause(),!s.closeLog&&console.info("remotevideooff: ",e),s.isRtcVideoOn=!1,s.rtcStateCallback&&s.rtcStateCallback({action:"remotevideooff",body:e}),_&&_({status:r.statusEnum.DH_LIB_CLOSE}),i(p)&&p(e),s.timeoutEvent.start()},onSuccess:function(){!s.closeLog&&console.info("rtc - success"),s.rtcStateCallback&&s.rtcStateCallback({action:"success",body:!0}),i(L)&&L()},onError:function(t){s.isRtcVideoOn=!1,!s.closeLog&&console.error("rtc - error:",t),s.rtcStateCallback&&s.rtcStateCallback({action:"error",body:t}),_&&_({status:r.statusEnum.DH_LIB_ERROR,content:{type:r.errorTypeEnum.RTC_ERROR}}),i(S)&&S(t),(t.includes("Lost connection to the server")||t.includes("Is the server down"))&&s.restartRtc&&s.restartRtc(e)}}})}})),e.defineProperty(this,"closeRtc",(function(){s.timeoutEvent.clear(),clearTimeout(s.reopenTimer),s.client&&s.client.destroy(),s.restarting=!1})),e.defineProperty(this,"restartRtc",(function(e){!s.restarting&&s.bizConfig&&s.bizConfig.autoReConnect&&(s.rtcStateCallback&&s.rtcStateCallback({action:"restartRtc",body:e}),s.restarting=!0,s.closeRtc(),s.reopenTimer=setTimeout((function(){!s.closeLog&&console.error("拉流失败,开始重启"),s.restarting=!1,s.openRtc(e)}),2e3))}));var d=l.rtcConnection,u=l.rtcConfig,m=l.closeLog,C=void 0===m||m,f=l.rtcCallback;this.rtcConnection=d,this.rtcConfig=u,this.rtcCallback=f,this.closeLog=C,this.timeoutEvent=new o.TimeoutController(6e4,(function(){if(!s.rtcConnection)return!s.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");s.timeoutEvent.clear(),s.restartRtc&&s.restartRtc(s.rtcConnection)}))}return e.createClass(a,[{key:"muteMicphone",value:function(e){this.client&&this.client.muteMicphone&&this.client.muteMicphone(e)}}]),a}();exports.default=a;
package/cjs/Client.d.ts DELETED
@@ -1,65 +0,0 @@
1
- /**
2
- * @file dh-realtime-human
3
- * @description 云渲染数字人sdk
4
- * @author zhangyue49
5
- */
6
- import { DhRealtimeHumanType, ConnectDataType, CallbackMsgType } from './interface';
7
- import { DHServerInterface, RenderCallback } from './Server';
8
- export default class DhRealtimeHuman {
9
- private token;
10
- private appKey;
11
- private appId;
12
- private connectParams;
13
- private readonly onDigitalHumanCallback?;
14
- private dhServer;
15
- private rtcServer?;
16
- private rtcConnectParams;
17
- private cutoutInstance?;
18
- private readonly isHuawei;
19
- private rtcServerUrl;
20
- private recordController;
21
- private wsReadyState;
22
- private readonly isPreOpenSession;
23
- constructor(props: DhRealtimeHumanType);
24
- init(props: DhRealtimeHumanType): void;
25
- onDigitalHumanCallbackPlus: (data: CallbackMsgType) => void;
26
- onRemoteVideoComing: (id: number) => void;
27
- onLocalStream: () => void;
28
- onRemoteVideoOn: () => void;
29
- connectListener: (data: ConnectDataType) => void;
30
- createServer: (sessionId?: string) => void;
31
- checkHumanInstansce: () => boolean;
32
- sendMessage: (message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null) => Promise<void> | null;
33
- interrupt: () => Promise<void>;
34
- textRender: (renderData: {
35
- requestId: string;
36
- body: string;
37
- onCallbackMsg: RenderCallback;
38
- }) => void;
39
- textStreamRender: (renderData: {
40
- requestId?: string;
41
- body: string;
42
- onCallbackMsg: RenderCallback;
43
- }) => void;
44
- audioRender: (renderData: {
45
- body: string;
46
- onCallbackMsg: RenderCallback;
47
- }) => void;
48
- audioStreamRender: (renderData: {
49
- requestId?: string;
50
- body: string;
51
- onCallbackMsg: RenderCallback;
52
- }) => void;
53
- textQuery: (queryData: {
54
- requestId: string;
55
- body: string;
56
- onCallbackMsg: RenderCallback;
57
- }) => void;
58
- destroy: () => Promise<void>;
59
- pauseHuman: () => void | Promise<void>;
60
- playHuman: () => void | Promise<void>;
61
- muteHuman: () => HTMLVideoElement;
62
- unMuteHuman: () => false | Promise<void> | undefined;
63
- startRecord(): void;
64
- stopRecord(): void;
65
- }
package/cjs/Client.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),t=require("@bddh/starling-json"),r=require("lodash/isEmpty"),n=require("lodash/omit"),o=require("lodash/pick"),a=require("uuid"),i=require("./interface.js"),s=require("./Server.js"),c=require("./BrtcClient.js"),u=require("./DomControl.js"),d=require("./Cutout.js"),l=require("./RecordController.js"),m=function(){function m(r){var c=this;e.classCallCheck(this,m),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",u.checkIsHuawei()),e.defineProperty(this,"rtcServerUrl",void 0),e.defineProperty(this,"recordController",null),e.defineProperty(this,"wsReadyState",-1),e.defineProperty(this,"isPreOpenSession",!1),e.defineProperty(this,"onDigitalHumanCallbackPlus",(function(e){var t;e.status===i.statusEnum.DH_LIB_FULL_STATUS&&"wsState"===(null===(t=e.content)||void 0===t?void 0:t.type)&&(c.wsReadyState=e.content.readyState),c.onDigitalHumanCallback&&c.onDigitalHumanCallback(e)})),e.defineProperty(this,"onRemoteVideoComing",(function(e){c.rtcConnectParams&&c.rtcConnectParams.feedId&&e===+c.rtcConnectParams.feedId&&c.rtcServer&&c.rtcServer.client&&c.rtcServer.client.subscribeStreaming("remotevideo500",+c.rtcConnectParams.feedId)})),e.defineProperty(this,"onLocalStream",(function(){(c.connectParams||{}).pullAudioFromRtc&&c.rtcServer&&c.rtcServer.muteMicphone(!0)})),e.defineProperty(this,"onRemoteVideoOn",(function(){setTimeout(e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){var r,n,o,a,i;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=document.getElementById(u.RTC_VIDEO_ID),e.next=3,c.cutoutInstance&&c.cutoutInstance.updateSource(u.RTC_VIDEO_ID);case 3:r&&(r.setAttribute("data-playing","true"),n=r.videoWidth,o=r.videoHeight,a=document.getElementById(u.DEFAULT_CANVAS_ID),i=a.getContext("2d"),a&&i&&(a.width=n,a.height=o,i.drawImage(r,0,0,n,o)));case 4:case"end":return e.stop()}}),t)}))),100)})),e.defineProperty(this,"connectListener",(function(e){var r=e.code,n=e.body,o=e.message;if(0===r&&c.onDigitalHumanCallback&&c.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_WS_SUCCESS,content:e}),0===r){var a=t.parse(n),s=a.rtcServerUrl,u=a.appId,d=a.clientToken,l=a.roomName,m=a.clientId,p=a.feedId,h=a.chargeId;u&&l&&(c.rtcConnectParams={server:c.rtcServerUrl||s,appId:u,token:d,roomName:l,userId:m,feedId:p,chargeId:h},c.rtcServer&&c.rtcServer.openRtc(c.rtcConnectParams))}else c.onDigitalHumanCallback&&c.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:r,errMsg:o}}})})),e.defineProperty(this,"createServer",(function(t){var r,a=e.objectSpread2(e.objectSpread2(e.objectSpread2({token:c.token,appKey:c.appKey,appId:c.appId},t?{sessionId:t}:{}),o(c.connectParams,i.CONNECT_MAIN_KEY)),{},{parameters:n(c.connectParams,i.CONNECT_MAIN_KEY),onConnect:c.connectListener,onDigitalHumanCallback:c.onDigitalHumanCallbackPlus});null!==(r=c.dhServer)&&void 0!==r&&r.preConnectSuccess?(c.dhServer.connectParams=a,c.dhServer&&c.dhServer.sendPreConnect(a)):c.dhServer&&c.dhServer.createSocket(a)})),e.defineProperty(this,"checkHumanInstansce",(function(){return c.dhServer?!(c.isPreOpenSession&&!c.dhServer.preConnectSuccess)||(c.onDigitalHumanCallback&&c.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:4001,errMsg:"webSocket连接中"}}}),!1):(c.onDigitalHumanCallback&&c.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:4002,errMsg:"请先初始化数字人实例"}}}),!1)})),e.defineProperty(this,"sendMessage",(function(e,t){return c.dhServer&&c.dhServer.sendMessage(e,t)})),e.defineProperty(this,"interrupt",e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){c.dhServer&&c.dhServer.sendMessage({requestId:a.v4(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(function(){return e()}))})));case 1:case"end":return e.stop()}}),t)})))),e.defineProperty(this,"textRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;c.checkHumanInstansce()&&c.dhServer&&c.dhServer.sendMessage({requestId:t||a.v4(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"textStreamRender",(function(e){var r=e.requestId,n=e.body,o=e.onCallbackMsg,i=t.parse(n).first;c.checkHumanInstansce()&&c.dhServer&&c.dhServer.sendMessage({requestId:r||a.v4(),action:"TEXT_STREAM_RENDER",body:n,clientTs:(new Date).getTime()},i?o:null)})),e.defineProperty(this,"audioRender",(function(e){var t=e.body,r=e.onCallbackMsg;c.checkHumanInstansce()&&c.dhServer&&c.dhServer.sendMessage({requestId:a.v4(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},r)})),e.defineProperty(this,"audioStreamRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;c.checkHumanInstansce()&&c.dhServer&&c.dhServer.sendMessage({requestId:t||a.v4(),action:"AUDIO_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"textQuery",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;c.dhServer&&c.dhServer.sendMessage({requestId:t||a.v4(),action:"TEXT_QUERY",body:r,clientTs:(new Date).getTime()},n)})),e.defineProperty(this,"destroy",e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,c.dhServer&&c.dhServer.closeSocket();case 2:c.rtcServer&&c.rtcServer.closeRtc(),u.removeHumanDom(),c.dhServer=null,c.rtcServer=null;case 6:case"end":return e.stop()}}),t)})))),e.defineProperty(this,"pauseHuman",(function(){return u.playHumanVideo(!1)})),e.defineProperty(this,"playHuman",(function(){return u.playHumanVideo(!0)})),e.defineProperty(this,"muteHuman",(function(){return u.muteHumanVideo(!0)})),e.defineProperty(this,"unMuteHuman",(function(){var e=u.muteHumanVideo(!1);try{return c.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));var d=r.isPreOpenSession,l=void 0!==d&&d,p=r.wsUrl,h=r.renderParams,v=r.onDigitalHumanCallback;this.isPreOpenSession=l,this.dhServer=new s.default(p||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration"),this.onDigitalHumanCallback=function(e){e.status!==i.statusEnum.DH_LIB_FULL_STATUS?v&&v(e):(null==h?void 0:h.fullStatus)&&v&&v(e)},l?this.dhServer.createSocket({onDigitalHumanCallback:this.onDigitalHumanCallbackPlus},l):this.init(r)}return e.createClass(m,[{key:"init",value:function(t){var n=this,o=t.wrapperId,a=t.token,s=t.appKey,m=t.appId,p=t.connectParams,h=t.renderParams,v=void 0===h?{}:h,f=t.rtcConnectParams,y=t.brtcParams,S=t.rtcServerUrl;if(this.token=a,this.appKey=s,this.appId=m,this.rtcServerUrl=S,this.connectParams=e.objectSpread2({autoChromaKey:(null==v?void 0:v.autoChromaKey)||!1},p),!m&&!s&&!a)throw new Error("appId and appKey or token is required");var g=v.closeLog,C=(u.createHumanDom({autoChromaKey:!!v.autoChromaKey||!r(v.chromaEffects)})||{}).playerWrapper,R=document.getElementById(o||"");R||console.error("dom with wrapperId is not find"),C&&R&&R.appendChild(C),u.appendRtcDomStyle();var I=e.objectSpread2({remotevideoviewid:o,showvideobps:!1,usingvideo:!1,usingaudio:!(null==p||!p.pullAudioFromRtc),aspublisher:!(null==p||!p.pullAudioFromRtc),autopublish:!(null==p||!p.pullAudioFromRtc),usingdatachannel:!0,autoplaymuted:!1},y);this.rtcServer=new c.default({closeLog:g,videoWrapperId:u.RTC_VIDEO_ID,rtcConfig:I,bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback,onLocalStream:this.onLocalStream}}),this.cutoutInstance=new d.default({sourceId:u.RTC_VIDEO_ID,effects:null==v?void 0:v.chromaEffects}),r(f)||(this.rtcConnectParams=f,this.rtcServer.openRtc(f)),null!=p&&p.pullAudioFromRtc?this.recordController=null:this.recordController=new l.default({pickAudioMode:null==p?void 0:p.pickAudioMode,onAudioData:function(e){1===n.wsReadyState&&n.sendMessage(e,null)},onError:function(e){n.onDigitalHumanCallback&&n.onDigitalHumanCallback({status:i.statusEnum.DH_LIB_ERROR,content:{type:i.errorTypeEnum.CONNECT_ERROR,msg:{code:-1,errMsg:e.message}}})}})}},{key:"startRecord",value:function(){var e;null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc?this.rtcServer&&this.rtcServer.muteMicphone(!1):this.recordController&&this.recordController.start()}},{key:"stopRecord",value:function(){var e;if(null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc)return this.rtcServer&&this.rtcServer.muteMicphone(!0),void this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:a.v4(),clientTs:Date.now(),body:""},null);this.recordController&&this.recordController.stop(),this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:a.v4(),clientTs:Date.now(),body:""},null)}}]),m}();exports.default=m;
package/cjs/Cutout.d.ts DELETED
@@ -1,36 +0,0 @@
1
- /**
2
- * @file lib/Cutout
3
- * @description 视频抠绿相关
4
- * @author zhangyue49
5
- */
6
- import { ChromaEffectOptions } from '@bddh/starling-cutout/es/interface';
7
- import Seriously from '@bddh/starling-cutout/es/Seriously';
8
- interface CutoutType {
9
- effects?: {
10
- version: number;
11
- chromaKey: Partial<ChromaEffectOptions>;
12
- };
13
- sourceId: string;
14
- }
15
- export declare const DEFAULT_EFFECTS: {
16
- version: number;
17
- chromaKey: {
18
- screen: number[];
19
- similarity: number;
20
- edgeShrink: number;
21
- smoothness: number;
22
- spill: number;
23
- opacity: number;
24
- contrast: number;
25
- brightness: number;
26
- gamma: number;
27
- };
28
- };
29
- declare class Cutout {
30
- cutoutInstance: Seriously;
31
- constructor(props: CutoutType);
32
- setOptions(options: Partial<ChromaEffectOptions>): void;
33
- destroy(): void;
34
- updateSource(video: HTMLVideoElement | string): Promise<void>;
35
- }
36
- export default Cutout;
package/cjs/Cutout.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("./_virtual/_rollupPluginBabelHelpers.js"),e=require("@bddh/starling-cutout/es/Seriously"),s={version:2,chromaKey:{screen:[53,186,123],similarity:90,edgeShrink:3,smoothness:80,spill:100,opacity:1,contrast:0,brightness:0,gamma:0}},r=function(){function r(u){t.classCallCheck(this,r),t.defineProperty(this,"cutoutInstance",void 0);var n=u.effects,o=u.sourceId;this.cutoutInstance=new e("starling-cutout-canvas",o||"starling-cutout-video",n&&n.chromaKey||s.chromaKey,n&&n.version||s.version)}return t.createClass(r,[{key:"setOptions",value:function(t){t&&this.cutoutInstance&&this.cutoutInstance.setOptions(t)}},{key:"destroy",value:function(){return this.cutoutInstance.destroy()}},{key:"updateSource",value:function(t){return this.cutoutInstance.updateSource(t)}}]),r}();exports.DEFAULT_EFFECTS=s,exports.default=r;
@@ -1,23 +0,0 @@
1
- /**
2
- * @file DomControl
3
- * @description 一些js创建dom的方法
4
- */
5
- interface CreateVideoDomOptions {
6
- id?: string;
7
- autoplay?: boolean;
8
- autoChromaKey?: boolean;
9
- }
10
- interface CreateVideoDomResult {
11
- playerWrapper: HTMLDivElement;
12
- video: HTMLVideoElement;
13
- }
14
- export declare const DEFAULT_CANVAS_ID = "starling-cutout-canvas";
15
- export declare const HUMAN_WRAPPER_ID = "cloud-brtc-player-wrapper";
16
- export declare const RTC_VIDEO_ID = "remotevideo500";
17
- export declare function createHumanDom(options: CreateVideoDomOptions): CreateVideoDomResult | null;
18
- export declare function removeHumanDom(): void;
19
- export declare function muteHumanVideo(muted: boolean): HTMLVideoElement;
20
- export declare function playHumanVideo(play: boolean): void | Promise<void>;
21
- export declare function checkIsHuawei(): boolean;
22
- export declare function appendRtcDomStyle(): void;
23
- export {};
package/cjs/DomControl.js DELETED
@@ -1 +0,0 @@
1
- "use strict";var 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(){var t=document.createElement("style");t.appendChild(document.createTextNode('\n [id^="videoremote1-"] {\n display: none !important;\n }\n \n video#remotevideo500 {\n width: auto !important;\n height: auto !important;\n max-width: 100% !important;\n max-height: 100% !important;\n width: 100% !important;\n height: 100% !important;\n object-fit: cover;\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(){var t=navigator.userAgent||navigator.vendor;return/huawei/i.test(t)||/honor/i.test(t)},exports.createHumanDom=function(i){var o=i.autoChromaKey,r=void 0!==o&&o,a=i.autoplay,d=void 0===a||a;if(document.getElementById(n))return console.error('DOM with id "'.concat(n,'" already exists.')),null;var u=document.createElement("div");u.className=e,u.id=e,u.style.position="relative";var c=document.createElement("video");c.id=n,c.width=0,c.height=0,c.setAttribute("width","100%"),c.setAttribute("height","100%"),c.setAttribute("data-playing","true"),c.setAttribute("playsinline","");var p=document.createElement("canvas");return p.id=t,Object.assign(p.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:r?"block":"none"}),d&&c.setAttribute("autoplay",""),r&&(c.style.visibility="hidden"),u.appendChild(c),u.appendChild(p),{playerWrapper:u,video:c}},exports.muteHumanVideo=function(t){var e=document.getElementById(n);return e&&(e.muted=t),e},exports.playHumanVideo=function(t){var e=document.getElementById(n);try{if(e)return t?e.play():e.pause()}catch(t){console.info(t)}},exports.removeHumanDom=function(){var t=document.getElementById(e);t&&t.parentNode&&t.parentNode.removeChild(t)};
@@ -1,20 +0,0 @@
1
- export type PickAudioMode = 'pressButton' | 'free';
2
- interface RecordControllerOptions {
3
- pickAudioMode?: PickAudioMode;
4
- onAudioData: (pcmData: ArrayBuffer) => void;
5
- onError?: (err: Error) => void;
6
- pullAudioFromRtc?: boolean;
7
- brtcClient?: any;
8
- }
9
- declare class RecordController {
10
- private readonly onAudioData;
11
- private readonly onError?;
12
- private audioContext;
13
- private processor;
14
- private mediaStream;
15
- private recording;
16
- constructor(options: RecordControllerOptions);
17
- start(): Promise<void>;
18
- stop(): void;
19
- }
20
- export default RecordController;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js");function t(e,t,r,o){try{for(var n=(o=o||{})&&"number"==typeof o.index?o.index:0,i=o&&"number"==typeof o.offset?o.offset:0,a=0,s=n;s<e.length;s++)a+=e[s].length;a=Math.max(0,a-Math.floor(i));var u=t/r;u>1?a=Math.floor(a/u):(u=1,r=t);for(var c=new Int16Array(a),d=0,h=e.length;n<h;n++){for(var l=e[n],f=i,p=l.length;f<p;){var m=Math.floor(f),v=Math.ceil(f),x=f-m;c[d]=l[m]+(l[v]-l[m])*x,d++,f+=u}i=f-p}return{index:n,offset:i,sampleRate:r,data:c}}catch(e){console.log("转音错误了",e)}}function r(e){for(var t=e,r=new Int16Array(e.length),o=0;o<t.length;o++){var n=Math.max(-1,Math.min(1,t[o]));r[o]=n<0?32768*n:32767*n}return r}var o=function(o){function n(t){e.classCallCheck(this,n),e.defineProperty(this,"onAudioData",void 0),e.defineProperty(this,"onError",void 0),e.defineProperty(this,"audioContext",null),e.defineProperty(this,"processor",null),e.defineProperty(this,"mediaStream",null),e.defineProperty(this,"recording",!1),this.onAudioData=t.onAudioData,this.onError=t.onError}return e.createClass(n,[{key:"start",value:function(){return(o=o||e.asyncToGenerator(e.regeneratorRuntime().mark((function o(){var n,i=this;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.recording){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:16e3}),e.next=6,navigator.mediaDevices.getUserMedia({audio:!0,video:!1});case 6:this.mediaStream=e.sent,n=this.audioContext.createMediaStreamSource(this.mediaStream),this.processor=this.audioContext.createScriptProcessor(1024,1,1),n.connect(this.processor),this.processor.connect(this.audioContext.destination),this.processor.onaudioprocess=function(e){if(i.recording){var o=t([r(e.inputBuffer.getChannelData(0))],i.audioContext.sampleRate,16e3,null);o&&o.data&&i.onAudioData(o.data.buffer)}},this.recording=!0,e.next=18;break;case 15:e.prev=15,e.t0=e.catch(2),this.onError&&this.onError(e.t0);case 18:case"end":return e.stop()}}),o,this,[[2,15]])})))).apply(this,arguments)}},{key:"stop",value:function(){this.recording=!1,this.processor&&(this.processor.disconnect(),this.processor.onaudioprocess=null),this.audioContext&&this.audioContext.close(),this.mediaStream&&this.mediaStream.getTracks().forEach((function(e){e.stop()}))}}]),n}();exports.default=o;
package/cjs/Server.d.ts DELETED
@@ -1,60 +0,0 @@
1
- /**
2
- * @file lib/Server
3
- * @description ws服务逻辑处理
4
- * @author zhangyue49
5
- */
6
- import { type WebSocketClient } from '@bddh/starling-web-socket/es/interface';
7
- import { CallbackMsgType, ConnectDataType, ConnectParamsType } from './interface';
8
- export interface SteamDataType {
9
- first: boolean;
10
- last: boolean;
11
- audio?: string;
12
- body?: string;
13
- }
14
- export interface DHServerInterface {
15
- action: string;
16
- requestId: string;
17
- clientTs: number;
18
- body: string | ArrayBuffer;
19
- }
20
- export interface DHErrServerInterface {
21
- action: string;
22
- requestId: string;
23
- code?: number;
24
- message?: string;
25
- error: Error;
26
- }
27
- type ConnectListener = (data: ConnectDataType, off?: () => void) => void;
28
- export interface createSocketParamsType {
29
- token?: string;
30
- appKey?: string;
31
- appId?: string;
32
- sessionId?: string;
33
- parameters?: ConnectParamsType;
34
- reConnect?: boolean;
35
- onConnect?: ConnectListener;
36
- onDigitalHumanCallback?: (data: CallbackMsgType) => void;
37
- }
38
- export interface RenderCallbackRes {
39
- requestId: string;
40
- action: string;
41
- code: number;
42
- body: string | null;
43
- message: string;
44
- }
45
- export type RenderCallback = (res: RenderCallbackRes) => void;
46
- declare class Server {
47
- dhServerSocket: WebSocketClient | null;
48
- preConnectSuccess: boolean;
49
- connectParams: createSocketParamsType | null;
50
- private socketClosingPromise;
51
- private readonly url;
52
- private firstConnect;
53
- constructor(url: string);
54
- sendPreConnect: (props: createSocketParamsType, resolve?: ((value: any) => void) | undefined) => void;
55
- createSocket: (props: createSocketParamsType, isPreOpenSession?: boolean) => Promise<WebSocketClient | null>;
56
- closeSocket: () => Promise<void>;
57
- handleConnect: () => Promise<void>;
58
- sendMessage(message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null): Promise<void>;
59
- }
60
- export default Server;
package/cjs/Server.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./_virtual/_rollupPluginBabelHelpers.js"),t=require("uuid"),r=require("@bddh/starling-web-socket/es/create-web-socket"),n=require("lodash/pick"),o=require("lodash/omit"),s=require("lodash/get"),c=require("./interface.js"),a=function(a){function i(a){var u,d=this;e.classCallCheck(this,i),e.defineProperty(this,"dhServerSocket",null),e.defineProperty(this,"preConnectSuccess",!1),e.defineProperty(this,"connectParams",null),e.defineProperty(this,"socketClosingPromise",null),e.defineProperty(this,"url",void 0),e.defineProperty(this,"firstConnect",!0),e.defineProperty(this,"sendPreConnect",(function(e,r){var n,o=e.token,s=e.sessionId,c=e.onConnect;null===(n=d.dhServerSocket)||void 0===n||n.request({action:"RE_CONNECT",requestId:t.v4(),body:JSON.stringify({token:o,sessionId:s})}).on((function(e,t){null==c||c(e),0!==e.code&&(t(),d.handleConnect()),null==r||r(d.dhServerSocket)})),d.firstConnect=!1})),e.defineProperty(this,"createSocket",(function(t,n){return(u=u||e.asyncToGenerator(e.regeneratorRuntime().mark((function t(n,o){var a,i;return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(d.connectParams=n,a=n.sessionId,i=n.onDigitalHumanCallback,!d.socketClosingPromise){e.next=5;break}return e.next=5,d.socketClosingPromise;case 5:if(!d.dhServerSocket){e.next=8;break}return e.next=8,d.closeSocket();case 8:return e.abrupt("return",new Promise((function(e,t){var u={keepAlive:"heartbeat",reopen:s(d.connectParams,"reConnect",!0),combine:function(e,t){return e&&t&&e.requestId===t.requestId},onOpen:function(){d.dhServerSocket=p,a&&d.firstConnect?d.sendPreConnect(n,e):o&&d.firstConnect||d.handleConnect()},onClose:function(){d.dhServerSocket=null,d.socketClosingPromise=null},onError:function(e){t(e)}},p=r.createWebSocket(d.url,u);p.onReadyStateChange((function(e){0===e&&i&&i({status:c.statusEnum.DH_LIB_INIT}),1===e&&o&&(d.preConnectSuccess=!0),3===e&&(d.preConnectSuccess=!1),i&&i({status:c.statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:c.WS_STATUS_MAP[e]}})})),p.onMessage((function(e){var t=e.action;if([c.errorTypeEnum.TIMEOUT_EXIT,c.errorTypeEnum.DISCONNECT_ALERT].includes(t)&&i&&i({status:c.statusEnum.DH_LIB_STATUS,content:{type:t}}),"DOWN_SUBTITLE"===t){var r=JSON.parse(e.body);["REPLY","QUERY"].includes(s(r,"type","").toUpperCase())&&i&&i({status:c.statusEnum.DH_LIB_STATUS,content:{type:t,body:e.body}})}})),o&&(d.dhServerSocket=p),p.open()})));case 9:case"end":return e.stop()}}),t)})))).apply(this,arguments)})),e.defineProperty(this,"closeSocket",e.asyncToGenerator(e.regeneratorRuntime().mark((function t(){return e.regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(d.dhServerSocket){e.next=2;break}return e.abrupt("return");case 2:return d.socketClosingPromise=d.dhServerSocket.close(),e.next=5,d.socketClosingPromise;case 5:d.dhServerSocket=null;case 6:case"end":return e.stop()}}),t)})))),e.defineProperty(this,"handleConnect",e.asyncToGenerator(e.regeneratorRuntime().mark((function r(){var s,a,i,u,p,l;return e.regeneratorRuntime().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(d.connectParams){r.next=2;break}return r.abrupt("return");case 2:if(s=d.connectParams,a=s.appId,i=s.appKey,u=s.token,p=s.parameters,l=s.onConnect,a||i||u){r.next=5;break}return r.abrupt("return");case 5:d.dhServerSocket&&d.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:t.v4(),body:JSON.stringify(e.objectSpread2(e.objectSpread2({token:u,appId:a,appKey:i},n(d.connectParams,c.CONNECT_MAIN_KEY)),{},{parameters:e.objectSpread2(e.objectSpread2({},o(p,["parameters"])),p&&p.parameters?p.parameters:{})}))}).on((function(e,t){null==l||l(e),0!==e.code&&t()}));case 6:case"end":return r.stop()}}),r)})))),this.url=a}return e.createClass(i,[{key:"sendMessage",value:function(r,n){return(a=a||e.asyncToGenerator(e.regeneratorRuntime().mark((function r(n,o){var s;return e.regeneratorRuntime().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(n).on((function(e){o&&o(e)}))}catch(r){s="object"===e.typeof(n)&&"requestId"in n?n.requestId:t.v4(),o&&o({code:-11,body:null,action:"RENDER_ERROR",requestId:s,message:JSON.stringify(r)})}case 1:case"end":return r.stop()}}),r,this)})))).apply(this,arguments)}}]),i}();exports.default=a;
@@ -1 +0,0 @@
1
- "use strict";function t(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function r(){r=function(){return e};var t,e={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",f=a.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=r&&r.prototype instanceof m?r:m,a=Object.create(o.prototype),c=new N(n||[]);return i(a,"_invoke",{value:S(t,e,c)}),a}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}e.wrap=s;var p="suspendedStart",y="suspendedYield",v="executing",g="completed",d={};function m(){}function b(){}function w(){}var x={};l(x,c,(function(){return this}));var O=Object.getPrototypeOf,j=O&&O(O(T([])));j&&j!==n&&o.call(j,c)&&(x=j);var L=w.prototype=m.prototype=Object.create(x);function E(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function P(t,r){function e(n,i,a,c){var u=h(t[n],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==typeof l&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function S(r,e,n){var o=p;return function(i,a){if(o===v)throw new Error("Generator is already running");if(o===g){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=_(c,n);if(u){if(u===d)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var f=h(r,e,n);if("normal"===f.type){if(o=n.done?g:y,f.arg===d)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(o=g,n.method="throw",n.arg=f.arg)}}}function _(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,_(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var i=h(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,d;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,d):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function k(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function G(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function T(r){if(r||""===r){var e=r[c];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return b.prototype=w,i(L,"constructor",{value:w,configurable:!0}),i(w,"constructor",{value:b,configurable:!0}),b.displayName=l(w,f,"GeneratorFunction"),e.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===b||"GeneratorFunction"===(r.displayName||r.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,l(t,f,"GeneratorFunction")),t.prototype=Object.create(L),t},e.awrap=function(t){return{__await:t}},E(P.prototype),l(P.prototype,u,(function(){return this})),e.AsyncIterator=P,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new P(s(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},E(L),l(L,f,"Generator"),l(L,c,(function(){return this})),l(L,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=T,N.prototype={constructor:N,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(G),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=o.call(a,"catchLoc"),f=o.call(a,"finallyLoc");if(u&&f){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!f)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),d},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),G(e),d}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;G(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:T(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),d}},e}function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function o(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,c(n.key),n)}}function i(t,r,e){return(r=c(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function a(t,r){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}function c(t){var r=a(t,"string");return"symbol"==typeof r?r:String(r)}exports.asyncToGenerator=function(t){return function(){var r=this,e=arguments;return new Promise((function(o,i){var a=t.apply(r,e);function c(t){n(a,o,i,c,u,"next",t)}function u(t){n(a,o,i,c,u,"throw",t)}c(void 0)}))}},exports.classCallCheck=function(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")},exports.createClass=function(t,r,e){return r&&o(t.prototype,r),e&&o(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t},exports.defineProperty=i,exports.objectSpread2=function(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?t(Object(n),!0).forEach((function(t){i(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))}))}return r},exports.regeneratorRuntime=r,exports.toPrimitive=a,exports.toPropertyKey=c,exports.typeof=e;
package/cjs/index.d.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * @file 云渲染SDK
3
- * @author zhangyue49
4
- */
5
- import HumanClient from './Client';
6
- export default HumanClient;
7
- export * from './interface';
package/cjs/index.js DELETED
@@ -1 +0,0 @@
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}});
@@ -1,107 +0,0 @@
1
- import { RtcConnectionType } from './BrtcClient';
2
- export interface ConnectDataType {
3
- action: string;
4
- body: string;
5
- code: number;
6
- message: string;
7
- }
8
- export interface ConnectParamsType {
9
- figureId?: string | number;
10
- resolutionHeight: number;
11
- resolutionWidth: number;
12
- x264BitRate?: number;
13
- cameraId?: string | number;
14
- characterOffset?: string;
15
- pickAudioMode?: 'pressButton' | 'free';
16
- autoChromaKey?: boolean;
17
- usingVideo?: boolean;
18
- ttsPer?: string | number;
19
- ttsPitch?: number;
20
- ttsSpeed?: number;
21
- ttsVolume?: number;
22
- ttsLan?: string;
23
- pullAudioFromRtc?: boolean;
24
- inactiveDisconnectSec?: number;
25
- preAlertSec?: 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;
38
- parameters?: any;
39
- reConnect?: boolean;
40
- }
41
- export declare const CONNECT_MAIN_KEY: string[];
42
- export interface RenderParamsType {
43
- chromaEffects?: object;
44
- autoChromaKey?: boolean;
45
- closeLog?: boolean;
46
- fullStatus?: boolean;
47
- }
48
- export declare enum statusEnum {
49
- DH_LIB_INIT = "DH_LIB_INIT",
50
- DH_LIB_WS_SUCCESS = "DH_LIB_WS_SUCCESS",
51
- DH_LIB_OPEN = "DH_LIB_OPEN",
52
- DH_LIB_STATUS = "DH_LIB_STATUS",
53
- DH_LIB_CLOSE = "DH_LIB_CLOSE",
54
- DH_LIB_ERROR = "DH_LIB_ERROR",
55
- DH_LIB_WARNING = "DH_LIB_WARNING",
56
- DH_LIB_FULL_STATUS = "DH_LIB_FULL_STATUS"
57
- }
58
- export declare enum errorTypeEnum {
59
- CONNECT_ERROR = "CONNECT_ERROR",
60
- DISCONNECT_ALERT = "DISCONNECT_ALERT",
61
- TIMEOUT_EXIT = "TIMEOUT_EXIT",
62
- LOCAL_VIDEO_MUTED = "LOCAL_VIDEO_MUTED",
63
- LOCAL_VIDEO_ERROR = "LOCAL_VIDEO_ERROR",
64
- RTC_ERROR = "RTC_ERROR"
65
- }
66
- export interface ErrorType {
67
- type: errorTypeEnum;
68
- msg?: {
69
- code: string | number;
70
- errMsg: string;
71
- };
72
- }
73
- export interface RtcStateType {
74
- action: string;
75
- type: string;
76
- body: any;
77
- }
78
- export declare const WS_STATUS_MAP: {
79
- '-1': string;
80
- '0': string;
81
- '1': string;
82
- '2': string;
83
- '3': string;
84
- };
85
- export interface WsStateType {
86
- readyState: number;
87
- type: string;
88
- body: string;
89
- }
90
- export interface CallbackMsgType {
91
- status: statusEnum;
92
- content?: ErrorType | WsStateType | RtcStateType | ConnectDataType;
93
- }
94
- export interface DhRealtimeHumanType {
95
- token?: string;
96
- wsUrl?: string;
97
- rtcServerUrl?: string;
98
- appKey?: string;
99
- appId?: string;
100
- wrapperId?: string;
101
- connectParams?: ConnectParamsType;
102
- renderParams?: RenderParamsType;
103
- rtcConnectParams?: RtcConnectionType;
104
- brtcParams?: any;
105
- isPreOpenSession?: boolean;
106
- onDigitalHumanCallback: (data: CallbackMsgType) => void;
107
- }
package/cjs/interface.js DELETED
@@ -1 +0,0 @@
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","reConnect"],exports.WS_STATUS_MAP={"-1":"UNINSTANTIATED",0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"};
@@ -1,97 +0,0 @@
1
- /**
2
- * @file lib/Brtc
3
- * @description brtc拉流相关
4
- * @author zhangyue49
5
- */
6
- import type { BRtcInstance } from '@bddh/starling-brtc';
7
- import { ChromaEffectOptions } from '@bddh/starling-cutout/es/interface';
8
- import { CallbackMsgType } from './interface';
9
- export interface RtcConnectionType {
10
- server: string;
11
- appId: string;
12
- token: string;
13
- roomName: string;
14
- userId: string;
15
- feedId?: number;
16
- chargeId?: number;
17
- }
18
- interface RtcConfig {
19
- [x: string]: any;
20
- videoprofile?: Record<string, any>;
21
- mediaserverip?: string;
22
- displayname?: string;
23
- remotevideoviewid?: string;
24
- localvideoviewid?: string;
25
- bitrate?: number;
26
- showvideobps?: boolean;
27
- usingvideo?: boolean;
28
- usingaudio?: boolean;
29
- aspublisher?: boolean;
30
- usingdatachannel?: boolean;
31
- autoplaymuted?: boolean;
32
- autosubscribe?: boolean;
33
- uploadVideoResolution?: {
34
- width: number;
35
- height: number;
36
- };
37
- uploadVideoBitrate?: number;
38
- }
39
- export interface BizConfig {
40
- autoCheck?: boolean;
41
- isCrash?: boolean;
42
- showMessage?: boolean;
43
- autoReConnect?: boolean;
44
- autoStart?: boolean;
45
- showLocalVideo?: boolean;
46
- welcomeContent?: string;
47
- autoChromaKey?: boolean;
48
- chromaEffects?: ChromaEffectOptions;
49
- }
50
- export interface RtcCallback {
51
- [x: string]: any;
52
- onLocalStream?: (stream: MediaStream, name: string) => void;
53
- onLocalVideoPublished?: () => void;
54
- onRemoteVideoComing?: (id: number) => void;
55
- onRemoteVideoOn?: (id: number) => void;
56
- onRemoteVideoOff?: (id: number) => void;
57
- onRemoteVideoLoading?: (id: number) => void;
58
- onSuccess?: () => void;
59
- onError?: (error: string) => void;
60
- onRemoteVideoConnected?: (id: number, on: boolean) => void;
61
- onRemoteMediaState?: (id: number, medium: MediaStream, on: boolean) => void;
62
- onLocalVideoConnected?: (on: boolean) => void;
63
- onPlayingError: (element: HTMLVideoElement) => void;
64
- onRemotedata: (data: any) => void;
65
- onLocalVideoPublishing: () => void;
66
- onDigitalHumanCallback: (data: CallbackMsgType) => void;
67
- }
68
- interface BrtcClientType {
69
- videoWrapperId: string;
70
- bizConfig: BizConfig;
71
- closeLog?: boolean;
72
- rtcConnection?: RtcConnectionType;
73
- preConnectInfo?: RtcConnectionType;
74
- rtcConfig?: RtcConfig;
75
- rtcCallback?: Partial<RtcCallback>;
76
- }
77
- declare class BrtcClient {
78
- client?: BRtcInstance;
79
- isRtcVideoOn: boolean;
80
- private rtcConnection;
81
- private readonly rtcConfig?;
82
- private readonly bizConfig?;
83
- private readonly rtcCallback?;
84
- private restarting;
85
- private readonly timeoutEvent;
86
- private reopenTimer;
87
- private restartCount;
88
- private readonly closeLog;
89
- private haveVideoOn;
90
- private rtcStateCallback;
91
- constructor(props: BrtcClientType);
92
- openRtc: (rtcConnection: RtcConnectionType) => void;
93
- closeRtc: () => void;
94
- restartRtc: (rtcConnection: RtcConnectionType) => void;
95
- muteMicphone(mute: boolean): void;
96
- }
97
- export default BrtcClient;
package/es/BrtcClient.js DELETED
@@ -1 +0,0 @@
1
- import{createClass as t,classCallCheck as o,defineProperty as e}from"./_virtual/_rollupPluginBabelHelpers.js";import n from"@bddh/starling-brtc";import{TimeoutController as c}from"@bddh/starling-timeout-controller";import i from"@bddh/starling-json";import a from"lodash/isEmpty";import r from"lodash/isFunction";import{statusEnum as l,errorTypeEnum as s}from"./interface.js";var d=function(){function d(t){var u=this;o(this,d),e(this,"client",void 0),e(this,"isRtcVideoOn",!1),e(this,"rtcConnection",void 0),e(this,"rtcConfig",void 0),e(this,"bizConfig",void 0),e(this,"rtcCallback",void 0),e(this,"restarting",!1),e(this,"timeoutEvent",void 0),e(this,"reopenTimer",void 0),e(this,"restartCount",0),e(this,"closeLog",!0),e(this,"haveVideoOn",!1),e(this,"rtcStateCallback",null),e(this,"openRtc",(function(t){if(u.restarting)!u.closeLog&&console.warn("rtc restarting");else if(t&&(u.rtcConnection=t),u.rtcConnection&&!a(u.rtcConnection)){var o=u.rtcConnection,e=o.server,c=o.appId,d=o.token,m=o.roomName,C=o.userId,f=u.rtcCallback||{},b=f.onRemotedata,g=f.onLocalStream,h=f.onRemoteVideoComing,v=f.onLocalVideoPublished,R=f.onLocalVideoPublishing,L=f.onRemoteVideoOn,S=f.onRemoteVideoOff,k=f.onRemoteVideoLoading,p=f.onSuccess,y=f.onError,V=f.onLocalVideoConnected,E=f.onRemoteVideoConnected,_=f.onRemoteMediaState,O=f.onPlayingError,I=f.onDigitalHumanCallback;u.timeoutEvent.start(),u.rtcStateCallback=function(t){var o=t.body,e=t.action;I&&I({status:l.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:e,body:o}})},u.client=new n({roomName:m,token:d,userId:C,appId:c,server:e,rtcConfig:u.rtcConfig,callback:{onRemoteVideoConnected:function(o,e){if(!e&&!u.haveVideoOn)var n=setTimeout((function(){u.restartCount<3?(u.restartCount=++u.restartCount,u.restartRtc&&u.restartRtc(t)):(u.restartCount=0,u.closeRtc()),clearTimeout(n)}),500);if(e){var c=document.getElementById("remotevideo500");c.muted=!1;var i=c.play();void 0!==i&&i.catch((function(){c.muted=!0,c.play().catch((function(t){!u.closeLog&&console.info("videoElement play error",t),O&&O(c),I&&I({status:l.DH_LIB_ERROR,content:{type:s.LOCAL_VIDEO_ERROR}})})),I&&I({status:l.DH_LIB_STATUS,content:{type:s.LOCAL_VIDEO_MUTED}})}))}!u.closeLog&&console.info("remoteVideoConnected",o,e,u.restartCount),u.rtcStateCallback&&u.rtcStateCallback({action:"remoteVideoConnected",body:{id:o,connected:e,restartCount:u.restartCount}}),r(E)&&E(o,e)},onRemoteVideoOn:function(t){u.haveVideoOn=!0,!u.closeLog&&console.info("remotevideoon by id: ",t),u.timeoutEvent.clear();var o=document.querySelector("#starlingRtcContainer"),e=o&&o.lastChild;e&&(e.style.display="none"),u.rtcStateCallback&&u.rtcStateCallback({action:"remotevideoon",body:t}),I&&I({status:l.DH_LIB_OPEN}),r(L)&&L(t)},onRemoteMediaState:function(t,o,e){!u.closeLog&&console.info("remoteMediaState",t,o,e),u.rtcStateCallback&&u.rtcStateCallback({action:"remoteMediaState",body:{id:t,medium:o,connected:e}}),r(_)&&_(t,o,e)},onLocalVideoConnected:function(t){!u.closeLog&&console.info("localVideoConnected",t),u.rtcStateCallback&&u.rtcStateCallback({action:"localVideoConnected",body:{connected:t}}),r(V)&&V(t)},onRemotedata:function(t){if(u.rtcConfig&&u.rtcConfig.usingdatachannel){var o=i.parse(t);!u.closeLog&&console.info("RTC - receive:",o),r(b)&&b(o)}},onLocalStream:function(t,o){!u.closeLog&&console.info("rtc - onlocalstream by name: "+o),u.rtcStateCallback&&u.rtcStateCallback({action:"onlocalstream",body:{stream:t,name:o}}),r(g)&&g(t,o)},onLocalVideoPublished:function(){!u.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),u.rtcStateCallback&&u.rtcStateCallback({action:"localvideopublished_ok",body:!0}),r(v)&&v()},onLocalVideoPublishing:function(){!u.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),u.rtcStateCallback&&u.rtcStateCallback({action:"localvideopublishing",body:!0}),r(R)&&R()},onRemoteVideoComing:function(t){!u.closeLog&&console.info("remotevideocoming",t),u.rtcStateCallback&&u.rtcStateCallback({action:"remotevideocoming",body:t}),r(h)&&h(t)},onRemoteVideoLoading:function(t){!u.closeLog&&console.info("remotevideoloading by id: ",t),u.rtcStateCallback&&u.rtcStateCallback({action:"remotevideoloading",body:t}),r(k)&&k(t)},onRemoteVideoOff:function(t){var o=document.getElementById("remotevideo500");o&&o.pause(),!u.closeLog&&console.info("remotevideooff: ",t),u.isRtcVideoOn=!1,u.rtcStateCallback&&u.rtcStateCallback({action:"remotevideooff",body:t}),I&&I({status:l.DH_LIB_CLOSE}),r(S)&&S(t),u.timeoutEvent.start()},onSuccess:function(){!u.closeLog&&console.info("rtc - success"),u.rtcStateCallback&&u.rtcStateCallback({action:"success",body:!0}),r(p)&&p()},onError:function(o){u.isRtcVideoOn=!1,!u.closeLog&&console.error("rtc - error:",o),u.rtcStateCallback&&u.rtcStateCallback({action:"error",body:o}),I&&I({status:l.DH_LIB_ERROR,content:{type:s.RTC_ERROR}}),r(y)&&y(o),(o.includes("Lost connection to the server")||o.includes("Is the server down"))&&u.restartRtc&&u.restartRtc(t)}}})}})),e(this,"closeRtc",(function(){u.timeoutEvent.clear(),clearTimeout(u.reopenTimer),u.client&&u.client.destroy(),u.restarting=!1})),e(this,"restartRtc",(function(t){!u.restarting&&u.bizConfig&&u.bizConfig.autoReConnect&&(u.rtcStateCallback&&u.rtcStateCallback({action:"restartRtc",body:t}),u.restarting=!0,u.closeRtc(),u.reopenTimer=setTimeout((function(){!u.closeLog&&console.error("拉流失败,开始重启"),u.restarting=!1,u.openRtc(t)}),2e3))}));var m=t.rtcConnection,C=t.rtcConfig,f=t.closeLog,b=void 0===f||f,g=t.rtcCallback;this.rtcConnection=m,this.rtcConfig=C,this.rtcCallback=g,this.closeLog=b,this.timeoutEvent=new c(6e4,(function(){if(!u.rtcConnection)return!u.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");u.timeoutEvent.clear(),u.restartRtc&&u.restartRtc(u.rtcConnection)}))}return t(d,[{key:"muteMicphone",value:function(t){this.client&&this.client.muteMicphone&&this.client.muteMicphone(t)}}]),d}();export{d as default};
package/es/Client.d.ts DELETED
@@ -1,65 +0,0 @@
1
- /**
2
- * @file dh-realtime-human
3
- * @description 云渲染数字人sdk
4
- * @author zhangyue49
5
- */
6
- import { DhRealtimeHumanType, ConnectDataType, CallbackMsgType } from './interface';
7
- import { DHServerInterface, RenderCallback } from './Server';
8
- export default class DhRealtimeHuman {
9
- private token;
10
- private appKey;
11
- private appId;
12
- private connectParams;
13
- private readonly onDigitalHumanCallback?;
14
- private dhServer;
15
- private rtcServer?;
16
- private rtcConnectParams;
17
- private cutoutInstance?;
18
- private readonly isHuawei;
19
- private rtcServerUrl;
20
- private recordController;
21
- private wsReadyState;
22
- private readonly isPreOpenSession;
23
- constructor(props: DhRealtimeHumanType);
24
- init(props: DhRealtimeHumanType): void;
25
- onDigitalHumanCallbackPlus: (data: CallbackMsgType) => void;
26
- onRemoteVideoComing: (id: number) => void;
27
- onLocalStream: () => void;
28
- onRemoteVideoOn: () => void;
29
- connectListener: (data: ConnectDataType) => void;
30
- createServer: (sessionId?: string) => void;
31
- checkHumanInstansce: () => boolean;
32
- sendMessage: (message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null) => Promise<void> | null;
33
- interrupt: () => Promise<void>;
34
- textRender: (renderData: {
35
- requestId: string;
36
- body: string;
37
- onCallbackMsg: RenderCallback;
38
- }) => void;
39
- textStreamRender: (renderData: {
40
- requestId?: string;
41
- body: string;
42
- onCallbackMsg: RenderCallback;
43
- }) => void;
44
- audioRender: (renderData: {
45
- body: string;
46
- onCallbackMsg: RenderCallback;
47
- }) => void;
48
- audioStreamRender: (renderData: {
49
- requestId?: string;
50
- body: string;
51
- onCallbackMsg: RenderCallback;
52
- }) => void;
53
- textQuery: (queryData: {
54
- requestId: string;
55
- body: string;
56
- onCallbackMsg: RenderCallback;
57
- }) => void;
58
- destroy: () => Promise<void>;
59
- pauseHuman: () => void | Promise<void>;
60
- playHuman: () => void | Promise<void>;
61
- muteHuman: () => HTMLVideoElement;
62
- unMuteHuman: () => false | Promise<void> | undefined;
63
- startRecord(): void;
64
- stopRecord(): void;
65
- }
package/es/Client.js DELETED
@@ -1 +0,0 @@
1
- import{createClass as e,classCallCheck as t,defineProperty as r,objectSpread2 as n,asyncToGenerator as a,regeneratorRuntime as o}from"./_virtual/_rollupPluginBabelHelpers.js";import i from"@bddh/starling-json";import s from"lodash/isEmpty";import c from"lodash/omit";import l from"lodash/pick";import{v4 as u}from"uuid";import{statusEnum as d,errorTypeEnum as m,CONNECT_MAIN_KEY as h}from"./interface.js";import p from"./Server.js";import v from"./BrtcClient.js";import{createHumanDom as S,appendRtcDomStyle as g,RTC_VIDEO_ID as C,checkIsHuawei as f,playHumanVideo as R,muteHumanVideo as I,removeHumanDom as b,DEFAULT_CANVAS_ID as k}from"./DomControl.js";import y from"./Cutout.js";import D from"./RecordController.js";var E=function(){function E(e){var s=this;t(this,E),r(this,"token",void 0),r(this,"appKey",void 0),r(this,"appId",void 0),r(this,"connectParams",void 0),r(this,"onDigitalHumanCallback",void 0),r(this,"dhServer",void 0),r(this,"rtcServer",void 0),r(this,"rtcConnectParams",void 0),r(this,"cutoutInstance",void 0),r(this,"isHuawei",f()),r(this,"rtcServerUrl",void 0),r(this,"recordController",null),r(this,"wsReadyState",-1),r(this,"isPreOpenSession",!1),r(this,"onDigitalHumanCallbackPlus",(function(e){var t;e.status===d.DH_LIB_FULL_STATUS&&"wsState"===(null===(t=e.content)||void 0===t?void 0:t.type)&&(s.wsReadyState=e.content.readyState),s.onDigitalHumanCallback&&s.onDigitalHumanCallback(e)})),r(this,"onRemoteVideoComing",(function(e){s.rtcConnectParams&&s.rtcConnectParams.feedId&&e===+s.rtcConnectParams.feedId&&s.rtcServer&&s.rtcServer.client&&s.rtcServer.client.subscribeStreaming("remotevideo500",+s.rtcConnectParams.feedId)})),r(this,"onLocalStream",(function(){(s.connectParams||{}).pullAudioFromRtc&&s.rtcServer&&s.rtcServer.muteMicphone(!0)})),r(this,"onRemoteVideoOn",(function(){setTimeout(a(o().mark((function e(){var t,r,n,a,i;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=document.getElementById(C),e.next=3,s.cutoutInstance&&s.cutoutInstance.updateSource(C);case 3:t&&(t.setAttribute("data-playing","true"),r=t.videoWidth,n=t.videoHeight,a=document.getElementById(k),i=a.getContext("2d"),a&&i&&(a.width=r,a.height=n,i.drawImage(t,0,0,r,n)));case 4:case"end":return e.stop()}}),e)}))),100)})),r(this,"connectListener",(function(e){var t=e.code,r=e.body,n=e.message;if(0===t&&s.onDigitalHumanCallback&&s.onDigitalHumanCallback({status:d.DH_LIB_WS_SUCCESS,content:e}),0===t){var a=i.parse(r),o=a.rtcServerUrl,c=a.appId,l=a.clientToken,u=a.roomName,h=a.clientId,p=a.feedId,v=a.chargeId;c&&u&&(s.rtcConnectParams={server:s.rtcServerUrl||o,appId:c,token:l,roomName:u,userId:h,feedId:p,chargeId:v},s.rtcServer&&s.rtcServer.openRtc(s.rtcConnectParams))}else s.onDigitalHumanCallback&&s.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:m.CONNECT_ERROR,msg:{code:t,errMsg:n}}})})),r(this,"createServer",(function(e){var t,r=n(n(n({token:s.token,appKey:s.appKey,appId:s.appId},e?{sessionId:e}:{}),l(s.connectParams,h)),{},{parameters:c(s.connectParams,h),onConnect:s.connectListener,onDigitalHumanCallback:s.onDigitalHumanCallbackPlus});null!==(t=s.dhServer)&&void 0!==t&&t.preConnectSuccess?(s.dhServer.connectParams=r,s.dhServer&&s.dhServer.sendPreConnect(r)):s.dhServer&&s.dhServer.createSocket(r)})),r(this,"checkHumanInstansce",(function(){return s.dhServer?!(s.isPreOpenSession&&!s.dhServer.preConnectSuccess)||(s.onDigitalHumanCallback&&s.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:m.CONNECT_ERROR,msg:{code:4001,errMsg:"webSocket连接中"}}}),!1):(s.onDigitalHumanCallback&&s.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:m.CONNECT_ERROR,msg:{code:4002,errMsg:"请先初始化数字人实例"}}}),!1)})),r(this,"sendMessage",(function(e,t){return s.dhServer&&s.dhServer.sendMessage(e,t)})),r(this,"interrupt",a(o().mark((function e(){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){s.dhServer&&s.dhServer.sendMessage({requestId:u(),action:"TEXT_RENDER",body:"<interrupt></interrupt>",clientTs:(new Date).getTime()},(function(){return e()}))})));case 1:case"end":return e.stop()}}),e)})))),r(this,"textRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;s.checkHumanInstansce()&&s.dhServer&&s.dhServer.sendMessage({requestId:t||u(),action:"TEXT_RENDER",body:r,clientTs:(new Date).getTime()},n)})),r(this,"textStreamRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg,a=i.parse(r).first;s.checkHumanInstansce()&&s.dhServer&&s.dhServer.sendMessage({requestId:t||u(),action:"TEXT_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},a?n:null)})),r(this,"audioRender",(function(e){var t=e.body,r=e.onCallbackMsg;s.checkHumanInstansce()&&s.dhServer&&s.dhServer.sendMessage({requestId:u(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},r)})),r(this,"audioStreamRender",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;s.checkHumanInstansce()&&s.dhServer&&s.dhServer.sendMessage({requestId:t||u(),action:"AUDIO_STREAM_RENDER",body:r,clientTs:(new Date).getTime()},n)})),r(this,"textQuery",(function(e){var t=e.requestId,r=e.body,n=e.onCallbackMsg;s.dhServer&&s.dhServer.sendMessage({requestId:t||u(),action:"TEXT_QUERY",body:r,clientTs:(new Date).getTime()},n)})),r(this,"destroy",a(o().mark((function e(){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,s.dhServer&&s.dhServer.closeSocket();case 2:s.rtcServer&&s.rtcServer.closeRtc(),b(),s.dhServer=null,s.rtcServer=null;case 6:case"end":return e.stop()}}),e)})))),r(this,"pauseHuman",(function(){return R(!1)})),r(this,"playHuman",(function(){return R(!0)})),r(this,"muteHuman",(function(){return I(!0)})),r(this,"unMuteHuman",(function(){var e=I(!1);try{return s.isHuawei?(e.pause(),e.play()):e.paused&&e.play()}catch(e){console.info(e)}}));var v=e.isPreOpenSession,S=void 0!==v&&v,g=e.wsUrl,y=e.renderParams,D=e.onDigitalHumanCallback;this.isPreOpenSession=S,this.dhServer=new p(g||"wss://open.xiling.baidu.com/cloud/digital-human-demonstration"),this.onDigitalHumanCallback=function(e){e.status!==d.DH_LIB_FULL_STATUS?D&&D(e):(null==y?void 0:y.fullStatus)&&D&&D(e)},S?this.dhServer.createSocket({onDigitalHumanCallback:this.onDigitalHumanCallbackPlus},S):this.init(e)}return e(E,[{key:"init",value:function(e){var t=this,r=e.wrapperId,a=e.token,o=e.appKey,i=e.appId,c=e.connectParams,l=e.renderParams,u=void 0===l?{}:l,h=e.rtcConnectParams,p=e.brtcParams,f=e.rtcServerUrl;if(this.token=a,this.appKey=o,this.appId=i,this.rtcServerUrl=f,this.connectParams=n({autoChromaKey:(null==u?void 0:u.autoChromaKey)||!1},c),!i&&!o&&!a)throw new Error("appId and appKey or token is required");var R=u.closeLog,I=(S({autoChromaKey:!!u.autoChromaKey||!s(u.chromaEffects)})||{}).playerWrapper,b=document.getElementById(r||"");b||console.error("dom with wrapperId is not find"),I&&b&&b.appendChild(I),g();var k=n({remotevideoviewid:r,showvideobps:!1,usingvideo:!1,usingaudio:!(null==c||!c.pullAudioFromRtc),aspublisher:!(null==c||!c.pullAudioFromRtc),autopublish:!(null==c||!c.pullAudioFromRtc),usingdatachannel:!0,autoplaymuted:!1},p);this.rtcServer=new v({closeLog:R,videoWrapperId:C,rtcConfig:k,bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback,onLocalStream:this.onLocalStream}}),this.cutoutInstance=new y({sourceId:C,effects:null==u?void 0:u.chromaEffects}),s(h)||(this.rtcConnectParams=h,this.rtcServer.openRtc(h)),null!=c&&c.pullAudioFromRtc?this.recordController=null:this.recordController=new D({pickAudioMode:null==c?void 0:c.pickAudioMode,onAudioData:function(e){1===t.wsReadyState&&t.sendMessage(e,null)},onError:function(e){t.onDigitalHumanCallback&&t.onDigitalHumanCallback({status:d.DH_LIB_ERROR,content:{type:m.CONNECT_ERROR,msg:{code:-1,errMsg:e.message}}})}})}},{key:"startRecord",value:function(){var e;null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc?this.rtcServer&&this.rtcServer.muteMicphone(!1):this.recordController&&this.recordController.start()}},{key:"stopRecord",value:function(){var e;if(null!==(e=this.connectParams)&&void 0!==e&&e.pullAudioFromRtc)return this.rtcServer&&this.rtcServer.muteMicphone(!0),void this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:u(),clientTs:Date.now(),body:""},null);this.recordController&&this.recordController.stop(),this.sendMessage({action:"AUDIO_QUERY_INTERRUPT",requestId:u(),clientTs:Date.now(),body:""},null)}}]),E}();export{E as default};
package/es/Cutout.d.ts DELETED
@@ -1,36 +0,0 @@
1
- /**
2
- * @file lib/Cutout
3
- * @description 视频抠绿相关
4
- * @author zhangyue49
5
- */
6
- import { ChromaEffectOptions } from '@bddh/starling-cutout/es/interface';
7
- import Seriously from '@bddh/starling-cutout/es/Seriously';
8
- interface CutoutType {
9
- effects?: {
10
- version: number;
11
- chromaKey: Partial<ChromaEffectOptions>;
12
- };
13
- sourceId: string;
14
- }
15
- export declare const DEFAULT_EFFECTS: {
16
- version: number;
17
- chromaKey: {
18
- screen: number[];
19
- similarity: number;
20
- edgeShrink: number;
21
- smoothness: number;
22
- spill: number;
23
- opacity: number;
24
- contrast: number;
25
- brightness: number;
26
- gamma: number;
27
- };
28
- };
29
- declare class Cutout {
30
- cutoutInstance: Seriously;
31
- constructor(props: CutoutType);
32
- setOptions(options: Partial<ChromaEffectOptions>): void;
33
- destroy(): void;
34
- updateSource(video: HTMLVideoElement | string): Promise<void>;
35
- }
36
- export default Cutout;
package/es/Cutout.js DELETED
@@ -1 +0,0 @@
1
- import{createClass as t,classCallCheck as e,defineProperty as s}from"./_virtual/_rollupPluginBabelHelpers.js";import n from"@bddh/starling-cutout/es/Seriously";var o={version:2,chromaKey:{screen:[53,186,123],similarity:90,edgeShrink:3,smoothness:80,spill:100,opacity:1,contrast:0,brightness:0,gamma:0}},r=function(){function r(t){e(this,r),s(this,"cutoutInstance",void 0);var u=t.effects,a=t.sourceId;this.cutoutInstance=new n("starling-cutout-canvas",a||"starling-cutout-video",u&&u.chromaKey||o.chromaKey,u&&u.version||o.version)}return t(r,[{key:"setOptions",value:function(t){t&&this.cutoutInstance&&this.cutoutInstance.setOptions(t)}},{key:"destroy",value:function(){return this.cutoutInstance.destroy()}},{key:"updateSource",value:function(t){return this.cutoutInstance.updateSource(t)}}]),r}();export{o as DEFAULT_EFFECTS,r as default};
@@ -1,23 +0,0 @@
1
- /**
2
- * @file DomControl
3
- * @description 一些js创建dom的方法
4
- */
5
- interface CreateVideoDomOptions {
6
- id?: string;
7
- autoplay?: boolean;
8
- autoChromaKey?: boolean;
9
- }
10
- interface CreateVideoDomResult {
11
- playerWrapper: HTMLDivElement;
12
- video: HTMLVideoElement;
13
- }
14
- export declare const DEFAULT_CANVAS_ID = "starling-cutout-canvas";
15
- export declare const HUMAN_WRAPPER_ID = "cloud-brtc-player-wrapper";
16
- export declare const RTC_VIDEO_ID = "remotevideo500";
17
- export declare function createHumanDom(options: CreateVideoDomOptions): CreateVideoDomResult | null;
18
- export declare function removeHumanDom(): void;
19
- export declare function muteHumanVideo(muted: boolean): HTMLVideoElement;
20
- export declare function playHumanVideo(play: boolean): void | Promise<void>;
21
- export declare function checkIsHuawei(): boolean;
22
- export declare function appendRtcDomStyle(): void;
23
- export {};
package/es/DomControl.js DELETED
@@ -1 +0,0 @@
1
- var t="starling-cutout-canvas",e="cloud-brtc-player-wrapper",n="remotevideo500";function i(i){var a=i.autoChromaKey,o=void 0!==a&&a,r=i.autoplay,d=void 0===r||r;if(document.getElementById(n))return console.error('DOM with id "'.concat(n,'" already exists.')),null;var c=document.createElement("div");c.className=e,c.id=e,c.style.position="relative";var u=document.createElement("video");u.id=n,u.width=0,u.height=0,u.setAttribute("width","100%"),u.setAttribute("height","100%"),u.setAttribute("data-playing","true"),u.setAttribute("playsinline","");var l=document.createElement("canvas");return l.id=t,Object.assign(l.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:o?"block":"none"}),d&&u.setAttribute("autoplay",""),o&&(u.style.visibility="hidden"),c.appendChild(u),c.appendChild(l),{playerWrapper:c,video:u}}function a(){var t=document.getElementById(e);t&&t.parentNode&&t.parentNode.removeChild(t)}function o(t){var e=document.getElementById(n);return e&&(e.muted=t),e}function r(t){var e=document.getElementById(n);try{if(e)return t?e.play():e.pause()}catch(t){console.info(t)}}function d(){var t=navigator.userAgent||navigator.vendor;return/huawei/i.test(t)||/honor/i.test(t)}function c(){var t=document.createElement("style");t.appendChild(document.createTextNode('\n [id^="videoremote1-"] {\n display: none !important;\n }\n \n video#remotevideo500 {\n width: auto !important;\n height: auto !important;\n max-width: 100% !important;\n max-height: 100% !important;\n width: 100% !important;\n height: 100% !important;\n object-fit: cover;\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,o as muteHumanVideo,r as playHumanVideo,a as removeHumanDom};
@@ -1,20 +0,0 @@
1
- export type PickAudioMode = 'pressButton' | 'free';
2
- interface RecordControllerOptions {
3
- pickAudioMode?: PickAudioMode;
4
- onAudioData: (pcmData: ArrayBuffer) => void;
5
- onError?: (err: Error) => void;
6
- pullAudioFromRtc?: boolean;
7
- brtcClient?: any;
8
- }
9
- declare class RecordController {
10
- private readonly onAudioData;
11
- private readonly onError?;
12
- private audioContext;
13
- private processor;
14
- private mediaStream;
15
- private recording;
16
- constructor(options: RecordControllerOptions);
17
- start(): Promise<void>;
18
- stop(): void;
19
- }
20
- export default RecordController;
@@ -1 +0,0 @@
1
- import{createClass as t,asyncToGenerator as e,classCallCheck as r,defineProperty as o,regeneratorRuntime as a}from"./_virtual/_rollupPluginBabelHelpers.js";function n(t,e,r,o){try{for(var a=(o=o||{})&&"number"==typeof o.index?o.index:0,n=o&&"number"==typeof o.offset?o.offset:0,i=0,s=a;s<t.length;s++)i+=t[s].length;i=Math.max(0,i-Math.floor(n));var c=e/r;c>1?i=Math.floor(i/c):(c=1,r=e);for(var u=new Int16Array(i),h=0,d=t.length;a<d;a++){for(var l=t[a],f=n,p=l.length;f<p;){var m=Math.floor(f),v=Math.ceil(f),x=f-m;u[h]=l[m]+(l[v]-l[m])*x,h++,f+=c}n=f-p}return{index:a,offset:n,sampleRate:r,data:u}}catch(t){console.log("转音错误了",t)}}function i(t){for(var e=t,r=new Int16Array(t.length),o=0;o<e.length;o++){var a=Math.max(-1,Math.min(1,e[o]));r[o]=a<0?32768*a:32767*a}return r}var s=function(s){function c(t){r(this,c),o(this,"onAudioData",void 0),o(this,"onError",void 0),o(this,"audioContext",null),o(this,"processor",null),o(this,"mediaStream",null),o(this,"recording",!1),this.onAudioData=t.onAudioData,this.onError=t.onError}return t(c,[{key:"start",value:function(){return(s=s||e(a().mark((function t(){var e,r=this;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.recording){t.next=2;break}return t.abrupt("return");case 2:return t.prev=2,this.audioContext=new(window.AudioContext||window.webkitAudioContext)({sampleRate:16e3}),t.next=6,navigator.mediaDevices.getUserMedia({audio:!0,video:!1});case 6:this.mediaStream=t.sent,e=this.audioContext.createMediaStreamSource(this.mediaStream),this.processor=this.audioContext.createScriptProcessor(1024,1,1),e.connect(this.processor),this.processor.connect(this.audioContext.destination),this.processor.onaudioprocess=function(t){if(r.recording){var e=n([i(t.inputBuffer.getChannelData(0))],r.audioContext.sampleRate,16e3,null);e&&e.data&&r.onAudioData(e.data.buffer)}},this.recording=!0,t.next=18;break;case 15:t.prev=15,t.t0=t.catch(2),this.onError&&this.onError(t.t0);case 18:case"end":return t.stop()}}),t,this,[[2,15]])})))).apply(this,arguments)}},{key:"stop",value:function(){this.recording=!1,this.processor&&(this.processor.disconnect(),this.processor.onaudioprocess=null),this.audioContext&&this.audioContext.close(),this.mediaStream&&this.mediaStream.getTracks().forEach((function(t){t.stop()}))}}]),c}();export{s as default};
package/es/Server.d.ts DELETED
@@ -1,60 +0,0 @@
1
- /**
2
- * @file lib/Server
3
- * @description ws服务逻辑处理
4
- * @author zhangyue49
5
- */
6
- import { type WebSocketClient } from '@bddh/starling-web-socket/es/interface';
7
- import { CallbackMsgType, ConnectDataType, ConnectParamsType } from './interface';
8
- export interface SteamDataType {
9
- first: boolean;
10
- last: boolean;
11
- audio?: string;
12
- body?: string;
13
- }
14
- export interface DHServerInterface {
15
- action: string;
16
- requestId: string;
17
- clientTs: number;
18
- body: string | ArrayBuffer;
19
- }
20
- export interface DHErrServerInterface {
21
- action: string;
22
- requestId: string;
23
- code?: number;
24
- message?: string;
25
- error: Error;
26
- }
27
- type ConnectListener = (data: ConnectDataType, off?: () => void) => void;
28
- export interface createSocketParamsType {
29
- token?: string;
30
- appKey?: string;
31
- appId?: string;
32
- sessionId?: string;
33
- parameters?: ConnectParamsType;
34
- reConnect?: boolean;
35
- onConnect?: ConnectListener;
36
- onDigitalHumanCallback?: (data: CallbackMsgType) => void;
37
- }
38
- export interface RenderCallbackRes {
39
- requestId: string;
40
- action: string;
41
- code: number;
42
- body: string | null;
43
- message: string;
44
- }
45
- export type RenderCallback = (res: RenderCallbackRes) => void;
46
- declare class Server {
47
- dhServerSocket: WebSocketClient | null;
48
- preConnectSuccess: boolean;
49
- connectParams: createSocketParamsType | null;
50
- private socketClosingPromise;
51
- private readonly url;
52
- private firstConnect;
53
- constructor(url: string);
54
- sendPreConnect: (props: createSocketParamsType, resolve?: ((value: any) => void) | undefined) => void;
55
- createSocket: (props: createSocketParamsType, isPreOpenSession?: boolean) => Promise<WebSocketClient | null>;
56
- closeSocket: () => Promise<void>;
57
- handleConnect: () => Promise<void>;
58
- sendMessage(message: DHServerInterface | ArrayBuffer, listener: RenderCallback | null): Promise<void>;
59
- }
60
- export default Server;
package/es/Server.js DELETED
@@ -1 +0,0 @@
1
- import{createClass as e,asyncToGenerator as t,classCallCheck as n,defineProperty as r,regeneratorRuntime as o,objectSpread2 as s,typeof as c}from"./_virtual/_rollupPluginBabelHelpers.js";import{v4 as a}from"uuid";import{createWebSocket as i}from"@bddh/starling-web-socket/es/create-web-socket";import u from"lodash/pick";import l from"lodash/omit";import d from"lodash/get";import{errorTypeEnum as p,CONNECT_MAIN_KEY as S,statusEnum as f,WS_STATUS_MAP as h}from"./interface.js";var k=function(k){function m(e){var c,k=this;n(this,m),r(this,"dhServerSocket",null),r(this,"preConnectSuccess",!1),r(this,"connectParams",null),r(this,"socketClosingPromise",null),r(this,"url",void 0),r(this,"firstConnect",!0),r(this,"sendPreConnect",(function(e,t){var n,r=e.token,o=e.sessionId,s=e.onConnect;null===(n=k.dhServerSocket)||void 0===n||n.request({action:"RE_CONNECT",requestId:a(),body:JSON.stringify({token:r,sessionId:o})}).on((function(e,n){null==s||s(e),0!==e.code&&(n(),k.handleConnect()),null==t||t(k.dhServerSocket)})),k.firstConnect=!1})),r(this,"createSocket",(function(e,n){return(c=c||t(o().mark((function e(t,n){var r,s;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(k.connectParams=t,r=t.sessionId,s=t.onDigitalHumanCallback,!k.socketClosingPromise){e.next=5;break}return e.next=5,k.socketClosingPromise;case 5:if(!k.dhServerSocket){e.next=8;break}return e.next=8,k.closeSocket();case 8:return e.abrupt("return",new Promise((function(e,o){var c={keepAlive:"heartbeat",reopen:d(k.connectParams,"reConnect",!0),combine:function(e,t){return e&&t&&e.requestId===t.requestId},onOpen:function(){k.dhServerSocket=a,r&&k.firstConnect?k.sendPreConnect(t,e):n&&k.firstConnect||k.handleConnect()},onClose:function(){k.dhServerSocket=null,k.socketClosingPromise=null},onError:function(e){o(e)}},a=i(k.url,c);a.onReadyStateChange((function(e){0===e&&s&&s({status:f.DH_LIB_INIT}),1===e&&n&&(k.preConnectSuccess=!0),3===e&&(k.preConnectSuccess=!1),s&&s({status:f.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:h[e]}})})),a.onMessage((function(e){var t=e.action;if([p.TIMEOUT_EXIT,p.DISCONNECT_ALERT].includes(t)&&s&&s({status:f.DH_LIB_STATUS,content:{type:t}}),"DOWN_SUBTITLE"===t){var n=JSON.parse(e.body);["REPLY","QUERY"].includes(d(n,"type","").toUpperCase())&&s&&s({status:f.DH_LIB_STATUS,content:{type:t,body:e.body}})}})),n&&(k.dhServerSocket=a),a.open()})));case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)})),r(this,"closeSocket",t(o().mark((function e(){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(k.dhServerSocket){e.next=2;break}return e.abrupt("return");case 2:return k.socketClosingPromise=k.dhServerSocket.close(),e.next=5,k.socketClosingPromise;case 5:k.dhServerSocket=null;case 6:case"end":return e.stop()}}),e)})))),r(this,"handleConnect",t(o().mark((function e(){var t,n,r,c,i,d;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(k.connectParams){e.next=2;break}return e.abrupt("return");case 2:if(t=k.connectParams,n=t.appId,r=t.appKey,c=t.token,i=t.parameters,d=t.onConnect,n||r||c){e.next=5;break}return e.abrupt("return");case 5:k.dhServerSocket&&k.dhServerSocket.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:a(),body:JSON.stringify(s(s({token:c,appId:n,appKey:r},u(k.connectParams,S)),{},{parameters:s(s({},l(i,["parameters"])),i&&i.parameters?i.parameters:{})}))}).on((function(e,t){null==d||d(e),0!==e.code&&t()}));case 6:case"end":return e.stop()}}),e)})))),this.url=e}return e(m,[{key:"sendMessage",value:function(e,n){return(k=k||t(o().mark((function e(t,n){var r;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:try{this.dhServerSocket&&this.dhServerSocket&&this.dhServerSocket.request(t).on((function(e){n&&n(e)}))}catch(e){r="object"===c(t)&&"requestId"in t?t.requestId:a(),n&&n({code:-11,body:null,action:"RENDER_ERROR",requestId:r,message:JSON.stringify(e)})}case 1:case"end":return e.stop()}}),e,this)})))).apply(this,arguments)}}]),m}();export{k as default};
@@ -1 +0,0 @@
1
- function t(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function r(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?t(Object(n),!0).forEach((function(t){f(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))}))}return r}function e(){e=function(){return r};var t,r={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",f=a.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=r&&r.prototype instanceof m?r:m,a=Object.create(o.prototype),c=new N(n||[]);return i(a,"_invoke",{value:S(t,e,c)}),a}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=s;var p="suspendedStart",y="suspendedYield",v="executing",g="completed",d={};function m(){}function b(){}function w(){}var O={};l(O,c,(function(){return this}));var j=Object.getPrototypeOf,L=j&&j(j(T([])));L&&L!==n&&o.call(L,c)&&(O=L);var E=w.prototype=m.prototype=Object.create(O);function x(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function P(t,r){function e(n,i,a,c){var u=h(t[n],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==typeof l&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function S(r,e,n){var o=p;return function(i,a){if(o===v)throw new Error("Generator is already running");if(o===g){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=_(c,n);if(u){if(u===d)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=g,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var f=h(r,e,n);if("normal"===f.type){if(o=n.done?g:y,f.arg===d)continue;return{value:f.arg,done:n.done}}"throw"===f.type&&(o=g,n.method="throw",n.arg=f.arg)}}}function _(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,_(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var i=h(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,d;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,d):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function k(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function G(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function T(r){if(r||""===r){var e=r[c];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return b.prototype=w,i(E,"constructor",{value:w,configurable:!0}),i(w,"constructor",{value:b,configurable:!0}),b.displayName=l(w,f,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===b||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,l(t,f,"GeneratorFunction")),t.prototype=Object.create(E),t},r.awrap=function(t){return{__await:t}},x(P.prototype),l(P.prototype,u,(function(){return this})),r.AsyncIterator=P,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new P(s(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(E),l(E,f,"Generator"),l(E,c,(function(){return this})),l(E,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=T,N.prototype={constructor:N,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(G),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=o.call(a,"catchLoc"),f=o.call(a,"finallyLoc");if(u&&f){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!f)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),d},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),G(e),d}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;G(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:T(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),d}},r}function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function i(t){return function(){var r=this,e=arguments;return new Promise((function(n,i){var a=t.apply(r,e);function c(t){o(a,n,i,c,u,"next",t)}function u(t){o(a,n,i,c,u,"throw",t)}c(void 0)}))}}function a(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function c(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,s(n.key),n)}}function u(t,r,e){return r&&c(t.prototype,r),e&&c(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function f(t,r,e){return(r=s(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function l(t,r){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}function s(t){var r=l(t,"string");return"symbol"==typeof r?r:String(r)}export{i as asyncToGenerator,a as classCallCheck,u as createClass,f as defineProperty,r as objectSpread2,e as regeneratorRuntime,l as toPrimitive,s as toPropertyKey,n as typeof};
package/es/index.d.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * @file 云渲染SDK
3
- * @author zhangyue49
4
- */
5
- import HumanClient from './Client';
6
- export default HumanClient;
7
- export * from './interface';
package/es/index.js DELETED
@@ -1 +0,0 @@
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 DELETED
@@ -1,107 +0,0 @@
1
- import { RtcConnectionType } from './BrtcClient';
2
- export interface ConnectDataType {
3
- action: string;
4
- body: string;
5
- code: number;
6
- message: string;
7
- }
8
- export interface ConnectParamsType {
9
- figureId?: string | number;
10
- resolutionHeight: number;
11
- resolutionWidth: number;
12
- x264BitRate?: number;
13
- cameraId?: string | number;
14
- characterOffset?: string;
15
- pickAudioMode?: 'pressButton' | 'free';
16
- autoChromaKey?: boolean;
17
- usingVideo?: boolean;
18
- ttsPer?: string | number;
19
- ttsPitch?: number;
20
- ttsSpeed?: number;
21
- ttsVolume?: number;
22
- ttsLan?: string;
23
- pullAudioFromRtc?: boolean;
24
- inactiveDisconnectSec?: number;
25
- preAlertSec?: 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;
38
- parameters?: any;
39
- reConnect?: boolean;
40
- }
41
- export declare const CONNECT_MAIN_KEY: string[];
42
- export interface RenderParamsType {
43
- chromaEffects?: object;
44
- autoChromaKey?: boolean;
45
- closeLog?: boolean;
46
- fullStatus?: boolean;
47
- }
48
- export declare enum statusEnum {
49
- DH_LIB_INIT = "DH_LIB_INIT",
50
- DH_LIB_WS_SUCCESS = "DH_LIB_WS_SUCCESS",
51
- DH_LIB_OPEN = "DH_LIB_OPEN",
52
- DH_LIB_STATUS = "DH_LIB_STATUS",
53
- DH_LIB_CLOSE = "DH_LIB_CLOSE",
54
- DH_LIB_ERROR = "DH_LIB_ERROR",
55
- DH_LIB_WARNING = "DH_LIB_WARNING",
56
- DH_LIB_FULL_STATUS = "DH_LIB_FULL_STATUS"
57
- }
58
- export declare enum errorTypeEnum {
59
- CONNECT_ERROR = "CONNECT_ERROR",
60
- DISCONNECT_ALERT = "DISCONNECT_ALERT",
61
- TIMEOUT_EXIT = "TIMEOUT_EXIT",
62
- LOCAL_VIDEO_MUTED = "LOCAL_VIDEO_MUTED",
63
- LOCAL_VIDEO_ERROR = "LOCAL_VIDEO_ERROR",
64
- RTC_ERROR = "RTC_ERROR"
65
- }
66
- export interface ErrorType {
67
- type: errorTypeEnum;
68
- msg?: {
69
- code: string | number;
70
- errMsg: string;
71
- };
72
- }
73
- export interface RtcStateType {
74
- action: string;
75
- type: string;
76
- body: any;
77
- }
78
- export declare const WS_STATUS_MAP: {
79
- '-1': string;
80
- '0': string;
81
- '1': string;
82
- '2': string;
83
- '3': string;
84
- };
85
- export interface WsStateType {
86
- readyState: number;
87
- type: string;
88
- body: string;
89
- }
90
- export interface CallbackMsgType {
91
- status: statusEnum;
92
- content?: ErrorType | WsStateType | RtcStateType | ConnectDataType;
93
- }
94
- export interface DhRealtimeHumanType {
95
- token?: string;
96
- wsUrl?: string;
97
- rtcServerUrl?: string;
98
- appKey?: string;
99
- appId?: string;
100
- wrapperId?: string;
101
- connectParams?: ConnectParamsType;
102
- renderParams?: RenderParamsType;
103
- rtcConnectParams?: RtcConnectionType;
104
- brtcParams?: any;
105
- isPreOpenSession?: boolean;
106
- onDigitalHumanCallback: (data: CallbackMsgType) => void;
107
- }
package/es/interface.js DELETED
@@ -1 +0,0 @@
1
- var _,I,E=["projectId","characterConfigId","configVersion","selectors","figureName","reConnect"];!function(_){_.DH_LIB_INIT="DH_LIB_INIT",_.DH_LIB_WS_SUCCESS="DH_LIB_WS_SUCCESS",_.DH_LIB_OPEN="DH_LIB_OPEN",_.DH_LIB_STATUS="DH_LIB_STATUS",_.DH_LIB_CLOSE="DH_LIB_CLOSE",_.DH_LIB_ERROR="DH_LIB_ERROR",_.DH_LIB_WARNING="DH_LIB_WARNING",_.DH_LIB_FULL_STATUS="DH_LIB_FULL_STATUS"}(_||(_={})),function(_){_.CONNECT_ERROR="CONNECT_ERROR",_.DISCONNECT_ALERT="DISCONNECT_ALERT",_.TIMEOUT_EXIT="TIMEOUT_EXIT",_.LOCAL_VIDEO_MUTED="LOCAL_VIDEO_MUTED",_.LOCAL_VIDEO_ERROR="LOCAL_VIDEO_ERROR",_.RTC_ERROR="RTC_ERROR"}(I||(I={}));var L={"-1":"UNINSTANTIATED",0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"};export{E as CONNECT_MAIN_KEY,L as WS_STATUS_MAP,I as errorTypeEnum,_ as statusEnum};