Skip to content

Commit

Permalink
chore: refactor multi-osc device to state handler flow SOFIE-2485 (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian authored Aug 26, 2024
1 parent 6fef9f7 commit 7d7dbb1
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 243 deletions.
13 changes: 2 additions & 11 deletions packages/timeline-state-resolver/src/conductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import { CasparCGDevice, DeviceOptionsCasparCGInternal } from './integrations/ca
import { SisyfosMessageDevice, DeviceOptionsSisyfosInternal } from './integrations/sisyfos'
import { VMixDevice, DeviceOptionsVMixInternal } from './integrations/vmix'
import { VizMSEDevice, DeviceOptionsVizMSEInternal } from './integrations/vizMSE'
import { DeviceOptionsMultiOSCInternal, MultiOSCMessageDevice } from './integrations/multiOsc'
import { BaseRemoteDeviceIntegration, RemoteDeviceInstance } from './service/remoteDeviceInstance'
import type { ImplementedServiceDeviceTypes } from './service/devices'
import { DeviceEvents } from './service/device'
Expand Down Expand Up @@ -536,15 +535,6 @@ export class Conductor extends EventEmitter<ConductorEvents> {
getCurrentTime,
threadedClassOptions
)
case DeviceType.MULTI_OSC:
return DeviceContainer.create<DeviceOptionsMultiOSC, typeof MultiOSCMessageDevice>(
'../../dist/integrations/multiOsc/index.js',
'MultiOSCMessageDevice',
deviceId,
deviceOptions,
getCurrentTime,
threadedClassOptions
)
case DeviceType.ABSTRACT:
case DeviceType.ATEM:
case DeviceType.HTTPSEND:
Expand All @@ -553,6 +543,7 @@ export class Conductor extends EventEmitter<ConductorEvents> {
case DeviceType.LAWO:
case DeviceType.OBS:
case DeviceType.OSC:
case DeviceType.MULTI_OSC:
case DeviceType.PANASONIC_PTZ:
case DeviceType.PHAROS:
case DeviceType.SHOTOKU:
Expand Down Expand Up @@ -1475,7 +1466,7 @@ export type DeviceOptionsAnyInternal =
| DeviceOptionsPharos
| DeviceOptionsOBS
| DeviceOptionsOSC
| DeviceOptionsMultiOSCInternal
| DeviceOptionsMultiOSC
| DeviceOptionsSisyfosInternal
| DeviceOptionsSofieChef
| DeviceOptionsQuantel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { Conductor } from '../../../conductor'
import {
Mappings,
DeviceType,
TimelineContentTypeOSC,
OSCValueType,
TimelineContentOSCMessage,
TSRTimelineObj,
MultiOSCDeviceType,
MappingMultiOscLayer,
Mapping,
MappingMultiOscType,
Timeline,
SomeOSCValue,
} from 'timeline-state-resolver-types'
import { MockTime } from '../../../__tests__/mockTime'
import { literal } from '../../../lib'
import { ThreadedClass } from 'threadedclass'
import { getMockCall } from '../../../__tests__/lib'
import { MultiOSCMessageDevice } from '..'
import { getDeviceContext } from '../../__tests__/testlib'
import { TSRTimelineContent } from 'timeline-state-resolver-types/src'

// let nowActual = Date.now()
describe('MultiOSC-Message', () => {
Expand All @@ -39,15 +39,9 @@ describe('MultiOSC-Message', () => {
myLayer0: myLayerMapping0,
}

const myConductor = new Conductor({
multiThreadedResolver: false,
getCurrentTime: mockTime.getCurrentTime,
})
myConductor.on('error', (e) => console.error(e))
await myConductor.init()
await myConductor.addDevice('osc0', {
type: DeviceType.MULTI_OSC,
options: {
const device = new MultiOSCMessageDevice(getDeviceContext())
await device.init(
{
connections: [
{
connectionId: 'osc0',
Expand All @@ -58,58 +52,71 @@ describe('MultiOSC-Message', () => {
],
timeBetweenCommands: 160,
},
oscSenders: { osc0: commandReceiver0 },
})
myConductor.setTimelineAndMappings([], myLayerMapping)
await mockTime.advanceTimeToTicks(10100)
{
oscSenders: { osc0: commandReceiver0 },
}
)

const deviceContainer = myConductor.getDevice('osc0')
const device = deviceContainer!.device as ThreadedClass<MultiOSCMessageDevice>
const testValues: SomeOSCValue[] = [
{
type: OSCValueType.INT,
value: 123,
},
{
type: OSCValueType.FLOAT,
value: 123.45,
},
{
type: OSCValueType.STRING,
value: 'abc',
},
{
type: OSCValueType.BLOB,
value: new Uint8Array([1, 3, 5]),
},
]

const state = device.convertTimelineStateToDeviceState(
createTimelineState({
obj0: {
id: 'obj0',

layer: 'myLayer0',

// Check that no commands has been scheduled:
expect(await device.queue).toHaveLength(0)
content: {
deviceType: DeviceType.OSC,
type: TimelineContentTypeOSC.OSC,

myConductor.setTimelineAndMappings([
literal<TSRTimelineObj<TimelineContentOSCMessage>>({
id: 'obj0',
enable: {
start: mockTime.now + 1000, // in 1 second
duration: 2000,
path: '/test-path',
values: testValues,
},
},
layer: 'myLayer0',
content: {
}),
myLayerMapping
)
expect(state).toBeTruthy()
expect(state).toEqual({
osc0: {
'/test-path': {
connectionId: 'osc0',
deviceType: DeviceType.OSC,
type: TimelineContentTypeOSC.OSC,

fromTlObject: 'obj0',
path: '/test-path',
values: [
{
type: OSCValueType.INT,
value: 123,
},
{
type: OSCValueType.FLOAT,
value: 123.45,
},
{
type: OSCValueType.STRING,
value: 'abc',
},
{
type: OSCValueType.BLOB,
value: new Uint8Array([1, 3, 5]),
},
],
values: testValues,
},
}),
])
},
})

await mockTime.advanceTimeToTicks(10990)
expect(commandReceiver0).toHaveBeenCalledTimes(0)
await mockTime.advanceTimeToTicks(11100)
const commands = device.diffStates(undefined, state)
expect(commands).toHaveLength(1)

expect(commandReceiver0).toHaveBeenCalledTimes(0)
for (const command of commands) {
await device.sendCommand(command)
}
expect(commandReceiver0).toHaveBeenCalledTimes(1)
// console.log(commandReceiver0.mock.calls)

expect(getMockCall(commandReceiver0, 0, 0)).toMatchObject({
address: '/test-path',
args: [
Expand All @@ -131,7 +138,15 @@ describe('MultiOSC-Message', () => {
},
],
})
await mockTime.advanceTimeToTicks(16000)
expect(commandReceiver0).toHaveBeenCalledTimes(1)
})
})

function createTimelineState(
objs: Record<string, { id: string; layer: string; content: TimelineContentOSCMessage }>
): Timeline.TimelineState<TSRTimelineContent> {
return {
time: 10,
layers: objs as any,
nextEvents: [],
}
}
Loading

0 comments on commit 7d7dbb1

Please sign in to comment.