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.

JingleSessionPC.spec.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* global $, 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. * @param {string} senders - 'both' or 'none'.
  10. * @param {number|undefined} maxFrameHeight - the receive max video frame height.
  11. * @returns {jQuery}
  12. */
  13. function createContentModify(senders = 'both', maxFrameHeight) {
  14. const modifyContentsIq = jQuery.parseXML(
  15. '<jingle action="content-modify" initiator="peer2" sid="sid12345" xmlns="urn:xmpp:jingle:1">'
  16. + `<content name="video" senders="${senders}">`
  17. + `<max-frame-height xmlns="http://jitsi.org/jitmeet/video">${maxFrameHeight}</max-frame-height>`
  18. + '</content>'
  19. + '</jingle>');
  20. return $(modifyContentsIq).find('>jingle');
  21. }
  22. describe('JingleSessionPC', () => {
  23. let jingleSession;
  24. let connection;
  25. let rtc;
  26. const offerIQ = {
  27. find: () => {
  28. return {
  29. // eslint-disable-next-line no-empty-function
  30. each: () => { }
  31. };
  32. }
  33. };
  34. const SID = 'sid12345';
  35. beforeEach(() => {
  36. connection = new MockStropheConnection();
  37. jingleSession = new JingleSessionPC(
  38. SID,
  39. 'peer1',
  40. 'peer2',
  41. connection,
  42. { },
  43. { },
  44. true,
  45. false);
  46. rtc = new MockRTC();
  47. jingleSession.initialize(
  48. /* ChatRoom */ new MockChatRoom(),
  49. /* RTC */ rtc,
  50. /* Signaling layer */ { },
  51. /* options */ { });
  52. // eslint-disable-next-line no-empty-function
  53. // connection.connect('jid', undefined, () => { }); */
  54. });
  55. describe('send/receive video constraints', () => {
  56. it('sends content-modify with recv frame size', () => {
  57. const sendIQSpy = spyOn(connection, 'sendIQ').and.callThrough();
  58. jingleSession.setReceiverVideoConstraint(180);
  59. expect(jingleSession.getState()).toBe(JingleSessionState.PENDING);
  60. return new Promise((resolve, reject) => {
  61. jingleSession.acceptOffer(
  62. offerIQ,
  63. resolve,
  64. reject,
  65. /* local tracks */ []);
  66. }).then(() => {
  67. expect(jingleSession.getState()).toBe(JingleSessionState.ACTIVE);
  68. // FIXME content-modify is sent before session-accept
  69. expect(sendIQSpy.calls.count()).toBe(2);
  70. expect(sendIQSpy.calls.first().args[0].toString()).toBe(
  71. '<iq to="peer2" type="set" xmlns="jabber:client">'
  72. + '<jingle action="content-modify" initiator="peer2" sid="sid12345" xmlns="urn:xmpp:jingle:1">'
  73. + '<content name="video" senders="both">'
  74. + '<max-frame-height xmlns="http://jitsi.org/jitmeet/video">180</max-frame-height>'
  75. + '</content>'
  76. + '</jingle>'
  77. + '</iq>');
  78. });
  79. });
  80. it('fires an event when remote peer sends content-modify', () => {
  81. let remoteRecvMaxFrameHeight;
  82. const remoteVideoConstraintsListener = session => {
  83. remoteRecvMaxFrameHeight = session.getRemoteRecvMaxFrameHeight();
  84. };
  85. jingleSession.addListener(
  86. MediaSessionEvents.REMOTE_VIDEO_CONSTRAINTS_CHANGED,
  87. remoteVideoConstraintsListener);
  88. return new Promise((resolve, reject) => {
  89. jingleSession.acceptOffer(
  90. offerIQ,
  91. resolve,
  92. reject,
  93. /* local tracks */ []);
  94. }).then(() => {
  95. jingleSession.modifyContents(createContentModify('both', 180));
  96. expect(remoteRecvMaxFrameHeight).toBe(180);
  97. jingleSession.modifyContents(createContentModify('both', 360));
  98. expect(remoteRecvMaxFrameHeight).toBe(360);
  99. jingleSession.modifyContents(createContentModify('both', 180));
  100. expect(remoteRecvMaxFrameHeight).toBe(180);
  101. });
  102. });
  103. });
  104. });