yjz-web-sdk 1.0.4-beta.5 → 1.0.4-beta.6
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.
|
@@ -10,6 +10,16 @@ export declare class GroupControllerManager extends EventEmitter {
|
|
|
10
10
|
private loopManager;
|
|
11
11
|
constructor(interval?: number, visibility?: VisibilityManager);
|
|
12
12
|
startControl(configMap: Map<string, WebRTCConfigOptions>): void;
|
|
13
|
+
switchToMain(targetRoomId: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* 找到当前主控config, 设置为从控
|
|
16
|
+
*/
|
|
17
|
+
clearCurrentControl(): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* 找到目标config, 设置为主控
|
|
20
|
+
* @param roomId
|
|
21
|
+
*/
|
|
22
|
+
setAsControl(roomId: string): string | undefined;
|
|
13
23
|
stopControl(): void;
|
|
14
24
|
private addController;
|
|
15
25
|
getConfigs(): Map<string, WebRTCConfigOptions>;
|
package/lib/yjz-web-sdk.js
CHANGED
|
@@ -3711,8 +3711,8 @@ class WebRTCSdk extends EventEmitter {
|
|
|
3711
3711
|
}
|
|
3712
3712
|
/** 停止连接,并发送退出信令 */
|
|
3713
3713
|
stop() {
|
|
3714
|
-
this.webRTCClient.closeConnection();
|
|
3715
3714
|
this.sendSignOut();
|
|
3715
|
+
this.webRTCClient.closeConnection();
|
|
3716
3716
|
this.removeAllListeners();
|
|
3717
3717
|
}
|
|
3718
3718
|
/** 开始推流:触发媒体采集与轨道添加 */
|
|
@@ -4051,6 +4051,49 @@ class GroupControllerManager extends EventEmitter {
|
|
|
4051
4051
|
this.configs.forEach((cfg) => this.addController(cfg));
|
|
4052
4052
|
this.loopManager.start();
|
|
4053
4053
|
}
|
|
4054
|
+
switchToMain(targetRoomId) {
|
|
4055
|
+
const oldControlId = this.clearCurrentControl();
|
|
4056
|
+
const newControlId = this.setAsControl(targetRoomId);
|
|
4057
|
+
if (oldControlId === newControlId) {
|
|
4058
|
+
console.log("targetRoomId当前就是主控, 不需要切换");
|
|
4059
|
+
return;
|
|
4060
|
+
}
|
|
4061
|
+
if (oldControlId && newControlId) {
|
|
4062
|
+
this.refreshController(oldControlId);
|
|
4063
|
+
this.refreshController(newControlId);
|
|
4064
|
+
}
|
|
4065
|
+
}
|
|
4066
|
+
/**
|
|
4067
|
+
* 找到当前主控config, 设置为从控
|
|
4068
|
+
*/
|
|
4069
|
+
clearCurrentControl() {
|
|
4070
|
+
for (const [roomId, config] of this.configs.entries()) {
|
|
4071
|
+
if (config.isControl) {
|
|
4072
|
+
this.configs.set(roomId, {
|
|
4073
|
+
...config,
|
|
4074
|
+
isControl: false
|
|
4075
|
+
});
|
|
4076
|
+
return roomId;
|
|
4077
|
+
}
|
|
4078
|
+
}
|
|
4079
|
+
return void 0;
|
|
4080
|
+
}
|
|
4081
|
+
/**
|
|
4082
|
+
* 找到目标config, 设置为主控
|
|
4083
|
+
* @param roomId
|
|
4084
|
+
*/
|
|
4085
|
+
setAsControl(roomId) {
|
|
4086
|
+
for (const [id, config] of this.configs.entries()) {
|
|
4087
|
+
if (id === roomId) {
|
|
4088
|
+
this.configs.set(id, {
|
|
4089
|
+
...config,
|
|
4090
|
+
isControl: true
|
|
4091
|
+
});
|
|
4092
|
+
return id;
|
|
4093
|
+
}
|
|
4094
|
+
}
|
|
4095
|
+
return void 0;
|
|
4096
|
+
}
|
|
4054
4097
|
stopControl() {
|
|
4055
4098
|
this.controllers.forEach((c) => {
|
|
4056
4099
|
c.removeAllListeners();
|
|
@@ -4123,9 +4166,11 @@ class GroupControllerManager extends EventEmitter {
|
|
|
4123
4166
|
try {
|
|
4124
4167
|
const changes = this.visibility.getChanges();
|
|
4125
4168
|
changes.forEach(({ viewId, nowVisible, wasVisible }) => {
|
|
4169
|
+
var _a;
|
|
4126
4170
|
const sdk = this.controllers.get(viewId);
|
|
4127
4171
|
if (!sdk) return;
|
|
4128
|
-
|
|
4172
|
+
const isMain = (_a = this.configs.get(viewId)) == null ? void 0 : _a.isControl;
|
|
4173
|
+
if (nowVisible && !isMain) sdk.requestScreenshot(true);
|
|
4129
4174
|
else if (wasVisible && !nowVisible) sdk.requestScreenshot(false);
|
|
4130
4175
|
});
|
|
4131
4176
|
} catch (err) {
|
package/lib/yjz-web-sdk.umd.cjs
CHANGED
|
@@ -83,7 +83,7 @@ r(this,"sendAnswer",(e=>{if(e&&e.length>0){const t={type:p.Answer,identity:p.Ide
|
|
|
83
83
|
/** 发送 ICE 候选信息 */
|
|
84
84
|
r(this,"sendICEMessage",(e=>{if(e&&e.length>0){const t={type:p.IceCandidates,identity:p.Identity,roomId:this.config.roomId,senderId:this.config.myId,targetId:this.config.targetId,ice:e};this.signalingClient.sendMessage(JSON.stringify(t))}})),this.config=new Te(e),this.signalingClient=new C(this.config),this.webRTCClient=new Le(this.config),this.signalingClient.on(m.signalMessage,(e=>this.handleSignaling(e))),this.signalingClient.on(m.webrtcError,(e=>{this.emit(m.webrtcError,e)})),this.webRTCClient.on(m.sendOffer,(e=>this.sendOffer(e))),this.webRTCClient.on(m.sendAnswer,(e=>this.sendAnswer(e))),this.webRTCClient.on(m.sendICEMessage,(e=>this.sendICEMessage(e))),this.webRTCClient.on(m.streamTrack,(e=>this.emit(m.streamTrack,e))),this.webRTCClient.on(m.iceConnectionState,(e=>this.emit(m.iceConnectionState,e))),this.webRTCClient.on(m.cloudStatusChanged,(e=>this.emit(m.cloudStatusChanged,e))),this.webRTCClient.on(m.cloudClipData,(e=>this.emit(m.cloudClipData,e))),this.webRTCClient.on(m.webrtcError,(e=>{this.emit(m.webrtcError,e)})),this.webRTCClient.on(m.statisticInfo,(e=>{this.emit(m.statisticInfo,e)}))}
|
|
85
85
|
/** 开始连接 signal 服务 */startConnection(){this.signalingClient.start()}
|
|
86
|
-
/** 停止连接,并发送退出信令 */stop(){this.
|
|
86
|
+
/** 停止连接,并发送退出信令 */stop(){this.sendSignOut(),this.webRTCClient.closeConnection(),this.removeAllListeners()}
|
|
87
87
|
/** 开始推流:触发媒体采集与轨道添加 */async startPush(){}
|
|
88
88
|
/** 发送信道数据 */sendChannelData(e,t){this.webRTCClient.sendChannelData(e,t)}sendControlEvent(e){const t=new Me(e,0);this.webRTCClient.sendChannelData(Ee.ActionInput,t)}sendRequestScreenshot(e){this.signalingClient.sendRequestScreenshot(e)}sendPong(){const e={type:p.Pong},t=JSON.stringify(e);this.signalingClient.sendMessage(t)}sendSignOut(){const e={type:p.SignOut,identity:p.Identity,roomId:this.config.roomId,myId:this.config.myId};this.signalingClient.sendMessage(JSON.stringify(e))}}const je={
|
|
89
89
|
// 数字键
|
|
@@ -119,6 +119,13 @@ Insert:124,Delete:112,Home:122,End:123,PageUp:92,PageDown:93,ScrollLock:116,Paus
|
|
|
119
119
|
(...e)=>t.unref(A)&&t.unref(A)(...e)),onPointerup:n[6]||(n[6]=//@ts-ignore
|
|
120
120
|
(...e)=>t.unref(I)&&t.unref(I)(...e)),onPointerleave:n[7]||(n[7]=//@ts-ignore
|
|
121
121
|
(...e)=>t.unref(O)&&t.unref(O)(...e)),onWheel:n[8]||(n[8]=//@ts-ignore
|
|
122
|
-
(...e)=>t.unref(M)&&t.unref(M)(...e)),style:t.normalizeStyle({backgroundColor:`${t.unref(p)}`}),autoplay:"",playsinline:"",muted:"",disablePictureInPicture:!0},null,38)],36)],512))}}),[["__scopeId","data-v-50ed9974"]]);e.ActionCommandType=ke,e.ActionType=_e,e.ChannelDataType=Ee,e.ContainerDirection=De,e.EmitType=m,e.GestureData=class{constructor(e){r(this,"mode"),this.mode=e}},e.GroupControllerManager=class extends d{constructor(e=1e3,t=new Ke){super(),r(this,"configs",new Map),r(this,"controllers",new Map),r(this,"visibility"),r(this,"loopManager"),this.visibility=t,this.loopManager=new We(e,(()=>this.handleLoop()))}startControl(e){if(!e.size)throw new Error("配置为空");if(1!==Array.from(e.values()).filter((e=>e.isControl)).length)throw new Error("必须且仅有一个主控");this.configs=new Map(e),this.configs.forEach((e=>this.addController(e))),this.loopManager.start()}
|
|
122
|
+
(...e)=>t.unref(M)&&t.unref(M)(...e)),style:t.normalizeStyle({backgroundColor:`${t.unref(p)}`}),autoplay:"",playsinline:"",muted:"",disablePictureInPicture:!0},null,38)],36)],512))}}),[["__scopeId","data-v-50ed9974"]]);e.ActionCommandType=ke,e.ActionType=_e,e.ChannelDataType=Ee,e.ContainerDirection=De,e.EmitType=m,e.GestureData=class{constructor(e){r(this,"mode"),this.mode=e}},e.GroupControllerManager=class extends d{constructor(e=1e3,t=new Ke){super(),r(this,"configs",new Map),r(this,"controllers",new Map),r(this,"visibility"),r(this,"loopManager"),this.visibility=t,this.loopManager=new We(e,(()=>this.handleLoop()))}startControl(e){if(!e.size)throw new Error("配置为空");if(1!==Array.from(e.values()).filter((e=>e.isControl)).length)throw new Error("必须且仅有一个主控");this.configs=new Map(e),this.configs.forEach((e=>this.addController(e))),this.loopManager.start()}switchToMain(e){const t=this.clearCurrentControl(),n=this.setAsControl(e);t!==n&&t&&n&&(this.refreshController(t),this.refreshController(n))}
|
|
123
|
+
/**
|
|
124
|
+
* 找到当前主控config, 设置为从控
|
|
125
|
+
*/clearCurrentControl(){for(const[e,t]of this.configs.entries())if(t.isControl)return this.configs.set(e,{...t,isControl:!1}),e}
|
|
126
|
+
/**
|
|
127
|
+
* 找到目标config, 设置为主控
|
|
128
|
+
* @param roomId
|
|
129
|
+
*/setAsControl(e){for(const[t,n]of this.configs.entries())if(t===e)return this.configs.set(t,{...n,isControl:!0}),t}stopControl(){this.controllers.forEach((e=>{e.removeAllListeners(),e.stop()})),this.controllers.clear(),this.configs.clear(),this.visibility.clear(),this.loopManager.stop(),this.removeAllListeners()}addController(e){const t=new Je(e);t.on(m.streamTrack,(e=>{this.emit(m.streamTrack,e)})),t.on(m.iceConnectionState,((e,t)=>{this.emit(m.iceConnectionState,e,t)})),t.on(m.cloudStatusChanged,(e=>{this.emit(m.cloudStatusChanged,e)})),t.on(m.webrtcError,((e,t)=>{this.emit(m.webrtcError,e,t)})),t.on(m.screenshot,((e,t)=>{this.emit(m.screenshot,e,t)})),t.start(),this.controllers.set(e.roomId,t)}getConfigs(){return new Map(this.configs)}
|
|
123
130
|
// 🔥 新增:暴露拿单个 controller
|
|
124
|
-
getController(e){return this.controllers.get(e)}refreshController(e){const t=this.configs.get(e);if(!t)throw new Error(`未找到配置项: ${e}`);const n=this.controllers.get(e);n&&(n.removeAllListeners(),n.stop(),this.controllers.delete(e)),this.addController(t)}updateProperty(e,t,n){const r=this.configs.get(e);if(!r)throw new Error(`未找到 ${e}`);r[t]=n}setVisibility(e,t){this.visibility.set(e,t)}setViewIds(e,t){this.visibility.setViewIds(e,t)}sendData(e,t){this.controllers.forEach((n=>n.sendData(e,t)))}sendControlEvent(e){this.controllers.forEach((t=>t.sendControlData(e)))}handleLoop(){try{this.visibility.getChanges().forEach((({viewId:e,nowVisible:t,wasVisible:n})=>{const
|
|
131
|
+
getController(e){return this.controllers.get(e)}refreshController(e){const t=this.configs.get(e);if(!t)throw new Error(`未找到配置项: ${e}`);const n=this.controllers.get(e);n&&(n.removeAllListeners(),n.stop(),this.controllers.delete(e)),this.addController(t)}updateProperty(e,t,n){const r=this.configs.get(e);if(!r)throw new Error(`未找到 ${e}`);r[t]=n}setVisibility(e,t){this.visibility.set(e,t)}setViewIds(e,t){this.visibility.setViewIds(e,t)}sendData(e,t){this.controllers.forEach((n=>n.sendData(e,t)))}sendControlEvent(e){this.controllers.forEach((t=>t.sendControlData(e)))}handleLoop(){try{this.visibility.getChanges().forEach((({viewId:e,nowVisible:t,wasVisible:n})=>{var r;const i=this.controllers.get(e);if(!i)return;const o=null==(r=this.configs.get(e))?void 0:r.isControl;t&&!o?i.requestScreenshot(!0):n&&!t&&i.requestScreenshot(!1)}))}catch(e){}}},e.InputData=class{constructor(e){r(this,"text"),this.text=e}},e.KeyEventData=Me,e.RemotePlayer=Ge,e.TouchData=Ie,e.WebRTCSdk=Ne,e.WheelData=Oe,e.getKeyEventData=Ue,e.transformCoordinate=Fe,e.valueToPercentage=ze,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|