modified lib-jitsi-meet dev repo
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 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* global */
  2. import Listenable from '../util/Listenable';
  3. import { nextTick } from '../util/TestUtils';
  4. import IceFailedHandling from './IceFailedHandling';
  5. import networkInfo from './NetworkInfo';
  6. /**
  7. * Mock conference for the purpose of this test.
  8. */
  9. class MockConference extends Listenable {
  10. /**
  11. * A constructor...
  12. */
  13. constructor() {
  14. super();
  15. this.options = {
  16. config: { }
  17. };
  18. }
  19. }
  20. describe('IceFailedHandling', () => {
  21. let mockConference;
  22. let iceFailedHandling;
  23. let emitEventSpy;
  24. beforeEach(() => {
  25. jasmine.clock().install();
  26. networkInfo.updateNetworkInfo({ isOnline: true });
  27. mockConference = new MockConference();
  28. iceFailedHandling = new IceFailedHandling(mockConference);
  29. mockConference.eventEmitter = {
  30. // eslint-disable-next-line no-empty-function
  31. emit: () => { }
  32. };
  33. emitEventSpy = spyOn(mockConference.eventEmitter, 'emit');
  34. });
  35. afterEach(() => {
  36. jasmine.clock().uninstall();
  37. });
  38. describe('when ICE restarts are disabled', () => {
  39. beforeEach(() => {
  40. mockConference.options.config.enableIceRestart = false;
  41. });
  42. it('emits ICE failed with 15 seconds delay', () => {
  43. iceFailedHandling.start();
  44. jasmine.clock().tick(10000);
  45. expect(emitEventSpy).not.toHaveBeenCalled();
  46. jasmine.clock().tick(5100);
  47. expect(emitEventSpy).toHaveBeenCalled();
  48. });
  49. it('starts counting the time after the internet comes back online', () => {
  50. iceFailedHandling.start();
  51. jasmine.clock().tick(3000);
  52. networkInfo.updateNetworkInfo({ isOnline: false });
  53. jasmine.clock().tick(16000);
  54. expect(emitEventSpy).not.toHaveBeenCalled();
  55. networkInfo.updateNetworkInfo({ isOnline: true });
  56. jasmine.clock().tick(16000);
  57. expect(emitEventSpy).toHaveBeenCalled();
  58. });
  59. it('cancel method cancels the ICE failed event', () => {
  60. iceFailedHandling.start();
  61. jasmine.clock().tick(10000);
  62. expect(emitEventSpy).not.toHaveBeenCalled();
  63. iceFailedHandling.cancel();
  64. jasmine.clock().tick(5100);
  65. expect(emitEventSpy).not.toHaveBeenCalled();
  66. });
  67. });
  68. describe('when ICE restart are enabled', () => {
  69. let sendIceFailedSpy;
  70. beforeEach(() => {
  71. mockConference.options.config.enableIceRestart = true;
  72. mockConference.xmpp = {
  73. isPingSupported: () => true,
  74. ping: () => Promise.resolve()
  75. };
  76. mockConference.jvbJingleSession = {
  77. getIceConnectionState: () => 'failed',
  78. // eslint-disable-next-line no-empty-function
  79. sendIceFailedNotification: () => { }
  80. };
  81. sendIceFailedSpy = spyOn(mockConference.jvbJingleSession, 'sendIceFailedNotification');
  82. });
  83. it('send ICE failed notification to Jicofo', () => {
  84. iceFailedHandling.start();
  85. // first it send ping which is async - need next tick
  86. return nextTick().then(() => {
  87. jasmine.clock().tick(3000);
  88. expect(sendIceFailedSpy).toHaveBeenCalled();
  89. });
  90. });
  91. it('not send ICE failed notification to Jicofo if canceled', () => {
  92. iceFailedHandling.start();
  93. // first it send ping which is async - need next tick
  94. return nextTick().then(() => {
  95. jasmine.clock().tick(1000);
  96. expect(sendIceFailedSpy).not.toHaveBeenCalled();
  97. iceFailedHandling.cancel();
  98. jasmine.clock().tick(3000);
  99. expect(sendIceFailedSpy).not.toHaveBeenCalled();
  100. });
  101. });
  102. });
  103. });