Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaboleken committed Oct 4, 2023
1 parent 7c00b1b commit 7e8baf8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/webapp/js/webrtc_adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ export class WebRTCAdaptor {
this.iceConnectionState(this.publishStreamId) != "connected" &&
this.iceConnectionState(this.publishStreamId) != "completed")
{
// notify that reconnection process started
// notify that reconnection process started for publish
this.notifyEventListeners("reconnection_attempt_for_publisher", this.publishStreamId);

this.closePeerConnection(this.publishStreamId);
Expand All @@ -656,7 +656,7 @@ export class WebRTCAdaptor {
this.iceConnectionState(streamId) != "connected" &&
this.iceConnectionState(streamId) != "completed")
{
// notify that reconnection process started
// notify that reconnection process started for play
this.notifyEventListeners("reconnection_attempt_for_player", streamId);

console.log("It will try to play again because it is not stopped on purpose")
Expand Down
22 changes: 18 additions & 4 deletions src/test/js/test/webrtc_adaptor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,17 @@ describe("WebRTCAdaptor", function() {

it("Test reconnection process started callback", async function()
{
var isReconnectionProcessStarted = false;
var isReconnectionProcessStartedForPublisher = false;
var isReconnectionProcessStartedForPlayer = false;

var adaptor = new WebRTCAdaptor({
websocketURL: "ws://example.com",
isPlayMode: true,
callback: (info, obj) => {
if (info === "reconnection_process_started") {
isReconnectionProcessStarted = true;
if (info === "reconnection_attempt_for_publisher") {
isReconnectionProcessStartedForPublisher = true;
} else if (info === "reconnection_attempt_for_player") {
isReconnectionProcessStartedForPlayer = true;
}
}
});
Expand All @@ -212,11 +216,21 @@ describe("WebRTCAdaptor", function() {
// some times Data.now() returns 0 and it is blocking the test
// so we set lastReconnectiontionTrialTime to -3000 to avoid this
adaptor.lastReconnectiontionTrialTime = -3000;

adaptor.publishStreamId = "testPublisher";
adaptor.remotePeerConnection["testPublisher"] = sinon.mock(RTCPeerConnection);
adaptor.remotePeerConnection["testPublisher"].iceConnectionState = "disconnected";

adaptor.playStreamId.push("testPlayer");
adaptor.remotePeerConnection["testPlayer"] = sinon.mock(RTCPeerConnection);
adaptor.remotePeerConnection["testPlayer"].iceConnectionState = "disconnected";

adaptor.tryAgain();

clock.tick(3000);

expect(isReconnectionProcessStarted).equal(true);
expect(isReconnectionProcessStartedForPublisher).equal(true);
expect(isReconnectionProcessStartedForPlayer).equal(true);
});

it("Reconnection for play", async function()
Expand Down

0 comments on commit 7e8baf8

Please sign in to comment.