Skip to content

Commit

Permalink
Merge branch 'master' into fixReconnectionIssues
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaboleken authored Oct 4, 2023
2 parents bb85382 + db4a64b commit 5153adf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/webapp/js/webrtc_adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ export class WebRTCAdaptor {
}
this.lastReconnectiontionTrialTime = now;

//reconnect publish
//reconnect publish
//if remotePeerConnection has a peer connection for the stream id, it means that it is not stopped on purpose

if (this.remotePeerConnection[this.publishStreamId] != null &&
Expand All @@ -638,6 +638,9 @@ export class WebRTCAdaptor {
this.iceConnectionState(this.publishStreamId) != "connected" &&
this.iceConnectionState(this.publishStreamId) != "completed")
{
// notify that reconnection process started for publish
this.notifyEventListeners("reconnection_attempt_for_publisher", this.publishStreamId);

this.closePeerConnection(this.publishStreamId);
Logger.log("It will try to publish again because it is not stopped on purpose")
this.publish(this.publishStreamId, this.publishToken, this.publishSubscriberId, this.publishSubscriberCode, this.publishStreamName, this.publishMainTrack, this.publishMetaData);
Expand All @@ -653,7 +656,10 @@ export class WebRTCAdaptor {
this.iceConnectionState(streamId) != "connected" &&
this.iceConnectionState(streamId) != "completed")
{
Logger.log("It will try to play again because it is not stopped on purpose")
// notify that reconnection process started for play
this.notifyEventListeners("reconnection_attempt_for_player", streamId);

Logger.log("It will try to play again because it is not stopped on purpose")
this.closePeerConnection(streamId);
this.play(streamId, this.playToken, this.playRoomId, this.playEnableTracks, this.playSubscriberId, this.playSubscriberCode, this.playMetaData);
}
Expand Down
42 changes: 42 additions & 0 deletions src/test/js/test/webrtc_adaptor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,48 @@ describe("WebRTCAdaptor", function() {
expect(adaptor.lastReconnectiontionTrialTime).not.to.be.equal(lrt);
});

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

var adaptor = new WebRTCAdaptor({
websocketURL: "ws://example.com",
isPlayMode: true,
callback: (info, obj) => {
if (info === "reconnection_attempt_for_publisher") {
isReconnectionProcessStartedForPublisher = true;
} else if (info === "reconnection_attempt_for_player") {
isReconnectionProcessStartedForPlayer = true;
}
}
});
var webSocketAdaptor = sinon.mock(adaptor.webSocketAdaptor);

var closeExpectation = webSocketAdaptor.expects("close");

var closePeerConnection = sinon.replace(adaptor, "closePeerConnection", sinon.fake());

// 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(isReconnectionProcessStartedForPublisher).equal(true);
expect(isReconnectionProcessStartedForPlayer).equal(true);
});

it("Reconnection for play", async function()
{
var adaptor = new WebRTCAdaptor({
Expand Down

0 comments on commit 5153adf

Please sign in to comment.