Skip to content

Commit

Permalink
Merge branch 'send-client-id-if-set-yle' into temp-yle-2
Browse files Browse the repository at this point in the history
  • Loading branch information
ylecuyer committed Aug 8, 2024
2 parents d6feaf2 + b922b70 commit 6f33e82
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 16 deletions.
12 changes: 10 additions & 2 deletions demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ $(() => {
}

function register(data) {
webPhone = new WebPhone(data, {
const webPhoneConfig: any = {
enableDscp: true,
clientId: localStorage.getItem('webPhoneclientId')!,
audioHelper: {
Expand All @@ -150,7 +150,15 @@ $(() => {
},
enableQos: true,
enableMediaReportLogging: true,
});
};

// check page query params for skipClientId and remove from config if found
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('skipClientId')) {
delete webPhoneConfig.clientId;
}

webPhone = new WebPhone(data, webPhoneConfig);
global.webPhone = webPhone; // for debugging

webPhone.userAgent.audioHelper.setVolume(0.3);
Expand Down
1 change: 0 additions & 1 deletion docs/index.9050f078.js.map

This file was deleted.

4 changes: 2 additions & 2 deletions docs/index.9050f078.js → docs/index.d04c129e.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/index.d04c129e.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html><html><head><script type="module" src="index.ff75d985.js"></script><link rel="stylesheet" href="index.f01e0bc4.css"><script type="module" src="index.runtime.42757dfb.js"></script><link rel="icon shortcut" href="favicon.4a73512e.png"><title>RingCentral WebPhone Demo</title></head><body> <div class="container"> <h1>RingCentral WebPhone Demo</h1> <div id="app"></div> </div> <video id="remoteVideo" hidden></video> <video id="localVideo" hidden muted></video> <script type="text/html" id="template-incoming">
<!doctype html><html><head><script type="module" src="index.ff75d985.js"></script><link rel="stylesheet" href="index.f01e0bc4.css"><script type="module" src="index.runtime.c3875ba5.js"></script><link rel="icon shortcut" href="favicon.4a73512e.png"><title>RingCentral WebPhone Demo</title></head><body> <div class="container"> <h1>RingCentral WebPhone Demo</h1> <div id="app"></div> </div> <video id="remoteVideo" hidden></video> <video id="localVideo" hidden muted></video> <script type="text/html" id="template-incoming">
<div class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
Expand Down Expand Up @@ -179,4 +179,4 @@ <h4 class="modal-title">
</div>
</div>
</div>
</script> <script type="module" src="index.9050f078.js"></script> </body></html>
</script> <script type="module" src="index.d04c129e.js"></script> </body></html>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-prettier": "^5.1.3",
"events": "^3.3.0",
"fix-esm": "^1.0.1",
"http-server": "^14.1.1",
"jest": "^29.7.0",
"jquery": "^3.7.1",
Expand Down
5 changes: 4 additions & 1 deletion src/userAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ export function createWebPhoneUserAgent(
userAgent.addListener = eventEmitter.addListener.bind(eventEmitter);
userAgent.removeListener = eventEmitter.removeListener.bind(eventEmitter);
userAgent.removeAllListeners = eventEmitter.removeAllListeners.bind(eventEmitter);
userAgent.defaultHeaders = [`P-rc-endpoint-id: ${id}`, `Client-id: ${options.clientId}`];
userAgent.defaultHeaders = [`P-rc-endpoint-id: ${id}`];
if (typeof options.clientId !== 'undefined') {
userAgent.defaultHeaders.push(`Client-id: ${options.clientId}`);
}
userAgent.regId = options.regId;
userAgent.media = {};
userAgent.enableQos = options.enableQos;
Expand Down
77 changes: 73 additions & 4 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
import type { BrowserContext } from '@playwright/test';
import { expect, test } from '@playwright/test';
import RingCentral from '@rc-ex/core';
const sip = require('fix-esm').require('sip.js'); // eslint-disable-line
const log = new sip.Core.LoggerFactory();
const logger = log.getLogger('test.parser');

const login = async (context: BrowserContext, jwtToken: string) => {
const waitFor = async (condition, pollInterval = 1000, timeout = 10000) => {
const startTime = Date.now();

while (true) {
if (Date.now() > startTime + timeout) {
throw 'timeout';
}

const result = await condition();

if (result) {
return result;
}

await new Promise((r) => setTimeout(r, pollInterval)); // eslint-disable-line
}
};

// eslint-disable-next-line max-params
const login = async (context: BrowserContext, jwtToken: string, ws: any, options: { skipClientId?: boolean } = {}) => {
const page = await context.newPage();
await page.goto('/');

let path = '/';

if (options && options.skipClientId) {
path += '?skipClientId=true';
}

await page.goto(path);
const title = page.locator('h1');
await expect(title).toHaveText('RingCentral WebPhone Demo');
await page.screenshot({ path: 'screenshots/before-login.png' });

page.on('websocket', ws);

await page.fill('input[name="server"]', process.env.RC_WP_SERVER!);
await page.fill('input[name="clientId"]', process.env.RC_WP_CLIENT_ID!);
await page.fill('input[name="clientSecret"]', process.env.RC_WP_CLIENT_SECRET!);
Expand All @@ -27,9 +58,9 @@ const login = async (context: BrowserContext, jwtToken: string) => {

test('home page', async ({ context }) => {
// login
const callerPage = await login(context, process.env.RC_WP_CALLER_JWT_TOKEN!);
const callerPage = await login(context, process.env.RC_WP_CALLER_JWT_TOKEN!, () => {});
await callerPage.screenshot({ path: 'screenshots/caller-logged-in.png' });
const receiverPage = await login(context, process.env.RC_WP_RECEIVER_JWT_TOKEN!);
const receiverPage = await login(context, process.env.RC_WP_RECEIVER_JWT_TOKEN!, () => {});
await receiverPage.screenshot({ path: 'screenshots/receiver-logged-in.png' });

// make the call
Expand Down Expand Up @@ -64,3 +95,41 @@ test('home page', async ({ context }) => {
await expect(receiverPage.locator('text=Call In Progress')).toBeHidden();
await receiverPage.screenshot({ path: 'screenshots/receiver-hung-up.png' });
});

test('send client id during register if set', async ({ context }) => {
let wsHandled = false;
await login(context, process.env.RC_WP_CALLER_JWT_TOKEN!, (ws) => {
ws.on('framesent', async (frame) => {
const parsed = sip.Core.Parser.parseMessage(frame.payload, logger);

if (parsed!.method === 'REGISTER') {
expect(parsed!.headers['Client-Id'].length).toEqual(1);
expect(parsed!.headers['Client-Id'][0].raw).toEqual(process.env.RC_WP_CLIENT_ID!);
wsHandled = true;
}
});
});

await waitFor(() => wsHandled);
});

test('skip client id during register if not set', async ({ context }) => {
let wsHandled = false;
await login(
context,
process.env.RC_WP_CALLER_JWT_TOKEN!,
(ws) => {
ws.on('framesent', async (frame) => {
const parsed = sip.Core.Parser.parseMessage(frame.payload, logger);

if (parsed!.method === 'REGISTER') {
expect(parsed!.headers['Client-Id']).toBeUndefined();
wsHandled = true;
}
});
},
{ skipClientId: true },
);

await waitFor(() => wsHandled);
});
Loading

0 comments on commit 6f33e82

Please sign in to comment.