Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor multi-osc device to state handler flow SOFIE-2485 #343

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading