Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

IceFailedHandling.spec.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. mockConference.xmpp = {
  36. ping: () => Promise.resolve()
  37. };
  38. emitEventSpy = spyOn(mockConference.eventEmitter, 'emit');
  39. });
  40. afterEach(() => {
  41. jasmine.clock().uninstall();
  42. });
  43. describe('if Jingle session restarts are supported', () => {
  44. let sendSessionTerminateSpy;
  45. beforeEach(() => {
  46. mockConference.room = {};
  47. mockConference.jvbJingleSession = {
  48. getIceConnectionState: () => 'failed',
  49. // eslint-disable-next-line no-empty-function
  50. terminate: () => { }
  51. };
  52. sendSessionTerminateSpy = spyOn(mockConference, '_stopJvbSession');
  53. });
  54. it('send "session-terminate" with the request restart attribute', () => {
  55. iceFailedHandling.start();
  56. return nextTick() // tick for ping
  57. .then(() => nextTick(2500)) // tick for ice timeout
  58. .then(() => {
  59. expect(sendSessionTerminateSpy).toHaveBeenCalledWith(
  60. {
  61. reason: 'connectivity-error',
  62. reasonDescription: 'ICE FAILED',
  63. requestRestart: true,
  64. sendSessionTerminate: true
  65. });
  66. });
  67. });
  68. it('cancel method cancels the call to terminate session', () => {
  69. iceFailedHandling.start();
  70. return nextTick(1000) // tick for ping
  71. .then(() => {
  72. expect(sendSessionTerminateSpy).not.toHaveBeenCalled();
  73. iceFailedHandling.cancel();
  74. return nextTick(2500); // tick for ice timeout
  75. })
  76. .then(() => {
  77. expect(sendSessionTerminateSpy).not.toHaveBeenCalled();
  78. });
  79. });
  80. });
  81. describe('when forced reloads are enabled', () => {
  82. beforeEach(() => {
  83. mockConference.options.config.enableForcedReload = true;
  84. mockConference.room = {};
  85. });
  86. it('emits conference restarted when force reloads are enabled', () => {
  87. iceFailedHandling.start();
  88. return nextTick() // tick for ping
  89. .then(() => nextTick(2500)) // tick for ice timeout
  90. .then(() => {
  91. expect(emitEventSpy).toHaveBeenCalled();
  92. });
  93. });
  94. });
  95. });