Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

refactor(voice-engine): drop unused runtime options and getters

Hampus91d934f1b1bb
diff --git a/packages/voice_engine_v2/src/runtime/VoiceEngineV2Runtime.ts b/packages/voice_engine_v2/src/runtime/VoiceEngineV2Runtime.ts
index 2bdf887ff..a8ec79754 100644
--- a/packages/voice_engine_v2/src/runtime/VoiceEngineV2Runtime.ts
+++ b/packages/voice_engine_v2/src/runtime/VoiceEngineV2Runtime.ts
@@ -65,23 +65,19 @@ export interface VoiceEngineV2RuntimeDiagnostic {
export type VoiceEngineV2RuntimeDiagnosticListener = (diagnostic: VoiceEngineV2RuntimeDiagnostic) => void;
-export interface VoiceEngineV2RuntimeListenerPayload {
+interface VoiceEngineV2RuntimeListenerPayload {
event: VoiceEngineV2Event;
transition: VoiceEngineV2Transition;
}
export type VoiceEngineV2RuntimeListener = (payload: VoiceEngineV2RuntimeListenerPayload) => void;
-export type VoiceEngineV2RuntimeClock = VoiceEngineV2ClockPort;
-
export interface VoiceEngineV2RuntimeOptions {
capabilities?: VoiceEngineV2Capabilities;
clock?: VoiceEngineV2ClockPort;
- eventLogCap?: number;
eventLogSpillSink: VoiceEngineV2EventLogSpillSink;
queuedCommandsCap?: number;
resourceQueuesCap?: number;
- cancelledOperationsCap?: number;
verifyEventLogInvariantsOnDispatch?: boolean;
}
@@ -107,24 +103,19 @@ export class VoiceEngineV2Runtime {
private readonly cancelledOperationIds = new Set<number>();
private readonly queuedCommandsCap: number;
private readonly resourceQueuesCap: number;
- private readonly cancelledOperationsCap: number;
private readonly verifyEventLogInvariantsOnDispatch: boolean;
private readonly coalesceCandidatesByTrack = new Map<
string,
{sequence: number; snapshotBefore: VoiceEngineV2Snapshot}
>();
private queueFullDropCount = 0;
- private coalescedEventsCountValue = 0;
constructor(
private readonly implementation: VoiceEngineV2Implementation,
options: VoiceEngineV2RuntimeOptions,
) {
this.clock = options.clock ?? createVoiceEngineV2SystemClockPort();
- const cap = options.eventLogCap ?? VOICE_ENGINE_V2_EVENT_LOG_CAP;
- assert.ok(Number.isInteger(cap), 'eventLogCap must be an integer');
- assert.ok(cap >= 1, 'eventLogCap must be >= 1');
- this.eventLogRing = new VoiceEngineV2EventLogRing(cap);
+ this.eventLogRing = new VoiceEngineV2EventLogRing(VOICE_ENGINE_V2_EVENT_LOG_CAP);
assert.ok(
options.eventLogSpillSink !== null && typeof options.eventLogSpillSink === 'object',
'eventLogSpillSink is required',
@@ -139,10 +130,6 @@ export class VoiceEngineV2Runtime {
assert.ok(Number.isInteger(resourceQueuesCap), 'resourceQueuesCap must be an integer');
assert.ok(resourceQueuesCap >= 1, 'resourceQueuesCap must be >= 1');
this.resourceQueuesCap = resourceQueuesCap;
- const cancelledOperationsCap = options.cancelledOperationsCap ?? VOICE_ENGINE_V2_CANCELLED_OPERATIONS_CAP;
- assert.ok(Number.isInteger(cancelledOperationsCap), 'cancelledOperationsCap must be an integer');
- assert.ok(cancelledOperationsCap >= 1, 'cancelledOperationsCap must be >= 1');
- this.cancelledOperationsCap = cancelledOperationsCap;
this.verifyEventLogInvariantsOnDispatch = options.verifyEventLogInvariantsOnDispatch === true;
this.snapshotValue = createVoiceEngineV2InitialSnapshot(
options.capabilities ?? availableVoiceEngineV2Capabilities(),
@@ -161,18 +148,10 @@ export class VoiceEngineV2Runtime {
return this.eventLogRing.snapshotEntries();
}
- get eventLogCap(): number {
- return this.eventLogRing.cap;
- }
-
get droppedEventsCount(): number {
return this.eventLogRing.droppedEventsCount;
}
- get evictedSequenceMin(): number | null {
- return this.eventLogRing.evictedSequenceMin;
- }
-
get commandQueue(): ReadonlyArray<VoiceEngineV2Command> {
return Array.from(this.queuedCommandsById.values());
}
@@ -185,10 +164,6 @@ export class VoiceEngineV2Runtime {
return this.queueFullDropCount;
}
- get activeResourceQueueCount(): number {
- return this.resourceQueues.size;
- }
-
getExecutingCommand(resourceKey: VoiceEngineV2ResourceKey): VoiceEngineV2Command | null {
assert.equal(typeof resourceKey, 'string', 'getExecutingCommand requires a string resourceKey');
assert.ok(resourceKey.length > 0, 'getExecutingCommand requires a non-empty resourceKey');
@@ -261,8 +236,6 @@ export class VoiceEngineV2Runtime {
event,
commands: transition.commands,
});
- this.coalescedEventsCountValue += 1;
- assert.ok(this.coalescedEventsCountValue >= 1, 'coalesced events count must stay positive after coalescing');
if (this.verifyEventLogInvariantsOnDispatch) {
this.verifyEventLogInvariants();
}
@@ -301,19 +274,6 @@ export class VoiceEngineV2Runtime {
}
}
- get coalescedEventsCount(): number {
- assert.ok(this.coalescedEventsCountValue >= 0, 'coalesced events count cannot be negative');
- return this.coalescedEventsCountValue;
- }
-
- get coalesceTrackedTracksCount(): number {
- assert.ok(
- this.coalesceCandidatesByTrack.size <= VOICE_ENGINE_V2_COALESCED_TRACKS_CAP,
- 'coalesce candidates exceeded cap',
- );
- return this.coalesceCandidatesByTrack.size;
- }
-
verifyEventLogInvariants(): void {
assertEventLogRingInvariants(this.eventLogRing);
const entries = this.eventLogRing.snapshotEntries();
@@ -457,7 +417,7 @@ export class VoiceEngineV2Runtime {
assert.ok(Number.isInteger(operationId), 'cancelOperation requires an integer operationId');
assert.ok(operationId >= 0, 'cancelOperation requires a non-negative operationId');
if (this.cancelledOperationIds.has(operationId)) return;
- if (this.cancelledOperationIds.size >= this.cancelledOperationsCap) {
+ if (this.cancelledOperationIds.size >= VOICE_ENGINE_V2_CANCELLED_OPERATIONS_CAP) {
const oldest = this.cancelledOperationIds.values().next();
assert.ok(oldest.done !== true, 'cancelledOperationIds at cap must yield an evictable id');
this.cancelledOperationIds.delete(oldest.value);
@@ -465,17 +425,16 @@ export class VoiceEngineV2Runtime {
}
this.cancelledOperationIds.add(operationId);
assert.ok(this.cancelledOperationIds.has(operationId), 'cancelledOperationIds insert postcondition');
- assert.ok(this.cancelledOperationIds.size <= this.cancelledOperationsCap, 'cancelledOperationIds exceeded cap');
+ assert.ok(
+ this.cancelledOperationIds.size <= VOICE_ENGINE_V2_CANCELLED_OPERATIONS_CAP,
+ 'cancelledOperationIds exceeded cap',
+ );
}
get cancelledOperationCount(): number {
return this.cancelledOperationIds.size;
}
- get cancelledOperationsCapacity(): number {
- return this.cancelledOperationsCap;
- }
-
private emitDiagnostic(diagnostic: VoiceEngineV2RuntimeDiagnostic): void {
assert.equal(diagnostic.kind, 'voiceEngineV2.queueFull', 'emitDiagnostic requires a known diagnostic kind');
assert.ok(diagnostic.cap >= 1, 'emitDiagnostic requires a positive cap');
@@ -491,7 +450,7 @@ export class VoiceEngineV2Runtime {
this.emitDiagnostic({
kind: 'voiceEngineV2.queueFull',
queue: 'cancelledOperations',
- cap: this.cancelledOperationsCap,
+ cap: VOICE_ENGINE_V2_CANCELLED_OPERATIONS_CAP,
droppedCommandType: queuedCommand === null ? 'operation.cancel' : queuedCommand.type,
droppedOperationId: evictedOperationId,
resourceKey: queuedCommand === null ? 'lifecycle' : getVoiceEngineV2CommandResourceKey(queuedCommand),
diff --git a/packages/voice_engine_v2/src/runtime/frameCoalescing.ts b/packages/voice_engine_v2/src/runtime/frameCoalescing.ts
index 5e09fe077..2120d3f79 100644
--- a/packages/voice_engine_v2/src/runtime/frameCoalescing.ts
+++ b/packages/voice_engine_v2/src/runtime/frameCoalescing.ts
@@ -20,22 +20,3 @@ export function canCoalesceVoiceEngineV2Events(tailEvent: VoiceEngineV2Event, ne
assert.equal(typeof nextEvent.frame.trackSid, 'string', 'next frame event must have a string trackSid');
return tailEvent.frame.trackSid === nextEvent.frame.trackSid;
}
-
-export function coalesceVoiceEngineV2EventSequence(
- events: ReadonlyArray<VoiceEngineV2Event>,
-): Array<VoiceEngineV2Event> {
- const coalesced: Array<VoiceEngineV2Event> = [];
- const limit = events.length;
- for (let index = 0; index < limit; index += 1) {
- const event = events[index];
- assert.ok(event !== undefined, 'coalesceVoiceEngineV2EventSequence must not encounter holes');
- const tail = coalesced[coalesced.length - 1];
- if (tail !== undefined && canCoalesceVoiceEngineV2Events(tail, event)) {
- coalesced[coalesced.length - 1] = event;
- } else {
- coalesced.push(event);
- }
- }
- assert.ok(coalesced.length <= events.length, 'coalescing must never grow the event sequence');
- return coalesced;
-}
diff --git a/packages/voice_engine_v2/src/runtime/platformPort.ts b/packages/voice_engine_v2/src/runtime/platformPort.ts
index d5087982b..1a4c6c6de 100644
--- a/packages/voice_engine_v2/src/runtime/platformPort.ts
+++ b/packages/voice_engine_v2/src/runtime/platformPort.ts
@@ -4,10 +4,6 @@ export interface VoiceEngineV2ClockPort {
now(): number;
}
-export interface VoiceEngineV2RandomPort {
- next(): number;
-}
-
export interface VoiceEngineV2WallClockSource {
read(): number;
}