Skip to content

Commit

Permalink
CF: parse to params for channel in dial (#1058)
Browse files Browse the repository at this point in the history
* parse  param in CF dial request and negotiate audio/video accordingly

* changeset added

* tests added

* changeset updated

* test description updated

* removed unused import

* applyLocalVideoOverLay: true and removed  mute test

* negotiateVideo: true

* moved tests into videoRoom.spec.ts

* fix tests after negotiateVideo: true

---------

Co-authored-by: Aye Min Aung <[email protected]>
  • Loading branch information
ayeminag and Aye Min Aung authored May 28, 2024
1 parent dd0c693 commit 1ff7424
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/odd-chairs-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@signalwire/js': patch
---

- Parse `to` parameter in `dial` request to detect `channel=audio|video` and negotiate media accordingly.
- Added e2e test
50 changes: 50 additions & 0 deletions internal/e2e-js/tests/callfabric/videoRoom.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
createCFClient,
expectLayoutChanged,
expectMCUVisible,
getStats,
setLayoutOnPage,
} from '../../utils'

Expand Down Expand Up @@ -265,4 +266,53 @@ test.describe('CallFabric VideoRoom', () => {

expect(roomSession.success).toBe(false)
})

test('should handle joining a room with audio channel only', async ({
createCustomPage,
}) => {
const page = await createCustomPage({ name: '[page]' })
await page.goto(SERVER_URL)

const roomName = 'cf-e2e-test-room'

await createCFClient(page)

// Dial an address with audio only channel
const roomSession = await page.evaluate(
async ({ roomName }) => {
return new Promise<any>(async (resolve, _reject) => {
// @ts-expect-error
const client = window._client

const call = await client.dial({
to: `/public/${roomName}?channel=audio`,
rootElement: document.getElementById('rootElement'),
})

call.on('room.joined', resolve)
call.on('room.updated', () => {})

// @ts-expect-error
window._roomObj = call

await call.start()
})
},
{ roomName }
)

expect(roomSession.room_session).toBeDefined()
expect(
roomSession.room_session.members.some(
(member: any) => member.member_id === roomSession.member_id
)
).toBeTruthy()


const stats = await getStats(page)

expect(stats.outboundRTP).not.toHaveProperty('video')

expect(stats.inboundRTP.audio.packetsReceived).toBeGreaterThan(0)
})
})
12 changes: 11 additions & 1 deletion packages/js/src/fabric/WSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,19 @@ export class WSClient {
return new Promise<CallFabricRoomSession>(async (resolve, reject) => {
try {
await this.connect()

const { to } = params

const channelRegex = /\?channel\=(?<channel>(audio|video))/
const result = channelRegex.exec(to)
let video = params.video ?? true
if (result && result.groups?.channel === 'audio') {
video = false
}

const call = this.wsClient.makeCallFabricObject({
audio: params.audio ?? true,
video: params.video ?? true,
video,
negotiateAudio: true,
negotiateVideo: true,
// iceServers,
Expand Down

0 comments on commit 1ff7424

Please sign in to comment.