Skip to content

Commit

Permalink
reset connectionHealthData before (re)connection
Browse files Browse the repository at this point in the history
  • Loading branch information
XHatan committed Dec 11, 2019
1 parent 55fc3e1 commit 9e8b5e0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/audiovideocontroller/DefaultAudioVideoController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default class DefaultAudioVideoController implements AudioVideoController
this._audioMixController,
this._deviceController
);
this.meetingSessionContext.logger = this._logger;
}

get configuration(): MeetingSessionConfiguration {
Expand Down Expand Up @@ -191,6 +192,7 @@ export default class DefaultAudioVideoController implements AudioVideoController
}

private async actionConnect(reconnecting: boolean): Promise<void> {
this.connectionHealthData.reset();
this.meetingSessionContext = new AudioVideoControllerState();
this.meetingSessionContext.logger = this.logger;
this.meetingSessionContext.browserBehavior = new DefaultBrowserBehavior();
Expand Down Expand Up @@ -296,7 +298,6 @@ export default class DefaultAudioVideoController implements AudioVideoController
this.configuration.connectionTimeoutMs
),
]).run();

this.sessionStateController.perform(SessionStateControllerAction.FinishConnecting, () => {
this.actionFinishConnecting();
});
Expand All @@ -313,6 +314,7 @@ export default class DefaultAudioVideoController implements AudioVideoController
}
});
}
this.connectionHealthData.setConnectionStartTime();
}

private actionFinishConnecting(): void {
Expand Down Expand Up @@ -359,7 +361,6 @@ export default class DefaultAudioVideoController implements AudioVideoController
} catch (error) {
this.logger.info('fail to clean');
}

this.sessionStateController.perform(SessionStateControllerAction.FinishDisconnecting, () => {
if (!reconnecting) {
this.forEachObserver(observer => {
Expand Down Expand Up @@ -479,6 +480,7 @@ export default class DefaultAudioVideoController implements AudioVideoController
});
}

this.connectionHealthData.reset();
try {
await new SerialGroupTask(this.logger, 'AudioVideoReconnect', [
new TimeoutTask(
Expand Down Expand Up @@ -526,6 +528,7 @@ export default class DefaultAudioVideoController implements AudioVideoController
);
});
}
this.connectionHealthData.setConnectionStartTime();
}

private getMeetingStatusCode(error: Error): MeetingSessionStatusCode | null {
Expand Down
21 changes: 21 additions & 0 deletions src/connectionhealthpolicy/ConnectionHealthData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ export default class ConnectionHealthData {
private static isTimestampRecent(timestampMs: number, recentDurationMs: number): boolean {
return Date.now() < timestampMs + recentDurationMs;
}

setConnectionStartTime(): void {
this.connectionStartTimestampMs = Date.now();
this.lastGoodSignalTimestampMs = Date.now();
}

reset(): void {
this.connectionStartTimestampMs = 0;
this.consecutiveStatsWithNoPackets = 0;
this.lastPacketLossInboundTimestampMs = 0;
this.lastGoodSignalTimestampMs = 0;
this.lastWeakSignalTimestampMs = 0;
this.lastNoSignalTimestampMs = 0;
this.consecutiveMissedPongs = 0;
this.packetsReceivedInLastMinute = [];
this.fractionPacketsLostInboundInLastMinute = [];
this.audioSpeakerDelayMs = 0;
this.connectionStartTimestampMs = Date.now();
this.lastGoodSignalTimestampMs = Date.now();
}

isConnectionStartRecent(recentDurationMs: number): boolean {
return ConnectionHealthData.isTimestampRecent(
this.connectionStartTimestampMs,
Expand Down
21 changes: 21 additions & 0 deletions test/task/CleanRestartedSessionTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,27 @@ import * as chai from 'chai';

import AudioVideoControllerState from '../../src/audiovideocontroller/AudioVideoControllerState';
import NoOpAudioVideoController from '../../src/audiovideocontroller/NoOpAudioVideoController';
import ConnectionHealthData from '../../src/connectionhealthpolicy/ConnectionHealthData';
import SignalingAndMetricsConnectionMonitor from '../../src/connectionmonitor/SignalingAndMetricsConnectionMonitor';
import NoOpDebugLogger from '../../src/logger/NoOpDebugLogger';
import PingPong from '../../src/pingpong/PingPong';
import PingPongObserver from '../../src/pingpongobserver/PingPongObserver';
import TimeoutScheduler from '../../src/scheduler/TimeoutScheduler';
import DefaultStatsCollector from '../../src/statscollector/DefaultStatsCollector';
import CleanRestartedSessionTask from '../../src/task/CleanRestartedSessionTask';
import Task from '../../src/task/Task';
import DefaultTransceiverController from '../../src/transceivercontroller/DefaultTransceiverController';
import DefaultVideoTileController from '../../src/videotilecontroller/DefaultVideoTileController';
import DefaultVideoTileFactory from '../../src/videotilefactory/DefaultVideoTileFactory';
import DOMMockBehavior from '../dommock/DOMMockBehavior';
import DOMMockBuilder from '../dommock/DOMMockBuilder';
class TestPingPong implements PingPong {
addObserver(_observer: PingPongObserver): void {}
removeObserver(_observer: PingPongObserver): void {}
forEachObserver(_observerFunc: (_observer: PingPongObserver) => void): void {}
start(): void {}
stop(): void {}
}

describe('CleanRestartedSessionTask', () => {
const expect: Chai.ExpectStatic = chai.expect;
Expand All @@ -33,6 +46,14 @@ describe('CleanRestartedSessionTask', () => {
context.audioVideoController,
context.audioVideoController.logger
);
context.connectionMonitor = new SignalingAndMetricsConnectionMonitor(
context.audioVideoController,
context.audioVideoController.realtimeController,
context.audioVideoController.videoTileController,
new ConnectionHealthData(),
new TestPingPong(),
new DefaultStatsCollector(context.audioVideoController, new NoOpDebugLogger())
);

task = new CleanRestartedSessionTask(context);
});
Expand Down

0 comments on commit 9e8b5e0

Please sign in to comment.