Skip to content

Commit

Permalink
Throw error from startScreenShare method if permission is denied (#…
Browse files Browse the repository at this point in the history
…1120)

* Throw error from startScreenShare method if permission is denied

* include changeset
  • Loading branch information
iAmmar7 authored Oct 2, 2024
1 parent d4a7195 commit 30fae88
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 44 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-colts-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@signalwire/js': patch
---

Throw error from `startScreenShare` method if permission is denied
2 changes: 1 addition & 1 deletion internal/playground-js/src/fabric/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
84 changes: 42 additions & 42 deletions packages/js/src/BaseRoomSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions packages/js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,5 @@ export type {
RoomSessionObjectEventsHandlerMap as RoomObjectEventsHandlerMap,
RoomSessionObjectEvents as RoomObjectEvents,
RoomEventNames,
StartScreenShareOptions,
} from './utils/interfaces'
1 change: 0 additions & 1 deletion packages/js/src/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ export type {
RoomSessionRecording,
RoomSessionPlayback,
} from '@signalwire/core'

0 comments on commit 30fae88

Please sign in to comment.