diff --git a/packages/transport-bridge/src/core.ts b/packages/transport-bridge/src/core.ts index be8740c831e..ce2c16f112e 100644 --- a/packages/transport-bridge/src/core.ts +++ b/packages/transport-bridge/src/core.ts @@ -109,6 +109,7 @@ export const createCore = (apiArg: 'usb' | 'udp' | AbstractApi, logger?: Log) => }; const enumerate = async ({ signal }: { signal: AbortSignal }) => { + await sessionsClient.enumerateIntent(); const enumerateResult = await api.enumerate(signal); if (!enumerateResult.success) { diff --git a/packages/transport/src/sessions/background.ts b/packages/transport/src/sessions/background.ts index 1eb5cb35659..4bf8ed9efd0 100644 --- a/packages/transport/src/sessions/background.ts +++ b/packages/transport/src/sessions/background.ts @@ -69,6 +69,9 @@ export class SessionsBackground extends TypedEmitter<{ case 'handshake': result = this.handshake(); break; + case 'enumerateIntent': + await this.enumerateIntent(); + break; case 'enumerateDone': result = await this.enumerateDone(message.payload); break; @@ -119,11 +122,19 @@ export class SessionsBackground extends TypedEmitter<{ return this.success(undefined); } + private async enumerateIntent() { + await this.waitInQueue(); + + return this.success(undefined); + } + /** * enumerate done * - caller informs about current descriptors */ private enumerateDone(payload: EnumerateDoneRequest) { + this.clearLock(); + const disconnectedDevices = this.filterDisconnectedDevices( Object.values(this.descriptors), payload.descriptors.map(d => d.path), // which paths are occupied paths after last interface read diff --git a/packages/transport/src/sessions/client.ts b/packages/transport/src/sessions/client.ts index 7aaa91e1f8f..3b1d2c810f6 100644 --- a/packages/transport/src/sessions/client.ts +++ b/packages/transport/src/sessions/client.ts @@ -54,7 +54,9 @@ export class SessionsClient extends TypedEmitter<{ handshake() { return this.request({ type: 'handshake' }); } - + enumerateIntent() { + return this.request({ type: 'enumerateIntent' }); + } enumerateDone(payload: EnumerateDoneRequest) { return this.request({ type: 'enumerateDone', payload }); } @@ -78,6 +80,7 @@ export class SessionsClient extends TypedEmitter<{ } dispose() { this.removeAllListeners('descriptors'); + return this.request({ type: 'dispose' }); } } diff --git a/packages/transport/src/sessions/types.ts b/packages/transport/src/sessions/types.ts index e4ae58b5edd..a35e188bfb6 100644 --- a/packages/transport/src/sessions/types.ts +++ b/packages/transport/src/sessions/types.ts @@ -83,6 +83,7 @@ export type Params = { export interface HandleMessageApi { handshake: () => HandshakeResponse; + enumerateIntent: () => BackgroundResponse; enumerateDone: (payload: EnumerateDoneRequest) => EnumerateDoneResponse; acquireIntent: (payload: AcquireIntentRequest) => AcquireIntentResponse; acquireDone: (payload: AcquireDoneRequest) => AcquireDoneResponse; diff --git a/packages/transport/src/transports/abstractApi.ts b/packages/transport/src/transports/abstractApi.ts index a61f7d034e5..38ebcc583b1 100644 --- a/packages/transport/src/transports/abstractApi.ts +++ b/packages/transport/src/transports/abstractApi.ts @@ -70,6 +70,9 @@ export abstract class AbstractApiTransport extends AbstractTransport { public enumerate() { return this.scheduleAction(async signal => { + // todo: consider doing await this.sessionsClient.enumerateIntent() here + // it looks like Webusb does not need it is not needed at least on macos. + // enumerate usb api const enumerateResult = await this.api.enumerate(signal);