Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/release52' into contribute/EAV…
Browse files Browse the repository at this point in the history
…-411
  • Loading branch information
ianshade committed Nov 27, 2024
2 parents 3c56693 + ad41ae6 commit 65b0dcc
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/timeline-state-resolver-types/src/integrations/vmix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export enum VMixCommand {
LIST_REMOVE_ALL = 'LIST_REMOVE_ALL',
RESTART_INPUT = 'RESTART_INPUT',
SET_TEXT = 'SET_TEXT',
BROWSER_NAVIGATE = 'BROWSER_NAVIGATE',
SELECT_INDEX = 'SELECT_INDEX',
}

export type TimelineContentVMixAny =
Expand Down Expand Up @@ -194,6 +196,16 @@ export interface TimelineContentVMixInput extends TimelineContentVMixBase {
* Titles (GT): Sets the values of text fields by name
*/
text?: VMixText

/** The URL for Browser input */
url?: string

/**
* Photos, List: Selects item in List
* Virtual Set: Zooms to selected preset using the current speed settings
* starts from 1
*/
index?: number
}

export interface TimelineContentVMixOutput extends TimelineContentVMixBase {
Expand Down Expand Up @@ -335,4 +347,5 @@ export enum VMixInputType {
Flash = 'Flash',
PowerPoint = 'PowerPoint',
List = 'List',
Browser = 'Browser',
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,33 @@ describe('VMixCommandSender', () => {
selectedName: 'myTitle.Text',
})
})

