Skip to content

Commit

Permalink
Fix safari 16 screen share (#494)
Browse files Browse the repository at this point in the history
* fix safari 16 screen share

* changeset
  • Loading branch information
lukasIO committed Oct 26, 2022
1 parent e1a0a7e commit 00dbd21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/tricky-eggs-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Fix safari v16 screen share
23 changes: 15 additions & 8 deletions src/room/participant/LocalParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
} from '../track/options';
import { Track } from '../track/Track';
import { constraintsForOptions, mergeDefaultOptions } from '../track/utils';
import { isFireFox, isWeb, supportsAV1 } from '../utils';
import { isFireFox, isSafari, isWeb, supportsAV1 } from '../utils';
import Participant from './Participant';
import { ParticipantTrackPermission, trackPermissionToProto } from './ParticipantTrackPermission';
import {
Expand Down Expand Up @@ -243,6 +243,7 @@ export default class LocalParticipant extends Participant {
}
const publishPromises: Array<Promise<LocalTrackPublication>> = [];
for (const localTrack of localTracks) {
log.info('publishing track', { localTrack });
publishPromises.push(this.publishTrack(localTrack, publishOptions));
}
const publishedTracks = await Promise.all(publishPromises);
Expand Down Expand Up @@ -374,14 +375,20 @@ export default class LocalParticipant extends Participant {

let videoConstraints: MediaTrackConstraints | boolean = true;
if (options.resolution) {
videoConstraints = {
width: options.resolution.width,
height: options.resolution.height,
frameRate: options.resolution.frameRate,
};
if (isSafari()) {
videoConstraints = {
width: { max: options.resolution.width },
height: { max: options.resolution.height },
frameRate: options.resolution.frameRate,
};
} else {
videoConstraints = {
width: { ideal: options.resolution.width },
height: { ideal: options.resolution.height },
frameRate: options.resolution.frameRate,
};
}
}
// typescript definition is missing getDisplayMedia: https://github.com/microsoft/TypeScript/issues/33232
// @ts-ignore
const stream: MediaStream = await navigator.mediaDevices.getDisplayMedia({
audio: options.audio ?? false,
video: videoConstraints,
Expand Down

0 comments on commit 00dbd21

Please sign in to comment.