Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

WatchRTC.ts 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import Logger from '@jitsi/logger';
  2. import watchRTC from '@testrtc/watchrtc-sdk';
  3. import { isAnalyticsEnabled, isRtcstatsEnabled, isWatchRTCEnabled } from './functions';
  4. import { IWatchRTCConfiguration } from './interfaces';
  5. const logger = Logger.getLogger(__filename);
  6. /**
  7. * Class that controls the watchRTC flow, because it overwrites and proxies global function it should only be
  8. * initialized once.
  9. */
  10. class WatchRTCHandler {
  11. options?: IWatchRTCConfiguration;
  12. /**
  13. * Initialize watchRTC, it overwrites GUM and PeerConnection global functions and adds a proxy over them
  14. * used to capture stats.
  15. *
  16. * @param {Object} options - Init options.
  17. * @returns {void}
  18. */
  19. init(options: any): void {
  20. if (isWatchRTCEnabled(options)) {
  21. if (!isAnalyticsEnabled(options)) {
  22. logger.error('Cannot initialize WatchRTC when analytics or third party requests are disabled.');
  23. return;
  24. }
  25. try {
  26. if (options?.watchRTCConfigParams?.rtcApiKey) {
  27. watchRTC.init({
  28. rtcApiKey: options.watchRTCConfigParams.rtcApiKey,
  29. });
  30. this.options = options.watchRTCConfigParams;
  31. logger.info('WatchRTC initialized.');
  32. } else {
  33. logger.error('WatchRTC is enabled but missing API key.');
  34. }
  35. } catch (error) {
  36. logger.error('Failed to initialize WatchRTC: ', error);
  37. }
  38. }
  39. }
  40. /**
  41. * Begin watchRTC session considering roomName and userName if already not available
  42. *
  43. * @param {string} roomName - The room name we are currently in.
  44. * @param {string} userName - The user name. This value is obtained from
  45. * JitsiConference.prototype.myUserId
  46. * @returns {void}
  47. */
  48. start(roomName: string, userName: string): void {
  49. try {
  50. if (this.options) {
  51. this.options.rtcRoomId = this.options.rtcRoomId ? this.options.rtcRoomId : roomName;
  52. this.options.rtcPeerId = this.options.rtcPeerId ? this.options.rtcPeerId : userName;
  53. watchRTC.setConfig(this.options);
  54. logger.info('WatchRTC setConfig.');
  55. }
  56. } catch (error) {
  57. logger.error('Failed to start WatchRTC session: ', error);
  58. }
  59. }
  60. }
  61. export default new WatchRTCHandler();