301 lines
9.1 KiB
TypeScript
301 lines
9.1 KiB
TypeScript
// Metro module 5009 (f5010).
|
|
import _slicedToArray from "../_bundle/_slicedToArray";
|
|
import ChannelStore from "./ChannelStore";
|
|
import MediaEngineStore from "./MediaEngineStore";
|
|
import RTCConnectionStore from "./RTCConnectionStore";
|
|
import SelectedChannelStore from "./SelectedChannelStore";
|
|
import { Permissions } from "../Constants";
|
|
import { MediaEngineContextTypes, SpeakingFlags } from "../_bundle/Module4250";
|
|
import { can } from "../utils/PermissionUtils";
|
|
import Module589 from "../_bundle/Module589";
|
|
import ProportionalVadIndicatorExperiment from "../modules/calls/ProportionalVadIndicatorExperiment";
|
|
import Dispatcher from "../Dispatcher";
|
|
let c3017_11, id, sessionId, c3017_14, isActive;
|
|
const anyoneHasFlagInContext = function anyoneHasFlagInContext(a0, a1, r7 = false) {
|
|
const r23 = c3017_11.get(a0);
|
|
if (r23 == null) {
|
|
return false;
|
|
}
|
|
for (const item of r23) {
|
|
const r31 = _slicedToArray(item, 2);
|
|
const r32 = r31[0];
|
|
const flags = r31[1].flags;
|
|
if (r7 && r32 === id) {
|
|
continue;
|
|
}
|
|
if ((flags & a1) !== a1) {
|
|
continue;
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
const handleConnectionOpen = function handleConnectionOpen({ user, sessionId: sessionId2 }) {
|
|
id = user.id;
|
|
sessionId = sessionId2;
|
|
c3017_14 = null;
|
|
};
|
|
c3017_11 = new Map();
|
|
id = null;
|
|
sessionId = null;
|
|
c3017_14 = null;
|
|
isActive = false;
|
|
class SpeakingStore extends Module589.Store {
|
|
static displayName = "SpeakingStore";
|
|
initialize() {
|
|
this.mustEmitChanges((a0) => a0.type !== "CONNECTION_OPEN" && a0.type !== "VOICE_STATE_UPDATES");
|
|
this.waitFor(ChannelStore, MediaEngineStore, RTCConnectionStore, SelectedChannelStore);
|
|
}
|
|
getSpeakingDuration(a0, a1, r5 = MediaEngineContextTypes.DEFAULT) {
|
|
const r6 = c3017_11.get(r5);
|
|
const r9 = r6 == null ? void 0 : r6.get(a0)?.since;
|
|
return r9 != null ? a1 - r9 : 0;
|
|
}
|
|
getSpeakers(r8 = MediaEngineContextTypes.DEFAULT) {
|
|
const DEFAULT = r8;
|
|
const r4 = Array;
|
|
const r12 = c3017_11.get(DEFAULT);
|
|
let r13 = r12 == null ? void 0 : r12.keys();
|
|
if (r13 == null) {
|
|
r13 = [];
|
|
}
|
|
return r4.from(r13).filter((item) => {
|
|
const VOICE = SpeakingFlags.VOICE;
|
|
const r8 = c3017_11.get(DEFAULT);
|
|
let r11 = r8 == null ? void 0 : r8.get(item)?.flags;
|
|
if (r11 == null) {
|
|
r11 = SpeakingFlags.NONE;
|
|
}
|
|
return (r11 & VOICE) === VOICE;
|
|
});
|
|
}
|
|
isSpeaking(a0, r7 = MediaEngineContextTypes.DEFAULT) {
|
|
const VOICE = SpeakingFlags.VOICE;
|
|
const r8 = c3017_11.get(r7);
|
|
let r11 = r8 == null ? void 0 : r8.get(a0)?.flags;
|
|
if (r11 == null) {
|
|
r11 = SpeakingFlags.NONE;
|
|
}
|
|
return (r11 & VOICE) === VOICE;
|
|
}
|
|
isPrioritySpeaker(a0, r7 = MediaEngineContextTypes.DEFAULT) {
|
|
const PRIORITY = SpeakingFlags.PRIORITY;
|
|
const r8 = c3017_11.get(r7);
|
|
let r11 = r8 == null ? void 0 : r8.get(a0)?.flags;
|
|
if (r11 == null) {
|
|
r11 = SpeakingFlags.NONE;
|
|
}
|
|
return (r11 & PRIORITY) === PRIORITY;
|
|
}
|
|
isSoundSharing(a0, r7 = MediaEngineContextTypes.DEFAULT) {
|
|
const SOUNDSHARE = SpeakingFlags.SOUNDSHARE;
|
|
const r8 = c3017_11.get(r7);
|
|
let r11 = r8 == null ? void 0 : r8.get(a0)?.flags;
|
|
if (r11 == null) {
|
|
r11 = SpeakingFlags.NONE;
|
|
}
|
|
return (r11 & SOUNDSHARE) === SOUNDSHARE;
|
|
}
|
|
isAnyoneElseSpeaking(r4 = MediaEngineContextTypes.DEFAULT) {
|
|
return anyoneHasFlagInContext(r4, SpeakingFlags.VOICE, true);
|
|
}
|
|
isCurrentUserSpeaking(r5 = MediaEngineContextTypes.DEFAULT) {
|
|
return id != null && this.isSpeaking(id, r5);
|
|
}
|
|
isCurrentUserPTTActive() {
|
|
return isActive;
|
|
}
|
|
isAnyonePrioritySpeaking(r4 = MediaEngineContextTypes.DEFAULT) {
|
|
return anyoneHasFlagInContext(r4, SpeakingFlags.VOICE | SpeakingFlags.PRIORITY);
|
|
}
|
|
isCurrentUserPrioritySpeaker(r5 = MediaEngineContextTypes.DEFAULT) {
|
|
return id != null && this.isPrioritySpeaker(id, r5);
|
|
}
|
|
isCurrentUserPrioritySpeaking(r5 = MediaEngineContextTypes.DEFAULT) {
|
|
return id != null && this.isPrioritySpeaker(id, r5) && this.isSpeaking(id, r5);
|
|
}
|
|
getVoiceVolume(a0, r7 = MediaEngineContextTypes.DEFAULT) {
|
|
const config = ProportionalVadIndicatorExperiment.getConfig({
|
|
location: "SpeakingStore"
|
|
});
|
|
const enabled = config.enabled;
|
|
let r15 = -Infinity;
|
|
if (enabled) {
|
|
const disableUI = config.disableUI;
|
|
r15 = -Infinity;
|
|
if (!disableUI) {
|
|
const r19 = c3017_11.get(r7);
|
|
let r20 = r19 == null ? void 0 : r19.get(a0)?.voiceDb;
|
|
if (r20 == null) {
|
|
r20 = -Infinity;
|
|
}
|
|
r15 = r20;
|
|
}
|
|
}
|
|
return r15;
|
|
}
|
|
}
|
|
const speakingStore = new SpeakingStore(Dispatcher, {
|
|
CONNECTION_OPEN: handleConnectionOpen,
|
|
OVERLAY_INITIALIZE: handleConnectionOpen,
|
|
SPEAKING: function handleSpeaking(a0) {
|
|
let r66, context, flags, userId, voiceDb;
|
|
L5: {
|
|
context = a0.context;
|
|
userId = a0.userId;
|
|
const speakingFlags = a0.speakingFlags;
|
|
voiceDb = a0.voiceDb;
|
|
const r9 = speakingFlags & SpeakingFlags.PRIORITY;
|
|
const PRIORITY = SpeakingFlags.PRIORITY;
|
|
flags = speakingFlags;
|
|
if (r9 === PRIORITY) {
|
|
const channel = ChannelStore.getChannel(SelectedChannelStore.getVoiceChannelId());
|
|
if (channel != null && can({
|
|
permission: Permissions.PRIORITY_SPEAKER,
|
|
user: userId,
|
|
context: channel
|
|
})) {
|
|
MediaEngineStore.setCanHavePriority(userId, true);
|
|
flags = speakingFlags;
|
|
break L5;
|
|
}
|
|
MediaEngineStore.setCanHavePriority(userId, false);
|
|
flags = speakingFlags & ~SpeakingFlags.PRIORITY;
|
|
}
|
|
}
|
|
if ((flags & SpeakingFlags.HIDDEN) === SpeakingFlags.HIDDEN) {
|
|
flags = 0;
|
|
}
|
|
if (voiceDb === void 0) {
|
|
voiceDb = -Infinity;
|
|
}
|
|
let r48 = context;
|
|
if (r48 === void 0) {
|
|
r48 = MediaEngineContextTypes.DEFAULT;
|
|
}
|
|
let r52 = c3017_11.get(r48);
|
|
const r54 = r48;
|
|
if (r52 == null) {
|
|
const map = new Map();
|
|
c3017_11.set(r54, map);
|
|
r52 = map;
|
|
}
|
|
const r63 = r52.get(userId);
|
|
let r65 = r63?.flags;
|
|
if (r65 == null) {
|
|
r65 = 0;
|
|
}
|
|
L31: {
|
|
if (r65 === 0) {
|
|
r66 = false;
|
|
if (flags === 0) {
|
|
break L31;
|
|
}
|
|
}
|
|
if (flags === 0) {
|
|
r52.delete(userId);
|
|
const size = r52.size;
|
|
r66 = true;
|
|
if (size === 0) {
|
|
c3017_11.delete(context);
|
|
r66 = true;
|
|
}
|
|
} else {
|
|
let since = r63?.since;
|
|
if (since == null) {
|
|
since = null;
|
|
}
|
|
const r69 = r65 & SpeakingFlags.VOICE;
|
|
const VOICE = SpeakingFlags.VOICE;
|
|
const r74 = (flags & SpeakingFlags.VOICE) === SpeakingFlags.VOICE;
|
|
if (r69 === VOICE !== r74) {
|
|
since = r74 ? Date.now() : null;
|
|
}
|
|
r52.set(userId, {
|
|
flags,
|
|
since,
|
|
voiceDb
|
|
});
|
|
r66 = true;
|
|
}
|
|
}
|
|
return r66;
|
|
},
|
|
VOICE_STATE_UPDATES: function handleVoiceStateUpdates(a0) {
|
|
return a0.voiceStates.reduce((acc, { userId, channelId, sessionId: sessionId2 }) => {
|
|
let r29, r53;
|
|
const r10 = c3017_14;
|
|
const r1 = userId === id && sessionId2 === sessionId;
|
|
let r17 = r10;
|
|
if (r1) {
|
|
let r5 = channelId;
|
|
if (r5 == null) {
|
|
r5 = null;
|
|
}
|
|
c3017_14 = r5;
|
|
r17 = r5;
|
|
}
|
|
const r7 = r10 !== r17 ? c3017_11.delete(MediaEngineContextTypes.DEFAULT) || false : false;
|
|
L37: {
|
|
if (channelId == null) {
|
|
if (userId === id && sessionId2 === sessionId) {
|
|
r53 = c3017_11.delete(MediaEngineContextTypes.DEFAULT) || r7;
|
|
} else {
|
|
const DEFAULT3 = MediaEngineContextTypes.DEFAULT;
|
|
const r51 = c3017_11.get(DEFAULT3);
|
|
const r52 = r51 == null;
|
|
r53 = false;
|
|
if (!r52) {
|
|
const r55 = r51.delete(userId);
|
|
const size2 = r51.size;
|
|
r53 = r55;
|
|
if (size2 === 0) {
|
|
c3017_11.delete(DEFAULT3);
|
|
r53 = r55;
|
|
}
|
|
}
|
|
if (!r53) {
|
|
r53 = r7;
|
|
}
|
|
}
|
|
r29 = r53;
|
|
} else {
|
|
if (userId === id && sessionId2 !== sessionId) {
|
|
r29 = c3017_11.delete(MediaEngineContextTypes.DEFAULT) || r7;
|
|
break L37;
|
|
}
|
|
const r2 = userId !== id && channelId !== RTCConnectionStore.getChannelId();
|
|
r29 = r7;
|
|
if (r2) {
|
|
const DEFAULT2 = MediaEngineContextTypes.DEFAULT;
|
|
const r32 = c3017_11.get(DEFAULT2);
|
|
const r33 = r32 == null;
|
|
let r34 = false;
|
|
if (!r33) {
|
|
const r36 = r32.delete(userId);
|
|
const size = r32.size;
|
|
r34 = r36;
|
|
if (size === 0) {
|
|
c3017_11.delete(DEFAULT2);
|
|
r34 = r36;
|
|
}
|
|
}
|
|
if (!r34) {
|
|
r34 = r7;
|
|
}
|
|
r29 = r34;
|
|
}
|
|
}
|
|
}
|
|
if (!r29) {
|
|
r29 = acc;
|
|
}
|
|
return r29;
|
|
}, false);
|
|
},
|
|
PUSH_TO_TALK_STATE_CHANGE: function handlePushToTalkStateChange(a0) {
|
|
isActive = a0.isActive;
|
|
}
|
|
});
|
|
export default speakingStore;
|