From 30fae885d5132be6ac697b725b5d630daf69a391 Mon Sep 17 00:00:00 2001 From: Ammar Ansari Date: Wed, 2 Oct 2024 20:41:39 +0500 Subject: [PATCH] Throw error from `startScreenShare` method if permission is denied (#1120) * Throw error from startScreenShare method if permission is denied * include changeset --- .changeset/lazy-colts-hang.md | 5 ++ internal/playground-js/src/fabric/index.js | 2 +- packages/js/src/BaseRoomSession.ts | 84 +++++++++++----------- packages/js/src/index.ts | 1 + packages/js/src/video.ts | 1 - 5 files changed, 49 insertions(+), 44 deletions(-) create mode 100644 .changeset/lazy-colts-hang.md diff --git a/.changeset/lazy-colts-hang.md b/.changeset/lazy-colts-hang.md new file mode 100644 index 000000000..4f1c57df6 --- /dev/null +++ b/.changeset/lazy-colts-hang.md @@ -0,0 +1,5 @@ +--- +'@signalwire/js': patch +--- + +Throw error from `startScreenShare` method if permission is denied diff --git a/internal/playground-js/src/fabric/index.js b/internal/playground-js/src/fabric/index.js index 4a62f254f..6d4b21184 100644 --- a/internal/playground-js/src/fabric/index.js +++ b/internal/playground-js/src/fabric/index.js @@ -232,7 +232,7 @@ async function getClient() { /** * Connect with Relay creating a client and attaching all the event handler. */ -window.connect = async ({ reattach = false }) => { +window.connect = async ({ reattach = false } = {}) => { const client = await getClient() window.__client = client diff --git a/packages/js/src/BaseRoomSession.ts b/packages/js/src/BaseRoomSession.ts index b33e334bb..4bc28b1e4 100644 --- a/packages/js/src/BaseRoomSession.ts +++ b/packages/js/src/BaseRoomSession.ts @@ -146,52 +146,52 @@ export class RoomSessionConnection layout, positions, } = opts - const displayStream: MediaStream = await getDisplayMedia({ - audio: audio === true ? SCREENSHARE_AUDIO_CONSTRAINTS : audio, - video, - }) - const options: BaseConnectionOptions = { - ...this.options, - screenShare: true, - recoverCall: false, - localStream: displayStream, - remoteStream: undefined, - userVariables: { - ...(this.options?.userVariables || {}), - memberCallId: this.callId, - memberId: this.memberId, - }, - layout, - positions, - } - - const screenShare = connect< - RoomSessionScreenShareEvents, - RoomSessionScreenShareConnection, - RoomSessionScreenShare - >({ - store: this.store, - Component: RoomSessionScreenShareAPI, - })(options) + try { + const displayStream: MediaStream = await getDisplayMedia({ + audio: audio === true ? SCREENSHARE_AUDIO_CONSTRAINTS : audio, + video, + }) + const options: BaseConnectionOptions = { + ...this.options, + screenShare: true, + recoverCall: false, + localStream: displayStream, + remoteStream: undefined, + userVariables: { + ...(this.options?.userVariables || {}), + memberCallId: this.callId, + memberId: this.memberId, + }, + layout, + positions, + } - /** - * Hangup if the user stop the screenShare from the - * native browser button or if the videoTrack ends. - */ - displayStream.getVideoTracks().forEach((t) => { - t.addEventListener('ended', () => { - if (screenShare && screenShare.active) { - screenShare.leave() - } + const screenShare = connect< + RoomSessionScreenShareEvents, + RoomSessionScreenShareConnection, + RoomSessionScreenShare + >({ + store: this.store, + Component: RoomSessionScreenShareAPI, + })(options) + + /** + * Hangup if the user stop the screenShare from the + * native browser button or if the videoTrack ends. + */ + displayStream.getVideoTracks().forEach((t) => { + t.addEventListener('ended', () => { + if (screenShare && screenShare.active) { + screenShare.leave() + } + }) }) - }) - screenShare.once('destroy', () => { - screenShare.emit('room.left') - this._screenShareList.delete(screenShare) - }) + screenShare.once('destroy', () => { + screenShare.emit('room.left') + this._screenShareList.delete(screenShare) + }) - try { screenShare.runWorker('childMemberJoinedWorker', { worker: workers.childMemberJoinedWorker, onDone: () => resolve(screenShare), diff --git a/packages/js/src/index.ts b/packages/js/src/index.ts index f300450d2..8c63c8824 100644 --- a/packages/js/src/index.ts +++ b/packages/js/src/index.ts @@ -118,4 +118,5 @@ export type { RoomSessionObjectEventsHandlerMap as RoomObjectEventsHandlerMap, RoomSessionObjectEvents as RoomObjectEvents, RoomEventNames, + StartScreenShareOptions, } from './utils/interfaces' diff --git a/packages/js/src/video.ts b/packages/js/src/video.ts index 32e6aaaed..721d0119f 100644 --- a/packages/js/src/video.ts +++ b/packages/js/src/video.ts @@ -42,4 +42,3 @@ export type { RoomSessionRecording, RoomSessionPlayback, } from '@signalwire/core' -