Skip to content

Commit c2b754e

Browse files
authored
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
1 parent d257907 commit c2b754e

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

.changeset/serious-queens-suffer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@signalwire/js': patch
3+
---
4+
5+
CF SDK: Allow user to set the negotiate audio/video param

internal/e2e-js/tests/callfabric/videoRoom.spec.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ test.describe('CallFabric VideoRoom', () => {
9292
})
9393
})
9494

95-
Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(resolve)
95+
Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(
96+
resolve
97+
)
9698
})
9799

98100
const memberUpdatedUnmuted = new Promise((resolve) => {
@@ -118,7 +120,9 @@ test.describe('CallFabric VideoRoom', () => {
118120
})
119121
})
120122

121-
Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(resolve)
123+
Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(
124+
resolve
125+
)
122126
})
123127

124128
await roomObj.audioMute()
@@ -148,7 +152,7 @@ test.describe('CallFabric VideoRoom', () => {
148152
res(true)
149153
}
150154
})
151-
});
155+
})
152156
const memberUpdatedMutedEvent = new Promise((res) => {
153157
roomObj.on('member.updated.video_muted', (params) => {
154158
if (
@@ -159,9 +163,11 @@ test.describe('CallFabric VideoRoom', () => {
159163
res(true)
160164
}
161165
})
162-
});
166+
})
163167

164-
Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(resolve)
168+
Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(
169+
resolve
170+
)
165171
})
166172

167173
const memberUpdatedUnmuted = new Promise((resolve) => {
@@ -190,7 +196,9 @@ test.describe('CallFabric VideoRoom', () => {
190196
})
191197
})
192198

193-
Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(resolve)
199+
Promise.all([memberUpdatedEvent, memberUpdatedMutedEvent]).then(
200+
resolve
201+
)
194202
})
195203

196204
await roomObj.videoMute()
@@ -461,10 +469,16 @@ test.describe('CallFabric VideoRoom', () => {
461469
)
462470
).toBeTruthy()
463471

472+
// There should be no inbound/outbound video
464473
const stats = await getStats(page)
465-
466474
expect(stats.outboundRTP).not.toHaveProperty('video')
475+
expect(stats.inboundRTP).not.toHaveProperty('video')
467476

477+
// There should be audio packets
468478
expect(stats.inboundRTP.audio.packetsReceived).toBeGreaterThan(0)
479+
480+
// There should be no MCU either
481+
const videoElement = await page.$('div[id^="sw-sdk-"] > video')
482+
expect(videoElement).toBeNull()
469483
})
470484
})

packages/js/src/fabric/WSClient.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ type BuildRoomParams = Omit<DialParams, 'to'> & {
2020
nodeId?: string
2121
sdp?: string
2222
to?: string
23-
};
23+
}
24+
2425
export class WSClient {
2526
private wsClient: Client
2627
private logger = getLogger()
@@ -84,21 +85,23 @@ export class WSClient {
8485
const { to, callID, nodeId, sdp } = params
8586

8687
let video = params.video ?? true
88+
let negotiateVideo = params.negotiateAudio ?? true
8789

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

9294
if (result && result.groups?.channel === 'audio') {
9395
video = false
96+
negotiateVideo = false
9497
}
9598
}
9699

97100
const call = this.wsClient.makeCallFabricObject({
98101
audio: params.audio ?? true,
99102
video,
100-
negotiateAudio: true,
101-
negotiateVideo: true,
103+
negotiateAudio: params.negotiateAudio ?? true,
104+
negotiateVideo: negotiateVideo,
102105
rootElement: params.rootElement || this.options.rootElement,
103106
applyLocalVideoOverlay: true,
104107
stopCameraWhileMuted: true,

packages/js/src/fabric/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ export interface CallParams {
7171
audio?: MediaStreamConstraints['audio']
7272
/** Video constraints to use when joining the room. Default: `true`. */
7373
video?: MediaStreamConstraints['video']
74+
/** Negotiate the incoming audio from the RTC. Default: `true`. */
75+
negotiateAudio?: boolean
76+
/** Negotiate the incoming video from the RTC. Default: `true`. */
77+
negotiateVideo?: boolean
7478
/** User & UserAgent metadata */
7579
userVariables?: WSClientOptions['userVariables']
7680
}

0 commit comments

Comments
 (0)