Skip to content

Commit

Permalink
Add getDisplayMedia support check
Browse files Browse the repository at this point in the history
  • Loading branch information
kilimnik committed Jan 30, 2023
1 parent bc6db81 commit d70c76d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/room/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export class ConnectionError extends LivekitError {
}
}

export class DeviceUnsupportedError extends LivekitError {
constructor(message?: string) {
super(21, message ?? 'device is unsupported');
}
}

export class TrackInvalidError extends LivekitError {
constructor(message?: string) {
super(20, message ?? 'track is invalid');
Expand Down
7 changes: 6 additions & 1 deletion src/room/participant/LocalParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TrackPublishedResponse,
TrackUnpublishedResponse,
} from '../../proto/livekit_rtc';
import { TrackInvalidError, UnexpectedConnectionState } from '../errors';
import { DeviceUnsupportedError, TrackInvalidError, UnexpectedConnectionState } from '../errors';
import { EngineEvent, ParticipantEvent, TrackEvent } from '../events';
import type RTCEngine from '../RTCEngine';
import LocalAudioTrack from '../track/LocalAudioTrack';
Expand Down Expand Up @@ -389,6 +389,11 @@ export default class LocalParticipant extends Participant {
};
}
}

if (navigator.mediaDevices.getDisplayMedia === undefined) {
throw new DeviceUnsupportedError('getDisplayMedia not supported');
}

const stream: MediaStream = await navigator.mediaDevices.getDisplayMedia({
audio: options.audio ?? false,
video: videoConstraints,
Expand Down
7 changes: 6 additions & 1 deletion src/room/track/create.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DeviceManager from '../DeviceManager';
import { TrackInvalidError } from '../errors';
import { DeviceUnsupportedError, TrackInvalidError } from '../errors';
import { mediaTrackToLocalTrack } from '../participant/publishUtils';
import { audioDefaults, videoDefaults } from '../defaults';
import LocalAudioTrack from './LocalAudioTrack';
Expand Down Expand Up @@ -114,6 +114,11 @@ export async function createLocalScreenTracks(
height: options.resolution.height,
};
}

if (navigator.mediaDevices.getDisplayMedia === undefined) {
throw new DeviceUnsupportedError('getDisplayMedia not supported');
}

// typescript definition is missing getDisplayMedia: https://github.com/microsoft/TypeScript/issues/33232
// @ts-ignore
const stream: MediaStream = await navigator.mediaDevices.getDisplayMedia({
Expand Down

0 comments on commit d70c76d

Please sign in to comment.