diff --git a/companion/manifest.json b/companion/manifest.json index 8ae3081..0cabf2f 100644 --- a/companion/manifest.json +++ b/companion/manifest.json @@ -3,7 +3,7 @@ "name": "getontime-ontime", "shortname": "ontime", "description": "Companion module for ontime", - "version": "4.3.0", + "version": "4.2.0", "license": "MIT", "repository": "git+https://github.com/bitfocus/companion-module-getontime-ontime.git", "bugs": "https://github.com/bitfocus/companion-module-getontime-ontime/issues", diff --git a/package.json b/package.json index 2083e5f..d8a37b8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "getontime-ontime", - "version": "4.3.0", + "version": "4.2.0", "main": "/dist/index.js", "license": "MIT", "prettier": "@companion-module/tools/.prettierrc.json", diff --git a/src/enums.ts b/src/enums.ts index f71501a..cdca962 100644 --- a/src/enums.ts +++ b/src/enums.ts @@ -110,6 +110,10 @@ export enum variableId { NoteNext = 'noteNext', CueNext = 'cueNext', + CurrentBlockTitle = 'currentBlockTitle', + CurrentBlockStartedAt = 'currentBlockStartedAt_hms', + CurrentBlockStartedAtMs = 'currentBlockStartedAt_ms', + TimerMessage = 'timerMessage', TimerMessageVisible = 'timerMessageVisible', TimerBlink = 'timerBlink', diff --git a/src/v3/connection.ts b/src/v3/connection.ts index 0defe59..87d3cc0 100644 --- a/src/v3/connection.ts +++ b/src/v3/connection.ts @@ -4,6 +4,7 @@ import Websocket from 'ws' import { findPreviousPlayableEvent, msToSplitTime } from '../utilities' import { feedbackId, variableId } from '../enums' import { + CurrentBlockState, MessageState, OntimeBaseEvent, OntimeEvent, @@ -171,6 +172,16 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void { }) } + const updateCurrentBlock = (val: CurrentBlockState) => { + ontime.state.currentBlock = val + const startedAt = msToSplitTime(val.startedAt) + self.setVariableValues({ + [variableId.CurrentBlockStartedAt]: startedAt.hoursMinutesSeconds, + [variableId.CurrentBlockStartedAtMs]: val.startedAt ?? 0, + [variableId.CurrentBlockTitle]: val.block?.title ?? '', + }) + } + const updateAuxTimer1 = (val: SimpleTimerState) => { ontime.state.auxtimer1 = val const duration = msToSplitTime(val.duration) @@ -228,12 +239,21 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void { updateAuxTimer1(payload) break } + case 'ontime-currentBlock': { + updateCurrentBlock(payload) + break + } case 'ontime': { updateTimer(payload.timer) updateClock(payload.clock) updateMessage(payload.message) updateEventNow(payload.eventNow) updateEventNext(payload.eventNext) + + // currentBlock dons't exist in ontime prior to v3.5.0 + if ('currentBlock' in payload) { + updateCurrentBlock(payload.currentBlock) + } break } case 'version': { @@ -241,7 +261,6 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void { const majorVersion = payload.split('.').at(0) if (majorVersion === '3') { self.updateStatus(InstanceStatus.Ok, payload) - self.log('debug', 'refetching events') fetchAllEvents(self, ontime).then(() => { self.init_actions() const prev = findPreviousPlayableEvent(ontime) @@ -304,6 +323,7 @@ export async function fetchAllEvents(self: OnTimeInstance, ontime: OntimeV3): Pr headers: { Etag: rundownEtag }, }) if (!response.ok) { + ontime.events = [] self.log('error', `uable to fetch events: ${response.statusText}`) return } @@ -318,7 +338,7 @@ export async function fetchAllEvents(self: OnTimeInstance, ontime: OntimeV3): Pr } catch (e: any) { ontime.events = [] self.log('error', 'failed to fetch events from ontime') - self.log('error', e) + self.log('error', e.message) } } diff --git a/src/v3/ontime-types.ts b/src/v3/ontime-types.ts index bb42d05..6b0473c 100644 --- a/src/v3/ontime-types.ts +++ b/src/v3/ontime-types.ts @@ -63,7 +63,7 @@ export type RuntimeStore = { // publicEventNow: OntimeEvent | null eventNext: OntimeEvent | null // publicEventNext: OntimeEvent | null - + currentBlock: CurrentBlockState // extra timers auxtimer1: SimpleTimerState } @@ -180,3 +180,13 @@ export type SimpleTimerState = { playback: SimplePlayback direction: SimpleDirection } + +export type OntimeBlock = OntimeBaseEvent & { + type: SupportedEvent.Block + title: string +} + +export type CurrentBlockState = { + block: OntimeBlock | null + startedAt: number | null +} diff --git a/src/v3/presets.ts b/src/v3/presets.ts index 9a6897b..49ebb4f 100644 --- a/src/v3/presets.ts +++ b/src/v3/presets.ts @@ -9,7 +9,7 @@ import { ActionId, feedbackId } from '../enums' import { TimerPhase } from './ontime-types' export function presets(): CompanionPresetDefinitions { - return { ...playbackPresets, ...timerPresets, ...auxTimerPresets } + return { ...playbackPresets, ...timerPresets, ...auxTimerPresets, ...rundownPresets } } const White = combineRgb(255, 255, 255) @@ -385,6 +385,31 @@ const timerPhaseAndPauseFeedback = [ }, ] +const rundownPresets: { [id: string]: CompanionButtonPresetDefinition } = { + currentBlock: { + type: 'button', + category: 'Rundown', + name: 'Title of current block', + style: { + ...defaultStyle, + size: 'auto', + text: '$(ontime:currentBlockTitle)', + }, + previewStyle: { + ...defaultStyle, + size: 'auto', + text: 'Current Block', + }, + steps: [ + { + down: [], + up: [], + }, + ], + feedbacks: [], + }, +} + const timerPresets: { [id: string]: CompanionButtonPresetDefinition } = { add_1_min: { type: 'button', diff --git a/src/v3/state.ts b/src/v3/state.ts index 16cbe4c..382d253 100644 --- a/src/v3/state.ts +++ b/src/v3/state.ts @@ -31,6 +31,7 @@ const stateobj: RuntimeStore = { }, eventNow: null, eventNext: null, + currentBlock: { block: null, startedAt: null }, auxtimer1: { duration: 0, current: 0, diff --git a/src/v3/variables.ts b/src/v3/variables.ts index 548a2be..e96c90b 100644 --- a/src/v3/variables.ts +++ b/src/v3/variables.ts @@ -117,6 +117,18 @@ export function variables(): CompanionVariableDefinition[] { name: 'Rundown expected end (hh:mm:ss)', variableId: variableId.ExpectedEnd, }, + { + name: 'Title of current block', + variableId: variableId.CurrentBlockTitle, + }, + { + name: 'Start time of current block (hh:mm:ss)', + variableId: variableId.CurrentBlockStartedAt, + }, + { + name: 'Start time of current block (milliseconds)', + variableId: variableId.CurrentBlockStartedAtMs, + }, { name: 'ID of previous event', variableId: variableId.IdPrevious,