Skip to content

Commit

Permalink
fix: device api small fixes (#970)
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz authored Aug 23, 2023
1 parent 7495757 commit 15b09fd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
16 changes: 10 additions & 6 deletions packages/client/src/Call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,12 @@ export class Call {

// React uses a different device management for now
if (getSdkInfo()?.type !== SdkType.REACT) {
this.initCamera();
this.initMic();
try {
await this.initCamera();
await this.initMic();
} catch (error) {
this.logger('warn', 'Camera and/or mic init failed during join call');
}
}

// 3. once we have the "joinResponse", and possibly reconciled the local state
Expand Down Expand Up @@ -1713,7 +1717,7 @@ export class Call {
);
};

private initCamera() {
private async initCamera() {
if (
this.state.localParticipant?.videoStream ||
!this.permissionsContext.hasPermission('send-video')
Expand Down Expand Up @@ -1747,11 +1751,11 @@ export class Call {
this.camera.state.status === undefined &&
this.state.settings?.video.camera_default_on
) {
void this.camera.enable();
await this.camera.enable();
}
}

private initMic() {
private async initMic() {
if (
this.state.localParticipant?.audioStream ||
!this.permissionsContext.hasPermission('send-audio')
Expand All @@ -1776,7 +1780,7 @@ export class Call {
this.microphone.state.status === undefined &&
this.state.settings?.audio.mic_default_on
) {
void this.microphone.enable();
await this.microphone.enable();
}
}
}
2 changes: 1 addition & 1 deletion packages/client/src/devices/InputMediaDeviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export abstract class InputMediaDeviceManager<
* @returns
*/
async disable() {
this.state.prevStatus = this.state.status;
if (this.state.status === 'disabled') {
return;
}
this.state.prevStatus = this.state.status;
await this.muteStream(this.state.disableMode === 'stop-tracks');
this.state.setStatus('disabled');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,23 @@ describe('InputMediaDeviceManager.test', () => {
expect(manager.enable).not.toHaveBeenCalled();
});

it(`shouldn't resume if it were disabled while in pause`, async () => {
vi.spyOn(manager, 'enable');

await manager.enable();

expect(manager.enable).toHaveBeenCalledOnce();

// first call is pause
await manager.disable();
// second call is for example mute from call admin
await manager.disable();

await manager.resume();

expect(manager.enable).toHaveBeenCalledOnce();
});

afterEach(() => {
vi.clearAllMocks();
vi.resetModules();
Expand Down

0 comments on commit 15b09fd

Please sign in to comment.