Skip to content

Commit

Permalink
Make sure metadata check is async (#1187)
Browse files Browse the repository at this point in the history
* Make sure metadata check is async

* use proper error objects for rejection

* more generic signal error
  • Loading branch information
lukasIO authored Jul 11, 2024
1 parent 8a5cbed commit c3104bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/room/errors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ErrorResponse_Reason } from '@livekit/protocol';

export class LivekitError extends Error {
code: number;

Expand Down Expand Up @@ -63,6 +65,15 @@ export class PublishDataError extends LivekitError {
}
}

export class SignalRequestError extends LivekitError {
reason: ErrorResponse_Reason;

constructor(message: string, reason: ErrorResponse_Reason = ErrorResponse_Reason.UNKNOWN) {
super(15, message);
this.reason = reason;
}
}

export enum MediaDeviceFailure {
// user rejected permissions
PermissionDenied = 'PermissionDenied',
Expand Down
22 changes: 14 additions & 8 deletions src/room/participant/LocalParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ import type { InternalRoomOptions } from '../../options';
import { PCTransportState } from '../PCTransportManager';
import type RTCEngine from '../RTCEngine';
import { defaultVideoCodec } from '../defaults';
import { DeviceUnsupportedError, TrackInvalidError, UnexpectedConnectionState } from '../errors';
import {
DeviceUnsupportedError,
LivekitError,
SignalRequestError,
TrackInvalidError,
UnexpectedConnectionState,
} from '../errors';
import { EngineEvent, ParticipantEvent, TrackEvent } from '../events';
import LocalAudioTrack from '../track/LocalAudioTrack';
import LocalTrack from '../track/LocalTrack';
Expand Down Expand Up @@ -98,7 +104,7 @@ export default class LocalParticipant extends Participant {
number,
{
resolve: (arg: any) => void;
reject: (reason: any) => void;
reject: (reason: LivekitError) => void;
values: Partial<Record<keyof LocalParticipant, any>>;
}
>;
Expand Down Expand Up @@ -198,7 +204,7 @@ export default class LocalParticipant extends Participant {
const { requestId, reason, message } = error;
const failedRequest = this.pendingSignalRequests.get(requestId);
if (failedRequest) {
failedRequest.reject({ reason, message });
failedRequest.reject(new SignalRequestError(message, reason));
this.pendingSignalRequests.delete(requestId);
}
};
Expand Down Expand Up @@ -253,8 +259,8 @@ export default class LocalParticipant extends Participant {
const startTime = performance.now();
this.pendingSignalRequests.set(requestId, {
resolve,
reject: (reason: any) => {
reject(reason);
reject: (error: LivekitError) => {
reject(error);
isRejected = true;
},
values: { name, metadata, attributes },
Expand All @@ -270,11 +276,11 @@ export default class LocalParticipant extends Participant {
resolve();
return;
}
sleep(50);
await sleep(50);
}
reject({ reason: 'TIMEOUT', message: 'Request to update local metadata timed out' });
reject(new SignalRequestError('Request to update local metadata timed out'));
} catch (e: any) {
if (e instanceof Error) reject({ reason: e.name, message: e.message });
if (e instanceof Error) reject(e);
}
});
}
Expand Down

0 comments on commit c3104bc

Please sign in to comment.