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 015db16..afb73d8 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) => { @@ -165,7 +174,6 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void { if (!type) { return } - //https://docs.getontime.no/api/runtime-data/ switch (type) { case 'ontime-clock': { @@ -205,6 +213,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