您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

IceFailedHandling.spec.js 5.7KB

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