yjz-web-sdk 1.0.11-beta.6 → 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
|
/**
|
|
@@ -4207,14 +4245,13 @@ class WebRTCConfig {
|
|
|
4207
4245
|
this.signAgain = options.signAgain || true;
|
|
4208
4246
|
}
|
|
4209
4247
|
}
|
|
4210
|
-
const testTurnServer = (turnConfig, timeoutMs =
|
|
4248
|
+
const testTurnServer = (turnConfig, timeoutMs = 1500) => {
|
|
4211
4249
|
return new Promise((resolve) => {
|
|
4212
4250
|
const start = performance.now();
|
|
4213
4251
|
let resolved = false;
|
|
4214
4252
|
const pc = new RTCPeerConnection({
|
|
4215
4253
|
iceServers: [turnConfig],
|
|
4216
4254
|
iceTransportPolicy: "relay"
|
|
4217
|
-
// 强制走 TURN
|
|
4218
4255
|
});
|
|
4219
4256
|
pc.createDataChannel("test");
|
|
4220
4257
|
pc.createOffer().then((offer) => pc.setLocalDescription(offer)).catch(() => {
|
|
@@ -4233,9 +4270,11 @@ const testTurnServer = (turnConfig, timeoutMs = 600) => {
|
|
|
4233
4270
|
resolve({ ...turnConfig, rtt });
|
|
4234
4271
|
}
|
|
4235
4272
|
if (event.candidate === null) {
|
|
4236
|
-
resolved
|
|
4237
|
-
|
|
4238
|
-
|
|
4273
|
+
if (!resolved) {
|
|
4274
|
+
resolved = true;
|
|
4275
|
+
pc.close();
|
|
4276
|
+
resolve({ ...turnConfig, rtt: Infinity });
|
|
4277
|
+
}
|
|
4239
4278
|
}
|
|
4240
4279
|
};
|
|
4241
4280
|
setTimeout(() => {
|
|
@@ -4247,43 +4286,56 @@ const testTurnServer = (turnConfig, timeoutMs = 600) => {
|
|
|
4247
4286
|
}, timeoutMs);
|
|
4248
4287
|
});
|
|
4249
4288
|
};
|
|
4250
|
-
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) => {
|
|
4251
4306
|
const turnServers = servers.map((url) => ({
|
|
4252
4307
|
urls: url,
|
|
4253
4308
|
username: "yangyj",
|
|
4254
4309
|
credential: "hb@2025@168"
|
|
4255
4310
|
}));
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
const best = available.sort((a, b) => a.rtt - b.rtt)[0];
|
|
4269
|
-
return {
|
|
4270
|
-
best: best ? stripTurnAuth(best) : void 0,
|
|
4271
|
-
all: results.map(stripTurnAuth)
|
|
4272
|
-
};
|
|
4273
|
-
};
|
|
4274
|
-
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);
|
|
4275
4323
|
return {
|
|
4276
|
-
|
|
4277
|
-
|
|
4324
|
+
best: bestResult ? stripTurnAuth(bestResult) : void 0,
|
|
4325
|
+
all: allResults.map(stripTurnAuth)
|
|
4278
4326
|
};
|
|
4279
4327
|
};
|
|
4328
|
+
const stripTurnAuth = (result) => ({
|
|
4329
|
+
urls: result.urls,
|
|
4330
|
+
rtt: result.rtt
|
|
4331
|
+
});
|
|
4280
4332
|
const areTurnListsEmpty = (options) => {
|
|
4281
4333
|
return (!options.hostTurn || options.hostTurn.length === 0) && (!options.spareTurn || options.spareTurn.length === 0);
|
|
4282
4334
|
};
|
|
4283
|
-
const
|
|
4335
|
+
const selectBestTurnServerFast = async (turnList) => {
|
|
4284
4336
|
var _a, _b;
|
|
4285
4337
|
try {
|
|
4286
|
-
const result = await
|
|
4338
|
+
const result = await testMultipleTurnServersFast(turnList);
|
|
4287
4339
|
return { url: (_a = result.best) == null ? void 0 : _a.urls, rtt: (_b = result.best) == null ? void 0 : _b.rtt };
|
|
4288
4340
|
} catch (e) {
|
|
4289
4341
|
return { error: e.message || "未知错误" };
|
|
@@ -4309,7 +4361,6 @@ class WebRTCSdk extends EventEmitter {
|
|
|
4309
4361
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
4310
4362
|
if (!this.config) return;
|
|
4311
4363
|
Logger.debug("调试信息:", `信令消息=========>`, message);
|
|
4312
|
-
console.log(`信令消息=========>`, message);
|
|
4313
4364
|
switch (message.type) {
|
|
4314
4365
|
case MessageType.Peers:
|
|
4315
4366
|
this.config.myId = message.myId;
|
|
@@ -4479,9 +4530,9 @@ class WebRTCSdk extends EventEmitter {
|
|
|
4479
4530
|
const tryTurnList = async (list, isHost) => {
|
|
4480
4531
|
if (list.length === 0) return false;
|
|
4481
4532
|
try {
|
|
4482
|
-
const result = await
|
|
4533
|
+
const result = await selectBestTurnServerFast(list);
|
|
4483
4534
|
if (result.url && typeof result.rtt === "number") {
|
|
4484
|
-
if (isHost && result.rtt >
|
|
4535
|
+
if (isHost && result.rtt > 250) {
|
|
4485
4536
|
return false;
|
|
4486
4537
|
}
|
|
4487
4538
|
this.options.turnServerUri = result.url;
|
|
@@ -5060,8 +5111,8 @@ export {
|
|
|
5060
5111
|
isFunctionKey as i,
|
|
5061
5112
|
ActionCommandEventValue as j,
|
|
5062
5113
|
TrackEventData as k,
|
|
5063
|
-
|
|
5064
|
-
|
|
5114
|
+
ConnectorType as l,
|
|
5115
|
+
selectBestTurnServerFast as m,
|
|
5065
5116
|
setLogLevel as s,
|
|
5066
5117
|
transformCoordinate as t,
|
|
5067
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
|
};
|