diff --git a/src/speechmike_hid_device.ts b/src/speechmike_hid_device.ts index 8e571e0..3150395 100644 --- a/src/speechmike_hid_device.ts +++ b/src/speechmike_hid_device.ts @@ -369,7 +369,10 @@ export class SpeechMikeHidDevice extends DictationDeviceBase { } else if (this.commandResolvers.get(command) !== undefined) { await this.handleCommandResponse(command, data); } else { - throw new Error(`Unhandled input report from command ${command}`); + // Ignore extra status messages and slow replies from the device + // (common on wireless devices like the SpeechMike Ambient PSM5000, + // e.g. on device power off/on or machine lock/unlock). + console.debug(`Ignoring unhandled input report from command ${command}`); } } diff --git a/src/speechmike_hid_device_test.ts b/src/speechmike_hid_device_test.ts index c2979a8..09bebcd 100644 --- a/src/speechmike_hid_device_test.ts +++ b/src/speechmike_hid_device_test.ts @@ -474,6 +474,22 @@ describe('SpeechMikeHidDevice', () => { state.dictationDevice, MotionEvent.LAYED_DOWN); }); + it('ignores unrecognized input reports without throwing', async () => { + await createDictationDeviceForType(DeviceType.SPEECHMIKE_SMP_3700); + + // Wireless SpeechMikes (e.g. Ambient PSM5000) emit unsolicited + // status/handshake reports, and may deliver command replies after their + // resolver has timed out. Command 134 (0x86) matches neither a button, + // motion nor wireless-status event, and has no pending resolver, so it must + // be ignored rather than throwing. + await expectAsync( + state.fakeHidDevice.handleInputReport([134, 0, 0, 0, 0, 0, 0, 0, 0])) + .toBeResolved(); + + expect(state.buttonEventListener).not.toHaveBeenCalled(); + expect(state.motionEventListener).not.toHaveBeenCalled(); + }); + describe('handles input reports', () => { it('SpeechMikes_Pro', async () => { await createDictationDeviceForType(DeviceType.SPEECHMIKE_SMP_3700);