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 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /* global APP $ */
  2. import { multiremotebrowser } from '@wdio/globals';
  3. import { Key } from 'webdriverio';
  4. import { IConfig } from '../../react/features/base/config/configType';
  5. import { urlObjectToString } from '../../react/features/base/util/uri';
  6. import BreakoutRooms from '../pageobjects/BreakoutRooms';
  7. import ChatPanel from '../pageobjects/ChatPanel';
  8. import Filmstrip from '../pageobjects/Filmstrip';
  9. import IframeAPI from '../pageobjects/IframeAPI';
  10. import InviteDialog from '../pageobjects/InviteDialog';
  11. import Notifications from '../pageobjects/Notifications';
  12. import ParticipantsPane from '../pageobjects/ParticipantsPane';
  13. import SettingsDialog from '../pageobjects/SettingsDialog';
  14. import Toolbar from '../pageobjects/Toolbar';
  15. import VideoQualityDialog from '../pageobjects/VideoQualityDialog';
  16. import { LOG_PREFIX, logInfo } from './browserLogger';
  17. import { IContext, IJoinOptions } from './types';
  18. /**
  19. * Participant.
  20. */
  21. export class Participant {
  22. /**
  23. * The current context.
  24. *
  25. * @private
  26. */
  27. private _name: string;
  28. private _endpointId: string;
  29. private _jwt?: string;
  30. /**
  31. * The default config to use when joining.
  32. *
  33. * @private
  34. */
  35. private config = {
  36. analytics: {
  37. disabled: true
  38. },
  39. debug: true,
  40. requireDisplayName: false,
  41. testing: {
  42. testMode: true
  43. },
  44. disableAP: true,
  45. disable1On1Mode: true,
  46. disableModeratorIndicator: true,
  47. enableTalkWhileMuted: false,
  48. gatherStats: true,
  49. p2p: {
  50. enabled: false,
  51. useStunTurn: false
  52. },
  53. pcStatsInterval: 1500,
  54. prejoinConfig: {
  55. enabled: false
  56. },
  57. toolbarConfig: {
  58. alwaysVisible: true
  59. }
  60. } as IConfig;
  61. /**
  62. * Creates a participant with given name.
  63. *
  64. * @param {string} name - The name of the participant.
  65. * @param {string }jwt - The jwt if any.
  66. */
  67. constructor(name: string, jwt?: string) {
  68. this._name = name;
  69. this._jwt = jwt;
  70. }
  71. /**
  72. * Returns participant endpoint ID.
  73. *
  74. * @returns {Promise<string>} The endpoint ID.
  75. */
  76. async getEndpointId(): Promise<string> {
  77. if (!this._endpointId) {
  78. this._endpointId = await this.driver.execute(() => { // eslint-disable-line arrow-body-style
  79. return APP.conference.getMyUserId();
  80. });
  81. }
  82. return this._endpointId;
  83. }
  84. /**
  85. * The driver it uses.
  86. */
  87. get driver() {
  88. return multiremotebrowser.getInstance(this._name);
  89. }
  90. /**
  91. * The name.
  92. */
  93. get name() {
  94. return this._name;
  95. }
  96. /**
  97. * Adds a log to the participants log file.
  98. *
  99. * @param {string} message - The message to log.
  100. * @returns {void}
  101. */
  102. log(message: string): void {
  103. logInfo(this.driver, message);
  104. }
  105. /**
  106. * Joins conference.
  107. *
  108. * @param {IContext} ctx - The context.
  109. * @param {IJoinOptions} options - Options for joining.
  110. * @returns {Promise<void>}
  111. */
  112. async joinConference(ctx: IContext, options: IJoinOptions = {}): Promise<void> {
  113. const config = {
  114. room: ctx.roomName,
  115. configOverwrite: {
  116. ...this.config,
  117. ...options.configOverwrite || {}
  118. },
  119. interfaceConfigOverwrite: {
  120. SHOW_CHROME_EXTENSION_BANNER: false
  121. }
  122. };
  123. if (!options.skipDisplayName) {
  124. // @ts-ignore
  125. config.userInfo = {
  126. displayName: options.displayName || this._name
  127. };
  128. }
  129. if (ctx.iframeAPI) {
  130. config.room = 'iframeAPITest.html';
  131. }
  132. let url = urlObjectToString(config) || '';
  133. if (ctx.iframeAPI) {
  134. const baseUrl = new URL(this.driver.options.baseUrl || '');
  135. // @ts-ignore
  136. url = `${this.driver.iframePageBase}${url}&domain="${baseUrl.host}"&room="${ctx.roomName}"`;
  137. if (baseUrl.pathname.length > 1) {
  138. // remove leading slash
  139. url = `${url}&tenant="${baseUrl.pathname.substring(1)}"`;
  140. }
  141. }
  142. if (this._jwt) {
  143. url = `${url}&jwt="${this._jwt}"`;
  144. }
  145. await this.driver.setTimeout({ 'pageLoad': 30000 });
  146. // drop the leading '/' so we can use the tenant if any
  147. await this.driver.url(url.startsWith('/') ? url.substring(1) : url);
  148. await this.waitForPageToLoad();
  149. if (ctx.iframeAPI) {
  150. const mainFrame = this.driver.$('iframe');
  151. await this.driver.switchFrame(mainFrame);
  152. }
  153. await this.waitToJoinMUC();
  154. await this.postLoadProcess(options.skipInMeetingChecks);
  155. }
  156. /**
  157. * Loads stuff after the page loads.
  158. *
  159. * @param {boolean} skipInMeetingChecks - Whether to skip in meeting checks.
  160. * @returns {Promise<void>}
  161. * @private
  162. */
  163. private async postLoadProcess(skipInMeetingChecks = false): Promise<void> {
  164. const driver = this.driver;
  165. const parallel = [];
  166. parallel.push(driver.execute((name, sessionId, prefix) => {
  167. APP.UI.dockToolbar(true);
  168. // disable keyframe animations (.fadeIn and .fadeOut classes)
  169. $('<style>.notransition * { '
  170. + 'animation-duration: 0s !important; -webkit-animation-duration: 0s !important; transition:none; '
  171. + '} </style>') // @ts-ignore
  172. .appendTo(document.head);
  173. // @ts-ignore
  174. $('body').toggleClass('notransition');
  175. document.title = `${name}`;
  176. console.log(`${new Date().toISOString()} ${prefix} sessionId: ${sessionId}`);
  177. // disable the blur effect in firefox as it has some performance issues
  178. const blur = document.querySelector('.video_blurred_container');
  179. if (blur) {
  180. // @ts-ignore
  181. document.querySelector('.video_blurred_container').style.display = 'none';
  182. }
  183. }, this._name, driver.sessionId, LOG_PREFIX));
  184. if (skipInMeetingChecks) {
  185. await Promise.allSettled(parallel);
  186. return;
  187. }
  188. parallel.push(this.waitForIceConnected());
  189. parallel.push(this.waitForSendReceiveData());
  190. await Promise.all(parallel);
  191. }
  192. /**
  193. * Waits for the page to load.
  194. *
  195. * @returns {Promise<void>}
  196. */
  197. async waitForPageToLoad(): Promise<void> {
  198. return this.driver.waitUntil(
  199. async () => await this.driver.execute(() => document.readyState === 'complete'),
  200. {
  201. timeout: 30_000, // 30 seconds
  202. timeoutMsg: 'Timeout waiting for Page Load Request to complete.'
  203. }
  204. );
  205. }
  206. /**
  207. * Checks if the participant is in the meeting.
  208. */
  209. async isInMuc() {
  210. return await this.driver.execute(() => typeof APP !== 'undefined' && APP.conference?.isJoined());
  211. }
  212. /**
  213. * Checks if the participant is a moderator in the meeting.
  214. */
  215. async isModerator() {
  216. return await this.driver.execute(() => typeof APP !== 'undefined'
  217. && APP.store?.getState()['features/base/participants']?.local?.role === 'moderator');
  218. }
  219. /**
  220. * Checks if the meeting supports breakout rooms.
  221. */
  222. async isBreakoutRoomsSupported() {
  223. return await this.driver.execute(() => typeof APP !== 'undefined'
  224. && APP.store?.getState()['features/base/conference'].conference?.getBreakoutRooms()?.isSupported());
  225. }
  226. /**
  227. * Checks if the participant is in breakout room.
  228. */
  229. async isInBreakoutRoom() {
  230. return await this.driver.execute(() => typeof APP !== 'undefined'
  231. && APP.store?.getState()['features/base/conference'].conference?.getBreakoutRooms()?.isBreakoutRoom());
  232. }
  233. /**
  234. * Waits to join the muc.
  235. *
  236. * @returns {Promise<void>}
  237. */
  238. async waitToJoinMUC(): Promise<void> {
  239. return this.driver.waitUntil(
  240. () => this.isInMuc(),
  241. {
  242. timeout: 10_000, // 10 seconds
  243. timeoutMsg: 'Timeout waiting to join muc.'
  244. }
  245. );
  246. }
  247. /**
  248. * Waits for ICE to get connected.
  249. *
  250. * @returns {Promise<void>}
  251. */
  252. async waitForIceConnected(): Promise<void> {
  253. const driver = this.driver;
  254. return driver.waitUntil(async () =>
  255. await driver.execute(() => APP.conference.getConnectionState() === 'connected'), {
  256. timeout: 15_000,
  257. timeoutMsg: 'expected ICE to be connected for 15s'
  258. });
  259. }
  260. /**
  261. * Waits for send and receive data.
  262. *
  263. * @returns {Promise<void>}
  264. */
  265. async waitForSendReceiveData(timeout = 15_000, msg = 'expected to receive/send data in 15s'): Promise<void> {
  266. const driver = this.driver;
  267. return driver.waitUntil(async () =>
  268. await driver.execute(() => {
  269. const stats = APP.conference.getStats();
  270. const bitrateMap = stats?.bitrate || {};
  271. const rtpStats = {
  272. uploadBitrate: bitrateMap.upload || 0,
  273. downloadBitrate: bitrateMap.download || 0
  274. };
  275. return rtpStats.uploadBitrate > 0 && rtpStats.downloadBitrate > 0;
  276. }), {
  277. timeout,
  278. timeoutMsg: msg
  279. });
  280. }
  281. /**
  282. * Waits for remote streams.
  283. *
  284. * @param {number} number - The number of remote streams to wait for.
  285. * @returns {Promise<void>}
  286. */
  287. waitForRemoteStreams(number: number): Promise<void> {
  288. const driver = this.driver;
  289. return driver.waitUntil(async () =>
  290. await driver.execute(count => APP.conference.getNumberOfParticipantsWithTracks() >= count, number), {
  291. timeout: 15_000,
  292. timeoutMsg: 'expected remote streams in 15s'
  293. });
  294. }
  295. /**
  296. * Waits for number of participants.
  297. *
  298. * @param {number} number - The number of participant to wait for.
  299. * @param {string} msg - A custom message to use.
  300. * @returns {Promise<void>}
  301. */
  302. waitForParticipants(number: number, msg?: string): Promise<void> {
  303. const driver = this.driver;
  304. return driver.waitUntil(async () =>
  305. await driver.execute(count => APP.conference.listMembers().length === count, number), {
  306. timeout: 15_000,
  307. timeoutMsg: msg || `not the expected participants ${number} in 15s`
  308. });
  309. }
  310. /**
  311. * Returns the chat panel for this participant.
  312. */
  313. getChatPanel(): ChatPanel {
  314. return new ChatPanel(this);
  315. }
  316. /**
  317. * Returns the BreakoutRooms for this participant.
  318. *
  319. * @returns {BreakoutRooms}
  320. */
  321. getBreakoutRooms(): BreakoutRooms {
  322. return new BreakoutRooms(this);
  323. }
  324. /**
  325. * Returns the toolbar for this participant.
  326. *
  327. * @returns {Toolbar}
  328. */
  329. getToolbar(): Toolbar {
  330. return new Toolbar(this);
  331. }
  332. /**
  333. * Returns the filmstrip for this participant.
  334. *
  335. * @returns {Filmstrip}
  336. */
  337. getFilmstrip(): Filmstrip {
  338. return new Filmstrip(this);
  339. }
  340. /**
  341. * Returns the invite dialog for this participant.
  342. *
  343. * @returns {InviteDialog}
  344. */
  345. getInviteDialog(): InviteDialog {
  346. return new InviteDialog(this);
  347. }
  348. /**
  349. * Returns the notifications.
  350. */
  351. getNotifications(): Notifications {
  352. return new Notifications(this);
  353. }
  354. /**
  355. * Returns the participants pane.
  356. *
  357. * @returns {ParticipantsPane}
  358. */
  359. getParticipantsPane(): ParticipantsPane {
  360. return new ParticipantsPane(this);
  361. }
  362. /**
  363. * Returns the videoQuality Dialog.
  364. *
  365. * @returns {VideoQualityDialog}
  366. */
  367. getVideoQualityDialog(): VideoQualityDialog {
  368. return new VideoQualityDialog(this);
  369. }
  370. /**
  371. * Returns the settings Dialog.
  372. *
  373. * @returns {SettingsDialog}
  374. */
  375. getSettingsDialog(): SettingsDialog {
  376. return new SettingsDialog(this);
  377. }
  378. /**
  379. * Switches to the iframe API context
  380. */
  381. async switchToAPI() {
  382. await this.driver.switchFrame(null);
  383. }
  384. /**
  385. * Switches to the meeting page context.
  386. */
  387. async switchInPage() {
  388. const mainFrame = this.driver.$('iframe');
  389. await this.driver.switchFrame(mainFrame);
  390. }
  391. /**
  392. * Returns the iframe API for this participant.
  393. */
  394. getIframeAPI() {
  395. return new IframeAPI(this);
  396. }
  397. /**
  398. * Hangups the participant by leaving the page. base.html is an empty page on all deployments.
  399. */
  400. async hangup() {
  401. await this.driver.url('/base.html');
  402. }
  403. /**
  404. * Returns the local display name element.
  405. * @private
  406. */
  407. private async getLocalDisplayNameElement() {
  408. const localVideoContainer = this.driver.$('span[id="localVideoContainer"]');
  409. await localVideoContainer.moveTo();
  410. return localVideoContainer.$('span[id="localDisplayName"]');
  411. }
  412. /**
  413. * Returns the local display name.
  414. */
  415. async getLocalDisplayName() {
  416. return await (await this.getLocalDisplayNameElement()).getText();
  417. }
  418. /**
  419. * Sets the display name of the local participant.
  420. */
  421. async setLocalDisplayName(displayName: string) {
  422. const localDisplayName = await this.getLocalDisplayNameElement();
  423. await localDisplayName.click();
  424. await this.driver.keys(displayName);
  425. await this.driver.keys(Key.Return);
  426. // just click somewhere to lose focus, to make sure editing has ended
  427. const localVideoContainer = this.driver.$('span[id="localVideoContainer"]');
  428. await localVideoContainer.moveTo();
  429. await localVideoContainer.click();
  430. }
  431. /**
  432. * Gets avatar SRC attribute for the one displayed on local video thumbnail.
  433. */
  434. async getLocalVideoAvatar() {
  435. const avatar
  436. = this.driver.$('//span[@id="localVideoContainer"]//img[contains(@class,"userAvatar")]');
  437. return await avatar.isExisting() ? await avatar.getAttribute('src') : null;
  438. }
  439. /**
  440. * Gets avatar SRC attribute for the one displayed on large video.
  441. */
  442. async getLargeVideoAvatar() {
  443. const avatar = this.driver.$('//img[@id="dominantSpeakerAvatar"]');
  444. return await avatar.isExisting() ? await avatar.getAttribute('src') : null;
  445. }
  446. /**
  447. * Returns resource part of the JID of the user who is currently displayed in the large video area.
  448. */
  449. async getLargeVideoResource() {
  450. return await this.driver.execute(() => APP.UI.getLargeVideoID());
  451. }
  452. /**
  453. * Makes sure that the avatar is displayed in the local thumbnail and that the video is not displayed.
  454. * There are 3 options for avatar:
  455. * - defaultAvatar: true - the default avatar (with grey figure) is used
  456. * - image: true - the avatar is an image set in the settings
  457. * - defaultAvatar: false, image: false - the avatar is produced from the initials of the display name
  458. */
  459. async assertThumbnailShowsAvatar(
  460. participant: Participant, reverse = false, defaultAvatar = false, image = false): Promise<void> {
  461. const id = participant === this
  462. ? 'localVideoContainer' : `participant_${await participant.getEndpointId()}`;
  463. const xpath = defaultAvatar
  464. ? `//span[@id='${id}']//div[contains(@class,'userAvatar') and contains(@class, 'defaultAvatar')]`
  465. : `//span[@id="${id}"]//${image ? 'img' : 'div'}[contains(@class,"userAvatar")]`;
  466. await this.driver.$(xpath).waitForDisplayed({
  467. reverse,
  468. timeout: 2000,
  469. timeoutMsg: `Avatar is ${reverse ? '' : 'not'} displayed in the local thumbnail for ${participant.name}`
  470. });
  471. await this.driver.$(`//span[@id="${id}"]//video`).waitForDisplayed({
  472. reverse: !reverse,
  473. timeout: 2000,
  474. timeoutMsg: `Video is ${reverse ? 'not' : ''} displayed in the local thumbnail for ${participant.name}`
  475. });
  476. }
  477. /**
  478. * Makes sure that the default avatar is used.
  479. */
  480. async assertDefaultAvatarExist(participant: Participant): Promise<void> {
  481. const id = participant === this
  482. ? 'localVideoContainer' : `participant_${await participant.getEndpointId()}`;
  483. await this.driver.$(
  484. `//span[@id='${id}']//div[contains(@class,'userAvatar') and contains(@class, 'defaultAvatar')]`)
  485. .waitForExist({
  486. timeout: 2000,
  487. timeoutMsg: `Default avatar does not exist for ${participant.name}`
  488. });
  489. }
  490. /**
  491. * Makes sure that the local video is displayed in the local thumbnail and that the avatar is not displayed.
  492. */
  493. async asserLocalThumbnailShowsVideo(): Promise<void> {
  494. await this.assertThumbnailShowsAvatar(this, true);
  495. }
  496. /**
  497. * Make sure a display name is visible on the stage.
  498. * @param value
  499. */
  500. async assertDisplayNameVisibleOnStage(value: string) {
  501. const displayNameEl = this.driver.$('div[data-testid="stage-display-name"]');
  502. expect(await displayNameEl.isDisplayed()).toBe(true);
  503. expect(await displayNameEl.getText()).toBe(value);
  504. }
  505. }