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.

IceFailedHandling.spec.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* global */
  2. import Listenable from '../util/Listenable';
  3. import { nextTick } from '../util/TestUtils';
  4. import IceFailedHandling from './IceFailedHandling';
  5. /**
  6. * Mock conference for the purpose of this test.
  7. */
  8. class MockConference extends Listenable {
  9. /**
  10. * A constructor...
  11. */
  12. constructor() {
  13. super();
  14. this.options = {
  15. config: { }
  16. };
  17. }
  18. }
  19. describe('IceFailedHandling', () => {
  20. let mockConference;
  21. let iceFailedHandling;
  22. let emitEventSpy;
  23. beforeEach(() => {
  24. jasmine.clock().install();
  25. mockConference = new MockConference();
  26. iceFailedHandling = new IceFailedHandling(mockConference);
  27. mockConference.eventEmitter = {
  28. // eslint-disable-next-line no-empty-function
  29. emit: () => { }
  30. };
  31. mockConference.room = {
  32. supportsRestartByTerminate: () => false
  33. };
  34. mockConference.xmpp = {
  35. ping: () => Promise.resolve()
  36. };
  37. emitEventSpy = spyOn(mockConference.eventEmitter, 'emit');
  38. });
  39. afterEach(() => {
  40. jasmine.clock().uninstall();
  41. });
  42. describe('when ICE restarts are disabled', () => {
  43. beforeEach(() => {
  44. mockConference.options.config.enableIceRestart = false;
  45. });
  46. it('emits ICE failed with 2 seconds delay after XMPP ping comes through', () => {
  47. iceFailedHandling.start();
  48. return nextTick() // tick for ping
  49. .then(() => {
  50. expect(emitEventSpy).not.toHaveBeenCalled();
  51. return nextTick(2500); // tick for the 2 sec ice timeout
  52. })
  53. .then(() => {
  54. expect(emitEventSpy).toHaveBeenCalled();
  55. });
  56. });
  57. it('cancel method cancels the ICE failed event', () => {
  58. iceFailedHandling.start();
  59. return nextTick(1000) // tick for ping
  60. .then(() => {
  61. expect(emitEventSpy).not.toHaveBeenCalled();
  62. iceFailedHandling.cancel();
  63. return nextTick(2500); // tick for ice timeout
  64. })
  65. .then(() => {
  66. expect(emitEventSpy).not.toHaveBeenCalled();
  67. });
  68. });
  69. });
  70. describe('when ICE restart are enabled', () => {
  71. let sendIceFailedSpy;
  72. beforeEach(() => {
  73. mockConference.options.config.enableIceRestart = true;
  74. mockConference.jvbJingleSession = {
  75. getIceConnectionState: () => 'failed',
  76. // eslint-disable-next-line no-empty-function
  77. sendIceFailedNotification: () => { }
  78. };
  79. sendIceFailedSpy = spyOn(mockConference.jvbJingleSession, 'sendIceFailedNotification');
  80. });
  81. it('send ICE failed notification to Jicofo', () => {
  82. iceFailedHandling.start();
  83. return nextTick() // tick for ping
  84. .then(() => nextTick(2500)) // tick for ice timeout
  85. .then(() => {
  86. expect(sendIceFailedSpy).toHaveBeenCalled();
  87. });
  88. });
  89. it('not send ICE failed notification to Jicofo if canceled', () => {
  90. iceFailedHandling.start();
  91. // first it send ping which is async - need next tick
  92. return nextTick(1000)
  93. .then(() => {
  94. expect(sendIceFailedSpy).not.toHaveBeenCalled();
  95. iceFailedHandling.cancel();
  96. return nextTick(3000); // tick for ice timeout
  97. })
  98. .then(() => {
  99. expect(sendIceFailedSpy).not.toHaveBeenCalled();
  100. });
  101. });
  102. });
  103. describe('if Jingle session restarts are supported', () => {
  104. let sendSessionTerminateSpy;
  105. beforeEach(() => {
  106. mockConference.options.config.enableIceRestart = undefined;
  107. mockConference.room = {
  108. supportsRestartByTerminate: () => true
  109. };
  110. mockConference.jvbJingleSession = {
  111. getIceConnectionState: () => 'failed',
  112. // eslint-disable-next-line no-empty-function
  113. terminate: () => { }
  114. };
  115. sendSessionTerminateSpy = spyOn(mockConference.jvbJingleSession, 'terminate');
  116. });
  117. it('send "session-terminate" with the request restart attribute', () => {
  118. iceFailedHandling.start();
  119. return nextTick() // tick for ping
  120. .then(() => nextTick(2500)) // tick for ice timeout
  121. .then(() => {
  122. expect(sendSessionTerminateSpy).toHaveBeenCalledWith(
  123. jasmine.any(Function),
  124. jasmine.any(Function), {
  125. reason: 'connectivity-error',
  126. reasonDescription: 'ICE FAILED',
  127. requestRestart: true,
  128. sendSessionTerminate: true
  129. });
  130. });
  131. });
  132. });
  133. });