modified lib-jitsi-meet dev repo
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

E2EEncryption.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* global __filename */
  2. import { getLogger } from 'jitsi-meet-logger';
  3. import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
  4. import RTCEvents from '../../service/RTC/RTCEvents';
  5. import browser from '../browser';
  6. import E2EEContext from './E2EEContext';
  7. const logger = getLogger(__filename);
  8. /**
  9. * This module integrates {@link E2EEContext} with {@link JitsiConference} in order to enable E2E encryption.
  10. */
  11. export class E2EEncryption {
  12. /**
  13. * A constructor.
  14. * @param {JitsiConference} conference - The conference instance for which E2E encryption is to be enabled.
  15. * @param {Object} options
  16. * @param {string} options.salt - Salt to be used for key deviation. Check {@link E2EEContext} for more details.
  17. */
  18. constructor(conference, { salt }) {
  19. this.conference = conference;
  20. this._e2eeCtx = new E2EEContext({ salt });
  21. this.conference.on(
  22. JitsiConferenceEvents._MEDIA_SESSION_STARTED,
  23. this._onMediaSessionStarted.bind(this));
  24. // FIXME add events to TraceablePeerConnection which will allow to see when there's new receiver or sender
  25. // added instead of shenanigans around conference track events and track muted.
  26. this.conference.on(
  27. JitsiConferenceEvents.TRACK_ADDED,
  28. track => track.isLocal() && this._onLocalTrackAdded(track));
  29. this.conference.rtc.on(
  30. RTCEvents.REMOTE_TRACK_ADDED,
  31. (track, tpc) => this._setupReceiverE2EEForTrack(tpc, track));
  32. this.conference.on(
  33. JitsiConferenceEvents.TRACK_MUTE_CHANGED,
  34. this._trackMuteChanged.bind(this));
  35. }
  36. /**
  37. * Setups E2E encryption for the new session.
  38. * @param {JingleSessionPC} session - the new media session.
  39. * @private
  40. */
  41. _onMediaSessionStarted(session) {
  42. const localTracks = this.conference.getLocalTracks();
  43. for (const track of localTracks) {
  44. this._setupSenderE2EEForTrack(session, track);
  45. }
  46. }
  47. /**
  48. * Setup E2EE on the new track that has been added to the conference, apply it on all the open peerconnections.
  49. * @param {JitsiLocalTrack} track - the new track that's being added to the conference.
  50. * @private
  51. */
  52. _onLocalTrackAdded(track) {
  53. for (const session of this.conference._getMediaSessions()) {
  54. this._setupSenderE2EEForTrack(session, track);
  55. }
  56. }
  57. /**
  58. * Sets the key to be used for End-To-End encryption.
  59. *
  60. * @param {string} key - the key to be used.
  61. * @returns {void}
  62. */
  63. setKey(key) {
  64. this._e2eeCtx.setKey(key);
  65. }
  66. /**
  67. * Setup E2EE for the receiving side.
  68. *
  69. * @returns {void}
  70. */
  71. _setupReceiverE2EEForTrack(tpc, track) {
  72. const receiver = tpc.findReceiverForTrack(track.track);
  73. if (receiver) {
  74. this._e2eeCtx.handleReceiver(receiver, track.getType(), track.getParticipantId());
  75. } else {
  76. logger.warn(`Could not handle E2EE for ${track}: receiver not found in: ${tpc}`);
  77. }
  78. }
  79. /**
  80. * Setup E2EE for the sending side.
  81. *
  82. * @param {JingleSessionPC} session - the session which sends the media produced by the track.
  83. * @param {JitsiLocalTrack} track - the local track for which e2e encoder will be configured.
  84. * @returns {void}
  85. */
  86. _setupSenderE2EEForTrack(session, track) {
  87. const pc = session.peerconnection;
  88. const sender = pc && pc.findSenderForTrack(track.track);
  89. if (sender) {
  90. this._e2eeCtx.handleSender(sender, track.getType(), track.getParticipantId());
  91. } else {
  92. logger.warn(`Could not handle E2EE for ${track}: sender not found in ${pc}`);
  93. }
  94. }
  95. /**
  96. * Setup E2EE on the sender that is created for the unmuted local video track.
  97. * @param {JitsiLocalTrack} track - the track for which muted status has changed.
  98. * @private
  99. */
  100. _trackMuteChanged(track) {
  101. if (browser.doesVideoMuteByStreamRemove() && track.isLocal() && track.isVideoTrack() && !track.isMuted()) {
  102. for (const session of this.conference._getMediaSessions()) {
  103. this._setupSenderE2EEForTrack(session, track);
  104. }
  105. }
  106. }
  107. }