This commit is contained in:
90
tests/specs/helpers/DialIn.ts
Normal file
90
tests/specs/helpers/DialIn.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import https from 'node:https';
|
||||
import process from 'node:process';
|
||||
|
||||
import type { Participant } from '../../helpers/Participant';
|
||||
|
||||
/**
|
||||
* Helper functions for dial-in related operations.
|
||||
* To be able to create a fake dial-in test that will run most of the logic for the real dial-in test.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Waits for the audio from the dial-in participant.
|
||||
* @param participant
|
||||
*/
|
||||
export async function waitForAudioFromDialInParticipant(participant: Participant) {
|
||||
// waits 15 seconds for the participant to join
|
||||
await participant.waitForParticipants(1, `dial-in.test.jigasi.participant.no.join.for:${
|
||||
ctx.times.restAPIExecutionTS + 15_000} ms.`);
|
||||
|
||||
const joinedTS = performance.now();
|
||||
|
||||
console.log(`dial-in.test.jigasi.participant.join.after:${joinedTS - ctx.times.restAPIExecutionTS}`);
|
||||
|
||||
await participant.waitForIceConnected();
|
||||
await participant.waitForRemoteStreams(1);
|
||||
|
||||
await participant.waitForSendReceiveData(20_000, 'dial-in.test.jigasi.participant.no.audio.after.join');
|
||||
console.log(`dial-in.test.jigasi.participant.received.audio.after.join:${performance.now() - joinedTS} ms.`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up the dial-in participant by kicking it if the local participant is a moderator.
|
||||
* @param participant
|
||||
*/
|
||||
export async function cleanup(participant: Participant) {
|
||||
// cleanup
|
||||
if (await participant.isModerator()) {
|
||||
const jigasiEndpointId = await participant.execute(() => APP?.conference?.listMembers()[0].getId());
|
||||
|
||||
await participant.getFilmstrip().kickParticipant(jigasiEndpointId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the dial-in is enabled.
|
||||
* @param participant
|
||||
*/
|
||||
export async function isDialInEnabled(participant: Participant) {
|
||||
return await participant.execute(() => Boolean(
|
||||
config.dialInConfCodeUrl && config.dialInNumbersUrl && config.hosts?.muc));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request to the REST API to dial in the participant using the provided pin.
|
||||
* @param participant
|
||||
*/
|
||||
export async function dialIn(participant: Participant) {
|
||||
if (!await participant.isInMuc()) {
|
||||
// local participant did not join abort
|
||||
return;
|
||||
}
|
||||
|
||||
const dialInPin = await participant.getDialInPin();
|
||||
|
||||
const restUrl = process.env.DIAL_IN_REST_URL?.replace('{0}', dialInPin);
|
||||
|
||||
// we have already checked in the first test that DIAL_IN_REST_URL exist so restUrl cannot be ''
|
||||
const responseData: string = await new Promise((resolve, reject) => {
|
||||
https.get(restUrl || '', res => {
|
||||
let data = '';
|
||||
|
||||
res.on('data', chunk => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
ctx.times.restAPIExecutionTS = performance.now();
|
||||
|
||||
resolve(data);
|
||||
});
|
||||
}).on('error', err => {
|
||||
console.error('dial-in.test.restAPI.request.fail');
|
||||
console.error(err);
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
|
||||
console.log(`dial-in.test.call_session_history_id:${JSON.parse(responseData).call_session_history_id}`);
|
||||
console.log(`API response:${responseData}`);
|
||||
}
|
||||
62
tests/specs/helpers/jaas.ts
Normal file
62
tests/specs/helpers/jaas.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { Participant } from '../../helpers/Participant';
|
||||
import { config } from '../../helpers/TestsConfig';
|
||||
import { IToken, ITokenOptions, generateToken } from '../../helpers/token';
|
||||
import { IParticipantJoinOptions } from '../../helpers/types';
|
||||
|
||||
export function generateJaasToken(options: ITokenOptions): IToken {
|
||||
if (!config.jaas.enabled) {
|
||||
throw new Error('JaaS is not configured.');
|
||||
}
|
||||
|
||||
// Don't override the keyId and keyPath if they are already set in options, allow tests to set them.
|
||||
return generateToken({
|
||||
...options,
|
||||
keyId: options.keyId || config.jaas.kid,
|
||||
keyPath: options.keyPath || config.jaas.privateKeyPath
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Participant and joins the MUC with the given options. The jaas-specific properties must be set as
|
||||
* environment variables (see env.example and TestsConfig.ts). If no room name is specified, the default room name
|
||||
* from the context is used.
|
||||
*
|
||||
* @param instanceId This is the "name" passed to the Participant, I think it's used to match against one of the
|
||||
* pre-configured browser instances in wdio? It must be one of 'p1', 'p2', 'p3', or 'p4'. TODO: figure out how this
|
||||
* should be used.
|
||||
* @param token the token to use, if any.
|
||||
* @param joinOptions options to use when joining the MUC.
|
||||
* @returns {Promise<Participant>} The Participant that has joined the MUC.
|
||||
*/
|
||||
export async function joinMuc(
|
||||
instanceId: 'p1' | 'p2' | 'p3' | 'p4',
|
||||
token?: IToken,
|
||||
joinOptions?: Partial<IParticipantJoinOptions>): Promise<Participant> {
|
||||
|
||||
if (!config.jaas.enabled) {
|
||||
throw new Error('JaaS is not configured.');
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const p = ctx[instanceId] as Participant;
|
||||
|
||||
if (p) {
|
||||
// Load a blank page to make sure the page is reloaded (in case the new participant uses the same URL). Using
|
||||
// 'about:blank' was causing problems in the past, if we notice any issues we can change to "base.html".
|
||||
await p.driver.url('about:blank');
|
||||
}
|
||||
|
||||
const newParticipant = new Participant({
|
||||
name: instanceId,
|
||||
token
|
||||
});
|
||||
|
||||
// @ts-ignore
|
||||
ctx[instanceId] = newParticipant;
|
||||
|
||||
return await newParticipant.joinConference({
|
||||
...joinOptions,
|
||||
forceTenant: config.jaas.tenant,
|
||||
roomName: joinOptions?.roomName || ctx.roomName,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user