yjz-web-sdk 1.0.11-beta.5 → 1.0.11-beta.7
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.
|
@@ -3202,6 +3202,8 @@ function adapterFactory({ window: window2 } = {}, options = {
|
|
|
3202
3202
|
return adapter;
|
|
3203
3203
|
}
|
|
3204
3204
|
adapterFactory({ window: typeof window === "undefined" ? void 0 : window });
|
|
3205
|
+
let checkingTimer = null;
|
|
3206
|
+
let disconnectedTimer = null;
|
|
3205
3207
|
const setRemoteDescriptionWithHandleOffer = (peerConnection, sdp2, sendAnswer, onError) => {
|
|
3206
3208
|
Logger.info("信息日志:", "设置远程offer Description=======>");
|
|
3207
3209
|
const description = new RTCSessionDescription({ type: "offer", sdp: sdp2 });
|
|
@@ -3255,8 +3257,45 @@ const configPeerConnection = (peerConnection, onICEMessage, onTrack, onConnectSt
|
|
|
3255
3257
|
return;
|
|
3256
3258
|
}
|
|
3257
3259
|
Logger.debug("信息日志:", `webrtc p2p连接状态===>`, state);
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
+
switch (state) {
|
|
3261
|
+
case "new":
|
|
3262
|
+
case "checking":
|
|
3263
|
+
if (!checkingTimer) {
|
|
3264
|
+
checkingTimer = setTimeout(() => {
|
|
3265
|
+
onError == null ? void 0 : onError(createWebRtcError(
|
|
3266
|
+
FailCode.ICE_STATE,
|
|
3267
|
+
"TURN服务器连接超时"
|
|
3268
|
+
));
|
|
3269
|
+
}, 6e3);
|
|
3270
|
+
}
|
|
3271
|
+
break;
|
|
3272
|
+
case "connected":
|
|
3273
|
+
case "completed":
|
|
3274
|
+
if (checkingTimer) {
|
|
3275
|
+
clearTimeout(checkingTimer);
|
|
3276
|
+
checkingTimer = null;
|
|
3277
|
+
}
|
|
3278
|
+
if (disconnectedTimer) {
|
|
3279
|
+
clearTimeout(disconnectedTimer);
|
|
3280
|
+
disconnectedTimer = null;
|
|
3281
|
+
}
|
|
3282
|
+
break;
|
|
3283
|
+
case "disconnected":
|
|
3284
|
+
if (!disconnectedTimer) {
|
|
3285
|
+
disconnectedTimer = setTimeout(() => {
|
|
3286
|
+
onError == null ? void 0 : onError(createWebRtcError(
|
|
3287
|
+
FailCode.ICE_STATE,
|
|
3288
|
+
"TURN disconnected时间过长"
|
|
3289
|
+
));
|
|
3290
|
+
}, 8e3);
|
|
3291
|
+
}
|
|
3292
|
+
break;
|
|
3293
|
+
case "failed":
|
|
3294
|
+
onError == null ? void 0 : onError(createWebRtcError(
|
|
3295
|
+
FailCode.ICE_STATE,
|
|
3296
|
+
"TURN ICE failed"
|
|
3297
|
+
));
|
|
3298
|
+
break;
|
|
3260
3299
|
}
|
|
3261
3300
|
onConnectState == null ? void 0 : onConnectState(state);
|
|
3262
3301
|
};
|
|
@@ -3434,7 +3473,6 @@ class ChannelData {
|
|
|
3434
3473
|
* @param data 剪贴板数据,可以是字符串或其他类型
|
|
3435
3474
|
*/
|
|
3436
3475
|
static clipboard(data) {
|
|
3437
|
-
console.log(`剪贴板数据,可以是字符串或其他类型 ${data}`);
|
|
3438
3476
|
return new ChannelData("ClipboardData", this.formatData(data), "");
|
|
3439
3477
|
}
|
|
3440
3478
|
/**
|
|
@@ -3917,9 +3955,11 @@ class WebRTCClient extends EventEmitter {
|
|
|
3917
3955
|
const data = JSON.parse(event.data);
|
|
3918
3956
|
if (data.type === ChannelDataType.ActionCommandEvent) {
|
|
3919
3957
|
const { action, value, cameraId } = JSON.parse(data.data);
|
|
3958
|
+
console.error("data===>", data.data);
|
|
3920
3959
|
if (action === "ACTION_CONTROL_VIDEO") {
|
|
3921
3960
|
if (value === "ENABLE") {
|
|
3922
3961
|
if (this.isPushingStream) {
|
|
3962
|
+
await this.stopPush();
|
|
3923
3963
|
await this.switchCamera(Number(cameraId) === 0);
|
|
3924
3964
|
} else {
|
|
3925
3965
|
await this.startPush(Number(cameraId) === 0);
|
|
@@ -4205,14 +4245,13 @@ class WebRTCConfig {
|
|
|
4205
4245
|
this.signAgain = options.signAgain || true;
|
|
4206
4246
|
}
|
|
4207
4247
|
}
|
|
4208
|
-
const testTurnServer = (turnConfig, timeoutMs =
|
|
4248
|
+
const testTurnServer = (turnConfig, timeoutMs = 1500) => {
|
|
4209
4249
|
return new Promise((resolve) => {
|
|
4210
4250
|
const start = performance.now();
|
|
4211
4251
|
let resolved = false;
|
|
4212
4252
|
const pc = new RTCPeerConnection({
|
|
4213
4253
|
iceServers: [turnConfig],
|
|
4214
4254
|
iceTransportPolicy: "relay"
|
|
4215
|
-
// 强制走 TURN
|
|
4216
4255
|
});
|
|
4217
4256
|
pc.createDataChannel("test");
|
|
4218
4257
|
pc.createOffer().then((offer) => pc.setLocalDescription(offer)).catch(() => {
|
|
@@ -4231,9 +4270,11 @@ const testTurnServer = (turnConfig, timeoutMs = 600) => {
|
|
|
4231
4270
|
resolve({ ...turnConfig, rtt });
|
|
4232
4271
|
}
|
|
4233
4272
|
if (event.candidate === null) {
|
|
4234
|
-
resolved
|
|
4235
|
-
|
|
4236
|
-
|
|
4273
|
+
if (!resolved) {
|
|
4274
|
+
resolved = true;
|
|
4275
|
+
pc.close();
|
|
4276
|
+
resolve({ ...turnConfig, rtt: Infinity });
|
|
4277
|
+
}
|
|
4237
4278
|
}
|
|
4238
4279
|
};
|
|
4239
4280
|
setTimeout(() => {
|
|
@@ -4245,43 +4286,56 @@ const testTurnServer = (turnConfig, timeoutMs = 600) => {
|
|
|
4245
4286
|
}, timeoutMs);
|
|
4246
4287
|
});
|
|
4247
4288
|
};
|
|
4248
|
-
const
|
|
4289
|
+
const limitConcurrency = async (tasks, concurrency) => {
|
|
4290
|
+
const results = [];
|
|
4291
|
+
const executing = [];
|
|
4292
|
+
for (const task of tasks) {
|
|
4293
|
+
const p = task().then((r) => results.push(r));
|
|
4294
|
+
executing.push(p);
|
|
4295
|
+
if (executing.length >= concurrency) {
|
|
4296
|
+
await Promise.race(executing);
|
|
4297
|
+
for (let i = executing.length - 1; i >= 0; i--) {
|
|
4298
|
+
if (executing[i].resolved) executing.splice(i, 1);
|
|
4299
|
+
}
|
|
4300
|
+
}
|
|
4301
|
+
}
|
|
4302
|
+
await Promise.all(executing);
|
|
4303
|
+
return results;
|
|
4304
|
+
};
|
|
4305
|
+
const testMultipleTurnServersFast = async (servers, timeoutMs = 600, concurrency = 3) => {
|
|
4249
4306
|
const turnServers = servers.map((url) => ({
|
|
4250
4307
|
urls: url,
|
|
4251
4308
|
username: "yangyj",
|
|
4252
4309
|
credential: "hb@2025@168"
|
|
4253
4310
|
}));
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
const best = available.sort((a, b) => a.rtt - b.rtt)[0];
|
|
4267
|
-
return {
|
|
4268
|
-
best: best ? stripTurnAuth(best) : void 0,
|
|
4269
|
-
all: results.map(stripTurnAuth)
|
|
4270
|
-
};
|
|
4271
|
-
};
|
|
4272
|
-
const stripTurnAuth = (result) => {
|
|
4311
|
+
let bestResult = void 0;
|
|
4312
|
+
const allResults = [];
|
|
4313
|
+
const tasks = turnServers.map((cfg) => async () => {
|
|
4314
|
+
const res = await testTurnServer(cfg, timeoutMs);
|
|
4315
|
+
allResults.push(res);
|
|
4316
|
+
if (!bestResult && res.rtt !== Infinity) {
|
|
4317
|
+
bestResult = res;
|
|
4318
|
+
}
|
|
4319
|
+
return res;
|
|
4320
|
+
});
|
|
4321
|
+
await limitConcurrency(tasks, concurrency);
|
|
4322
|
+
Logger.debug("调试日志:", `TURN 测试结果======>`, allResults);
|
|
4273
4323
|
return {
|
|
4274
|
-
|
|
4275
|
-
|
|
4324
|
+
best: bestResult ? stripTurnAuth(bestResult) : void 0,
|
|
4325
|
+
all: allResults.map(stripTurnAuth)
|
|
4276
4326
|
};
|
|
4277
4327
|
};
|
|
4328
|
+
const stripTurnAuth = (result) => ({
|
|
4329
|
+
urls: result.urls,
|
|
4330
|
+
rtt: result.rtt
|
|
4331
|
+
});
|
|
4278
4332
|
const areTurnListsEmpty = (options) => {
|
|
4279
4333
|
return (!options.hostTurn || options.hostTurn.length === 0) && (!options.spareTurn || options.spareTurn.length === 0);
|
|
4280
4334
|
};
|
|
4281
|
-
const
|
|
4335
|
+
const selectBestTurnServerFast = async (turnList) => {
|
|
4282
4336
|
var _a, _b;
|
|
4283
4337
|
try {
|
|
4284
|
-
const result = await
|
|
4338
|
+
const result = await testMultipleTurnServersFast(turnList);
|
|
4285
4339
|
return { url: (_a = result.best) == null ? void 0 : _a.urls, rtt: (_b = result.best) == null ? void 0 : _b.rtt };
|
|
4286
4340
|
} catch (e) {
|
|
4287
4341
|
return { error: e.message || "未知错误" };
|
|
@@ -4307,7 +4361,6 @@ class WebRTCSdk extends EventEmitter {
|
|
|
4307
4361
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
4308
4362
|
if (!this.config) return;
|
|
4309
4363
|
Logger.debug("调试信息:", `信令消息=========>`, message);
|
|
4310
|
-
console.log(`信令消息=========>`, message);
|
|
4311
4364
|
switch (message.type) {
|
|
4312
4365
|
case MessageType.Peers:
|
|
4313
4366
|
this.config.myId = message.myId;
|
|
@@ -4477,9 +4530,9 @@ class WebRTCSdk extends EventEmitter {
|
|
|
4477
4530
|
const tryTurnList = async (list, isHost) => {
|
|
4478
4531
|
if (list.length === 0) return false;
|
|
4479
4532
|
try {
|
|
4480
|
-
const result = await
|
|
4533
|
+
const result = await selectBestTurnServerFast(list);
|
|
4481
4534
|
if (result.url && typeof result.rtt === "number") {
|
|
4482
|
-
if (isHost && result.rtt >
|
|
4535
|
+
if (isHost && result.rtt > 250) {
|
|
4483
4536
|
return false;
|
|
4484
4537
|
}
|
|
4485
4538
|
this.options.turnServerUri = result.url;
|
|
@@ -4714,6 +4767,7 @@ class WebRTCSdk extends EventEmitter {
|
|
|
4714
4767
|
sendSignOut() {
|
|
4715
4768
|
var _a, _b;
|
|
4716
4769
|
if (!this.config) return;
|
|
4770
|
+
console.log("sendSignOut===>主动断开连接");
|
|
4717
4771
|
if (this.config.connectorType === ConnectorType.LanForwarding) {
|
|
4718
4772
|
const message = {
|
|
4719
4773
|
type: SendType.GroupSignOut,
|
|
@@ -5057,8 +5111,8 @@ export {
|
|
|
5057
5111
|
isFunctionKey as i,
|
|
5058
5112
|
ActionCommandEventValue as j,
|
|
5059
5113
|
TrackEventData as k,
|
|
5060
|
-
|
|
5061
|
-
|
|
5114
|
+
ConnectorType as l,
|
|
5115
|
+
selectBestTurnServerFast as m,
|
|
5062
5116
|
setLogLevel as s,
|
|
5063
5117
|
transformCoordinate as t,
|
|
5064
5118
|
valueToPercentage as v
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TurnSelectionResult, TurnServerConfig, TurnTestResult, TurnTestSummary } from '../data/TurnType.ts';
|
|
2
2
|
import type { WebRTCConfigOptions } from '../rtc/WebRTCConfig.ts';
|
|
3
3
|
export declare const testTurnServer: (turnConfig: TurnServerConfig, timeoutMs?: number) => Promise<TurnTestResult>;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const testMultipleTurnServersFast: (servers: string[], timeoutMs?: number, concurrency?: number) => Promise<TurnTestSummary>;
|
|
5
5
|
export declare const areTurnListsEmpty: (options: WebRTCConfigOptions) => boolean;
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const selectBestTurnServerFast: (turnList: string[]) => Promise<TurnSelectionResult>;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WebRTCSdk } from './core/WebRTCSdk';
|
|
2
2
|
import { getKeyEventData } from "./core/util/KeyCodeUtil";
|
|
3
|
-
import {
|
|
3
|
+
import { selectBestTurnServerFast } from './core/util/TurnTestUtil';
|
|
4
4
|
import { transformCoordinate, valueToPercentage } from "./core/util/ScreenControlUtil";
|
|
5
5
|
import { ActionType, ChannelDataType, ContainerDirection, InputData, KeyEventData, TouchData, WheelData, GestureData, type ActionCommand, ActionCommandType, ActionCommandEventType, ActionCommandEventValue, TrackEventData, ClarityData } from "./core/data/WebrtcDataType";
|
|
6
6
|
import { type TurnServerConfig, type TurnTestResult, type TurnTestSummary } from "./core/data/TurnType";
|
|
@@ -9,4 +9,4 @@ import { EmitType, FailCode, type CameraError, type WebRtcError } from "./core/d
|
|
|
9
9
|
import RemotePlayer from './components/RemotePlayer/index.vue';
|
|
10
10
|
import { ConnectorType } from './core/data/MessageType';
|
|
11
11
|
import { GroupCtrlSocketManager } from './core/groupctrl/GroupCtrlSocketManager';
|
|
12
|
-
export { WebRTCSdk, getKeyEventData, transformCoordinate, valueToPercentage, ActionType, ChannelDataType, InputData, KeyEventData, TouchData, ContainerDirection, EmitType, WheelData, GestureData, ClarityData, type ActionCommand, ActionCommandType, type WebRTCConfigOptions, ActionCommandEventType, ActionCommandEventValue, RemotePlayer, TrackEventData, type TurnServerConfig, type TurnTestResult, type TurnTestSummary,
|
|
12
|
+
export { WebRTCSdk, getKeyEventData, transformCoordinate, valueToPercentage, ActionType, ChannelDataType, InputData, KeyEventData, TouchData, ContainerDirection, EmitType, WheelData, GestureData, ClarityData, type ActionCommand, ActionCommandType, type WebRTCConfigOptions, ActionCommandEventType, ActionCommandEventValue, RemotePlayer, TrackEventData, type TurnServerConfig, type TurnTestResult, type TurnTestSummary, type CameraError, type WebRtcError, ConnectorType, GroupCtrlSocketManager, FailCode, selectBestTurnServerFast };
|
package/lib/uni-sdk.js
CHANGED
|
@@ -10,7 +10,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
10
10
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
11
11
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
12
12
|
var _screenStatus, _isComposing, _direction, _screenWidth, _screenHeight, _clarityLevel, _gestureMode;
|
|
13
|
-
import { W as WheelData, t as transformCoordinate, A as ActionType, v as valueToPercentage, T as TouchData, g as getKeyEventData, I as InputData, i as isFunctionKey, E as EventEmitter, C as ChannelDataType, a as WebRTCSdk, b as EmitType, F as FailCode, c as ContainerDirection, K as KeyEventData, j as ActionCommandEventValue, h as ActionCommandEventType, d as ClarityData, G as GestureData } from "./ScreenControlUtil-
|
|
13
|
+
import { W as WheelData, t as transformCoordinate, A as ActionType, v as valueToPercentage, T as TouchData, g as getKeyEventData, I as InputData, i as isFunctionKey, E as EventEmitter, C as ChannelDataType, a as WebRTCSdk, b as EmitType, F as FailCode, c as ContainerDirection, K as KeyEventData, j as ActionCommandEventValue, h as ActionCommandEventType, d as ClarityData, G as GestureData } from "./ScreenControlUtil-Bf1obwOj.js";
|
|
14
14
|
var DocumentEvent = /* @__PURE__ */ ((DocumentEvent2) => {
|
|
15
15
|
DocumentEvent2["KEY_DOWN"] = "keydown";
|
|
16
16
|
DocumentEvent2["POINTER_ENTER"] = "pointerenter";
|
package/lib/yjz-web-sdk.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
import { A as ActionType, C as ChannelDataType, W as WheelData, t as transformCoordinate, v as valueToPercentage, T as TouchData, I as InputData, i as isFunctionKey, g as getKeyEventData, E as EventEmitter, a as WebRTCSdk, b as EmitType, e as enableLog, s as setLogLevel, K as KeyEventData } from "./ScreenControlUtil-
|
|
6
|
-
import { h, j, f, d,
|
|
5
|
+
import { A as ActionType, C as ChannelDataType, W as WheelData, t as transformCoordinate, v as valueToPercentage, T as TouchData, I as InputData, i as isFunctionKey, g as getKeyEventData, E as EventEmitter, a as WebRTCSdk, b as EmitType, e as enableLog, s as setLogLevel, K as KeyEventData } from "./ScreenControlUtil-Bf1obwOj.js";
|
|
6
|
+
import { h, j, f, d, l, c, F, G, k, m } from "./ScreenControlUtil-Bf1obwOj.js";
|
|
7
7
|
import { computed, onMounted, onUnmounted, ref, onBeforeUnmount, defineComponent, toRefs, createElementBlock, openBlock, createElementVNode, normalizeStyle, unref, createCommentVNode, normalizeClass } from "vue";
|
|
8
8
|
function useCursorStyle(cursorType) {
|
|
9
9
|
return computed(() => {
|
|
@@ -701,7 +701,7 @@ export {
|
|
|
701
701
|
ActionType,
|
|
702
702
|
ChannelDataType,
|
|
703
703
|
d as ClarityData,
|
|
704
|
-
|
|
704
|
+
l as ConnectorType,
|
|
705
705
|
c as ContainerDirection,
|
|
706
706
|
EmitType,
|
|
707
707
|
F as FailCode,
|
|
@@ -715,7 +715,7 @@ export {
|
|
|
715
715
|
WebRTCSdk,
|
|
716
716
|
WheelData,
|
|
717
717
|
getKeyEventData,
|
|
718
|
-
|
|
718
|
+
m as selectBestTurnServerFast,
|
|
719
719
|
transformCoordinate,
|
|
720
720
|
valueToPercentage
|
|
721
721
|
};
|