diff --git a/packages/timeline-state-resolver/src/service/ConnectionManager.ts b/packages/timeline-state-resolver/src/service/ConnectionManager.ts index b7bdd079c..b016068c0 100644 --- a/packages/timeline-state-resolver/src/service/ConnectionManager.ts +++ b/packages/timeline-state-resolver/src/service/ConnectionManager.ts @@ -42,7 +42,7 @@ export interface ConnectionManagerIntEvents { connectionRemoved: [id: string] } export type MappedDeviceEvents = { - [T in keyof DeviceInstanceEvents as `connectionEvent:${T}`]: [deviceId: string, ...DeviceInstanceEvents[T]] + [T in keyof DeviceInstanceEvents as `connectionEvent:${T}`]: [string, ...DeviceInstanceEvents[T]] } export class ConnectionManager extends EventEmitter { diff --git a/packages/timeline-state-resolver/src/service/__tests__/ConnectionManager.spec.ts b/packages/timeline-state-resolver/src/service/__tests__/ConnectionManager.spec.ts new file mode 100644 index 000000000..440651a4b --- /dev/null +++ b/packages/timeline-state-resolver/src/service/__tests__/ConnectionManager.spec.ts @@ -0,0 +1,54 @@ +import { DeviceType, OSCDeviceType } from 'timeline-state-resolver-types' +import { ConstructedMockDevices, MockDeviceInstanceWrapper } from '../../__tests__/mockDeviceInstanceWrapper' +import { ConnectionManager } from '../ConnectionManager' + +// Mock explicitly the 'dist' version, as that is what threadedClass is being told to load +jest.mock('../../../dist/service/DeviceInstance', () => ({ + DeviceInstanceWrapper: MockDeviceInstanceWrapper, +})) +jest.mock('../DeviceInstance', () => ({ + DeviceInstanceWrapper: MockDeviceInstanceWrapper, +})) + +describe('ConnectionManager', () => { + const connManager = new ConnectionManager() + + test('adding/removing a device', async () => { + let resolveAdded: undefined | (() => void) = undefined + const psAdded = new Promise((resolveCb) => (resolveAdded = resolveCb)) + connManager.on('connectionAdded', () => { + if (resolveAdded) resolveAdded() + }) + + let resolveRemoved: undefined | (() => void) = undefined + const psRemoved = new Promise((resolveCb) => (resolveRemoved = resolveCb)) + connManager.on('connectionRemoved', () => { + if (resolveRemoved) resolveRemoved() + }) + + connManager.setConnections( + new Map( + Object.entries({ + osc0: { + type: DeviceType.OSC, + options: { + host: '127.0.0.1', + port: 5250, + type: OSCDeviceType.UDP, + }, + }, + }) + ) + ) + + await psAdded + + expect(ConstructedMockDevices['osc0']).toBeTruthy() + + connManager.setConnections(new Map()) + + await psRemoved + + expect(ConstructedMockDevices['osc0']).toBeFalsy() + }) +})