Skip to content

Commit

Permalink
Current block (#74)
Browse files Browse the repository at this point in the history
* add current block

* update currentBlock on full patch from server

* add preset

* version bump
  • Loading branch information
alex-Arc authored Jul 30, 2024
1 parent b3b42dd commit c7342ee
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 6 deletions.
2 changes: 1 addition & 1 deletion companion/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
24 changes: 22 additions & 2 deletions src/v3/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Websocket from 'ws'
import { findPreviousPlayableEvent, msToSplitTime } from '../utilities'
import { feedbackId, variableId } from '../enums'
import {
CurrentBlockState,
MessageState,
OntimeBaseEvent,
OntimeEvent,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -228,20 +239,28 @@ 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': {
clearTimeout(versionTimeout as NodeJS.Timeout)
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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/v3/ontime-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export type RuntimeStore = {
// publicEventNow: OntimeEvent | null
eventNext: OntimeEvent | null
// publicEventNext: OntimeEvent | null

currentBlock: CurrentBlockState
// extra timers
auxtimer1: SimpleTimerState
}
Expand Down Expand Up @@ -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
}
27 changes: 26 additions & 1 deletion src/v3/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/v3/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const stateobj: RuntimeStore = {
},
eventNow: null,
eventNext: null,
currentBlock: { block: null, startedAt: null },
auxtimer1: {
duration: 0,
current: 0,
Expand Down
12 changes: 12 additions & 0 deletions src/v3/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c7342ee

Please sign in to comment.