From 89f2e84cc16a42d8747f09ce9aff3352774ab8a0 Mon Sep 17 00:00:00 2001 From: Mustafa BOLEKEN Date: Tue, 7 Jan 2025 01:37:50 +0300 Subject: [PATCH 1/3] Do not count streamIdInUseCounter in case of reconnection --- react/src/pages/AntMedia.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/react/src/pages/AntMedia.js b/react/src/pages/AntMedia.js index 8a0f1818..47ede572 100644 --- a/react/src/pages/AntMedia.js +++ b/react/src/pages/AntMedia.js @@ -1361,7 +1361,7 @@ function AntMedia(props) { }); //just run once when component is mounted - }, []); //eslint-disable-line + }, []); //eslint-disable-line useEffect(() => { if (devices.length > 0) { @@ -1786,13 +1786,16 @@ function AntMedia(props) { } else if (error.indexOf("no_stream_exist") !== -1) { setIsNoSreamExist(true); } else if (error.indexOf("streamIdInUse") !== -1) { - streamIdInUseCounter++; - if (streamIdInUseCounter > 3) { - console.log("This stream id is already in use. You may be logged in on another device."); - setLeaveRoomWithError("Streaming is already active with your username. Please check that you're not using it in another browser tab."); - setLeftTheRoom(true); - setIsJoining(false); - setIsReconnectionInProgress(false); + // if the stream id is in use when reconnection, don't display the error + if (!reconnecting) { + streamIdInUseCounter++; + if (streamIdInUseCounter > 3) { + console.log("This stream id is already in use. You may be logged in on another device."); + setLeaveRoomWithError("Streaming is already active with your username. Please check that you're not using it in another browser tab."); + setLeftTheRoom(true); + setIsJoining(false); + setIsReconnectionInProgress(false); + } } } else if (error.indexOf("data_channel_error") !== -1) { errorMessage = "There was a error during data channel communication"; @@ -3176,7 +3179,8 @@ function AntMedia(props) { speedTestCounter, setRoomName, setPublishStreamId, - settings + settings, + setReconnectingForUnitTests }} > {props.children} From ea78a13263462c8081b17828135f078d73800975 Mon Sep 17 00:00:00 2001 From: Mustafa BOLEKEN Date: Tue, 7 Jan 2025 11:37:22 +0300 Subject: [PATCH 2/3] Remove setReconnectingForUnitTests from context --- react/src/pages/AntMedia.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/react/src/pages/AntMedia.js b/react/src/pages/AntMedia.js index 47ede572..5575eac4 100644 --- a/react/src/pages/AntMedia.js +++ b/react/src/pages/AntMedia.js @@ -3179,8 +3179,7 @@ function AntMedia(props) { speedTestCounter, setRoomName, setPublishStreamId, - settings, - setReconnectingForUnitTests + settings }} > {props.children} From 1ce3f1775b30b67fdc8c79db624e7f1d5c43a2c6 Mon Sep 17 00:00:00 2001 From: Mustafa BOLEKEN Date: Mon, 13 Jan 2025 03:36:34 +0300 Subject: [PATCH 3/3] Add integration test --- react/src/__tests__/pages/AntMedia.test.js | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/react/src/__tests__/pages/AntMedia.test.js b/react/src/__tests__/pages/AntMedia.test.js index 66480ef4..c6012406 100644 --- a/react/src/__tests__/pages/AntMedia.test.js +++ b/react/src/__tests__/pages/AntMedia.test.js @@ -2275,6 +2275,37 @@ describe('AntMedia Component', () => { consoleSpy.mockRestore(); }); + it('streamIdInUseCounter is not incremented due to reconnection is true', async () => { + const consoleSpy = jest.spyOn(console, 'log').mockImplementation(); + + const {container} = render( + + + + + ); + + + await waitFor(() => { + expect(webRTCAdaptorConstructor).not.toBe(undefined); + }); + + await act(async () => { + webRTCAdaptorConstructor.callback("reconnection_attempt_for_player"); + }); + + await act(async () => { + webRTCAdaptorConstructor.callbackError("streamIdInUse", "Stream ID is in use"); + webRTCAdaptorConstructor.callbackError("streamIdInUse", "Stream ID is in use"); + webRTCAdaptorConstructor.callbackError("streamIdInUse", "Stream ID is in use"); + webRTCAdaptorConstructor.callbackError("streamIdInUse", "Stream ID is in use"); + }); + + expect(consoleSpy).not.toHaveBeenCalledWith("This stream id is already in use. You may be logged in on another device."); + + consoleSpy.mockRestore(); + }); + it('updates allParticipants and participantUpdated when subtrackList is provided', async () => { const { container } = render(