Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reconnection issues #400

Merged
merged 9 commits into from
Oct 19, 2023
15 changes: 9 additions & 6 deletions src/main/webapp/js/webrtc_adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ export class WebRTCAdaptor {
this.notifyEventListeners("reconnection_attempt_for_publisher", this.publishStreamId);

this.closePeerConnection(this.publishStreamId);
console.log("It will try to publish again because it is not stopped on purpose")
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 @@ -656,10 +656,10 @@ export class WebRTCAdaptor {
this.iceConnectionState(streamId) != "connected" &&
this.iceConnectionState(streamId) != "completed")
{
// notify that reconnection process started for play
this.notifyEventListeners("reconnection_attempt_for_player", streamId);
// 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")
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 Expand Up @@ -1658,8 +1658,11 @@ export class WebRTCAdaptor {
var CHUNK_SIZE = 16000;
if (this.remotePeerConnection[streamId] !== undefined) {
var dataChannel = this.remotePeerConnection[streamId].dataChannel;
if (dataChannel == undefined || dataChannel.readyState !== 'open') {
console.warn('dataChannel.readyState is not open: ' + dataChannel.readyState);
if (dataChannel === undefined || dataChannel === null || typeof dataChannel === 'undefined') {
Logger.warn('dataChannel is null or undefined');
return;
} else if (dataChannel.readyState !== 'open') {
Logger.warn('dataChannel.readyState is not open: ' + dataChannel.readyState);
return;
}
var length = data.length || data.size || data.byteLength;
Expand Down
7 changes: 7 additions & 0 deletions src/test/js/test/webrtc_adaptor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,18 @@ describe("WebRTCAdaptor", function() {
var webSocketAdaptor = sinon.mock(adaptor.webSocketAdaptor);

adaptor.remotePeerConnection[streamId] = sinon.mock(RTCPeerConnection);

adaptor.remotePeerConnection[streamId].dataChannel = sinon.fake.returns({
readyState: "open",
send: sinon.fake()
});
adaptor.sendData(streamId, "test");

adaptor.remotePeerConnection[streamId].dataChannel = undefined
adaptor.sendData(streamId, "test");

adaptor.remotePeerConnection[streamId].dataChannel = null
adaptor.sendData(streamId, "test");
} catch (e) {
console.error(e);
assert(false);
Expand Down