Skip to content

Commit

Permalink
Merge branch 'contribute/EAV-321' of github.com:tv2norge-collab/sofie…
Browse files Browse the repository at this point in the history
…-timeline-state-resolver into release52

# Conflicts:
#	packages/timeline-state-resolver/src/integrations/vmix/__tests__/vMixTimelineStateConverter.spec.ts
  • Loading branch information
nytamin committed Nov 27, 2024
2 parents 4bb7ff0 + f3504a9 commit 842fbf3
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export enum VMixCommand {
LIST_ADD = 'LIST_ADD',
LIST_REMOVE_ALL = 'LIST_REMOVE_ALL',
RESTART_INPUT = 'RESTART_INPUT',
BROWSER_NAVIGATE = 'BROWSER_NAVIGATE',
}

export type TimelineContentVMixAny =
Expand Down Expand Up @@ -188,6 +189,9 @@ export interface TimelineContentVMixInput extends TimelineContentVMixBase {

/** If media should start from the beginning or resume from where it left off */
restart?: boolean

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

export interface TimelineContentVMixOutput extends TimelineContentVMixBase {
Expand Down Expand Up @@ -325,4 +329,5 @@ export enum VMixInputType {
Flash = 'Flash',
PowerPoint = 'PowerPoint',
List = 'List',
Browser = 'Browser',
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,19 @@ describe('VMixCommandSender', () => {
value: 1.5,
})
})

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',
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,26 @@ describe('VMixStateDiffer', () => {
cropBottom: 0.8,
})
})

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,
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,26 @@ describe('VMixTimelineStateConverter', () => {
})
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)
})

// 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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ export class VMixCommandSender {
return this.listRemoveAll(command.input)
case VMixCommand.RESTART_INPUT:
return this.restart(command.input)
case VMixCommand.BROWSER_NAVIGATE:
return this.browserNavigate(command.input, command.value)
default:
throw new Error(`vmixAPI: Command ${((command || {}) as any).command} not implemented`)
}
Expand Down Expand Up @@ -467,6 +469,10 @@ export class VMixCommandSender {
return this.sendCommandFunction(`Restart`, { input })
}

public async browserNavigate(input: string | number, value: string): Promise<any> {
return this.sendCommandFunction(`BrowserNavigate`, { input, value: encodeURIComponent(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 @@ -203,6 +203,11 @@ export interface VMixStateCommandRestart extends VMixStateCommandBase {
command: VMixCommand.RESTART_INPUT
input: string | number
}
export interface VMixStateCommandBrowserNavigate extends VMixStateCommandBase {
command: VMixCommand.BROWSER_NAVIGATE
input: string | number
value: string
}
export type VMixStateCommand =
| VMixStateCommandPreviewInput
| VMixStateCommandTransition
Expand Down Expand Up @@ -248,6 +253,7 @@ export type VMixStateCommand =
| VMixStateCommandListAdd
| VMixStateCommandListRemoveAll
| VMixStateCommandRestart
| VMixStateCommandBrowserNavigate

export enum CommandContext {
None = 'none',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface VMixInput {
layers?: VMixLayers
listFilePaths?: string[]
restart?: boolean
url?: string
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export class VMixTimelineStateConverter {
(content.overlays ? this._convertDeprecatedInputOverlays(content.overlays) : undefined),
listFilePaths: content.listFilePaths,
restart: content.restart,
url: content.url,
},
{ key: mapping.options.index, filePath: content.filePath },
layerName
Expand Down

0 comments on commit 842fbf3

Please sign in to comment.