Skip to content

Commit

Permalink
fix(video): Added SIP and DTMF playing (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmantank authored Dec 16, 2022
1 parent 15503f9 commit 727027e
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 172 deletions.
48 changes: 47 additions & 1 deletion packages/video/__tests__/video.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MediaMode } from '../lib/interfaces/MediaMode';
import { ArchiveMode } from '../lib/interfaces/ArchiveMode';
import { Auth } from '@vonage/auth';

export const BASE_URL = 'https://video.api.vonage.com/'.replace(/\/+$/, '');
const BASE_URL = 'https://video.api.vonage.com/'.replace(/\/+$/, '');

describe('video', () => {
let client;
Expand Down Expand Up @@ -534,4 +534,50 @@ describe('video', () => {

await client.setStreamClassLists('sess-1234', [{id: 'stream-1234', layoutClassList: ["full"]}]);
});

test("can initiate a SIP call", async () => {
const options = {
token: client.generateClientToken(),
sip: {
uri: 'sip:[email protected];transport=tls'
}
}

const expectedResponse = {
id: "b0a5a8c7-dc38-459f-a48d-a7f2008da853",
connectionId: "e9f8c166-6c67-440d-994a-04fb6dfed007",
streamId: "482bce73-f882-40fd-8ca5-cb74ff416036",
};

const expectedBody = Object.assign({}, { sessionId: "2_MX40NTMyODc3Mn5-fg" }, options);

nock(BASE_URL, {reqheaders: {'Authorization': value => value.startsWith('Bearer ') && value.length > 10 }})
.persist()
.post('/v2/project/abcd-1234/dial', expectedBody)
.reply(200, expectedResponse);

const resp = await client.intiateSIPCall("2_MX40NTMyODc3Mn5-fg", options);

expect(resp.id).toEqual(expectedResponse.id);
expect(resp.connectionId).toEqual(expectedResponse.connectionId);
expect(resp.streamId).toEqual(expectedResponse.streamId);
});

test("can play DTMF digits to everyone", async () => {
nock(BASE_URL, {reqheaders: {'Authorization': value => value.startsWith('Bearer ') && value.length > 10 }})
.persist()
.post('/v2/project/abcd-1234/session/2_MX40NTMyODc3Mn5-fg/play-dtmf', { digits: '1234#'})
.reply(200);

await client.playDTMF("2_MX40NTMyODc3Mn5-fg", "1234#");
});

test("can play DTMF digits into one connection", async () => {
nock(BASE_URL, {reqheaders: {'Authorization': value => value.startsWith('Bearer ') && value.length > 10 }})
.persist()
.post('/v2/project/abcd-1234/session/2_MX40NTMyODc3Mn5-fg/connection/396edda0-fc30-41fd-8e63/play-dtmf', {digits: "1234#"})
.reply(200);

await client.playDTMF("2_MX40NTMyODc3Mn5-fg", "1234#", "396edda0-fc30-41fd-8e63");
});
});
1 change: 1 addition & 0 deletions packages/video/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { Video } from './video';
export { SIPCallOptions } from './interfaces/SIPCallOptions';
5 changes: 5 additions & 0 deletions packages/video/lib/interfaces/Response/SIPCallResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface SIPCallResponse {
id: string;
connectionId: string;
streamId: string;
}
17 changes: 17 additions & 0 deletions packages/video/lib/interfaces/SIPCallOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface SIPCallOptions {
token: string;
sip: {
uri: string;
from?: string;
headers?: {
[key: string]: string;
},
auth?: {
username: string;
password: string;
}
secure?: boolean;
video?: boolean;
observeForceMute?: boolean;
}
}
2 changes: 1 addition & 1 deletion packages/video/lib/interfaces/VideoResponse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { VetchResponse } from '@vonage/vetch';

export interface VideoResponse<T> extends VetchResponse<T> {}
export type VideoResponse<T> = VetchResponse<T>
Loading

0 comments on commit 727027e

Please sign in to comment.