Skip to content

Commit b2b2c0a

Browse files
Start and stop radio bridge connection on delegate status (#15)
1 parent 523377e commit b2b2c0a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/usb-radio-bridge.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,15 @@ export class MicrobitRadioBridgeConnection
4747
private remoteDeviceId: number | undefined;
4848

4949
private delegateStatusListner = (e: ConnectionStatusEvent) => {
50+
const currentStatus = this.status;
5051
if (e.status !== ConnectionStatus.CONNECTED) {
5152
this.setStatus(e.status);
53+
this.serialSession?.dispose();
5254
} else {
5355
this.status = ConnectionStatus.NOT_CONNECTED;
56+
if (currentStatus === ConnectionStatus.NOT_CONNECTED) {
57+
this.serialSession?.connect();
58+
}
5459
}
5560
};
5661

@@ -117,7 +122,9 @@ export class MicrobitRadioBridgeConnection
117122
type: "Serial",
118123
message: "Serial connection lost 1",
119124
});
120-
this.serialSession?.dispose();
125+
// This is the point we tell the consumer that we're trying to reconnect
126+
// in the background.
127+
// Leave serial connection running in case the remote device comes back.
121128
},
122129
() => {
123130
// Remote connection... even more lost?

0 commit comments

Comments
 (0)