@whereby.com/media 7.0.1 → 8.0.1
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/dist/index.cjs +200 -216
- package/dist/index.d.cts +5 -14
- package/dist/index.d.mts +5 -14
- package/dist/index.d.ts +5 -14
- package/dist/index.mjs +200 -216
- package/dist/legacy-esm.js +200 -216
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2217,8 +2217,7 @@ var _a$4;
|
|
|
2217
2217
|
const adapter$4 = (_a$4 = adapterRaw.default) !== null && _a$4 !== void 0 ? _a$4 : adapterRaw;
|
|
2218
2218
|
const logger$7 = new Logger();
|
|
2219
2219
|
class Session {
|
|
2220
|
-
constructor({
|
|
2221
|
-
this.peerConnectionId = peerConnectionId;
|
|
2220
|
+
constructor({ clientId, bandwidth, peerConnectionConfig, deprioritizeH264Encoding, incrementAnalyticMetric, }) {
|
|
2222
2221
|
this.relayCandidateSeen = false;
|
|
2223
2222
|
this.serverReflexiveCandidateSeen = false;
|
|
2224
2223
|
this.publicHostCandidateSeen = false;
|
|
@@ -2534,11 +2533,78 @@ var rtcManagerEvents = {
|
|
|
2534
2533
|
|
|
2535
2534
|
var _a$2, _b$1;
|
|
2536
2535
|
const adapter$2 = (_a$2 = adapterRaw.default) !== null && _a$2 !== void 0 ? _a$2 : adapterRaw;
|
|
2536
|
+
const isSafari = ((_b$1 = adapter$2.browserDetails) === null || _b$1 === void 0 ? void 0 : _b$1.browser) === "safari";
|
|
2537
|
+
const parseResolution = (res) => res.split(/[^\d]/g).map((n) => parseInt(n, 10));
|
|
2538
|
+
function getMediaConstraints({ disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }) {
|
|
2539
|
+
var _a, _b;
|
|
2540
|
+
let HIGH_HEIGHT = 480;
|
|
2541
|
+
let LOW_HEIGHT = 240;
|
|
2542
|
+
if (hd) {
|
|
2543
|
+
HIGH_HEIGHT = lax || isSafari ? 720 : { min: 360, ideal: 720 };
|
|
2544
|
+
}
|
|
2545
|
+
if (simulcast) {
|
|
2546
|
+
if (hd === false) {
|
|
2547
|
+
HIGH_HEIGHT = 360;
|
|
2548
|
+
LOW_HEIGHT = 270;
|
|
2549
|
+
}
|
|
2550
|
+
else {
|
|
2551
|
+
LOW_HEIGHT = 360;
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
const constraints = {
|
|
2555
|
+
audio: Object.assign({}, (preferredDeviceIds.audioId && { deviceId: preferredDeviceIds.audioId })),
|
|
2556
|
+
video: Object.assign(Object.assign({}, (preferredDeviceIds.videoId ? { deviceId: preferredDeviceIds.videoId } : { facingMode: "user" })), { height: lowDataMode ? LOW_HEIGHT : HIGH_HEIGHT, frameRate: lowDataMode && !simulcast ? 15 : 24 }),
|
|
2557
|
+
};
|
|
2558
|
+
if (lax) {
|
|
2559
|
+
if (!((_a = constraints.audio) === null || _a === void 0 ? void 0 : _a.deviceId))
|
|
2560
|
+
constraints.audio = true;
|
|
2561
|
+
(_b = constraints.video) === null || _b === void 0 ? true : delete _b.facingMode;
|
|
2562
|
+
return constraints;
|
|
2563
|
+
}
|
|
2564
|
+
if (resolution) {
|
|
2565
|
+
const [w, h, fps] = parseResolution(resolution);
|
|
2566
|
+
if (w)
|
|
2567
|
+
constraints.video.width = { exact: w };
|
|
2568
|
+
if (h)
|
|
2569
|
+
constraints.video.height = { exact: h };
|
|
2570
|
+
if (fps)
|
|
2571
|
+
constraints.video.frameRate = { exact: fps };
|
|
2572
|
+
delete constraints.video.facingMode;
|
|
2573
|
+
}
|
|
2574
|
+
else {
|
|
2575
|
+
constraints.video.aspectRatio = widescreen ? 16 / 9 : 4 / 3;
|
|
2576
|
+
}
|
|
2577
|
+
if (disableAGC)
|
|
2578
|
+
constraints.audio.autoGainControl = false;
|
|
2579
|
+
if (disableAEC)
|
|
2580
|
+
constraints.audio.echoCancellation = false;
|
|
2581
|
+
return constraints;
|
|
2582
|
+
}
|
|
2583
|
+
function getConstraints({ devices, videoId, audioId, options, type = "ideal" }) {
|
|
2584
|
+
const audioDevices = devices.filter((d) => d.kind === "audioinput");
|
|
2585
|
+
const videoDevices = devices.filter((d) => d.kind === "videoinput");
|
|
2586
|
+
const useDefaultAudio = !audioId || !audioDevices.some((d) => d.deviceId === audioId);
|
|
2587
|
+
const useDefaultVideo = !videoId || !videoDevices.some((d) => d.deviceId === videoId);
|
|
2588
|
+
const constraints = getMediaConstraints(Object.assign({ preferredDeviceIds: {
|
|
2589
|
+
audioId: useDefaultAudio ? null : { [type]: audioId },
|
|
2590
|
+
videoId: useDefaultVideo ? null : { [type]: videoId },
|
|
2591
|
+
} }, options));
|
|
2592
|
+
if (audioId === false || !audioDevices.length) {
|
|
2593
|
+
delete constraints.audio;
|
|
2594
|
+
}
|
|
2595
|
+
if (videoId === false || !videoDevices.length) {
|
|
2596
|
+
delete constraints.video;
|
|
2597
|
+
}
|
|
2598
|
+
return constraints;
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
var _a$1, _b;
|
|
2602
|
+
const adapter$1 = (_a$1 = adapterRaw.default) !== null && _a$1 !== void 0 ? _a$1 : adapterRaw;
|
|
2537
2603
|
const logger$6 = new Logger();
|
|
2538
2604
|
const ICE_PUBLIC_IP_GATHERING_TIMEOUT = 3 * 1000;
|
|
2539
2605
|
const ICE_RESTART_DELAY = 2 * 1000;
|
|
2540
|
-
const browserName$1 = (_b
|
|
2541
|
-
const browserVersion = adapter$
|
|
2606
|
+
const browserName$1 = (_b = adapter$1.browserDetails) === null || _b === void 0 ? void 0 : _b.browser;
|
|
2607
|
+
const browserVersion = adapter$1.browserDetails.version;
|
|
2542
2608
|
let unloading$1 = false;
|
|
2543
2609
|
if (browserName$1 === "chrome") {
|
|
2544
2610
|
window.document.addEventListener("beforeunload", () => {
|
|
@@ -2688,8 +2754,8 @@ class P2pRtcManager {
|
|
|
2688
2754
|
}
|
|
2689
2755
|
disconnectAll() {
|
|
2690
2756
|
logger$6.info("disconnectAll()");
|
|
2691
|
-
Object.keys(this.peerConnections).forEach((
|
|
2692
|
-
this.disconnect(
|
|
2757
|
+
Object.keys(this.peerConnections).forEach((clientId) => {
|
|
2758
|
+
this.disconnect(clientId);
|
|
2693
2759
|
});
|
|
2694
2760
|
this.peerConnections = {};
|
|
2695
2761
|
this._socketListenerDeregisterFunctions.forEach((func) => {
|
|
@@ -2888,16 +2954,14 @@ class P2pRtcManager {
|
|
|
2888
2954
|
_emit(eventName, data) {
|
|
2889
2955
|
this._emitter.emit(eventName, data);
|
|
2890
2956
|
}
|
|
2891
|
-
_getSession(
|
|
2892
|
-
if (!(
|
|
2957
|
+
_getSession(clientId) {
|
|
2958
|
+
if (!(clientId in this.peerConnections)) {
|
|
2893
2959
|
return null;
|
|
2894
2960
|
}
|
|
2895
|
-
return this.peerConnections[
|
|
2961
|
+
return this.peerConnections[clientId];
|
|
2896
2962
|
}
|
|
2897
|
-
_createSession({ clientId, initialBandwidth, isOfferer
|
|
2898
|
-
|
|
2899
|
-
throw new Error("peerConnectionId is missing");
|
|
2900
|
-
}
|
|
2963
|
+
_createSession({ clientId, initialBandwidth, isOfferer }) {
|
|
2964
|
+
var _a, _b;
|
|
2901
2965
|
if (!clientId) {
|
|
2902
2966
|
throw new Error("clientId is missing");
|
|
2903
2967
|
}
|
|
@@ -2912,17 +2976,121 @@ class P2pRtcManager {
|
|
|
2912
2976
|
browserVersion >= 14 &&
|
|
2913
2977
|
this._features.deprioritizeH264OnSafari;
|
|
2914
2978
|
const session = new Session({
|
|
2915
|
-
peerConnectionId,
|
|
2916
2979
|
clientId,
|
|
2917
2980
|
peerConnectionConfig,
|
|
2918
2981
|
bandwidth: initialBandwidth,
|
|
2919
2982
|
deprioritizeH264Encoding,
|
|
2920
2983
|
incrementAnalyticMetric: (metric) => this.analytics[metric]++,
|
|
2921
2984
|
});
|
|
2922
|
-
this.peerConnections[
|
|
2985
|
+
this.peerConnections[clientId] = session;
|
|
2923
2986
|
setTimeout(() => this._emit(rtcManagerEvents.NEW_PC), 0);
|
|
2924
2987
|
this.analytics.numNewPc++;
|
|
2925
2988
|
const { pc } = session;
|
|
2989
|
+
pc.onicegatheringstatechange = (event) => {
|
|
2990
|
+
const connection = event.target;
|
|
2991
|
+
switch (connection.iceGatheringState) {
|
|
2992
|
+
case "gathering":
|
|
2993
|
+
if (this._icePublicIPGatheringTimeoutID)
|
|
2994
|
+
clearTimeout(this._icePublicIPGatheringTimeoutID);
|
|
2995
|
+
this._icePublicIPGatheringTimeoutID = setTimeout(() => {
|
|
2996
|
+
if (!session.publicHostCandidateSeen &&
|
|
2997
|
+
!session.relayCandidateSeen &&
|
|
2998
|
+
!session.serverReflexiveCandidateSeen) {
|
|
2999
|
+
if (pc.iceConnectionState !== "connected" && pc.iceConnectionState !== "completed")
|
|
3000
|
+
this.analytics.numIceNoPublicIpGatheredIn3sec++;
|
|
3001
|
+
}
|
|
3002
|
+
}, ICE_PUBLIC_IP_GATHERING_TIMEOUT);
|
|
3003
|
+
break;
|
|
3004
|
+
case "complete":
|
|
3005
|
+
if (this._icePublicIPGatheringTimeoutID)
|
|
3006
|
+
clearTimeout(this._icePublicIPGatheringTimeoutID);
|
|
3007
|
+
this._icePublicIPGatheringTimeoutID = null;
|
|
3008
|
+
break;
|
|
3009
|
+
}
|
|
3010
|
+
};
|
|
3011
|
+
pc.onicecandidate = (event) => {
|
|
3012
|
+
if (event.candidate) {
|
|
3013
|
+
if (event.candidate.type === "relayed") {
|
|
3014
|
+
this.analytics.P2PRelayedIceCandidate++;
|
|
3015
|
+
}
|
|
3016
|
+
switch (event.candidate.type) {
|
|
3017
|
+
case "host":
|
|
3018
|
+
const address = event.candidate.address;
|
|
3019
|
+
if (!address) {
|
|
3020
|
+
break;
|
|
3021
|
+
}
|
|
3022
|
+
try {
|
|
3023
|
+
if (ipRegex.v4({ exact: true }).test(address)) {
|
|
3024
|
+
const ipv4 = checkIp(address);
|
|
3025
|
+
if (ipv4.isPublicIp)
|
|
3026
|
+
session.publicHostCandidateSeen = true;
|
|
3027
|
+
}
|
|
3028
|
+
else if (ipRegex.v6({ exact: true }).test(address.replace(/^\[(.*)\]/, "$1"))) {
|
|
3029
|
+
const ipv6 = new ipAddress.Address6(address.replace(/^\[(.*)\]/, "$1"));
|
|
3030
|
+
session.ipv6HostCandidateSeen = true;
|
|
3031
|
+
if (ipv6.getScope() === "Global") {
|
|
3032
|
+
session.publicHostCandidateSeen = true;
|
|
3033
|
+
}
|
|
3034
|
+
if (ipv6.isTeredo()) {
|
|
3035
|
+
session.ipv6HostCandidateTeredoSeen = true;
|
|
3036
|
+
}
|
|
3037
|
+
if (ipv6.is6to4()) {
|
|
3038
|
+
session.ipv6HostCandidate6to4Seen = true;
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
else {
|
|
3042
|
+
const uuidv4 = address.replace(/.local/, "");
|
|
3043
|
+
if (uuidv4 && validate(uuidv4, 4)) {
|
|
3044
|
+
session.mdnsHostCandidateSeen = true;
|
|
3045
|
+
}
|
|
3046
|
+
}
|
|
3047
|
+
}
|
|
3048
|
+
catch (error) {
|
|
3049
|
+
logger$6.info("Error during parsing candidates! Error: ", { error });
|
|
3050
|
+
}
|
|
3051
|
+
break;
|
|
3052
|
+
case "srflx":
|
|
3053
|
+
session.serverReflexiveCandidateSeen = true;
|
|
3054
|
+
break;
|
|
3055
|
+
case "relayed":
|
|
3056
|
+
case "relay":
|
|
3057
|
+
session.relayCandidateSeen = true;
|
|
3058
|
+
break;
|
|
3059
|
+
}
|
|
3060
|
+
this._emitServerEvent(RELAY_MESSAGES.ICE_CANDIDATE, {
|
|
3061
|
+
receiverId: clientId,
|
|
3062
|
+
message: event.candidate,
|
|
3063
|
+
});
|
|
3064
|
+
}
|
|
3065
|
+
else {
|
|
3066
|
+
this._emitServerEvent(RELAY_MESSAGES.ICE_END_OF_CANDIDATES, {
|
|
3067
|
+
receiverId: clientId,
|
|
3068
|
+
});
|
|
3069
|
+
if (!session.publicHostCandidateSeen &&
|
|
3070
|
+
!session.relayCandidateSeen &&
|
|
3071
|
+
!session.serverReflexiveCandidateSeen &&
|
|
3072
|
+
pc.iceConnectionState !== "connected" &&
|
|
3073
|
+
pc.iceConnectionState !== "completed") {
|
|
3074
|
+
this.analytics.numIceNoPublicIpGathered++;
|
|
3075
|
+
}
|
|
3076
|
+
if (session.ipv6HostCandidateSeen) {
|
|
3077
|
+
this.analytics.numIceIpv6Seen++;
|
|
3078
|
+
if (session.ipv6HostCandidate6to4Seen)
|
|
3079
|
+
this.analytics.numIceIpv6SixToFour++;
|
|
3080
|
+
if (session.ipv6HostCandidateTeredoSeen)
|
|
3081
|
+
this.analytics.numIceIpv6TeredoSeen++;
|
|
3082
|
+
}
|
|
3083
|
+
if (session.mdnsHostCandidateSeen)
|
|
3084
|
+
this.analytics.numIceMdnsSeen++;
|
|
3085
|
+
}
|
|
3086
|
+
};
|
|
3087
|
+
pc.onnegotiationneeded = () => {
|
|
3088
|
+
if (pc.iceConnectionState === "new" || !session.connectionStatus) {
|
|
3089
|
+
return;
|
|
3090
|
+
}
|
|
3091
|
+
logger$6.info(`onnegotiationneeded client ${clientId}`);
|
|
3092
|
+
this._negotiatePeerConnection({ clientId, session });
|
|
3093
|
+
};
|
|
2926
3094
|
pc.ontrack = (event) => {
|
|
2927
3095
|
const stream = event.streams[0];
|
|
2928
3096
|
if (!stream) {
|
|
@@ -3054,16 +3222,22 @@ class P2pRtcManager {
|
|
|
3054
3222
|
});
|
|
3055
3223
|
}
|
|
3056
3224
|
}
|
|
3225
|
+
if (this._features.increaseIncomingMediaBufferOn) {
|
|
3226
|
+
this._setJitterBufferTarget(pc);
|
|
3227
|
+
}
|
|
3228
|
+
if (((_b = (_a = this._localCameraStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks()) === null || _b === void 0 ? void 0 : _b.length) && this._stoppedVideoTrack) {
|
|
3229
|
+
pc.addTrack(this._stoppedVideoTrack, this._localCameraStream);
|
|
3230
|
+
}
|
|
3057
3231
|
return session;
|
|
3058
3232
|
}
|
|
3059
|
-
_cleanup(
|
|
3060
|
-
const session = this._getSession(
|
|
3233
|
+
_cleanup(clientId) {
|
|
3234
|
+
const session = this._getSession(clientId);
|
|
3061
3235
|
if (!session) {
|
|
3062
|
-
logger$6.warn("No RTCPeerConnection in RTCManager.disconnect()",
|
|
3236
|
+
logger$6.warn("No RTCPeerConnection in RTCManager.disconnect()", clientId);
|
|
3063
3237
|
return;
|
|
3064
3238
|
}
|
|
3065
3239
|
session.close();
|
|
3066
|
-
delete this.peerConnections[
|
|
3240
|
+
delete this.peerConnections[clientId];
|
|
3067
3241
|
}
|
|
3068
3242
|
_forEachPeerConnection(func) {
|
|
3069
3243
|
Object.values(this.peerConnections).forEach((peerConnection) => {
|
|
@@ -3164,7 +3338,7 @@ class P2pRtcManager {
|
|
|
3164
3338
|
else {
|
|
3165
3339
|
initialBandwidth = this._changeBandwidthForAllClients(true);
|
|
3166
3340
|
}
|
|
3167
|
-
session = this.
|
|
3341
|
+
session = this._createSession({
|
|
3168
3342
|
clientId,
|
|
3169
3343
|
initialBandwidth,
|
|
3170
3344
|
isOfferer: true,
|
|
@@ -3328,128 +3502,6 @@ class P2pRtcManager {
|
|
|
3328
3502
|
});
|
|
3329
3503
|
return bandwidth;
|
|
3330
3504
|
}
|
|
3331
|
-
_createP2pSession({ clientId, initialBandwidth, isOfferer = false, }) {
|
|
3332
|
-
var _a, _b;
|
|
3333
|
-
const session = this._createSession({
|
|
3334
|
-
peerConnectionId: clientId,
|
|
3335
|
-
clientId,
|
|
3336
|
-
initialBandwidth,
|
|
3337
|
-
isOfferer,
|
|
3338
|
-
});
|
|
3339
|
-
const pc = session.pc;
|
|
3340
|
-
if (this._features.increaseIncomingMediaBufferOn) {
|
|
3341
|
-
this._setJitterBufferTarget(pc);
|
|
3342
|
-
}
|
|
3343
|
-
if (((_b = (_a = this._localCameraStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks()) === null || _b === void 0 ? void 0 : _b.length) && this._stoppedVideoTrack) {
|
|
3344
|
-
pc.addTrack(this._stoppedVideoTrack, this._localCameraStream);
|
|
3345
|
-
}
|
|
3346
|
-
pc.onicegatheringstatechange = (event) => {
|
|
3347
|
-
const connection = event.target;
|
|
3348
|
-
switch (connection.iceGatheringState) {
|
|
3349
|
-
case "gathering":
|
|
3350
|
-
if (this._icePublicIPGatheringTimeoutID)
|
|
3351
|
-
clearTimeout(this._icePublicIPGatheringTimeoutID);
|
|
3352
|
-
this._icePublicIPGatheringTimeoutID = setTimeout(() => {
|
|
3353
|
-
if (!session.publicHostCandidateSeen &&
|
|
3354
|
-
!session.relayCandidateSeen &&
|
|
3355
|
-
!session.serverReflexiveCandidateSeen) {
|
|
3356
|
-
if (pc.iceConnectionState !== "connected" && pc.iceConnectionState !== "completed")
|
|
3357
|
-
this.analytics.numIceNoPublicIpGatheredIn3sec++;
|
|
3358
|
-
}
|
|
3359
|
-
}, ICE_PUBLIC_IP_GATHERING_TIMEOUT);
|
|
3360
|
-
break;
|
|
3361
|
-
case "complete":
|
|
3362
|
-
if (this._icePublicIPGatheringTimeoutID)
|
|
3363
|
-
clearTimeout(this._icePublicIPGatheringTimeoutID);
|
|
3364
|
-
this._icePublicIPGatheringTimeoutID = null;
|
|
3365
|
-
break;
|
|
3366
|
-
}
|
|
3367
|
-
};
|
|
3368
|
-
pc.onicecandidate = (event) => {
|
|
3369
|
-
if (event.candidate) {
|
|
3370
|
-
if (event.candidate.type === "relayed") {
|
|
3371
|
-
this.analytics.P2PRelayedIceCandidate++;
|
|
3372
|
-
}
|
|
3373
|
-
switch (event.candidate.type) {
|
|
3374
|
-
case "host":
|
|
3375
|
-
const address = event.candidate.address;
|
|
3376
|
-
if (!address) {
|
|
3377
|
-
break;
|
|
3378
|
-
}
|
|
3379
|
-
try {
|
|
3380
|
-
if (ipRegex.v4({ exact: true }).test(address)) {
|
|
3381
|
-
const ipv4 = checkIp(address);
|
|
3382
|
-
if (ipv4.isPublicIp)
|
|
3383
|
-
session.publicHostCandidateSeen = true;
|
|
3384
|
-
}
|
|
3385
|
-
else if (ipRegex.v6({ exact: true }).test(address.replace(/^\[(.*)\]/, "$1"))) {
|
|
3386
|
-
const ipv6 = new ipAddress.Address6(address.replace(/^\[(.*)\]/, "$1"));
|
|
3387
|
-
session.ipv6HostCandidateSeen = true;
|
|
3388
|
-
if (ipv6.getScope() === "Global") {
|
|
3389
|
-
session.publicHostCandidateSeen = true;
|
|
3390
|
-
}
|
|
3391
|
-
if (ipv6.isTeredo()) {
|
|
3392
|
-
session.ipv6HostCandidateTeredoSeen = true;
|
|
3393
|
-
}
|
|
3394
|
-
if (ipv6.is6to4()) {
|
|
3395
|
-
session.ipv6HostCandidate6to4Seen = true;
|
|
3396
|
-
}
|
|
3397
|
-
}
|
|
3398
|
-
else {
|
|
3399
|
-
const uuidv4 = address.replace(/.local/, "");
|
|
3400
|
-
if (uuidv4 && validate(uuidv4, 4)) {
|
|
3401
|
-
session.mdnsHostCandidateSeen = true;
|
|
3402
|
-
}
|
|
3403
|
-
}
|
|
3404
|
-
}
|
|
3405
|
-
catch (error) {
|
|
3406
|
-
logger$6.info("Error during parsing candidates! Error: ", { error });
|
|
3407
|
-
}
|
|
3408
|
-
break;
|
|
3409
|
-
case "srflx":
|
|
3410
|
-
session.serverReflexiveCandidateSeen = true;
|
|
3411
|
-
break;
|
|
3412
|
-
case "relayed":
|
|
3413
|
-
case "relay":
|
|
3414
|
-
session.relayCandidateSeen = true;
|
|
3415
|
-
break;
|
|
3416
|
-
}
|
|
3417
|
-
this._emitServerEvent(RELAY_MESSAGES.ICE_CANDIDATE, {
|
|
3418
|
-
receiverId: clientId,
|
|
3419
|
-
message: event.candidate,
|
|
3420
|
-
});
|
|
3421
|
-
}
|
|
3422
|
-
else {
|
|
3423
|
-
this._emitServerEvent(RELAY_MESSAGES.ICE_END_OF_CANDIDATES, {
|
|
3424
|
-
receiverId: clientId,
|
|
3425
|
-
});
|
|
3426
|
-
if (!session.publicHostCandidateSeen &&
|
|
3427
|
-
!session.relayCandidateSeen &&
|
|
3428
|
-
!session.serverReflexiveCandidateSeen &&
|
|
3429
|
-
pc.iceConnectionState !== "connected" &&
|
|
3430
|
-
pc.iceConnectionState !== "completed") {
|
|
3431
|
-
this.analytics.numIceNoPublicIpGathered++;
|
|
3432
|
-
}
|
|
3433
|
-
if (session.ipv6HostCandidateSeen) {
|
|
3434
|
-
this.analytics.numIceIpv6Seen++;
|
|
3435
|
-
if (session.ipv6HostCandidate6to4Seen)
|
|
3436
|
-
this.analytics.numIceIpv6SixToFour++;
|
|
3437
|
-
if (session.ipv6HostCandidateTeredoSeen)
|
|
3438
|
-
this.analytics.numIceIpv6TeredoSeen++;
|
|
3439
|
-
}
|
|
3440
|
-
if (session.mdnsHostCandidateSeen)
|
|
3441
|
-
this.analytics.numIceMdnsSeen++;
|
|
3442
|
-
}
|
|
3443
|
-
};
|
|
3444
|
-
pc.onnegotiationneeded = () => {
|
|
3445
|
-
if (pc.iceConnectionState === "new" || !session.connectionStatus) {
|
|
3446
|
-
return;
|
|
3447
|
-
}
|
|
3448
|
-
logger$6.info(`onnegotiationneeded client ${clientId}`);
|
|
3449
|
-
this._negotiatePeerConnection({ clientId, session });
|
|
3450
|
-
};
|
|
3451
|
-
return session;
|
|
3452
|
-
}
|
|
3453
3505
|
acceptNewStream({ streamId, clientId }) {
|
|
3454
3506
|
logger$6.info("acceptNewStream() [streamId: %s}, clientId: %s]", streamId, clientId);
|
|
3455
3507
|
let session = this._getSession(clientId);
|
|
@@ -3463,7 +3515,7 @@ class P2pRtcManager {
|
|
|
3463
3515
|
else {
|
|
3464
3516
|
initialBandwidth = this._changeBandwidthForAllClients(true);
|
|
3465
3517
|
}
|
|
3466
|
-
session = this.
|
|
3518
|
+
session = this._createSession({
|
|
3467
3519
|
clientId,
|
|
3468
3520
|
initialBandwidth,
|
|
3469
3521
|
isOfferer: false,
|
|
@@ -3532,7 +3584,7 @@ class P2pRtcManager {
|
|
|
3532
3584
|
}
|
|
3533
3585
|
else {
|
|
3534
3586
|
if (localStream.getVideoTracks().length === 0) {
|
|
3535
|
-
const constraints = this._webrtcProvider.
|
|
3587
|
+
const constraints = getConstraints(this._webrtcProvider.getMediaOptions()).video;
|
|
3536
3588
|
if (!constraints) {
|
|
3537
3589
|
return;
|
|
3538
3590
|
}
|
|
@@ -4401,10 +4453,10 @@ const STREAM_TYPES = {
|
|
|
4401
4453
|
screenshare: "screenshare",
|
|
4402
4454
|
};
|
|
4403
4455
|
|
|
4404
|
-
var _a
|
|
4405
|
-
const adapter
|
|
4456
|
+
var _a;
|
|
4457
|
+
const adapter = (_a = adapterRaw.default) !== null && _a !== void 0 ? _a : adapterRaw;
|
|
4406
4458
|
const logger$2 = new Logger();
|
|
4407
|
-
const browserName = adapter
|
|
4459
|
+
const browserName = adapter.browserDetails.browser;
|
|
4408
4460
|
let unloading = false;
|
|
4409
4461
|
const RESTARTICE_ERROR_RETRY_THRESHOLD_IN_MS = 3500;
|
|
4410
4462
|
const RESTARTICE_ERROR_MAX_RETRY_COUNT = 5;
|
|
@@ -5491,7 +5543,7 @@ class VegaRtcManager {
|
|
|
5491
5543
|
}, stopCameraDelay);
|
|
5492
5544
|
}
|
|
5493
5545
|
else if (localStream.getVideoTracks().length === 0) {
|
|
5494
|
-
const constraints = this._webrtcProvider.
|
|
5546
|
+
const constraints = getConstraints(this._webrtcProvider.getMediaOptions()).video;
|
|
5495
5547
|
navigator.mediaDevices
|
|
5496
5548
|
.getUserMedia({ video: constraints })
|
|
5497
5549
|
.then((stream) => {
|
|
@@ -7016,73 +7068,6 @@ class BandwidthTester extends EventEmitter {
|
|
|
7016
7068
|
}
|
|
7017
7069
|
}
|
|
7018
7070
|
|
|
7019
|
-
var _a, _b;
|
|
7020
|
-
const adapter = (_a = adapterRaw.default) !== null && _a !== void 0 ? _a : adapterRaw;
|
|
7021
|
-
const isSafari = ((_b = adapter.browserDetails) === null || _b === void 0 ? void 0 : _b.browser) === "safari";
|
|
7022
|
-
const parseResolution = (res) => res.split(/[^\d]/g).map((n) => parseInt(n, 10));
|
|
7023
|
-
function getMediaConstraints({ disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }) {
|
|
7024
|
-
var _a, _b;
|
|
7025
|
-
let HIGH_HEIGHT = 480;
|
|
7026
|
-
let LOW_HEIGHT = 240;
|
|
7027
|
-
if (hd) {
|
|
7028
|
-
HIGH_HEIGHT = lax || isSafari ? 720 : { min: 360, ideal: 720 };
|
|
7029
|
-
}
|
|
7030
|
-
if (simulcast) {
|
|
7031
|
-
if (hd === false) {
|
|
7032
|
-
HIGH_HEIGHT = 360;
|
|
7033
|
-
LOW_HEIGHT = 270;
|
|
7034
|
-
}
|
|
7035
|
-
else {
|
|
7036
|
-
LOW_HEIGHT = 360;
|
|
7037
|
-
}
|
|
7038
|
-
}
|
|
7039
|
-
const constraints = {
|
|
7040
|
-
audio: Object.assign({}, (preferredDeviceIds.audioId && { deviceId: preferredDeviceIds.audioId })),
|
|
7041
|
-
video: Object.assign(Object.assign({}, (preferredDeviceIds.videoId ? { deviceId: preferredDeviceIds.videoId } : { facingMode: "user" })), { height: lowDataMode ? LOW_HEIGHT : HIGH_HEIGHT, frameRate: lowDataMode && !simulcast ? 15 : 24 }),
|
|
7042
|
-
};
|
|
7043
|
-
if (lax) {
|
|
7044
|
-
if (!((_a = constraints.audio) === null || _a === void 0 ? void 0 : _a.deviceId))
|
|
7045
|
-
constraints.audio = true;
|
|
7046
|
-
(_b = constraints.video) === null || _b === void 0 ? true : delete _b.facingMode;
|
|
7047
|
-
return constraints;
|
|
7048
|
-
}
|
|
7049
|
-
if (resolution) {
|
|
7050
|
-
const [w, h, fps] = parseResolution(resolution);
|
|
7051
|
-
if (w)
|
|
7052
|
-
constraints.video.width = { exact: w };
|
|
7053
|
-
if (h)
|
|
7054
|
-
constraints.video.height = { exact: h };
|
|
7055
|
-
if (fps)
|
|
7056
|
-
constraints.video.frameRate = { exact: fps };
|
|
7057
|
-
delete constraints.video.facingMode;
|
|
7058
|
-
}
|
|
7059
|
-
else {
|
|
7060
|
-
constraints.video.aspectRatio = widescreen ? 16 / 9 : 4 / 3;
|
|
7061
|
-
}
|
|
7062
|
-
if (disableAGC)
|
|
7063
|
-
constraints.audio.autoGainControl = false;
|
|
7064
|
-
if (disableAEC)
|
|
7065
|
-
constraints.audio.echoCancellation = false;
|
|
7066
|
-
return constraints;
|
|
7067
|
-
}
|
|
7068
|
-
function getConstraints({ devices, videoId, audioId, options, type = "ideal" }) {
|
|
7069
|
-
const audioDevices = devices.filter((d) => d.kind === "audioinput");
|
|
7070
|
-
const videoDevices = devices.filter((d) => d.kind === "videoinput");
|
|
7071
|
-
const useDefaultAudio = !audioId || !audioDevices.some((d) => d.deviceId === audioId);
|
|
7072
|
-
const useDefaultVideo = !videoId || !videoDevices.some((d) => d.deviceId === videoId);
|
|
7073
|
-
const constraints = getMediaConstraints(Object.assign({ preferredDeviceIds: {
|
|
7074
|
-
audioId: useDefaultAudio ? null : { [type]: audioId },
|
|
7075
|
-
videoId: useDefaultVideo ? null : { [type]: videoId },
|
|
7076
|
-
} }, options));
|
|
7077
|
-
if (audioId === false || !audioDevices.length) {
|
|
7078
|
-
delete constraints.audio;
|
|
7079
|
-
}
|
|
7080
|
-
if (videoId === false || !videoDevices.length) {
|
|
7081
|
-
delete constraints.video;
|
|
7082
|
-
}
|
|
7083
|
-
return constraints;
|
|
7084
|
-
}
|
|
7085
|
-
|
|
7086
7071
|
const logger = new Logger();
|
|
7087
7072
|
const isMobile = /mobi/i.test(navigator.userAgent);
|
|
7088
7073
|
class NoDevicesError extends Error {
|
|
@@ -7156,7 +7141,6 @@ function getSettingsFromTrack(kind, track, devices, lastUsedId) {
|
|
|
7156
7141
|
if (settings.deviceId)
|
|
7157
7142
|
return settings;
|
|
7158
7143
|
settings.deviceId = (_c = track.getConstraints()) === null || _c === void 0 ? void 0 : _c.deviceId;
|
|
7159
|
-
settings.broken = 1;
|
|
7160
7144
|
return settings;
|
|
7161
7145
|
}
|
|
7162
7146
|
function getDeviceData({ audioTrack, videoTrack, devices, stoppedVideoTrack, lastAudioId, lastVideoId, }) {
|
package/dist/index.d.cts
CHANGED
|
@@ -482,7 +482,7 @@ type SignalIceEndOfCandidatesMessage = {
|
|
|
482
482
|
clientId: string;
|
|
483
483
|
};
|
|
484
484
|
interface WebRTCProvider {
|
|
485
|
-
|
|
485
|
+
getMediaOptions: () => GetConstraintsOptions;
|
|
486
486
|
}
|
|
487
487
|
type GetMediaConstraintsOptions = {
|
|
488
488
|
disableAEC: boolean;
|
|
@@ -503,7 +503,6 @@ type GetMediaConstraintsOptions = {
|
|
|
503
503
|
resolution?: string;
|
|
504
504
|
simulcast: boolean;
|
|
505
505
|
widescreen: boolean;
|
|
506
|
-
usingAspectRatio16x9: boolean;
|
|
507
506
|
};
|
|
508
507
|
type GetConstraintsOptions = {
|
|
509
508
|
devices: MediaDeviceInfo[];
|
|
@@ -1189,7 +1188,6 @@ declare function getUpdatedDevices({ oldDevices, newDevices, currentAudioId, cur
|
|
|
1189
1188
|
}): GetUpdatedDevicesResult;
|
|
1190
1189
|
|
|
1191
1190
|
interface P2PSessionOptions {
|
|
1192
|
-
peerConnectionId: string;
|
|
1193
1191
|
clientId: string;
|
|
1194
1192
|
bandwidth: number;
|
|
1195
1193
|
peerConnectionConfig: RTCConfiguration;
|
|
@@ -1197,7 +1195,6 @@ interface P2PSessionOptions {
|
|
|
1197
1195
|
incrementAnalyticMetric: P2PIncrementAnalyticMetric;
|
|
1198
1196
|
}
|
|
1199
1197
|
declare class Session {
|
|
1200
|
-
peerConnectionId: any;
|
|
1201
1198
|
relayCandidateSeen: boolean;
|
|
1202
1199
|
serverReflexiveCandidateSeen: boolean;
|
|
1203
1200
|
publicHostCandidateSeen: boolean;
|
|
@@ -1223,7 +1220,7 @@ declare class Session {
|
|
|
1223
1220
|
srdComplete: any;
|
|
1224
1221
|
_incrementAnalyticMetric: P2PIncrementAnalyticMetric;
|
|
1225
1222
|
pendingReplaceTrackActions: (() => Promise<void>)[];
|
|
1226
|
-
constructor({
|
|
1223
|
+
constructor({ clientId, bandwidth, peerConnectionConfig, deprioritizeH264Encoding, incrementAnalyticMetric, }: P2PSessionOptions);
|
|
1227
1224
|
addStream(stream: MediaStream): void;
|
|
1228
1225
|
addTrack(track: MediaStreamTrack, stream?: MediaStream): void;
|
|
1229
1226
|
removeTrack(track: MediaStreamTrack): void;
|
|
@@ -1241,7 +1238,6 @@ declare class Session {
|
|
|
1241
1238
|
}
|
|
1242
1239
|
|
|
1243
1240
|
interface CreateSessionOptions {
|
|
1244
|
-
peerConnectionId: string;
|
|
1245
1241
|
clientId: string;
|
|
1246
1242
|
initialBandwidth: number;
|
|
1247
1243
|
isOfferer: boolean;
|
|
@@ -1343,9 +1339,9 @@ declare class P2pRtcManager implements RtcManager {
|
|
|
1343
1339
|
_setJitterBufferTarget(pc: RTCPeerConnection): void;
|
|
1344
1340
|
_emitServerEvent(eventName: string, data?: any): void;
|
|
1345
1341
|
_emit(eventName: string, data?: any): void;
|
|
1346
|
-
_getSession(
|
|
1347
|
-
_createSession({ clientId, initialBandwidth, isOfferer
|
|
1348
|
-
_cleanup(
|
|
1342
|
+
_getSession(clientId: string): Session | null;
|
|
1343
|
+
_createSession({ clientId, initialBandwidth, isOfferer }: CreateSessionOptions): Session;
|
|
1344
|
+
_cleanup(clientId: string): void;
|
|
1349
1345
|
_forEachPeerConnection(func: any): void;
|
|
1350
1346
|
_addStreamToPeerConnections(stream: MediaStream): void;
|
|
1351
1347
|
_addTrackToPeerConnections(track: MediaStreamTrack, stream?: MediaStream): void;
|
|
@@ -1362,11 +1358,6 @@ declare class P2pRtcManager implements RtcManager {
|
|
|
1362
1358
|
_negotiatePeerConnection({ clientId, session, constraints, isInitialOffer, }: NegotiatePeerConnectionOptions): void;
|
|
1363
1359
|
_withForcedRenegotiation(session: Session, action: any): void;
|
|
1364
1360
|
_changeBandwidthForAllClients(isJoining: boolean): number;
|
|
1365
|
-
_createP2pSession({ clientId, initialBandwidth, isOfferer, }: {
|
|
1366
|
-
clientId: string;
|
|
1367
|
-
initialBandwidth: number;
|
|
1368
|
-
isOfferer: boolean;
|
|
1369
|
-
}): Session;
|
|
1370
1361
|
acceptNewStream({ streamId, clientId }: {
|
|
1371
1362
|
streamId: string;
|
|
1372
1363
|
clientId: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -482,7 +482,7 @@ type SignalIceEndOfCandidatesMessage = {
|
|
|
482
482
|
clientId: string;
|
|
483
483
|
};
|
|
484
484
|
interface WebRTCProvider {
|
|
485
|
-
|
|
485
|
+
getMediaOptions: () => GetConstraintsOptions;
|
|
486
486
|
}
|
|
487
487
|
type GetMediaConstraintsOptions = {
|
|
488
488
|
disableAEC: boolean;
|
|
@@ -503,7 +503,6 @@ type GetMediaConstraintsOptions = {
|
|
|
503
503
|
resolution?: string;
|
|
504
504
|
simulcast: boolean;
|
|
505
505
|
widescreen: boolean;
|
|
506
|
-
usingAspectRatio16x9: boolean;
|
|
507
506
|
};
|
|
508
507
|
type GetConstraintsOptions = {
|
|
509
508
|
devices: MediaDeviceInfo[];
|
|
@@ -1189,7 +1188,6 @@ declare function getUpdatedDevices({ oldDevices, newDevices, currentAudioId, cur
|
|
|
1189
1188
|
}): GetUpdatedDevicesResult;
|
|
1190
1189
|
|
|
1191
1190
|
interface P2PSessionOptions {
|
|
1192
|
-
peerConnectionId: string;
|
|
1193
1191
|
clientId: string;
|
|
1194
1192
|
bandwidth: number;
|
|
1195
1193
|
peerConnectionConfig: RTCConfiguration;
|
|
@@ -1197,7 +1195,6 @@ interface P2PSessionOptions {
|
|
|
1197
1195
|
incrementAnalyticMetric: P2PIncrementAnalyticMetric;
|
|
1198
1196
|
}
|
|
1199
1197
|
declare class Session {
|
|
1200
|
-
peerConnectionId: any;
|
|
1201
1198
|
relayCandidateSeen: boolean;
|
|
1202
1199
|
serverReflexiveCandidateSeen: boolean;
|
|
1203
1200
|
publicHostCandidateSeen: boolean;
|
|
@@ -1223,7 +1220,7 @@ declare class Session {
|
|
|
1223
1220
|
srdComplete: any;
|
|
1224
1221
|
_incrementAnalyticMetric: P2PIncrementAnalyticMetric;
|
|
1225
1222
|
pendingReplaceTrackActions: (() => Promise<void>)[];
|
|
1226
|
-
constructor({
|
|
1223
|
+
constructor({ clientId, bandwidth, peerConnectionConfig, deprioritizeH264Encoding, incrementAnalyticMetric, }: P2PSessionOptions);
|
|
1227
1224
|
addStream(stream: MediaStream): void;
|
|
1228
1225
|
addTrack(track: MediaStreamTrack, stream?: MediaStream): void;
|
|
1229
1226
|
removeTrack(track: MediaStreamTrack): void;
|
|
@@ -1241,7 +1238,6 @@ declare class Session {
|
|
|
1241
1238
|
}
|
|
1242
1239
|
|
|
1243
1240
|
interface CreateSessionOptions {
|
|
1244
|
-
peerConnectionId: string;
|
|
1245
1241
|
clientId: string;
|
|
1246
1242
|
initialBandwidth: number;
|
|
1247
1243
|
isOfferer: boolean;
|
|
@@ -1343,9 +1339,9 @@ declare class P2pRtcManager implements RtcManager {
|
|
|
1343
1339
|
_setJitterBufferTarget(pc: RTCPeerConnection): void;
|
|
1344
1340
|
_emitServerEvent(eventName: string, data?: any): void;
|
|
1345
1341
|
_emit(eventName: string, data?: any): void;
|
|
1346
|
-
_getSession(
|
|
1347
|
-
_createSession({ clientId, initialBandwidth, isOfferer
|
|
1348
|
-
_cleanup(
|
|
1342
|
+
_getSession(clientId: string): Session | null;
|
|
1343
|
+
_createSession({ clientId, initialBandwidth, isOfferer }: CreateSessionOptions): Session;
|
|
1344
|
+
_cleanup(clientId: string): void;
|
|
1349
1345
|
_forEachPeerConnection(func: any): void;
|
|
1350
1346
|
_addStreamToPeerConnections(stream: MediaStream): void;
|
|
1351
1347
|
_addTrackToPeerConnections(track: MediaStreamTrack, stream?: MediaStream): void;
|
|
@@ -1362,11 +1358,6 @@ declare class P2pRtcManager implements RtcManager {
|
|
|
1362
1358
|
_negotiatePeerConnection({ clientId, session, constraints, isInitialOffer, }: NegotiatePeerConnectionOptions): void;
|
|
1363
1359
|
_withForcedRenegotiation(session: Session, action: any): void;
|
|
1364
1360
|
_changeBandwidthForAllClients(isJoining: boolean): number;
|
|
1365
|
-
_createP2pSession({ clientId, initialBandwidth, isOfferer, }: {
|
|
1366
|
-
clientId: string;
|
|
1367
|
-
initialBandwidth: number;
|
|
1368
|
-
isOfferer: boolean;
|
|
1369
|
-
}): Session;
|
|
1370
1361
|
acceptNewStream({ streamId, clientId }: {
|
|
1371
1362
|
streamId: string;
|
|
1372
1363
|
clientId: string;
|