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.

IframeAPI.ts 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import { LOG_PREFIX } from '../helpers/browserLogger';
  2. import BasePageObject from './BasePageObject';
  3. /**
  4. * The Iframe API and helpers from iframeAPITest.html
  5. */
  6. export default class IframeAPI extends BasePageObject {
  7. /**
  8. * Returns the json object from the iframeAPI helper.
  9. * @param event
  10. */
  11. getEventResult(event: string): Promise<any> {
  12. return this.participant.execute(
  13. eventName => {
  14. const result = window.jitsiAPI.test[eventName];
  15. if (!result) {
  16. return false;
  17. }
  18. return result;
  19. }, event);
  20. }
  21. /**
  22. * Clears the history of an event.
  23. * @param event
  24. */
  25. clearEventResults(event: string) {
  26. return this.participant.execute(
  27. eventName => {
  28. window.jitsiAPI.test[eventName] = undefined;
  29. }, event);
  30. }
  31. /**
  32. * Adds an event listener to the iframeAPI.
  33. * @param eventName The event name.
  34. */
  35. addEventListener(eventName: string) {
  36. return this.participant.execute(
  37. (event, prefix) => {
  38. console.log(`${new Date().toISOString()} ${prefix}iframeAPI - Adding listener for event: ${event}`);
  39. window.jitsiAPI.addListener(event, evt => {
  40. console.log(
  41. `${new Date().toISOString()} ${prefix}iframeAPI - Received ${event} event: ${JSON.stringify(evt)}`);
  42. window.jitsiAPI.test[event] = evt;
  43. });
  44. }, eventName, LOG_PREFIX);
  45. }
  46. /**
  47. * Returns an array of available rooms and details of it.
  48. */
  49. getRoomsInfo() {
  50. return this.participant.execute(() => window.jitsiAPI.getRoomsInfo());
  51. }
  52. /**
  53. * Returns the number of participants in the conference.
  54. */
  55. getNumberOfParticipants() {
  56. return this.participant.execute(() => window.jitsiAPI.getNumberOfParticipants());
  57. }
  58. /**
  59. * Executes command using iframeAPI.
  60. * @param command The command.
  61. * @param args The arguments.
  62. */
  63. executeCommand(command: string, ...args: any[]) {
  64. return this.participant.execute(
  65. (commandName, commandArgs) =>
  66. window.jitsiAPI.executeCommand(commandName, ...commandArgs)
  67. , command, args);
  68. }
  69. /**
  70. * Returns the current state of the participant's pane.
  71. */
  72. isParticipantsPaneOpen() {
  73. return this.participant.execute(() => window.jitsiAPI.isParticipantsPaneOpen());
  74. }
  75. /**
  76. * Removes the embedded Jitsi Meet conference.
  77. */
  78. dispose() {
  79. return this.participant.execute(() => window.jitsiAPI.dispose());
  80. }
  81. /**
  82. * Invite the given participant to the meeting via PSTN.
  83. */
  84. invitePhone(value: string) {
  85. return this.participant.execute(v => window.jitsiAPI.invite([ {
  86. type: 'phone',
  87. number: v
  88. } ]), value);
  89. }
  90. /**
  91. * Invite the given participant to the meeting via sip (sip jibri).
  92. */
  93. inviteSIP(value: string) {
  94. return this.participant.execute(v => window.jitsiAPI.invite([ {
  95. type: 'sip',
  96. address: v
  97. } ]), value);
  98. }
  99. /**
  100. * Starts a file recording or streaming session.
  101. * @param options
  102. */
  103. startRecording(options: any) {
  104. return this.participant.execute(o => window.jitsiAPI.startRecording(o), options);
  105. }
  106. /**
  107. * Stop a file recording or streaming session.
  108. * @param mode
  109. */
  110. stopRecording(mode: string) {
  111. return this.participant.execute(m => window.jitsiAPI.stopRecording(m), mode);
  112. }
  113. /**
  114. * Returns the live-streaming url.
  115. */
  116. async getLivestreamUrl() {
  117. return this.participant.execute(() => window.jitsiAPI.getLivestreamUrl());
  118. }
  119. }