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 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. });