You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Participant.ts 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. /* global APP $ */
  2. import { multiremotebrowser } from '@wdio/globals';
  3. import assert from 'assert';
  4. import { Key } from 'webdriverio';
  5. import { IConfig } from '../../react/features/base/config/configType';
  6. import { urlObjectToString } from '../../react/features/base/util/uri';
  7. import BreakoutRooms from '../pageobjects/BreakoutRooms';
  8. import ChatPanel from '../pageobjects/ChatPanel';
  9. import Filmstrip from '../pageobjects/Filmstrip';
  10. import IframeAPI from '../pageobjects/IframeAPI';
  11. import InviteDialog from '../pageobjects/InviteDialog';
  12. import LargeVideo from '../pageobjects/LargeVideo';
  13. import LobbyScreen from '../pageobjects/LobbyScreen';
  14. import Notifications from '../pageobjects/Notifications';
  15. import ParticipantsPane from '../pageobjects/ParticipantsPane';
  16. import PreJoinScreen from '../pageobjects/PreJoinScreen';
  17. import SecurityDialog from '../pageobjects/SecurityDialog';
  18. import SettingsDialog from '../pageobjects/SettingsDialog';
  19. import Toolbar from '../pageobjects/Toolbar';
  20. import VideoQualityDialog from '../pageobjects/VideoQualityDialog';
  21. import { LOG_PREFIX, logInfo } from './browserLogger';
  22. import { IContext, IJoinOptions } from './types';
  23. export const P1_DISPLAY_NAME = 'p1';
  24. export const P2_DISPLAY_NAME = 'p2';
  25. export const P3_DISPLAY_NAME = 'p3';
  26. export const P4_DISPLAY_NAME = 'p4';
  27. interface IWaitForSendReceiveDataOptions {
  28. checkReceive?: boolean;
  29. checkSend?: boolean;
  30. msg?: string;
  31. timeout?: number;
  32. }
  33. /**
  34. * Participant.
  35. */
  36. export class Participant {
  37. /**
  38. * The current context.
  39. *
  40. * @private
  41. */
  42. private _name: string;
  43. private _displayName: string;
  44. private _endpointId: string;
  45. private _jwt?: string;
  46. /**
  47. * The default config to use when joining.
  48. *
  49. * @private
  50. */
  51. private config = {
  52. analytics: {
  53. disabled: true
  54. },
  55. requireDisplayName: false,
  56. testing: {
  57. testMode: true
  58. },
  59. disableAP: true,
  60. disable1On1Mode: true,
  61. disableModeratorIndicator: true,
  62. enableTalkWhileMuted: false,
  63. gatherStats: true,
  64. p2p: {
  65. enabled: false,
  66. useStunTurn: false
  67. },
  68. pcStatsInterval: 1500,
  69. prejoinConfig: {
  70. enabled: false
  71. },
  72. toolbarConfig: {
  73. alwaysVisible: true
  74. }
  75. } as IConfig;
  76. /**
  77. * Creates a participant with given name.
  78. *
  79. * @param {string} name - The name of the participant.
  80. * @param {string }jwt - The jwt if any.
  81. */
  82. constructor(name: string, jwt?: string) {
  83. this._name = name;
  84. this._jwt = jwt;
  85. }
  86. /**
  87. * Returns participant endpoint ID.
  88. *
  89. * @returns {Promise<string>} The endpoint ID.
  90. */
  91. async getEndpointId(): Promise<string> {
  92. if (!this._endpointId) {
  93. this._endpointId = await this.driver.execute(() => { // eslint-disable-line arrow-body-style
  94. return APP?.conference?.getMyUserId();
  95. });
  96. }
  97. return this._endpointId;
  98. }
  99. /**
  100. * The driver it uses.
  101. */
  102. get driver() {
  103. return multiremotebrowser.getInstance(this._name);
  104. }
  105. /**
  106. * The name.
  107. */
  108. get name() {
  109. return this._name;
  110. }
  111. /**
  112. * The name.
  113. */
  114. get displayName() {
  115. return this._displayName || this.name;
  116. }
  117. /**
  118. * Adds a log to the participants log file.
  119. *
  120. * @param {string} message - The message to log.
  121. * @returns {void}
  122. */
  123. log(message: string): void {
  124. logInfo(this.driver, message);
  125. }
  126. /**
  127. * Joins conference.
  128. *
  129. * @param {IContext} ctx - The context.
  130. * @param {IJoinOptions} options - Options for joining.
  131. * @returns {Promise<void>}
  132. */
  133. async joinConference(ctx: IContext, options: IJoinOptions = {}): Promise<void> {
  134. const config = {
  135. room: ctx.roomName,
  136. configOverwrite: {
  137. ...this.config,
  138. ...options.configOverwrite || {}
  139. },
  140. interfaceConfigOverwrite: {
  141. SHOW_CHROME_EXTENSION_BANNER: false
  142. }
  143. };
  144. if (!options.skipDisplayName) {
  145. // @ts-ignore
  146. config.userInfo = {
  147. displayName: this._displayName = options.displayName || this._name
  148. };
  149. }
  150. if (ctx.iframeAPI) {
  151. config.room = 'iframeAPITest.html';
  152. }
  153. let url = urlObjectToString(config) || '';
  154. if (ctx.iframeAPI) {
  155. const baseUrl = new URL(this.driver.options.baseUrl || '');
  156. // @ts-ignore
  157. url = `${this.driver.iframePageBase}${url}&domain="${baseUrl.host}"&room="${ctx.roomName}"`;
  158. if (baseUrl.pathname.length > 1) {
  159. // remove leading slash
  160. url = `${url}&tenant="${baseUrl.pathname.substring(1)}"`;
  161. }
  162. }
  163. if (this._jwt) {
  164. url = `${url}&jwt="${this._jwt}"`;
  165. }
  166. await this.driver.setTimeout({ 'pageLoad': 30000 });
  167. // drop the leading '/' so we can use the tenant if any
  168. await this.driver.url(url.startsWith('/') ? url.substring(1) : url);
  169. await this.waitForPageToLoad();
  170. if (ctx.iframeAPI) {
  171. const mainFrame = this.driver.$('iframe');
  172. await this.driver.switchFrame(mainFrame);
  173. }
  174. if (!options.skipWaitToJoin) {
  175. await this.waitToJoinMUC();
  176. }
  177. await this.postLoadProcess(options.skipInMeetingChecks);
  178. }
  179. /**
  180. * Loads stuff after the page loads.
  181. *
  182. * @param {boolean} skipInMeetingChecks - Whether to skip in meeting checks.
  183. * @returns {Promise<void>}
  184. * @private
  185. */
  186. private async postLoadProcess(skipInMeetingChecks = false): Promise<void> {
  187. const driver = this.driver;
  188. const parallel = [];
  189. parallel.push(driver.execute((name, sessionId, prefix) => {
  190. APP?.UI?.dockToolbar(true);
  191. // disable keyframe animations (.fadeIn and .fadeOut classes)
  192. $('<style>.notransition * { '
  193. + 'animation-duration: 0s !important; -webkit-animation-duration: 0s !important; transition:none; '
  194. + '} </style>') // @ts-ignore
  195. .appendTo(document.head);
  196. // @ts-ignore
  197. $('body').toggleClass('notransition');
  198. document.title = `${name}`;
  199. console.log(`${new Date().toISOString()} ${prefix} sessionId: ${sessionId}`);
  200. // disable the blur effect in firefox as it has some performance issues
  201. const blur = document.querySelector('.video_blurred_container');
  202. if (blur) {
  203. // @ts-ignore
  204. document.querySelector('.video_blurred_container').style.display = 'none';
  205. }
  206. }, this._name, driver.sessionId, LOG_PREFIX));
  207. if (skipInMeetingChecks) {
  208. await Promise.allSettled(parallel);
  209. return;
  210. }
  211. parallel.push(this.waitForIceConnected());
  212. parallel.push(this.waitForSendReceiveData());
  213. await Promise.all(parallel);
  214. }
  215. /**
  216. * Waits for the page to load.
  217. *
  218. * @returns {Promise<void>}
  219. */
  220. async waitForPageToLoad(): Promise<void> {
  221. return this.driver.waitUntil(
  222. () => this.driver.execute(() => document.readyState === 'complete'),
  223. {
  224. timeout: 30_000, // 30 seconds
  225. timeoutMsg: `Timeout waiting for Page Load Request to complete for ${this.name}.`
  226. }
  227. );
  228. }
  229. /**
  230. * Waits for the tile view to display.
  231. */
  232. async waitForTileViewDisplay(reverse = false) {
  233. await this.driver.$('//div[@id="videoconference_page" and contains(@class, "tile-view")]').waitForDisplayed({
  234. reverse,
  235. timeout: 10_000,
  236. timeoutMsg: `Tile view did not display in 10s for ${this.name}`
  237. });
  238. }
  239. /**
  240. * Checks if the participant is in the meeting.
  241. */
  242. isInMuc() {
  243. return this.driver.execute(() => typeof APP !== 'undefined' && APP.conference?.isJoined());
  244. }
  245. /**
  246. * Checks if the participant is a moderator in the meeting.
  247. */
  248. async isModerator() {
  249. return await this.driver.execute(() => typeof APP !== 'undefined'
  250. && APP.store?.getState()['features/base/participants']?.local?.role === 'moderator');
  251. }
  252. /**
  253. * Checks if the meeting supports breakout rooms.
  254. */
  255. async isBreakoutRoomsSupported() {
  256. return await this.driver.execute(() => typeof APP !== 'undefined'
  257. && APP.store?.getState()['features/base/conference'].conference?.getBreakoutRooms()?.isSupported());
  258. }
  259. /**
  260. * Checks if the participant is in breakout room.
  261. */
  262. async isInBreakoutRoom() {
  263. return await this.driver.execute(() => typeof APP !== 'undefined'
  264. && APP.store?.getState()['features/base/conference'].conference?.getBreakoutRooms()?.isBreakoutRoom());
  265. }
  266. /**
  267. * Waits to join the muc.
  268. *
  269. * @returns {Promise<void>}
  270. */
  271. async waitToJoinMUC(): Promise<void> {
  272. return this.driver.waitUntil(
  273. () => this.isInMuc(),
  274. {
  275. timeout: 10_000, // 10 seconds
  276. timeoutMsg: `Timeout waiting to join muc for ${this.name}`
  277. }
  278. );
  279. }
  280. /**
  281. * Waits for ICE to get connected.
  282. *
  283. * @returns {Promise<void>}
  284. */
  285. async waitForIceConnected(): Promise<void> {
  286. const driver = this.driver;
  287. return driver.waitUntil(() =>
  288. driver.execute(() => APP?.conference?.getConnectionState() === 'connected'), {
  289. timeout: 15_000,
  290. timeoutMsg: `expected ICE to be connected for 15s for ${this.name}`
  291. });
  292. }
  293. /**
  294. * Waits for send and receive data.
  295. *
  296. * @param {Object} options
  297. * @param {boolean} options.checkSend - If true we will chec
  298. * @returns {Promise<void>}
  299. */
  300. waitForSendReceiveData({
  301. checkSend = true,
  302. checkReceive = true,
  303. timeout = 15_000,
  304. msg
  305. } = {} as IWaitForSendReceiveDataOptions): Promise<void> {
  306. if (!checkSend && !checkReceive) {
  307. return Promise.resolve();
  308. }
  309. const lMsg = msg ?? `expected to ${
  310. checkSend && checkReceive ? 'receive/send' : checkSend ? 'send' : 'receive'} data in 15s for ${this.name}`;
  311. return this.driver.waitUntil(() => this.driver.execute((pCheckSend: boolean, pCheckReceive: boolean) => {
  312. const stats = APP?.conference?.getStats();
  313. const bitrateMap = stats?.bitrate || {};
  314. const rtpStats = {
  315. uploadBitrate: bitrateMap.upload || 0,
  316. downloadBitrate: bitrateMap.download || 0
  317. };
  318. return (rtpStats.uploadBitrate > 0 || !pCheckSend) && (rtpStats.downloadBitrate > 0 || !pCheckReceive);
  319. }, checkSend, checkReceive), {
  320. timeout,
  321. timeoutMsg: lMsg
  322. });
  323. }
  324. /**
  325. * Waits for remote streams.
  326. *
  327. * @param {number} number - The number of remote streams to wait for.
  328. * @returns {Promise<void>}
  329. */
  330. waitForRemoteStreams(number: number): Promise<void> {
  331. const driver = this.driver;
  332. return driver.waitUntil(() =>
  333. driver.execute(count => (APP?.conference?.getNumberOfParticipantsWithTracks() ?? -1) >= count, number), {
  334. timeout: 15_000,
  335. timeoutMsg: `expected number of remote streams:${number} in 15s for ${this.name}`
  336. });
  337. }
  338. /**
  339. * Waits for number of participants.
  340. *
  341. * @param {number} number - The number of participant to wait for.
  342. * @param {string} msg - A custom message to use.
  343. * @returns {Promise<void>}
  344. */
  345. waitForParticipants(number: number, msg?: string): Promise<void> {
  346. const driver = this.driver;
  347. return driver.waitUntil(
  348. () => driver.execute(count => (APP?.conference?.listMembers()?.length ?? -1) === count, number),
  349. {
  350. timeout: 15_000,
  351. timeoutMsg: msg || `not the expected participants ${number} in 15s for ${this.name}`
  352. });
  353. }
  354. /**
  355. * Returns the chat panel for this participant.
  356. */
  357. getChatPanel(): ChatPanel {
  358. return new ChatPanel(this);
  359. }
  360. /**
  361. * Returns the BreakoutRooms for this participant.
  362. *
  363. * @returns {BreakoutRooms}
  364. */
  365. getBreakoutRooms(): BreakoutRooms {
  366. return new BreakoutRooms(this);
  367. }
  368. /**
  369. * Returns the toolbar for this participant.
  370. *
  371. * @returns {Toolbar}
  372. */
  373. getToolbar(): Toolbar {
  374. return new Toolbar(this);
  375. }
  376. /**
  377. * Returns the filmstrip for this participant.
  378. *
  379. * @returns {Filmstrip}
  380. */
  381. getFilmstrip(): Filmstrip {
  382. return new Filmstrip(this);
  383. }
  384. /**
  385. * Returns the invite dialog for this participant.
  386. *
  387. * @returns {InviteDialog}
  388. */
  389. getInviteDialog(): InviteDialog {
  390. return new InviteDialog(this);
  391. }
  392. /**
  393. * Returns the notifications.
  394. */
  395. getNotifications(): Notifications {
  396. return new Notifications(this);
  397. }
  398. /**
  399. * Returns the participants pane.
  400. *
  401. * @returns {ParticipantsPane}
  402. */
  403. getParticipantsPane(): ParticipantsPane {
  404. return new ParticipantsPane(this);
  405. }
  406. /**
  407. * Returns the large video page object.
  408. *
  409. * @returns {LargeVideo}
  410. */
  411. getLargeVideo(): LargeVideo {
  412. return new LargeVideo(this);
  413. }
  414. /**
  415. * Returns the videoQuality Dialog.
  416. *
  417. * @returns {VideoQualityDialog}
  418. */
  419. getVideoQualityDialog(): VideoQualityDialog {
  420. return new VideoQualityDialog(this);
  421. }
  422. /**
  423. * Returns the security Dialog.
  424. *
  425. * @returns {SecurityDialog}
  426. */
  427. getSecurityDialog(): SecurityDialog {
  428. return new SecurityDialog(this);
  429. }
  430. /**
  431. * Returns the settings Dialog.
  432. *
  433. * @returns {SettingsDialog}
  434. */
  435. getSettingsDialog(): SettingsDialog {
  436. return new SettingsDialog(this);
  437. }
  438. /**
  439. * Returns the prejoin screen.
  440. */
  441. getPreJoinScreen(): PreJoinScreen {
  442. return new PreJoinScreen(this);
  443. }
  444. /**
  445. * Returns the lobby screen.
  446. */
  447. getLobbyScreen(): LobbyScreen {
  448. return new LobbyScreen(this);
  449. }
  450. /**
  451. * Switches to the iframe API context
  452. */
  453. async switchToAPI() {
  454. await this.driver.switchFrame(null);
  455. }
  456. /**
  457. * Switches to the meeting page context.
  458. */
  459. async switchInPage() {
  460. const mainFrame = this.driver.$('iframe');
  461. await this.driver.switchFrame(mainFrame);
  462. }
  463. /**
  464. * Returns the iframe API for this participant.
  465. */
  466. getIframeAPI() {
  467. return new IframeAPI(this);
  468. }
  469. /**
  470. * Hangups the participant by leaving the page. base.html is an empty page on all deployments.
  471. */
  472. async hangup() {
  473. const current = await this.driver.getUrl();
  474. // already hangup
  475. if (current.endsWith('/base.html')) {
  476. return;
  477. }
  478. // do a hangup, to make sure unavailable presence is sent
  479. await this.driver.execute(() => typeof APP !== 'undefined' && APP.conference?.hangup());
  480. // let's give it some time to leave the muc, we redirect after hangup so we should wait for the
  481. // change of url
  482. await this.driver.waitUntil(
  483. async () => current !== await this.driver.getUrl(),
  484. {
  485. timeout: 5000,
  486. timeoutMsg: `${this.name} did not leave the muc in 5s`
  487. }
  488. );
  489. await this.driver.url('/base.html');
  490. }
  491. /**
  492. * Returns the local display name element.
  493. * @private
  494. */
  495. private async getLocalDisplayNameElement() {
  496. const localVideoContainer = this.driver.$('span[id="localVideoContainer"]');
  497. await localVideoContainer.moveTo();
  498. return localVideoContainer.$('span[id="localDisplayName"]');
  499. }
  500. /**
  501. * Returns the local display name.
  502. */
  503. async getLocalDisplayName() {
  504. return (await this.getLocalDisplayNameElement()).getText();
  505. }
  506. /**
  507. * Sets the display name of the local participant.
  508. */
  509. async setLocalDisplayName(displayName: string) {
  510. const localDisplayName = await this.getLocalDisplayNameElement();
  511. await localDisplayName.click();
  512. await this.driver.keys(displayName);
  513. await this.driver.keys(Key.Return);
  514. // just click somewhere to lose focus, to make sure editing has ended
  515. const localVideoContainer = this.driver.$('span[id="localVideoContainer"]');
  516. await localVideoContainer.moveTo();
  517. await localVideoContainer.click();
  518. }
  519. /**
  520. * Gets avatar SRC attribute for the one displayed on local video thumbnail.
  521. */
  522. async getLocalVideoAvatar() {
  523. const avatar
  524. = this.driver.$('//span[@id="localVideoContainer"]//img[contains(@class,"userAvatar")]');
  525. return await avatar.isExisting() ? await avatar.getAttribute('src') : null;
  526. }
  527. /**
  528. * Makes sure that the avatar is displayed in the local thumbnail and that the video is not displayed.
  529. * There are 3 options for avatar:
  530. * - defaultAvatar: true - the default avatar (with grey figure) is used
  531. * - image: true - the avatar is an image set in the settings
  532. * - defaultAvatar: false, image: false - the avatar is produced from the initials of the display name
  533. */
  534. async assertThumbnailShowsAvatar(
  535. participant: Participant, reverse = false, defaultAvatar = false, image = false): Promise<void> {
  536. const id = participant === this
  537. ? 'localVideoContainer' : `participant_${await participant.getEndpointId()}`;
  538. const xpath = defaultAvatar
  539. ? `//span[@id='${id}']//div[contains(@class,'userAvatar') and contains(@class, 'defaultAvatar')]`
  540. : `//span[@id="${id}"]//${image ? 'img' : 'div'}[contains(@class,"userAvatar")]`;
  541. await this.driver.$(xpath).waitForDisplayed({
  542. reverse,
  543. timeout: 2000,
  544. timeoutMsg: `Avatar is ${reverse ? '' : 'not'} displayed in the local thumbnail for ${participant.name}`
  545. });
  546. await this.driver.$(`//span[@id="${id}"]//video`).waitForDisplayed({
  547. reverse: !reverse,
  548. timeout: 2000,
  549. timeoutMsg: `Video is ${reverse ? 'not' : ''} displayed in the local thumbnail for ${participant.name}`
  550. });
  551. }
  552. /**
  553. * Makes sure that the default avatar is used.
  554. */
  555. async assertDefaultAvatarExist(participant: Participant): Promise<void> {
  556. const id = participant === this
  557. ? 'localVideoContainer' : `participant_${await participant.getEndpointId()}`;
  558. await this.driver.$(
  559. `//span[@id='${id}']//div[contains(@class,'userAvatar') and contains(@class, 'defaultAvatar')]`)
  560. .waitForExist({
  561. timeout: 2000,
  562. timeoutMsg: `Default avatar does not exist for ${participant.name}`
  563. });
  564. }
  565. /**
  566. * Makes sure that the local video is displayed in the local thumbnail and that the avatar is not displayed.
  567. */
  568. async asserLocalThumbnailShowsVideo(): Promise<void> {
  569. await this.assertThumbnailShowsAvatar(this, true);
  570. }
  571. /**
  572. * Make sure a display name is visible on the stage.
  573. * @param value
  574. */
  575. async assertDisplayNameVisibleOnStage(value: string) {
  576. const displayNameEl = this.driver.$('div[data-testid="stage-display-name"]');
  577. expect(await displayNameEl.isDisplayed()).toBe(true);
  578. expect(await displayNameEl.getText()).toBe(value);
  579. }
  580. /**
  581. * Checks if the leave reason dialog is open.
  582. */
  583. async isLeaveReasonDialogOpen() {
  584. return this.driver.$('div[data-testid="dialog.leaveReason"]').isDisplayed();
  585. }
  586. /**
  587. * Returns the audio level for a participant.
  588. *
  589. * @param observer
  590. * @param participant
  591. * @return
  592. */
  593. async getRemoteAudioLevel(p: Participant) {
  594. const jid = await p.getEndpointId();
  595. return await this.driver.execute(id => {
  596. const level = APP?.conference?.getPeerSSRCAudioLevel(id);
  597. return level ? level.toFixed(2) : null;
  598. }, jid);
  599. }
  600. /**
  601. * For the participant to have his audio muted/unmuted from given observer's
  602. * perspective. The method will fail the test if something goes wrong or
  603. * the audio muted status is different than the expected one. We wait up to
  604. * 3 seconds for the expected status to appear.
  605. *
  606. * @param testee - instance of the participant for whom we're checking the audio muted status.
  607. * @param muted - <tt>true</tt> to wait for audio muted status or <tt>false</tt> to wait for the participant to
  608. * unmute.
  609. */
  610. async waitForAudioMuted(testee: Participant, muted: boolean): Promise<void> {
  611. // Waits for the correct icon
  612. await this.getFilmstrip().assertAudioMuteIconIsDisplayed(testee, !muted);
  613. // Extended timeout for 'unmuted' to make tests more resilient to
  614. // unexpected glitches.
  615. const timeout = muted ? 3_000 : 6_000;
  616. // Give it 3 seconds to not get any audio or to receive some
  617. // depending on "muted" argument
  618. try {
  619. await this.driver.waitUntil(async () => {
  620. const audioLevel = await this.getRemoteAudioLevel(testee);
  621. if (muted) {
  622. if (audioLevel !== null && audioLevel > 0.1) {
  623. console.log(`muted exiting on: ${audioLevel}`);
  624. return true;
  625. }
  626. return false;
  627. }
  628. // When testing for unmuted we wait for first sound
  629. if (audioLevel !== null && audioLevel > 0.1) {
  630. console.log(`unmuted exiting on: ${audioLevel}`);
  631. return true;
  632. }
  633. return false;
  634. },
  635. { timeout });
  636. // When testing for muted we don't want to have
  637. // the condition succeeded
  638. if (muted) {
  639. const name = await testee.displayName;
  640. assert.fail(`There was some sound coming from muted: '${name}'`);
  641. } // else we're good for unmuted participant
  642. } catch (_timeoutE) {
  643. if (!muted) {
  644. const name = await testee.displayName;
  645. assert.fail(`There was no sound from unmuted: '${name}'`);
  646. } // else we're good for muted participant
  647. }
  648. }
  649. /**
  650. * Waits for remote video state - receiving and displayed.
  651. * @param endpointId
  652. */
  653. async waitForRemoteVideo(endpointId: string) {
  654. await this.driver.waitUntil(async () =>
  655. await this.driver.execute(epId => JitsiMeetJS.app.testing.isRemoteVideoReceived(`${epId}`),
  656. endpointId) && await this.driver.$(
  657. `//span[@id="participant_${endpointId}" and contains(@class, "display-video")]`).isExisting(), {
  658. timeout: 15_000,
  659. timeoutMsg: `expected remote video for ${endpointId} to be received 15s by ${this.name}`
  660. });
  661. }
  662. /**
  663. * Waits for ninja icon to be displayed.
  664. * @param endpointId
  665. */
  666. async waitForNinjaIcon(endpointId: string) {
  667. await this.driver.$(`//span[@id='participant_${endpointId}']//span[@class='connection_ninja']`)
  668. .waitForDisplayed({
  669. timeout: 15_000,
  670. timeoutMsg: `expected ninja icon for ${endpointId} to be displayed in 15s by ${this.name}`
  671. });
  672. }
  673. }