Skip to content

Commit

Permalink
New message api (#81)
Browse files Browse the repository at this point in the history
* add action for Secondary Source

* add feedback

* add variable

* add presets

* show warning

* use common colours

* any secondary source feedback

Co-authored-by: Carlos Valente <[email protected]>

* bump: v4.4.0

---------

Co-authored-by: Carlos Valente <[email protected]>
  • Loading branch information
alex-Arc and cpvalente authored Oct 2, 2024
1 parent da5d73d commit be6cb7a
Show file tree
Hide file tree
Showing 14 changed files with 364 additions and 95 deletions.
15 changes: 15 additions & 0 deletions src/assets/colours.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { combineRgb } from '@companion-module/base'

export const White = combineRgb(255, 255, 255)
export const Black = combineRgb(0, 0, 0)

export const PlaybackGreen = combineRgb(51, 158, 78)
export const PlaybackRed = combineRgb(228, 40, 30)
export const PauseOrange = combineRgb(192, 86, 33)
export const RollBlue = combineRgb(2, 116, 182)

export const ActiveBlue = combineRgb(43, 90, 188)

export const NormalGray = combineRgb(211, 211, 211)
export const WarningOrange = combineRgb(255, 171, 51)
export const DangerRed = combineRgb(237, 51, 51)
6 changes: 6 additions & 0 deletions src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export enum ActionId {
TimerBlackout = 'TimerBlackout',
TimerBlink = 'TimerBlink',
MessageVisibility = 'setMessageVisibility',
MessageVisibilityAndText = 'setMessageVisibilityAndText',
MessageSecondarySource = 'setMessageSecondarySource',
MessageText = 'setMessage',

AuxTimerDuration = 'auxTimerDuration',
Expand Down Expand Up @@ -52,7 +54,9 @@ export enum feedbackId {
ColorPlayback = 'colorPlayback',
ColorAddRemove = 'state_color_add_remove',
OnAir = 'onAir',

MessageVisible = 'messageVisible',
MessageSecondarySourceVisible = 'messageSecondarySourceVisible',
TimerBlink = 'timerBlink',
TimerBlackout = 'timerBlackout',
TimerPhase = 'timerPhase',
Expand Down Expand Up @@ -121,6 +125,8 @@ export enum variableId {
TimerMessageVisible = 'timerMessageVisible',
TimerBlink = 'timerBlink',
TimerBlackout = 'timerBlackout',
ExternalMessage = 'externalMessage',
TimerSecondarySource = 'timerSecondarySource',

AuxTimerDurationMs = 'auxTimer_duration_ms',
AuxTimerPlayback = 'auxTimer_playback',
Expand Down
145 changes: 109 additions & 36 deletions src/v3/actions/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,75 @@ import { socketSendJson } from '../connection'
import { ActionId } from '../../enums'
import { ActionCommand } from './commands'
import { OntimeV3 } from '../ontimev3'
import { MessageState } from '../ontime-types'

enum ToggleOnOff {
Off = 0,
On = 1,
Toggle = 2,
}

export function createMessageActions(ontime: OntimeV3): { [id: string]: CompanionActionDefinition } {
function messageVisibility(action: CompanionActionEvent): void {
const destination = action.options.destination as keyof MessageState
const visible = action.options.value === 2 ? !ontime.state.message[destination].visible : action.options.value
socketSendJson('message', { [destination]: { visible } })
const value = action.options.value as ToggleOnOff
const visible = value === ToggleOnOff.Toggle ? !ontime.state.message.timer.visible : value
socketSendJson('message', { timer: { visible } })
}

function messageVisibilityAndText(action: CompanionActionEvent): void {
const value = action.options.value as ToggleOnOff
const text = action.options.text as string
const textIsDifferent = text !== ontime.state.message.timer.text
const thisTextIsVisible = ontime.state.message.timer.visible && !textIsDifferent
switch (value) {
case ToggleOnOff.Off:
if (thisTextIsVisible) {
socketSendJson('message', { timer: { visible: false } })
}
break
case ToggleOnOff.On:
socketSendJson('message', { timer: { visible: true, text } })
break
case ToggleOnOff.Toggle:
if (thisTextIsVisible) {
socketSendJson('message', { timer: { visible: false, text } })
} else {
socketSendJson('message', { timer: { visible: true, text } })
}
break
}
}

function timerBlackout(action: CompanionActionEvent): void {
const blackout = action.options.value === 2 ? !ontime.state.message.timer.blackout : action.options.value
const value = action.options.value as ToggleOnOff
const blackout = value === ToggleOnOff.Toggle ? !ontime.state.message.timer.blackout : value
socketSendJson(ActionCommand.Message, { timer: { blackout } })
}

function timerBlink(action: CompanionActionEvent): void {
const blink = action.options.value === 2 ? !ontime.state.message.timer.blink : action.options.value
const value = action.options.value as ToggleOnOff
const blink = value === ToggleOnOff.Toggle ? !ontime.state.message.timer.blink : value
socketSendJson(ActionCommand.Message, { timer: { blink } })
}

function setSecondarySource(action: CompanionActionEvent): void {
const value = action.options.value as ToggleOnOff
const source = action.options.source
const isActive = ontime.state.message.timer.secondarySource === source
const shouldShow = value === ToggleOnOff.Toggle ? !isActive : value
const secondarySource = shouldShow ? source : 'off'
socketSendJson(ActionCommand.Message, { timer: { secondarySource } })
}

return {
[ActionId.MessageVisibility]: {
name: 'Toggle/On/Off visibility of message',
options: [
{
type: 'dropdown',
choices: [{ id: 'timer', label: 'Timer' }],
default: 'timer',
id: 'destination',
label: 'Message Destination',
},
{
type: 'dropdown',
choices: [
{ id: 2, label: 'Toggle' },
{ id: 1, label: 'On' },
{ id: 0, label: 'Off' },
{ id: ToggleOnOff.Toggle, label: 'Toggle' },
{ id: ToggleOnOff.On, label: 'On' },
{ id: ToggleOnOff.Off, label: 'Off' },
],
default: 2,
id: 'value',
Expand All @@ -50,17 +83,6 @@ export function createMessageActions(ontime: OntimeV3): { [id: string]: Companio
[ActionId.MessageText]: {
name: 'Set text for message',
options: [
{
type: 'dropdown',
choices: [
{ id: 'timer', label: 'Timer' },
{ id: 'lower', label: 'Lower' },
{ id: 'public', label: 'Public' },
],
default: 'timer',
id: 'destination',
label: 'Message Destination',
},
{
type: 'textinput',
label: 'Timer message',
Expand All @@ -70,19 +92,43 @@ export function createMessageActions(ontime: OntimeV3): { [id: string]: Companio
],
callback: ({ options }) =>
socketSendJson(ActionCommand.Message, {
[options.destination as string]: { text: options.value },
timer: { text: options.value },
}),
},

[ActionId.MessageVisibilityAndText]: {
name: 'Toggle/On/Off visibility and text for message',
description:
'Combined action for setting the text and visibility. "Toggle" will replace the current message. "Off" will disable the message visibility',
options: [
{
type: 'textinput',
label: 'Timer message',
id: 'text',
required: true,
},
{
type: 'dropdown',
choices: [
{ id: ToggleOnOff.Toggle, label: 'Toggle' },
{ id: ToggleOnOff.On, label: 'On' },
{ id: ToggleOnOff.Off, label: 'Off' },
],
default: 2,
id: 'value',
label: 'Action',
},
],
callback: messageVisibilityAndText,
},
[ActionId.TimerBlackout]: {
name: 'Toggle/On/Off Blackout of timer',
name: 'Toggle/On/Off blackout timer',
options: [
{
type: 'dropdown',
choices: [
{ id: 2, label: 'Toggle' },
{ id: 1, label: 'Blackout On' },
{ id: 0, label: 'Blackout Off' },
{ id: ToggleOnOff.Toggle, label: 'Toggle' },
{ id: ToggleOnOff.On, label: 'On' },
{ id: ToggleOnOff.Off, label: 'Off' },
],
default: 2,
id: 'value',
Expand All @@ -97,9 +143,9 @@ export function createMessageActions(ontime: OntimeV3): { [id: string]: Companio
{
type: 'dropdown',
choices: [
{ id: 2, label: 'Toggle' },
{ id: 1, label: 'On' },
{ id: 0, label: 'Off' },
{ id: ToggleOnOff.Toggle, label: 'Toggle' },
{ id: ToggleOnOff.On, label: 'On' },
{ id: ToggleOnOff.Off, label: 'Off' },
],
default: 2,
id: 'value',
Expand All @@ -108,5 +154,32 @@ export function createMessageActions(ontime: OntimeV3): { [id: string]: Companio
],
callback: timerBlink,
},
[ActionId.MessageSecondarySource]: {
name: 'Toggle/On/Off visibility of secondary source',
options: [
{
type: 'dropdown',
choices: [
{ id: 'external', label: 'External' },
{ id: 'aux', label: 'Aux timer' },
],
default: 'external',
id: 'source',
label: 'Source',
},
{
type: 'dropdown',
choices: [
{ id: ToggleOnOff.Toggle, label: 'Toggle' },
{ id: ToggleOnOff.On, label: 'On' },
{ id: ToggleOnOff.Off, label: 'Off' },
],
default: 2,
id: 'value',
label: 'Action',
},
],
callback: setSecondarySource,
},
}
}
21 changes: 17 additions & 4 deletions src/v3/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,19 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void {
ontime.state.message = val
self.setVariableValues({
[variableId.TimerMessage]: val.timer.text,
[variableId.ExternalMessage]: val.external,
[variableId.TimerMessageVisible]: val.timer.visible,
[variableId.TimerBlackout]: val.timer.blackout,
[variableId.TimerBlink]: val.timer.blink,
[variableId.TimerSecondarySource]: val.timer.secondarySource as string,
})

self.checkFeedbacks(feedbackId.MessageVisible, feedbackId.TimerBlackout, feedbackId.TimerBlink)
self.checkFeedbacks(
feedbackId.MessageVisible,
feedbackId.TimerBlackout,
feedbackId.TimerBlink,
feedbackId.MessageSecondarySourceVisible
)
}

const updateRuntime = (val: Runtime) => {
Expand Down Expand Up @@ -260,9 +267,15 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void {
}
case 'version': {
clearTimeout(versionTimeout as NodeJS.Timeout)
const majorVersion = payload.split('.').at(0)
if (majorVersion === '3') {
self.updateStatus(InstanceStatus.Ok, payload)
const version = payload.split('.')
self.log('info', `Ontime version "${payload}"`)
self.log('debug', version)
if (version.at(0) === '3') {
if (Number(version.at(1)) < 6) {
self.updateStatus(InstanceStatus.BadConfig, 'Ontime version is too old (required >3.6.0) some features are not available')
} else {
self.updateStatus(InstanceStatus.Ok, payload)
}
fetchAllEvents(self, ontime).then(() => {
self.init_actions()
const prev = findPreviousPlayableEvent(ontime)
Expand Down
11 changes: 6 additions & 5 deletions src/v3/feedbacks/auxTimer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { CompanionFeedbackDefinition, combineRgb } from '@companion-module/base'
import { CompanionFeedbackDefinition } from '@companion-module/base'
import { OntimeV3 } from '../ontimev3'
import { feedbackId } from '../../enums'
import { SimplePlayback } from '../ontime-types'
import { getAuxTimerState } from '../../utilities'
import { DangerRed, PlaybackGreen, White } from '../../assets/colours'

export function createAuxTimerFeedbacks(ontime: OntimeV3): { [id: string]: CompanionFeedbackDefinition } {
return {
Expand All @@ -11,8 +12,8 @@ export function createAuxTimerFeedbacks(ontime: OntimeV3): { [id: string]: Compa
name: 'Aux Timer Playback state',
description: 'Indicator colour for playback state',
defaultStyle: {
color: combineRgb(255, 255, 255),
bgcolor: combineRgb(0, 204, 0),
color: White,
bgcolor: PlaybackGreen,
},
options: [
{
Expand Down Expand Up @@ -43,8 +44,8 @@ export function createAuxTimerFeedbacks(ontime: OntimeV3): { [id: string]: Compa
name: 'Aux Timer negative',
description: 'Indicator colour for Aux Timer negative',
defaultStyle: {
color: combineRgb(255, 255, 255),
bgcolor: combineRgb(0, 204, 0),
color: White,
bgcolor: DangerRed,
},
options: [
{
Expand Down
Loading

0 comments on commit be6cb7a

Please sign in to comment.