Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

JingleSessionPC.spec.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. import $ from 'jquery';
  2. import { MockRTC } from '../RTC/MockClasses';
  3. import JingleSessionPC from './JingleSessionPC';
  4. import * as JingleSessionState from './JingleSessionState';
  5. import MediaSessionEvents from './MediaSessionEvents';
  6. import { MockChatRoom, MockStropheConnection } from './MockClasses';
  7. /**
  8. * Creates 'content-modify' Jingle IQ.
  9. * @returns {jQuery}
  10. */
  11. function createContentModifyForSourceNames() {
  12. const modifyContentsIq = $.parseXML(
  13. '<jingle action="content-modify" initiator="peer2" sid="sid12345" xmlns="urn:xmpp:jingle:1">'
  14. + '<content name="video" senders="both">'
  15. + '<source-frame-height maxHeight="180" sourceName="8d519815-v0" xmlns="http://jitsi.org/jitmeet/video"/>'
  16. + '<source-frame-height maxHeight="2160" sourceName="8d519815-v1" xmlns="http://jitsi.org/jitmeet/video"/>'
  17. + '</content>'
  18. + '</jingle>');
  19. return $(modifyContentsIq).find('>jingle');
  20. }
  21. describe('JingleSessionPC', () => {
  22. let jingleSession;
  23. let connection;
  24. let rtc;
  25. const offerIQ = {
  26. find: () => {
  27. return {
  28. // eslint-disable-next-line no-empty-function
  29. each: () => { }
  30. };
  31. }
  32. };
  33. const SID = 'sid12345';
  34. beforeEach(() => {
  35. connection = new MockStropheConnection();
  36. jingleSession = new JingleSessionPC(
  37. SID,
  38. 'peer1',
  39. 'peer2',
  40. connection,
  41. { },
  42. { },
  43. true,
  44. false);
  45. rtc = new MockRTC();
  46. jingleSession.initialize(
  47. /* ChatRoom */ new MockChatRoom(),
  48. /* RTC */ rtc,
  49. /* Signaling layer */ {
  50. setSSRCOwner: () => { }, // eslint-disable-line no-empty-function,
  51. removeSSRCOwners: () => { } // eslint-disable-line no-empty-function
  52. },
  53. /* options */ { });
  54. // eslint-disable-next-line no-empty-function
  55. // connection.connect('jid', undefined, () => { }); */
  56. });
  57. describe('send/receive video constraints w/ source-name', () => {
  58. it('sends content-modify with recv frame size', () => {
  59. const sendIQSpy = spyOn(connection, 'sendIQ').and.callThrough();
  60. const sourceConstraints = new Map();
  61. sourceConstraints.set('8d519815-v0', 180);
  62. sourceConstraints.set('8d519815-v1', 2160);
  63. jingleSession.setReceiverVideoConstraint(sourceConstraints);
  64. expect(jingleSession.getState()).toBe(JingleSessionState.PENDING);
  65. return new Promise((resolve, reject) => {
  66. jingleSession.acceptOffer(
  67. offerIQ,
  68. resolve,
  69. reject,
  70. /* local tracks */ []);
  71. }).then(() => {
  72. expect(jingleSession.getState()).toBe(JingleSessionState.ACTIVE);
  73. // FIXME content-modify is sent before session-accept
  74. expect(sendIQSpy.calls.count()).toBe(2);
  75. expect(sendIQSpy.calls.first().args[0].toString()).toBe(
  76. '<iq to="peer2" type="set" xmlns="jabber:client">'
  77. + '<jingle action="content-modify" initiator="peer2" sid="sid12345" xmlns="urn:xmpp:jingle:1">'
  78. + '<content name="video" senders="both">'
  79. + '<source-frame-height maxHeight="180" sourceName="8d519815-v0"'
  80. + ' xmlns="http://jitsi.org/jitmeet/video"/>'
  81. + '<source-frame-height maxHeight="2160" sourceName="8d519815-v1"'
  82. + ' xmlns="http://jitsi.org/jitmeet/video"/>'
  83. + '</content>'
  84. + '</jingle>'
  85. + '</iq>');
  86. });
  87. });
  88. it('fires an event when remote peer sends content-modify', () => {
  89. let remoteSourcesRecvMaxFrameHeight;
  90. const remoteVideoConstraintsListener = () => {
  91. remoteSourcesRecvMaxFrameHeight = jingleSession.getRemoteSourcesRecvMaxFrameHeight();
  92. };
  93. jingleSession.addListener(
  94. MediaSessionEvents.REMOTE_SOURCE_CONSTRAINTS_CHANGED,
  95. remoteVideoConstraintsListener);
  96. return new Promise((resolve, reject) => {
  97. jingleSession.acceptOffer(
  98. offerIQ,
  99. resolve,
  100. reject,
  101. /* local tracks */ []);
  102. }).then(() => {
  103. jingleSession.modifyContents(createContentModifyForSourceNames());
  104. const v0Height = remoteSourcesRecvMaxFrameHeight[0].maxHeight;
  105. const v1Height = remoteSourcesRecvMaxFrameHeight[1].maxHeight;
  106. expect(v0Height).toBe('180');
  107. expect(v1Height).toBe('2160');
  108. });
  109. });
  110. });
  111. describe('_processSourceAddOrRemove', () => {
  112. let peerconnection, removeSsrcOwnersSpy, setSsrcOwnerSpy, sourceInfo, updateRemoteSourcesSpy;
  113. beforeEach(() => {
  114. peerconnection = jingleSession.peerconnection;
  115. setSsrcOwnerSpy = spyOn(jingleSession._signalingLayer, 'setSSRCOwner');
  116. removeSsrcOwnersSpy = spyOn(jingleSession._signalingLayer, 'removeSSRCOwners');
  117. updateRemoteSourcesSpy = spyOn(peerconnection, 'updateRemoteSources');
  118. });
  119. it('should handle no sources', () => {
  120. const jingle = $.parseXML(
  121. `<jingle xmlns='urn:xmpp:jingle:1'>
  122. <content name='audio'>
  123. <description xmlns='urn:xmpp:jingle:apps:rtp:1' media='audio'/>
  124. </content>
  125. <content name='video'>
  126. <description xmlns='urn:xmpp:jingle:apps:rtp:1' media='video'/>
  127. </content>
  128. </jingle>`
  129. );
  130. const sourceAddElem = $(jingle).find('>jingle>content');
  131. sourceInfo = jingleSession._processSourceMapFromJingle(sourceAddElem, true);
  132. expect(sourceInfo.size).toBe(0);
  133. expect(setSsrcOwnerSpy).not.toHaveBeenCalled();
  134. expect(removeSsrcOwnersSpy).not.toHaveBeenCalled();
  135. expect(updateRemoteSourcesSpy).not.toHaveBeenCalled();
  136. });
  137. it('should handle a single source', () => {
  138. const jingle = $.parseXML(
  139. `<jingle xmlns='urn:xmpp:jingle:1'>
  140. <content name='audio'>
  141. <description xmlns='urn:xmpp:jingle:apps:rtp:1' media='audio'>
  142. <source xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' ssrc='1234' name='source1' owner='peer'>
  143. <parameter name='msid' value='stream1'/>
  144. </source>
  145. </description>
  146. </content>
  147. </jingle>`
  148. );
  149. const sourceAddElem = $(jingle).find('>jingle>content');
  150. sourceInfo = jingleSession._processSourceMapFromJingle(sourceAddElem, true);
  151. expect(sourceInfo.size).toBe(1);
  152. expect(sourceInfo.get('source1').ssrcList).toEqual([ '1234' ]);
  153. expect(sourceInfo.get('source1').msid).toBe('stream1');
  154. expect(setSsrcOwnerSpy).toHaveBeenCalledWith(1234, null, 'source1');
  155. expect(updateRemoteSourcesSpy).toHaveBeenCalledWith(sourceInfo, true);
  156. sourceInfo = jingleSession._processSourceMapFromJingle(sourceAddElem, false);
  157. expect(removeSsrcOwnersSpy).toHaveBeenCalledWith([ 1234 ]);
  158. expect(updateRemoteSourcesSpy).toHaveBeenCalledWith(sourceInfo, false);
  159. });
  160. it('should handle multiple ssrcs belonging to the same source', () => {
  161. const jingle = $.parseXML(
  162. `<jingle xmlns='urn:xmpp:jingle:1'>
  163. <content name='audio'>
  164. <description xmlns='urn:xmpp:jingle:apps:rtp:1' media='audio'/>
  165. </content>
  166. <content name='video'>
  167. <description xmlns='urn:xmpp:jingle:apps:rtp:1' media='video'>
  168. <source xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' ssrc='1234' name='source1' owner='peer'>
  169. <parameter name='msid' value='stream1'/>
  170. </source>
  171. <source xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' ssrc='5678' name='source1' owner='peer'>
  172. <parameter name='msid' value='stream1'/>
  173. </source>
  174. <ssrc-group xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' semantics='FID'>
  175. <source xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' ssrc='1234'/>
  176. <source xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' ssrc='5678'/>
  177. </ssrc-group>
  178. </description>
  179. </content>
  180. </jingle>`
  181. );
  182. const sourceAddElem = $(jingle).find('>jingle>content');
  183. sourceInfo = jingleSession._processSourceMapFromJingle(sourceAddElem, true);
  184. expect(sourceInfo.size).toBe(1);
  185. expect(sourceInfo.get('source1').ssrcList).toEqual([ '1234', '5678' ]);
  186. expect(sourceInfo.get('source1').msid).toBe('stream1');
  187. expect(sourceInfo.get('source1').mediaType).toBe('video');
  188. expect(sourceInfo.get('source1').groups).toEqual([ {
  189. semantics: 'FID',
  190. ssrcs: [ '1234', '5678' ] } ]);
  191. expect(setSsrcOwnerSpy).toHaveBeenCalledWith(1234, null, 'source1');
  192. expect(setSsrcOwnerSpy).toHaveBeenCalledWith(5678, null, 'source1');
  193. expect(updateRemoteSourcesSpy).toHaveBeenCalledWith(sourceInfo, true);
  194. sourceInfo = jingleSession._processSourceMapFromJingle(sourceAddElem, false);
  195. expect(removeSsrcOwnersSpy).toHaveBeenCalledWith([ 1234, 5678 ]);
  196. expect(updateRemoteSourcesSpy).toHaveBeenCalledWith(sourceInfo, false);
  197. });
  198. it('should handle multiple ssrcs belonging to different sources', () => {
  199. const jingle = $.parseXML(
  200. `<jingle xmlns='urn:xmpp:jingle:1'>
  201. <content name='audio'>
  202. <description xmlns='urn:xmpp:jingle:apps:rtp:1' media='audio'/>
  203. </content>
  204. <content name='video'>
  205. <description xmlns='urn:xmpp:jingle:apps:rtp:1' media='video'>
  206. <source xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' ssrc='1234' name='source1' owner='peer'>
  207. <parameter name='msid' value='stream1'/>
  208. </source>
  209. <source xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' ssrc='5678' name='source1' owner='peer'>
  210. <parameter name='msid' value='stream1'/>
  211. </source>
  212. <source xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' ssrc='4321' name='source2' owner='peer'>
  213. <parameter name='msid' value='stream2'/>
  214. </source>
  215. <source xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' ssrc='8765' name='source2' owner='peer'>
  216. <parameter name='msid' value='stream2'/>
  217. </source>
  218. <ssrc-group xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' semantics='FID'>
  219. <source xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' ssrc='1234'/>
  220. <source xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' ssrc='5678'/>
  221. </ssrc-group>
  222. <ssrc-group xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' semantics='FID'>
  223. <source xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' ssrc='4321'/>
  224. <source xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' ssrc='8765'/>
  225. </ssrc-group>
  226. </description>
  227. </content>
  228. </jingle>`
  229. );
  230. const sourceAddElem = $(jingle).find('>jingle>content');
  231. sourceInfo = jingleSession._processSourceMapFromJingle(sourceAddElem, true);
  232. expect(sourceInfo.size).toBe(2);
  233. expect(sourceInfo.get('source1').ssrcList).toEqual([ '1234', '5678' ]);
  234. expect(sourceInfo.get('source1').msid).toBe('stream1');
  235. expect(sourceInfo.get('source1').groups).toEqual([ {
  236. semantics: 'FID',
  237. ssrcs: [ '1234', '5678' ] } ]);
  238. expect(sourceInfo.get('source1').mediaType).toBe('video');
  239. expect(sourceInfo.get('source2').ssrcList).toEqual([ '4321', '8765' ]);
  240. expect(sourceInfo.get('source2').msid).toBe('stream2');
  241. expect(sourceInfo.get('source2').groups).toEqual([ {
  242. semantics: 'FID',
  243. ssrcs: [ '4321', '8765' ] } ]);
  244. expect(sourceInfo.get('source2').mediaType).toBe('video');
  245. expect(setSsrcOwnerSpy).toHaveBeenCalledWith(1234, null, 'source1');
  246. expect(setSsrcOwnerSpy).toHaveBeenCalledWith(5678, null, 'source1');
  247. expect(setSsrcOwnerSpy).toHaveBeenCalledWith(4321, null, 'source2');
  248. expect(setSsrcOwnerSpy).toHaveBeenCalledWith(8765, null, 'source2');
  249. expect(updateRemoteSourcesSpy).toHaveBeenCalledWith(sourceInfo, true);
  250. sourceInfo = jingleSession._processSourceMapFromJingle(sourceAddElem, false);
  251. expect(removeSsrcOwnersSpy).toHaveBeenCalledWith([ 1234, 5678, 4321, 8765 ]);
  252. expect(updateRemoteSourcesSpy).toHaveBeenCalledWith(sourceInfo, false);
  253. });
  254. });
  255. });