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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. /* options */ { });
  51. // eslint-disable-next-line no-empty-function
  52. // connection.connect('jid', undefined, () => { }); */
  53. });
  54. describe('send/receive video constraints', () => {
  55. it('sends content-modify with recv frame size', () => {
  56. const sendIQSpy = spyOn(connection, 'sendIQ').and.callThrough();
  57. jingleSession.setReceiverVideoConstraint(180);
  58. expect(jingleSession.getState()).toBe(JingleSessionState.PENDING);
  59. return new Promise((resolve, reject) => {
  60. jingleSession.acceptOffer(
  61. offerIQ,
  62. resolve,
  63. reject,
  64. /* local tracks */ []);
  65. }).then(() => {
  66. expect(jingleSession.getState()).toBe(JingleSessionState.ACTIVE);
  67. // FIXME content-modify is sent before session-accept
  68. expect(sendIQSpy.calls.count()).toBe(2);
  69. expect(sendIQSpy.calls.first().args[0].toString()).toBe(
  70. '<iq to="peer2" type="set" xmlns="jabber:client">'
  71. + '<jingle action="content-modify" initiator="peer2" sid="sid12345" xmlns="urn:xmpp:jingle:1">'
  72. + '<content name="video" senders="both">'
  73. + '<max-frame-height xmlns="http://jitsi.org/jitmeet/video">180</max-frame-height>'
  74. + '</content>'
  75. + '</jingle>'
  76. + '</iq>');
  77. });
  78. });
  79. it('fires an event when remote peer sends content-modify', () => {
  80. let remoteRecvMaxFrameHeight;
  81. const remoteVideoConstraintsListener = session => {
  82. remoteRecvMaxFrameHeight = session.getRemoteRecvMaxFrameHeight();
  83. };
  84. jingleSession.addListener(
  85. MediaSessionEvents.REMOTE_VIDEO_CONSTRAINTS_CHANGED,
  86. remoteVideoConstraintsListener);
  87. return new Promise((resolve, reject) => {
  88. jingleSession.acceptOffer(
  89. offerIQ,
  90. resolve,
  91. reject,
  92. /* local tracks */ []);
  93. }).then(() => {
  94. jingleSession.modifyContents(createContentModify('both', 180));
  95. expect(remoteRecvMaxFrameHeight).toBe(180);
  96. jingleSession.modifyContents(createContentModify('both', 360));
  97. expect(remoteRecvMaxFrameHeight).toBe(360);
  98. jingleSession.modifyContents(createContentModify('both', 180));
  99. expect(remoteRecvMaxFrameHeight).toBe(180);
  100. });
  101. });
  102. });
  103. });