Skip to content

Commit

Permalink
ugly, hyper-specific TS fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO committed May 17, 2024
1 parent cb62d72 commit 42b8381
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/room/RTCEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
TrackUnpublishedResponse,
Transcription,
UpdateSubscription,
UserPacket,
} from '@livekit/protocol';
import { EventEmitter } from 'events';
import type { MediaAttributes } from 'sdp-transform';
Expand Down Expand Up @@ -650,8 +651,8 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
} else {
if (dp.value?.case === 'user') {
// compatibility
compatString(dp, dp.value.value, 'participantIdentity');
compatArray(dp, dp.value.value, 'destinationIdentities');
applyParticipantIdentityCompat(dp, dp.value.value);
applyDestinationCompat(dp, dp.value.value);
}
this.emit(EngineEvent.DataPacketReceived, dp);
}
Expand Down Expand Up @@ -1418,11 +1419,11 @@ function supportOptionalDatachannel(protocol: number | undefined): boolean {
return protocol !== undefined && protocol > 13;
}

interface PartialStringObj {
[key: string]: string | undefined;
}

function compatString(newObj: PartialStringObj, oldObj: PartialStringObj, name: string) {
function applyParticipantIdentityCompat(
newObj: DataPacket,
oldObj: UserPacket,
name: 'participantIdentity' = 'participantIdentity',
) {
if (newObj[name] === '' && oldObj[name] !== '') {
newObj[name] = oldObj[name];
}
Expand All @@ -1431,11 +1432,11 @@ function compatString(newObj: PartialStringObj, oldObj: PartialStringObj, name:
}
}

interface PartialArrayObj {
[key: string]: any[] | undefined;
}

function compatArray(newObj: PartialArrayObj, oldObj: PartialArrayObj, name: string) {
function applyDestinationCompat(
newObj: DataPacket,
oldObj: UserPacket,
name: 'destinationIdentities' = 'destinationIdentities',
) {
if (newObj[name]?.length === 0 && oldObj[name]?.length !== 0) {
newObj[name] = oldObj[name];
}
Expand Down

0 comments on commit 42b8381

Please sign in to comment.