it('sends url', async () => {
const { sender, mockConnection } = createTestee()
await sender.sendCommand({
command: VMixCommand.BROWSER_NAVIGATE,
input: 5,
value: 'https://example.com',
})

expect(mockConnection.sendCommandFunction).toHaveBeenCalledTimes(1)
expect(mockConnection.sendCommandFunction).toHaveBeenLastCalledWith('BrowserNavigate', {
input: 5,
value: 'https%3A%2F%2Fexample.com',
})
})
it('selects index', async () => {
const { sender, mockConnection } = createTestee()
await sender.sendCommand({
command: VMixCommand.SELECT_INDEX,
input: 5,
value: 3,
})

expect(mockConnection.sendCommandFunction).toHaveBeenCalledTimes(1)
expect(mockConnection.sendCommandFunction).toHaveBeenLastCalledWith('SelectIndex', {
input: 5,
value: 3,
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,47 @@ describe('VMixStateDiffer', () => {
fieldName: 'myTitle.Text',
})
})

it('sets browser url', () => {
const differ = createTestee()

const oldState = makeMockFullState()
const newState = makeMockFullState()

oldState.reportedState.existingInputs['99'] = differ.getDefaultInputState(99)

newState.reportedState.existingInputs['99'] = differ.getDefaultInputState(99)
const url = 'https://example.com'
newState.reportedState.existingInputs['99'].url = url

const commands = differ.getCommandsToAchieveState(Date.now(), oldState, newState)

expect(commands.length).toBe(1)
expect(commands[0].command).toMatchObject({
command: VMixCommand.BROWSER_NAVIGATE,
input: '99',
value: url,
})
})
it('sets index', () => {
const differ = createTestee()

const oldState = makeMockFullState()
const newState = makeMockFullState()

oldState.reportedState.existingInputs['99'] = differ.getDefaultInputState(99)

newState.reportedState.existingInputs['99'] = differ.getDefaultInputState(99)
const index = 3
newState.reportedState.existingInputs['99'].index = index

const commands = differ.getCommandsToAchieveState(Date.now(), oldState, newState)

expect(commands.length).toBe(1)
expect(commands[0].command).toMatchObject({
command: VMixCommand.SELECT_INDEX,
input: '99',
value: index,
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TimelineContentTypeVMix,
TimelineContentVMixAny,
VMixInputType,
VMixTransitionType,
} from 'timeline-state-resolver-types'
import { VMixTimelineStateConverter } from '../vMixTimelineStateConverter'
import { VMixOutput, VMixStateDiffer } from '../vMixStateDiffer'
Expand Down Expand Up @@ -157,6 +158,114 @@ describe('VMixTimelineStateConverter', () => {
expect(result.reportedState.existingInputs['1'].text).toEqual(text)
})

it('allows overriding transitions in usual layer order', () => {
const converter = createTestee()
const result = converter.getVMixStateFromTimelineState(
wrapInTimelineState({
pgm0: wrapInTimelineObject('pgm0', {
deviceType: DeviceType.VMIX,
type: TimelineContentTypeVMix.PROGRAM,
input: 2,
}),
pgm1: wrapInTimelineObject('pgm1', {
deviceType: DeviceType.VMIX,
type: TimelineContentTypeVMix.PROGRAM,
transition: {
duration: 500,
effect: VMixTransitionType.Fade,
},
}),
}),
{
pgm0: wrapInMapping({
mappingType: MappingVmixType.Program,
}),
pgm1: wrapInMapping({
mappingType: MappingVmixType.Program,
}),
}
)
expect(result.reportedState.mixes[0]?.transition).toEqual({
duration: 500,
effect: VMixTransitionType.Fade,
})
expect(result.reportedState.mixes[0]?.program).toEqual(2)
})

it('does not allow overriding transitions in reverse layer order', () => {
const converter = createTestee()
const result = converter.getVMixStateFromTimelineState(
wrapInTimelineState({
pgm0: wrapInTimelineObject('pgm0', {
deviceType: DeviceType.VMIX,
type: TimelineContentTypeVMix.PROGRAM,
transition: {
duration: 500,
effect: VMixTransitionType.Fade,
},
}),
pgm1: wrapInTimelineObject('pgm1', {
deviceType: DeviceType.VMIX,
type: TimelineContentTypeVMix.PROGRAM,
input: 2,
}),
}),
{
pgm0: wrapInMapping({
mappingType: MappingVmixType.Program,
}),
pgm1: wrapInMapping({
mappingType: MappingVmixType.Program,
}),
}
)
expect(result.reportedState.mixes[0]?.transition).toEqual({
duration: 0,
effect: VMixTransitionType.Cut,
})
expect(result.reportedState.mixes[0]?.program).toEqual(2)
})
it('supports url', () => {
const converter = createTestee()
const url = 'https://example.com'
const result = converter.getVMixStateFromTimelineState(
wrapInTimelineState({
inp0: wrapInTimelineObject('inp0', {
deviceType: DeviceType.VMIX,
url,
type: TimelineContentTypeVMix.INPUT,
}),
}),
{
inp0: wrapInMapping({
mappingType: MappingVmixType.Input,
index: '1',
}),
}
)
expect(result.reportedState.existingInputs['1'].url).toEqual(url)
})
it('supports index', () => {
const converter = createTestee()
const index = 3
const result = converter.getVMixStateFromTimelineState(
wrapInTimelineState({
inp0: wrapInTimelineObject('inp0', {
deviceType: DeviceType.VMIX,
index,
type: TimelineContentTypeVMix.INPUT,
}),
}),
{
inp0: wrapInMapping({
mappingType: MappingVmixType.Input,
index: '1',
}),
}
)
expect(result.reportedState.existingInputs['1'].index).toEqual(index)
})

// TODO: maybe we can't trust the defaults when adding an input? Make this test pass eventually
// it('tracks audio state for mapped inputs added by us', () => {
// const converter = createTestee()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ export class VMixCommandSender {
return this.restart(command.input)
case VMixCommand.SET_TEXT:
return this.setText(command.input, command.value, command.fieldName)
case VMixCommand.BROWSER_NAVIGATE:
return this.browserNavigate(command.input, command.value)
case VMixCommand.SELECT_INDEX:
return this.selectIndex(command.input, command.value)
default:
throw new Error(`vmixAPI: Command ${((command || {}) as any).command} not implemented`)
}
Expand Down Expand Up @@ -467,6 +471,14 @@ export class VMixCommandSender {
return this.sendCommandFunction(`SetText`, { input, value, selectedName: fieldName })
}

public async browserNavigate(input: string | number, value: string): Promise<any> {
return this.sendCommandFunction(`BrowserNavigate`, { input, value: encodeURIComponent(value) })
}

public async selectIndex(input: string | number, value: number): Promise<any> {
return this.sendCommandFunction(`SelectIndex`, { input, value })
}

private async sendCommandFunction(func: string, args: SentCommandArgs) {
return this.vMixConnection.sendCommandFunction(func, args)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ export interface VMixStateCommandSetText extends VMixStateCommandBase {
fieldName: string
value: string
}
export interface VMixStateCommandBrowserNavigate extends VMixStateCommandBase {
command: VMixCommand.BROWSER_NAVIGATE
input: string | number
value: string
}
export interface VMixStateCommanSelectIndex extends VMixStateCommandBase {
command: VMixCommand.SELECT_INDEX
input: string | number
value: number
}
export type VMixStateCommand =
| VMixStateCommandPreviewInput
| VMixStateCommandTransition
Expand Down Expand Up @@ -255,6 +265,8 @@ export type VMixStateCommand =
| VMixStateCommandListRemoveAll
| VMixStateCommandRestart
| VMixStateCommandSetText
| VMixStateCommandBrowserNavigate
| VMixStateCommanSelectIndex

export enum CommandContext {
None = 'none',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export interface VMixInput {
listFilePaths?: string[]
restart?: boolean
text?: VMixText
url?: string
index?: number
}

export interface VMixInputAudio {
Expand Down Expand Up @@ -601,6 +603,28 @@ export class VMixStateDiffer {
}
}
}
if (input.url !== undefined && oldInput.url !== input.url) {
commands.push({
command: {
command: VMixCommand.BROWSER_NAVIGATE,
input: key,
value: input.url,
},
context: CommandContext.None,
timelineId: '',
})
}
if (input.index !== undefined && oldInput.index !== input.index) {
commands.push({
command: {
command: VMixCommand.SELECT_INDEX,
input: key,
value: input.index,
},
context: CommandContext.None,
timelineId: '',
})
}
return { preTransitionCommands, postTransitionCommands }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export class VMixTimelineStateConverter {
this._switchToInput(content.input, deviceState, mixProgram, content.transition)
} else if (content.inputLayer) {
this._switchToInput(content.inputLayer, deviceState, mixProgram, content.transition, true)
} else if (content.transition) {
const mixState = deviceState.reportedState.mixes[mixProgram]
if (mixState) {
mixState.transition = content.transition
}
}
}
break
Expand Down Expand Up @@ -144,6 +149,8 @@ export class VMixTimelineStateConverter {
listFilePaths: content.listFilePaths,
restart: content.restart,
text: content.text,
url: content.url,
index: content.index,
},
{ key: mapping.options.index, filePath: content.filePath },
layerName
Expand Down Expand Up @@ -239,7 +246,7 @@ export class VMixTimelineStateConverter {
mixState.preview = mixState.program
mixState.program = input

mixState.transition = transition || { effect: VMixTransitionType.Cut, duration: 0 }
mixState.transition = transition ?? { effect: VMixTransitionType.Cut, duration: 0 }
mixState.layerToProgram = layerToProgram
}
}
Expand Down

0 comments on commit 65b0dcc

Please sign in to comment.