Skip to content

Commit

Permalink
Merge pull request #448 from ant-media/fix/issue-446
Browse files Browse the repository at this point in the history
Do not count streamIdInUseCounter in case of reconnection
  • Loading branch information
burak-58 authored Jan 13, 2025
2 parents fa471f1 + 1ce3f17 commit 3c5979f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
31 changes: 31 additions & 0 deletions react/src/__tests__/pages/AntMedia.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<ThemeProvider theme={theme(ThemeList.Green)}>
<AntMedia isTest={true}>
<MockChild/>
</AntMedia>
</ThemeProvider>);


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(
<ThemeProvider theme={theme(ThemeList.Green)}>
Expand Down
17 changes: 10 additions & 7 deletions react/src/pages/AntMedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -1797,13 +1797,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";
Expand Down

0 comments on commit 3c5979f

Please sign in to comment.