Skip to content

Commit

Permalink
feat(video): Added audio connector (#791)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmantank authored Feb 7, 2023
1 parent 882f800 commit daa72f6
Show file tree
Hide file tree
Showing 5 changed files with 369 additions and 179 deletions.
22 changes: 22 additions & 0 deletions packages/video/__tests__/video.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,26 @@ describe('video', () => {

await client.playDTMF("2_MX40NTMyODc3Mn5-fg", "1234#", "396edda0-fc30-41fd-8e63");
});

test("can connect to a websocket", async () => {
const token = client.generateClientToken();

nock(BASE_URL, {reqheaders: {'Authorization': value => value.startsWith('Bearer ') && value.length > 10 }})
.persist()
.post('/v2/project/abcd-1234/connect', {sessionId: "2_MX40NTMyODc3Mn5-fg", token, websocket: {uri: 'wss://mydomain.com/websocket/'}})
.reply(200, {id: 'CALLID', connectionId: 'CONNECTIONID'});

const resp = await client.connectToWebsocket("2_MX40NTMyODc3Mn5-fg", token, {uri: 'wss://mydomain.com/websocket/'});
expect(resp.id).toEqual('CALLID')
expect(resp.connectionId).toEqual('CONNECTIONID')
});

test("can disconnect a websocket", async () => {
nock(BASE_URL, {reqheaders: {'Authorization': value => value.startsWith('Bearer ') && value.length > 10 }})
.persist()
.post('/v2/project/abcd-1234/connect/CALLID/stop')
.reply(200);

await client.disconnectWebsocket('CALLID');
});
});
4 changes: 4 additions & 0 deletions packages/video/lib/enums/AudioRate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum AudioRate {
"16KHZ" = 16000,
"8KHZ" = 8000
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface WebSocketConnectResponse {
id: string
connectionId: string
}
10 changes: 10 additions & 0 deletions packages/video/lib/interfaces/WebSocketConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { AudioRate } from '../enums/AudioRate';

export interface WebSocketConfig {
uri: string
streams?: string[]
headers?: {
[key: string]: string
}
audioRate?: AudioRate
}
Loading

0 comments on commit daa72f6

Please sign in to comment.