1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import Listenable from '../util/Listenable';
- import { nextTick } from '../util/TestUtils';
-
- import IceFailedHandling from './IceFailedHandling';
-
- /**
- * Mock conference for the purpose of this test.
- */
- class MockConference extends Listenable {
- /**
- * A constructor...
- */
- constructor() {
- super();
- this.options = {
- config: { }
- };
- }
-
- /**
- * Mock function.
- */
- _stopJvbSession() {} // eslint-disable-line no-empty-function
- }
-
- describe('IceFailedHandling', () => {
- let mockConference;
- let iceFailedHandling;
- let emitEventSpy;
-
- beforeEach(() => {
- jasmine.clock().install();
- mockConference = new MockConference();
- iceFailedHandling = new IceFailedHandling(mockConference);
- mockConference.eventEmitter = {
- // eslint-disable-next-line no-empty-function
- emit: () => { }
- };
- mockConference.room = {};
- mockConference.xmpp = {
- ping: () => Promise.resolve()
- };
- emitEventSpy = spyOn(mockConference.eventEmitter, 'emit');
- });
-
- afterEach(() => {
- jasmine.clock().uninstall();
- });
-
- describe('if Jingle session restarts are supported', () => {
- let sendSessionTerminateSpy;
-
- beforeEach(() => {
- mockConference.room = {};
- mockConference.jvbJingleSession = {
- getIceConnectionState: () => 'failed',
- // eslint-disable-next-line no-empty-function
- terminate: () => { }
- };
- sendSessionTerminateSpy = spyOn(mockConference, '_stopJvbSession');
- });
- it('send "session-terminate" with the request restart attribute', () => {
- iceFailedHandling.start();
-
- return nextTick() // tick for ping
- .then(() => nextTick(2500)) // tick for ice timeout
- .then(() => {
- expect(sendSessionTerminateSpy).toHaveBeenCalledWith(
- {
- reason: 'connectivity-error',
- reasonDescription: 'ICE FAILED',
- requestRestart: true,
- sendSessionTerminate: true
- });
- });
- });
- it('cancel method cancels the call to terminate session', () => {
- iceFailedHandling.start();
-
- return nextTick(1000) // tick for ping
- .then(() => {
- expect(sendSessionTerminateSpy).not.toHaveBeenCalled();
- iceFailedHandling.cancel();
-
- return nextTick(2500); // tick for ice timeout
- })
- .then(() => {
- expect(sendSessionTerminateSpy).not.toHaveBeenCalled();
- });
- });
- });
- });
|