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.

iFrameApiRecording.spec.ts 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import { ensureOneParticipant } from '../../helpers/participants';
  2. describe('Recording', () => {
  3. it('join participant', async () => {
  4. await ensureOneParticipant(ctx);
  5. const { p1 } = ctx;
  6. // check for dial-in dial-out sip-jibri maybe
  7. if (await p1.execute(() => config.disableIframeAPI)) {
  8. // skip the test if iframeAPI is disabled
  9. ctx.skipSuiteTests = true;
  10. return;
  11. }
  12. ctx.data.recordingDisabled = Boolean(!await p1.execute(() => config.recordingService?.enabled));
  13. ctx.data.liveStreamingDisabled = Boolean(!await p1.execute(() => config.liveStreaming?.enabled))
  14. || !process.env.YTUBE_TEST_STREAM_KEY;
  15. });
  16. it('start/stop function', async () => {
  17. if (ctx.data.recordingDisabled) {
  18. return;
  19. }
  20. await testRecordingStarted(true);
  21. await testRecordingStopped(true);
  22. });
  23. it('start/stop command', async () => {
  24. if (ctx.data.recordingDisabled) {
  25. return;
  26. }
  27. await testRecordingStarted(false);
  28. await testRecordingStopped(false);
  29. });
  30. it('start/stop Livestreaming command', async () => {
  31. if (ctx.data.liveStreamingDisabled) {
  32. return;
  33. }
  34. const { p1, webhooksProxy } = ctx;
  35. await p1.switchToAPI();
  36. await p1.getIframeAPI().addEventListener('recordingStatusChanged');
  37. await p1.getIframeAPI().executeCommand('startRecording', {
  38. youtubeBroadcastID: process.env.YTUBE_TEST_BROADCAST_ID,
  39. mode: 'stream',
  40. youtubeStreamKey: process.env.YTUBE_TEST_STREAM_KEY
  41. });
  42. if (webhooksProxy) {
  43. const customerId = process.env.IFRAME_TENANT?.replace('vpaas-magic-cookie-', '');
  44. const liveStreamEvent: {
  45. customerId: string;
  46. eventType: string;
  47. } = await webhooksProxy.waitForEvent('LIVE_STREAM_STARTED', 15000);
  48. expect('LIVE_STREAM_STARTED').toBe(liveStreamEvent.eventType);
  49. expect(liveStreamEvent.customerId).toBe(customerId);
  50. }
  51. const statusEvent = (await p1.getIframeAPI().getEventResult('recordingStatusChanged'));
  52. expect(statusEvent.mode).toBe('stream');
  53. expect(statusEvent.on).toBe(true);
  54. if (process.env.YTUBE_TEST_BROADCAST_ID) {
  55. const liveStreamUrl = await p1.getIframeAPI().getLivestreamUrl();
  56. expect(liveStreamUrl.livestreamUrl).toBeDefined();
  57. }
  58. await p1.getIframeAPI().executeCommand('stopRecording', 'stream');
  59. if (webhooksProxy) {
  60. const customerId = process.env.IFRAME_TENANT?.replace('vpaas-magic-cookie-', '');
  61. const liveStreamEvent: {
  62. customerId: string;
  63. eventType: string;
  64. } = await webhooksProxy.waitForEvent('LIVE_STREAM_ENDED');
  65. expect('LIVE_STREAM_ENDED').toBe(liveStreamEvent.eventType);
  66. expect(liveStreamEvent.customerId).toBe(customerId);
  67. }
  68. const stoppedStatusEvent = (await p1.getIframeAPI().getEventResult('recordingStatusChanged'));
  69. expect(stoppedStatusEvent.mode).toBe('stream');
  70. expect(stoppedStatusEvent.on).toBe(false);
  71. });
  72. });
  73. /**
  74. * Checks if the recording is started.
  75. * @param command
  76. */
  77. async function testRecordingStarted(command: boolean) {
  78. const { p1, webhooksProxy } = ctx;
  79. await p1.switchToAPI();
  80. await p1.getIframeAPI().addEventListener('recordingStatusChanged');
  81. await p1.getIframeAPI().addEventListener('recordingLinkAvailable');
  82. if (command) {
  83. await p1.getIframeAPI().executeCommand('startRecording', {
  84. mode: 'file'
  85. });
  86. } else {
  87. await p1.getIframeAPI().startRecording({
  88. mode: 'file'
  89. });
  90. }
  91. if (webhooksProxy) {
  92. const customerId = process.env.IFRAME_TENANT?.replace('vpaas-magic-cookie-', '');
  93. const recordingEvent: {
  94. customerId: string;
  95. eventType: string;
  96. } = await webhooksProxy.waitForEvent('RECORDING_STARTED', 15000);
  97. expect('RECORDING_STARTED').toBe(recordingEvent.eventType);
  98. expect(recordingEvent.customerId).toBe(customerId);
  99. webhooksProxy?.clearCache();
  100. }
  101. const statusEvent = (await p1.getIframeAPI().getEventResult('recordingStatusChanged'));
  102. expect(statusEvent.mode).toBe('file');
  103. expect(statusEvent.on).toBe(true);
  104. const linkEvent = (await p1.getIframeAPI().getEventResult('recordingLinkAvailable'));
  105. expect(linkEvent.link.startsWith('https://')).toBe(true);
  106. expect(linkEvent.link.includes(process.env.IFRAME_TENANT)).toBe(true);
  107. expect(linkEvent.ttl > 0).toBe(true);
  108. }
  109. /**
  110. * Checks if the recording is stopped.
  111. * @param command
  112. */
  113. async function testRecordingStopped(command: boolean) {
  114. const { p1, webhooksProxy } = ctx;
  115. await p1.switchToAPI();
  116. if (command) {
  117. await p1.getIframeAPI().executeCommand('stopRecording', 'file');
  118. } else {
  119. await p1.getIframeAPI().stopRecording('file');
  120. }
  121. if (webhooksProxy) {
  122. const customerId = process.env.IFRAME_TENANT?.replace('vpaas-magic-cookie-', '');
  123. const liveStreamEvent: {
  124. customerId: string;
  125. eventType: string;
  126. } = await webhooksProxy.waitForEvent('RECORDING_ENDED');
  127. expect('RECORDING_ENDED').toBe(liveStreamEvent.eventType);
  128. expect(liveStreamEvent.customerId).toBe(customerId);
  129. const recordingUploadedEvent: {
  130. customerId: string;
  131. data: {
  132. initiatorId: string;
  133. participants: Array<string>;
  134. };
  135. eventType: string;
  136. } = await webhooksProxy.waitForEvent('RECORDING_UPLOADED', 20000);
  137. const jwtPayload = ctx.data[`${p1.name}-jwt-payload`];
  138. expect(recordingUploadedEvent.data.initiatorId).toBe(jwtPayload?.context?.user?.id);
  139. expect(recordingUploadedEvent.data.participants.some(
  140. // @ts-ignore
  141. e => e.id === jwtPayload?.context?.user?.id)).toBe(true);
  142. webhooksProxy?.clearCache();
  143. }
  144. const statusEvent = (await p1.getIframeAPI().getEventResult('recordingStatusChanged'));
  145. expect(statusEvent.mode).toBe('file');
  146. expect(statusEvent.on).toBe(false);
  147. await p1.getIframeAPI().clearEventResults('recordingStatusChanged');
  148. }