299 lines
10 KiB
JavaScript
299 lines
10 KiB
JavaScript
// Metro module 4297 (f4298).
|
|
import { ConnectionStates, DEFAULT_VOICE_BITRATE, MediaEngineContextTypes, MediaTypes, ResolutionTypes, SIMULCAST_HQ_QUALITY, VIDEO_QUALITY_FRAMERATE } from "./Module4250";
|
|
import TypedEventEmitter from "./TypedEventEmitter";
|
|
import { VideoQualityManager, VIDEO_QUALITY_MODES_TO_OVERWRITES } from "./WantsVideoQuality";
|
|
import * as _ConnectionEventFramerateReducer from "./ConnectionEventFramerateReducer";
|
|
import * as _Module4301 from "./Module4301";
|
|
import cloneDeep from "./cloneDeep";
|
|
import Module4331 from "./Module4331";
|
|
let c2532_11 = 0;
|
|
class BaseConnection extends TypedEventEmitter {
|
|
constructor(a0, a1) {
|
|
super();
|
|
const r16 = +c2532_11;
|
|
c2532_11 = r16 + 1;
|
|
this.mediaEngineConnectionId = "WebRTC-" + r16;
|
|
this.destroyed = false;
|
|
this.audioSSRC = 0;
|
|
this.videoSSRC = 0;
|
|
this.selfDeaf = false;
|
|
this.selfMute = false;
|
|
this.localMutes = {};
|
|
this.disabledLocalVideos = {};
|
|
this.localVolumes = {};
|
|
this.isActiveOutputSinksEnabled = false;
|
|
this.activeOutputSinks = new Map();
|
|
this.videoSupported = false;
|
|
this.useElectronVideo = false;
|
|
this.spatialAudioEnabled = false;
|
|
this.voiceBitrate = DEFAULT_VOICE_BITRATE;
|
|
this.remoteSinkWantsMaxFramerate = VIDEO_QUALITY_FRAMERATE;
|
|
this.wantsPriority = new Set();
|
|
this.localSpeakingFlags = {};
|
|
this.videoReady = false;
|
|
this.videoStreamParameters = [];
|
|
this.remoteVideoSinkWants = {
|
|
any: 100
|
|
};
|
|
this.localVideoSinkWants = {
|
|
any: 100
|
|
};
|
|
this.connectionState = ConnectionStates.CONNECTING;
|
|
this.onDesktopEncodingOptionsSet = (a0, a1, a2) => {};
|
|
this.experimentFlags = new Set();
|
|
this.calcMaxBitrateFunc = (a0) => null;
|
|
this.context = a0;
|
|
this.userId = a1;
|
|
this.videoQualityManager = new VideoQualityManager(a0, this);
|
|
this.framerateReducer = new _ConnectionEventFramerateReducer.default(this, this.videoQualityManager);
|
|
}
|
|
destroy() {
|
|
this.destroyed = true;
|
|
this.framerateReducer.destroy();
|
|
this.setConnectionState(ConnectionStates.DISCONNECTED);
|
|
this.emit(_Module4301.BaseConnectionEvent.Destroy, this);
|
|
this.removeAllListeners();
|
|
}
|
|
getLocalMute(a0) {
|
|
return this.localMutes[a0] || false;
|
|
}
|
|
getLocalVideoDisabled(a0) {
|
|
let r4 = this.disabledLocalVideos[a0];
|
|
if (r4 == null) {
|
|
r4 = false;
|
|
}
|
|
return r4;
|
|
}
|
|
setLocalVideoDisabled(a0, a1) {
|
|
this.disabledLocalVideos[a0] = a1;
|
|
this.emit(_Module4301.BaseConnectionEvent.LocalVideoDisabled, a0, a1);
|
|
}
|
|
getHasActiveVideoOutputSink(a0) {
|
|
return this.activeOutputSinks.has(a0) && this.activeOutputSinks.get(a0).size > 0;
|
|
}
|
|
setHasActiveVideoOutputSink(a0, a1, a2) {
|
|
const hasActiveVideoOutputSink = this.getHasActiveVideoOutputSink(a0);
|
|
let r6 = this.activeOutputSinks.get(a0);
|
|
if (r6 == null) {
|
|
r6 = new Set();
|
|
}
|
|
if (a1) {
|
|
r6.add(a2);
|
|
} else {
|
|
r6.delete(a2);
|
|
}
|
|
this.activeOutputSinks.set(a0, r6);
|
|
const hasActiveVideoOutputSink2 = this.getHasActiveVideoOutputSink(a0);
|
|
this.isActiveOutputSinksEnabled = true;
|
|
if (hasActiveVideoOutputSink !== hasActiveVideoOutputSink2) {
|
|
this.emit(_Module4301.BaseConnectionEvent.ActiveSinksChange, a0, hasActiveVideoOutputSink2);
|
|
}
|
|
}
|
|
getActiveOutputSinkTrackingEnabled() {
|
|
return this.isActiveOutputSinksEnabled;
|
|
}
|
|
setUseElectronVideo(a0) {
|
|
this.useElectronVideo = a0;
|
|
}
|
|
setClipRecordUser(a0, a1, a2) {}
|
|
setViewerSideClip(a0) {}
|
|
setRemoteAudioHistory(a0) {}
|
|
setClipsKeyFrameInterval(a0) {}
|
|
setQualityDecoupling(a0) {}
|
|
presentDesktopSourcePicker(a0) {}
|
|
getStreamParameters() {
|
|
return cloneDeep(this.videoStreamParameters);
|
|
}
|
|
setExperimentFlag(a0, a1) {
|
|
const experimentFlags = this.experimentFlags;
|
|
if (a1) {
|
|
experimentFlags.add(a0);
|
|
} else {
|
|
experimentFlags.delete(a0);
|
|
}
|
|
}
|
|
setConnectionState(a0) {
|
|
this.logger.info(`Connection state change: ${this.connectionState} => ${a0}`);
|
|
this.connectionState = a0;
|
|
this.emit(_Module4301.BaseConnectionEvent.ConnectionStateChange, this.connectionState);
|
|
}
|
|
updateVideoQuality(a0) {
|
|
let length;
|
|
let r15 = this.videoStreamParameters.findIndex((videoStreamParameter) => videoStreamParameter.quality === 100);
|
|
if (r15 === -1) {
|
|
r15 = 0;
|
|
}
|
|
const r31 = this.applyQualityConstraints({}, this.videoStreamParameters[r15].ssrc);
|
|
const { quality, constraints } = r31;
|
|
const videoStreamParameters = cloneDeep(this.videoStreamParameters);
|
|
if (quality != null) {
|
|
videoStreamParameters[r15].maxBitrate = quality.bitrateMax;
|
|
videoStreamParameters[r15].minBitrate = quality.bitrateMin;
|
|
const r42 = videoStreamParameters[r15];
|
|
let bitrateTarget = quality.bitrateTarget;
|
|
if (bitrateTarget == null) {
|
|
bitrateTarget = 0;
|
|
}
|
|
r42.targetBitrate = bitrateTarget;
|
|
if (quality.encode != null) {
|
|
videoStreamParameters[r15].maxPixelCount = quality.encode.pixelCount;
|
|
videoStreamParameters[r15].maxFrameRate = quality.encode.framerate;
|
|
}
|
|
}
|
|
this.videoStreamParameters = videoStreamParameters;
|
|
const r6 = 0 < this.videoStreamParameters.length;
|
|
let r1 = 0;
|
|
let r54 = constraints;
|
|
let r55 = quality;
|
|
let r56 = r54;
|
|
let r57 = r55;
|
|
if (r6) {
|
|
do {
|
|
const r0 = r1;
|
|
const r21 = r54;
|
|
const r20 = r55;
|
|
let r17 = r21;
|
|
let r16 = r20;
|
|
if (r0 !== r15) {
|
|
const r61 = this.applyQualityConstraints({}, this.videoStreamParameters[r0].ssrc);
|
|
const { quality: quality2, constraints: constraints2 } = r61;
|
|
if (quality2 != null) {
|
|
this.videoStreamParameters[r0].maxBitrate = quality2.bitrateMax;
|
|
this.videoStreamParameters[r0].minBitrate = quality2.bitrateMin;
|
|
const r70 = this.videoStreamParameters[r0];
|
|
let bitrateTarget2 = quality2.bitrateTarget;
|
|
if (bitrateTarget2 == null) {
|
|
bitrateTarget2 = 0;
|
|
}
|
|
r70.targetBitrate = bitrateTarget2;
|
|
if (quality2.encode != null) {
|
|
this.videoStreamParameters[r0].maxPixelCount = quality2.encode.pixelCount;
|
|
this.videoStreamParameters[r0].maxFrameRate = quality2.encode.framerate;
|
|
}
|
|
}
|
|
const quality3 = this.videoStreamParameters[r0].quality;
|
|
r17 = r21;
|
|
r16 = r20;
|
|
if (quality3 === 100) {
|
|
r17 = constraints2;
|
|
r16 = quality2;
|
|
}
|
|
}
|
|
r1 = r0 + 1;
|
|
length = this.videoStreamParameters.length;
|
|
r54 = r17;
|
|
r55 = r16;
|
|
r56 = r54;
|
|
r57 = r55;
|
|
} while (r1 < length);
|
|
}
|
|
r56.streamParameters = cloneDeep(this.videoStreamParameters);
|
|
const r94 = Math;
|
|
r56.remoteSinkWantsPixelCount = r94.max.apply(r94, [...this.videoStreamParameters.map(({ maxPixelCount }) => {
|
|
if (maxPixelCount == null) {
|
|
maxPixelCount = 0;
|
|
}
|
|
return maxPixelCount;
|
|
})]);
|
|
const r105 = a0 != null ? Module4331(r56, a0) : {
|
|
...r56
|
|
};
|
|
this.logger.verbose(`updateVideoQuality: ${JSON.stringify(r105)}`);
|
|
this.updateVideoQualityCore(r105, r57);
|
|
}
|
|
applyVideoQualityMode(a0) {
|
|
if (this.context === MediaEngineContextTypes.DEFAULT) {
|
|
this.videoQualityManager.setQualityOverwrite(VIDEO_QUALITY_MODES_TO_OVERWRITES[a0]);
|
|
this.updateVideoQuality();
|
|
}
|
|
}
|
|
overwriteQualityForTesting(a0) {
|
|
this.videoQualityManager.setQualityOverwrite(a0);
|
|
this.updateVideoQuality();
|
|
}
|
|
applyQualityConstraints(r4 = {}) {
|
|
return this.videoQualityManager.applyQualityConstraints(r4, arguments[1]);
|
|
}
|
|
initializeStreamParameters(a0) {
|
|
this.videoStreamParameters = a0.filter((item) => (item.type === MediaTypes.VIDEO || item.type === MediaTypes.SCREEN) && typeof item.rid === "string").map((item) => {
|
|
const quality = this.videoQualityManager.getQuality(item.ssrc);
|
|
let quality2 = item.quality;
|
|
if (quality2 == null) {
|
|
quality2 = 100;
|
|
}
|
|
return {
|
|
type: item.type,
|
|
active: item.active,
|
|
rid: item.rid,
|
|
ssrc: item.ssrc,
|
|
rtxSsrc: item.rtxSsrc,
|
|
quality: item.quality,
|
|
maxBitrate: quality2 < 100 ? quality.bitrateMax / 4 : quality.bitrateMax,
|
|
maxFrameRate: quality.capture?.framerate,
|
|
maxResolution: {
|
|
type: ResolutionTypes.FIXED,
|
|
width: quality.capture?.width,
|
|
height: quality.capture?.height
|
|
}
|
|
};
|
|
});
|
|
}
|
|
getLocalWant(a0) {
|
|
let r7 = a0;
|
|
const r11 = this.videoStreamParameters.some((videoStreamParameter) => videoStreamParameter.ssrc === a0 && videoStreamParameter.quality === SIMULCAST_HQ_QUALITY) || a0 === void 0;
|
|
const r16 = this.context === MediaEngineContextTypes.DEFAULT || r11;
|
|
const remoteVideoSinkWants = this.remoteVideoSinkWants;
|
|
if (a0 == null) {
|
|
r7 = this.videoStreamParameters[0]?.ssrc;
|
|
}
|
|
if (r7 == null) {
|
|
r7 = 0;
|
|
}
|
|
const r21 = remoteVideoSinkWants[r7];
|
|
if (r21 != null && r21 > 0) {
|
|
return r21;
|
|
}
|
|
let any = this.remoteVideoSinkWants.any;
|
|
if (!(any != null && (any > 0 && r16))) {
|
|
any = r16 ? 100 : 0;
|
|
}
|
|
return any;
|
|
}
|
|
getRemoteVideoSinkWants(a0) {
|
|
return this.remoteVideoSinkWants[a0];
|
|
}
|
|
getRemoteVideoSinkPixelCount(a0) {
|
|
let r3 = 0;
|
|
if (a0 !== void 0) {
|
|
const pixelCounts = this.remoteVideoSinkWants.pixelCounts;
|
|
let r9 = pixelCounts == null ? void 0 : pixelCounts[a0];
|
|
if (r9 == null) {
|
|
r9 = 0;
|
|
}
|
|
r3 = r9;
|
|
}
|
|
return r3;
|
|
}
|
|
async emitStats() {
|
|
const _this = this;
|
|
let c25047_1;
|
|
c25047_1 = void 0;
|
|
let c29313_0 = await _this.getStats();
|
|
if (c29313_0 != null) {
|
|
_this.emit(_Module4301.BaseConnectionEvent.Stats, c29313_0);
|
|
}
|
|
return c29313_0;
|
|
}
|
|
getSpatialAudioEnabled() {
|
|
return this.spatialAudioEnabled;
|
|
}
|
|
setSpatialAudioEnabled(a0) {
|
|
this.spatialAudioEnabled = a0 ? this.context === MediaEngineContextTypes.DEFAULT : a0;
|
|
}
|
|
setCalcMaxBitrateFunc(a0) {
|
|
this.calcMaxBitrateFunc = a0;
|
|
}
|
|
}
|
|
export default BaseConnection;
|
|
export const BaseConnectionEvent = _Module4301.BaseConnectionEvent;
|