Skip to content

Commit

Permalink
Allow user to set the negotiate audio/video param (#1106)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
iAmmar7 authored Aug 9, 2024
1 parent d257907 commit c2b754e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-queens-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@signalwire/js': patch
---

CF SDK: Allow user to set the negotiate audio/video param
28 changes: 21 additions & 7 deletions internal/e2e-js/tests/callfabric/videoRoom.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -118,7 +120,9 @@ test.describe('CallFabric VideoRoom', () => {
})
})

Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(resolve)
Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(
resolve
)
})

await roomObj.audioMute()
Expand Down Expand Up @@ -148,7 +152,7 @@ test.describe('CallFabric VideoRoom', () => {
res(true)
}
})
});
})
const memberUpdatedMutedEvent = new Promise((res) => {
roomObj.on('member.updated.video_muted', (params) => {
if (
Expand All @@ -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) => {
Expand Down Expand Up @@ -190,7 +196,9 @@ test.describe('CallFabric VideoRoom', () => {
})
})

Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(resolve)
Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(
resolve
)
})

await roomObj.videoMute()
Expand Down Expand Up @@ -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()
})
})
9 changes: 6 additions & 3 deletions packages/js/src/fabric/WSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type BuildRoomParams = Omit<DialParams, 'to'> & {
nodeId?: string
sdp?: string
to?: string
};
}

export class WSClient {
private wsClient: Client
private logger = getLogger()
Expand Down Expand Up @@ -84,21 +85,23 @@ export class WSClient {
const { to, callID, nodeId, sdp } = params

let video = params.video ?? true
let negotiateVideo = params.negotiateAudio ?? true

if (to) {
const channelRegex = /\?channel\=(?<channel>(audio|video))/
const result = channelRegex.exec(to)

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,
Expand Down
4 changes: 4 additions & 0 deletions packages/js/src/fabric/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
Expand Down

0 comments on commit c2b754e

Please sign in to comment.