diff --git a/companion/manifest.json b/companion/manifest.json index 8ae3081..48fbfaa 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.4.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 c30142e..957850a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "getontime-ontime", - "version": "4.3.0", + "version": "4.4.0", "main": "/dist/index.js", "license": "MIT", "prettier": "@companion-module/tools/.prettierrc.json", diff --git a/src/config.ts b/src/config.ts index d4307b3..1005477 100644 --- a/src/config.ts +++ b/src/config.ts @@ -3,6 +3,7 @@ import { SomeCompanionConfigField, Regex } from '@companion-module/base' export interface OntimeConfig { host: string port: string + ssl: boolean version: string refetchEvents: boolean reconnect: boolean @@ -38,12 +39,20 @@ export function GetConfigFields(): SomeCompanionConfigField[] { regex: Regex.PORT, tooltip: 'Ontime server port. Default is 4001', }, + { + label: 'Use SSL', + id: 'ssl', + type: 'checkbox', + default: false, + width: 2, + tooltip: 'Use SSL to connect to the Ontime server.', + }, { label: 'Refetch events', id: 'refetchEvents', type: 'checkbox', default: true, - width: 4, + width: 3, tooltip: 'Whether Companion should keep the rundown updated with Ontime by refetching on change.', }, { @@ -51,7 +60,7 @@ export function GetConfigFields(): SomeCompanionConfigField[] { id: 'reconnect', type: 'checkbox', default: true, - width: 4, + width: 3, tooltip: 'Chose if you want Companion to try to reconnect to ontime when the connection is lost.', }, { diff --git a/src/utilities.ts b/src/utilities.ts index 412070c..dd2995d 100644 --- a/src/utilities.ts +++ b/src/utilities.ts @@ -18,6 +18,11 @@ const defaultTimerObject = { negative: '', } +export function sanitizeHost(host: string) { + const pattern = /^((http|https):\/\/)/ + return host.replace(pattern, '') +} + type SplitTime = typeof defaultTimerObject export function msToSplitTime(time: number | null): SplitTime { @@ -87,7 +92,7 @@ export function findPreviousPlayableEvent(ontime: OntimeV3): OntimeEvent | null now = true continue } - if (now && !ontime.events[i].skip ) { + if (now && !ontime.events[i].skip) { return ontime.events[i] } } diff --git a/src/v3/connection.ts b/src/v3/connection.ts index 161096d..b25b3fb 100644 --- a/src/v3/connection.ts +++ b/src/v3/connection.ts @@ -1,7 +1,7 @@ import { InputValue, InstanceStatus } from '@companion-module/base' import { OnTimeInstance } from '..' import Websocket from 'ws' -import { findPreviousPlayableEvent, msToSplitTime } from '../utilities' +import { findPreviousPlayableEvent, msToSplitTime, sanitizeHost } from '../utilities' import { feedbackId, variableId } from '../enums' import { CurrentBlockState, @@ -26,7 +26,7 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void { reconnectInterval = self.config.reconnectInterval * 1000 shouldReconnect = self.config.reconnect - const host = self.config.host + const host = sanitizeHost(self.config.host) const port = self.config.port if (!host || !port) { @@ -40,13 +40,9 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void { ws.close() } - const pattern = /^((http|https):\/\/)/ + const prefix = self.config.ssl ? 'wss' : 'ws' - if (pattern.test(host)) { - host.replace(pattern, '') - } - - ws = new Websocket(`ws://${host}:${port}/ws`) + ws = new Websocket(`${prefix}://${host}:${port}/ws`) ws.onopen = () => { clearTimeout(reconnectionTimeout as NodeJS.Timeout) @@ -322,9 +318,12 @@ export function socketSendJson(type: string, payload?: InputValue | object): voi let rundownEtag: string = '' export async function fetchAllEvents(self: OnTimeInstance, ontime: OntimeV3): Promise { + const prefix = self.config.ssl ? 'https' : 'http' + const host = sanitizeHost(self.config.host) + self.log('debug', 'fetching events from ontime') try { - const response = await fetch(`http://${self.config.host}:${self.config.port}/data/rundown`, { + const response = await fetch(`${prefix}://${host}:${self.config.port}/data/rundown`, { method: 'GET', headers: { Etag: rundownEtag }, }) @@ -352,13 +351,16 @@ let customFieldsEtag: string = '' let customFieldsTimeout: NodeJS.Timeout export async function fetchCustomFields(self: OnTimeInstance, ontime: OntimeV3): Promise { + const prefix = self.config.ssl ? 'https' : 'http' + const host = sanitizeHost(self.config.host) + clearTimeout(customFieldsTimeout) if (self.config.refetchEvents) { customFieldsTimeout = setTimeout(() => fetchCustomFields(self, ontime), 60000) } self.log('debug', 'fetching custom-fields from ontime') try { - const response = await fetch(`http://${self.config.host}:${self.config.port}/data/custom-fields`, { + const response = await fetch(`${prefix}://${host}:${self.config.port}/data/custom-fields`, { method: 'GET', headers: { Etag: customFieldsEtag }, })