Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CodecSelection.spec.js 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. import EventEmitter from 'events';
  2. import * as JitsiConferenceEvents from '../../JitsiConferenceEvents.ts';
  3. import Listenable from '../util/Listenable.js';
  4. import JingleSessionPC from '../xmpp/JingleSessionPC.js';
  5. import { MockChatRoom, MockStropheConnection } from '../xmpp/MockClasses.js';
  6. import { CodecSelection } from './CodecSelection.js';
  7. import { MockRTC, MockSignalingLayerImpl } from './MockClasses.js';
  8. /**
  9. * MockParticipant
  10. */
  11. class MockParticipant {
  12. /**
  13. * A constructor...
  14. */
  15. constructor(id) {
  16. this.id = id;
  17. }
  18. /**
  19. * Returns the endpoint id of the participant.
  20. * @returns <string>
  21. */
  22. getId() {
  23. return this.id;
  24. }
  25. }
  26. /**
  27. * MockConference
  28. */
  29. class MockConference extends Listenable {
  30. /**
  31. * A constructor...
  32. */
  33. constructor() {
  34. super();
  35. this.options = {
  36. config: {}
  37. };
  38. this.activeMediaSession = undefined;
  39. this.eventEmitter = new EventEmitter();
  40. this.mediaSessions = [];
  41. this.participants = [];
  42. this._signalingLayer = new MockSignalingLayerImpl();
  43. }
  44. /**
  45. * Add a mock participant to the conference
  46. * @param {MockParticipant} participant
  47. * @param {Array<string>} codecList
  48. * @param {String} codecType
  49. */
  50. addParticipant(participant, codecList, codecType) {
  51. this.participants.push(participant);
  52. this._signalingLayer.setPeerMediaInfo(true, participant.getId(), codecList, codecType);
  53. this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED);
  54. }
  55. /**
  56. * Returns the list of participants.
  57. * @returns Array<MockParticipant>
  58. */
  59. getParticipants() {
  60. return this.participants;
  61. }
  62. /**
  63. * Checks if E2EE is enabled.
  64. * @returns {boolean}
  65. */
  66. isE2EEEnabled() {
  67. return false;
  68. }
  69. /**
  70. * Removes the participant from the conference.
  71. * @param {MockParticipant} endpoint
  72. */
  73. removeParticipant(endpoint) {
  74. this.participants = this.participants.filter(p => p !== endpoint);
  75. this._signalingLayer.setPeerMediaInfo(false, endpoint.getId());
  76. this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT);
  77. }
  78. }
  79. describe('Codec Selection', () => {
  80. /* eslint-disable-next-line no-unused-vars */
  81. let codecSelection;
  82. let conference;
  83. let connection;
  84. let jingleSession;
  85. let options;
  86. let participant1, participant2;
  87. let rtc;
  88. const SID = 'sid12345';
  89. beforeEach(() => {
  90. conference = new MockConference();
  91. connection = new MockStropheConnection();
  92. jingleSession = new JingleSessionPC(
  93. SID,
  94. 'peer1',
  95. 'peer2',
  96. connection,
  97. { },
  98. { },
  99. false,
  100. false);
  101. rtc = new MockRTC();
  102. jingleSession.initialize(
  103. /* ChatRoom */ new MockChatRoom(),
  104. /* RTC */ rtc,
  105. /* Signaling layer */ conference._signalingLayer,
  106. /* options */ { });
  107. conference.jvbJingleSession = jingleSession;
  108. });
  109. describe('when codec preference list is used in config.js', () => {
  110. beforeEach(() => {
  111. options = {
  112. jvb: {
  113. preferenceOrder: [ 'VP9', 'VP8', 'H264' ]
  114. }
  115. };
  116. codecSelection = new CodecSelection(conference, options);
  117. spyOn(jingleSession, 'setVideoCodecs');
  118. });
  119. it('and remote endpoints use the new codec selection logic', () => {
  120. // Add a second user joining the call.
  121. participant1 = new MockParticipant('remote-1');
  122. conference.addParticipant(participant1, [ 'vp9', 'vp8' ]);
  123. expect(jingleSession.setVideoCodecs).toHaveBeenCalledTimes(0);
  124. // Add a third user joining the call with a subset of codecs.
  125. participant2 = new MockParticipant('remote-2');
  126. conference.addParticipant(participant2, [ 'vp8' ]);
  127. expect(jingleSession.setVideoCodecs).toHaveBeenCalledWith([ 'vp8' ]);
  128. // Make p2 leave the call
  129. conference.removeParticipant(participant2);
  130. expect(jingleSession.setVideoCodecs).toHaveBeenCalledTimes(1);
  131. });
  132. it('and remote endpoints use the old codec selection logic (RN)', () => {
  133. // Add a second user joining the call.
  134. participant1 = new MockParticipant('remote-1');
  135. conference.addParticipant(participant1, null, 'vp8');
  136. expect(jingleSession.setVideoCodecs).toHaveBeenCalledWith([ 'vp8' ]);
  137. // Add a third user (newer) to the call.
  138. participant2 = new MockParticipant('remote-2');
  139. conference.addParticipant(participant2, [ 'vp9', 'vp8' ]);
  140. expect(jingleSession.setVideoCodecs).toHaveBeenCalledWith([ 'vp8' ]);
  141. // Make p1 leave the call
  142. conference.removeParticipant(participant1);
  143. expect(jingleSession.setVideoCodecs).toHaveBeenCalledTimes(2);
  144. });
  145. });
  146. describe('when deprecated configs are used in config.js', () => {
  147. beforeEach(() => {
  148. options = {
  149. jvb: {
  150. preferredCodec: 'VP9',
  151. disabledCodec: 'H264'
  152. }
  153. };
  154. codecSelection = new CodecSelection(conference, options);
  155. spyOn(jingleSession, 'setVideoCodecs');
  156. });
  157. it('and remote endpoints use the new codec selection logic', () => {
  158. // Add a second user joining the call.
  159. participant1 = new MockParticipant('remote-1');
  160. conference.addParticipant(participant1, [ 'vp9', 'vp8', 'h264' ]);
  161. expect(jingleSession.setVideoCodecs).toHaveBeenCalledTimes(0);
  162. // Add a third user joining the call with a subset of codecs.
  163. participant2 = new MockParticipant('remote-2');
  164. conference.addParticipant(participant2, [ 'vp8' ]);
  165. expect(jingleSession.setVideoCodecs).toHaveBeenCalledWith([ 'vp8' ]);
  166. // Make p2 leave the call
  167. conference.removeParticipant(participant2);
  168. expect(jingleSession.setVideoCodecs).toHaveBeenCalledTimes(1);
  169. });
  170. it('and remote endpoint prefers a codec that is locally disabled', () => {
  171. // Add a second user joining the call the prefers H.264 and VP8.
  172. participant1 = new MockParticipant('remote-1');
  173. conference.addParticipant(participant1, [ 'h264', 'vp8' ]);
  174. expect(jingleSession.setVideoCodecs).toHaveBeenCalledWith([ 'vp8' ]);
  175. });
  176. it('and remote endpoints use the old codec selection logic (RN)', () => {
  177. // Add a second user joining the call.
  178. participant1 = new MockParticipant('remote-1');
  179. conference.addParticipant(participant1, null, 'vp8');
  180. expect(jingleSession.setVideoCodecs).toHaveBeenCalledWith([ 'vp8' ]);
  181. // Add a third user (newer) to the call.
  182. participant2 = new MockParticipant('remote-2');
  183. conference.addParticipant(participant2, [ 'vp9', 'vp8', 'h264' ]);
  184. expect(jingleSession.setVideoCodecs).toHaveBeenCalledWith([ 'vp8' ]);
  185. // Make p1 leave the call
  186. conference.removeParticipant(participant1);
  187. expect(jingleSession.setVideoCodecs).toHaveBeenCalledTimes(2);
  188. });
  189. });
  190. });