From c2b754e54fbbefcb38606015bec8709554265e04 Mon Sep 17 00:00:00 2001 From: Ammar Ansari Date: Fri, 9 Aug 2024 16:42:36 +0200 Subject: [PATCH] Allow user to set the negotiate audio/video param (#1106) * Allow user to set the negotiate audio/video param * update comment * include the changeset * not negotiate video for audio only call * remove wrong test * include e2e test * remove only --- .changeset/serious-queens-suffer.md | 5 ++++ .../e2e-js/tests/callfabric/videoRoom.spec.ts | 28 ++++++++++++++----- packages/js/src/fabric/WSClient.ts | 9 ++++-- packages/js/src/fabric/types.ts | 4 +++ 4 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 .changeset/serious-queens-suffer.md diff --git a/.changeset/serious-queens-suffer.md b/.changeset/serious-queens-suffer.md new file mode 100644 index 000000000..3bafbd718 --- /dev/null +++ b/.changeset/serious-queens-suffer.md @@ -0,0 +1,5 @@ +--- +'@signalwire/js': patch +--- + +CF SDK: Allow user to set the negotiate audio/video param diff --git a/internal/e2e-js/tests/callfabric/videoRoom.spec.ts b/internal/e2e-js/tests/callfabric/videoRoom.spec.ts index 21eb50f7d..4b75902e0 100644 --- a/internal/e2e-js/tests/callfabric/videoRoom.spec.ts +++ b/internal/e2e-js/tests/callfabric/videoRoom.spec.ts @@ -92,7 +92,9 @@ test.describe('CallFabric VideoRoom', () => { }) }) - Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(resolve) + Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then( + resolve + ) }) const memberUpdatedUnmuted = new Promise((resolve) => { @@ -118,7 +120,9 @@ test.describe('CallFabric VideoRoom', () => { }) }) - Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(resolve) + Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then( + resolve + ) }) await roomObj.audioMute() @@ -148,7 +152,7 @@ test.describe('CallFabric VideoRoom', () => { res(true) } }) - }); + }) const memberUpdatedMutedEvent = new Promise((res) => { roomObj.on('member.updated.video_muted', (params) => { if ( @@ -159,9 +163,11 @@ test.describe('CallFabric VideoRoom', () => { res(true) } }) - }); + }) - Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(resolve) + Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then( + resolve + ) }) const memberUpdatedUnmuted = new Promise((resolve) => { @@ -190,7 +196,9 @@ test.describe('CallFabric VideoRoom', () => { }) }) - Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(resolve) + Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then( + resolve + ) }) await roomObj.videoMute() @@ -461,10 +469,16 @@ test.describe('CallFabric VideoRoom', () => { ) ).toBeTruthy() + // There should be no inbound/outbound video const stats = await getStats(page) - expect(stats.outboundRTP).not.toHaveProperty('video') + expect(stats.inboundRTP).not.toHaveProperty('video') + // There should be audio packets expect(stats.inboundRTP.audio.packetsReceived).toBeGreaterThan(0) + + // There should be no MCU either + const videoElement = await page.$('div[id^="sw-sdk-"] > video') + expect(videoElement).toBeNull() }) }) diff --git a/packages/js/src/fabric/WSClient.ts b/packages/js/src/fabric/WSClient.ts index 778f18a47..61f88595e 100644 --- a/packages/js/src/fabric/WSClient.ts +++ b/packages/js/src/fabric/WSClient.ts @@ -20,7 +20,8 @@ type BuildRoomParams = Omit & { nodeId?: string sdp?: string to?: string -}; +} + export class WSClient { private wsClient: Client private logger = getLogger() @@ -84,6 +85,7 @@ export class WSClient { const { to, callID, nodeId, sdp } = params let video = params.video ?? true + let negotiateVideo = params.negotiateAudio ?? true if (to) { const channelRegex = /\?channel\=(?(audio|video))/ @@ -91,14 +93,15 @@ export class WSClient { if (result && result.groups?.channel === 'audio') { video = false + negotiateVideo = false } } const call = this.wsClient.makeCallFabricObject({ audio: params.audio ?? true, video, - negotiateAudio: true, - negotiateVideo: true, + negotiateAudio: params.negotiateAudio ?? true, + negotiateVideo: negotiateVideo, rootElement: params.rootElement || this.options.rootElement, applyLocalVideoOverlay: true, stopCameraWhileMuted: true, diff --git a/packages/js/src/fabric/types.ts b/packages/js/src/fabric/types.ts index a0af8f80a..8a2c18096 100644 --- a/packages/js/src/fabric/types.ts +++ b/packages/js/src/fabric/types.ts @@ -71,6 +71,10 @@ export interface CallParams { audio?: MediaStreamConstraints['audio'] /** Video constraints to use when joining the room. Default: `true`. */ video?: MediaStreamConstraints['video'] + /** Negotiate the incoming audio from the RTC. Default: `true`. */ + negotiateAudio?: boolean + /** Negotiate the incoming video from the RTC. Default: `true`. */ + negotiateVideo?: boolean /** User & UserAgent metadata */ userVariables?: WSClientOptions['userVariables'] }