Skip to content

Commit

Permalink
Reset connection state after second reconnect failure
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-robert committed Nov 15, 2024
1 parent cbe0977 commit 576a891
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/get-next-connection-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ describe("getNextConnectionState for radio connection", () => {
type: "radioRemote",
},
initialOnFirstConnectAttempt: false,
expectedOnFirstConnectAttempt: false,
expectedOnFirstConnectAttempt: true,
initialHasAttemptedReconnect: true,
expectedHasAttemptedReconnect: true,
expectedHasAttemptedReconnect: false,
expectedNextConnectionState: {
status: ConnectionStatus.FailedToReconnectTwice,
flowType: ConnectionFlowType.ConnectRadioRemote,
Expand Down Expand Up @@ -548,9 +548,9 @@ describe("getNextConnectionState for bluetooth connection", () => {
type: "bluetooth",
},
initialOnFirstConnectAttempt: false,
expectedOnFirstConnectAttempt: false,
expectedOnFirstConnectAttempt: true,
initialHasAttemptedReconnect: true,
expectedHasAttemptedReconnect: true,
expectedHasAttemptedReconnect: false,
expectedNextConnectionState: {
status: ConnectionStatus.FailedToReconnectTwice,
flowType: ConnectionFlowType.ConnectBluetooth,
Expand Down
3 changes: 3 additions & 0 deletions src/get-next-connection-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ export const getNextConnectionState = ({
hasAttempedReconnect &&
deviceStatus === DeviceConnectionStatus.DISCONNECTED
) {
// Reset connection state fields so that the next connection attempt is clean.
setOnFirstConnectAttempt(true);
setHasAttemptedReconnect(false);
return { status: ConnectionStatus.FailedToReconnectTwice, flowType };
}
if (
Expand Down

0 comments on commit 576a891

Please sign in to comment.