From 6ed6b36526149d38c23475e66eafc790322d62ae Mon Sep 17 00:00:00 2001 From: Alex Christoffer Rasmussen Date: Thu, 2 May 2024 22:23:13 +0200 Subject: [PATCH] add version check (#52) --- companion/manifest.json | 2 +- package.json | 2 +- src/v3/connection.ts | 31 +++++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/companion/manifest.json b/companion/manifest.json index 32d9237..e17c230 100644 --- a/companion/manifest.json +++ b/companion/manifest.json @@ -3,7 +3,7 @@ "name": "getontime-ontime", "shortname": "ontime", "description": "Companion module for ontime", - "version": "3.2.0", + "version": "4.0.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 e6261c8..fd5e923 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "getontime-ontime", - "version": "3.2.0", + "version": "4.0.0", "main": "/dist/index.js", "license": "MIT", "prettier": "@companion-module/tools/.prettierrc.json", diff --git a/src/v3/connection.ts b/src/v3/connection.ts index e29efc9..ed6e3e8 100644 --- a/src/v3/connection.ts +++ b/src/v3/connection.ts @@ -10,7 +10,7 @@ import { TimerZone } from './ontime-types' let ws: Websocket | null = null let reconnectionTimeout: NodeJS.Timeout | null = null -// let versionTimeout: NodeJS.Timeout | null = null //TODO: later +let versionTimeout: NodeJS.Timeout | null = null let reconnectInterval: number let shouldReconnect = false @@ -42,8 +42,17 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void { ws.onopen = () => { clearTimeout(reconnectionTimeout as NodeJS.Timeout) - self.updateStatus(InstanceStatus.Ok) - //TODO: later authenticate the version number + clearTimeout(versionTimeout as NodeJS.Timeout) + self.updateStatus(InstanceStatus.Connecting) + socketSendJson('version') + versionTimeout = setTimeout(() => { + self.updateStatus(InstanceStatus.ConnectionFailure, 'Unsupported version: see log') + self.log( + 'error', + 'The version request timed out, this is most likely do to an old ontime version. You can download the latest version of Ontime through the website https://www.getontime.no/' + ) + ws?.close() + }, 500) } ws.onclose = (event) => { @@ -178,7 +187,6 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void { if (!type) { return } - //https://docs.getontime.no/api/runtime-data/ switch (type) { case 'ontime-clock': { @@ -218,6 +226,21 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void { updateEventNext(payload.eventNext) break } + case 'version': { + clearTimeout(versionTimeout as NodeJS.Timeout) + const majorVersion = payload.split('.').at(0) + if (majorVersion === '3') { + self.updateStatus(InstanceStatus.Ok, payload) + } else { + self.updateStatus(InstanceStatus.ConnectionFailure, 'Unsupported version: see log') + self.log( + 'error', + `Unsupported version "${payload}" You can download the latest version of Ontime through the website https://www.getontime.no/` + ) + ws?.close() + } + break + } case 'ontime-refetch': { if (self.config.refetchEvents === false) { break