From f4f7feba6352f664608360693e2ce388fd70b52e Mon Sep 17 00:00:00 2001 From: arc-alex Date: Mon, 29 Apr 2024 11:49:02 +0200 Subject: [PATCH 1/4] add version check --- package.json | 2 ++ src/v3/connection.ts | 23 +++++++++++++++++++---- yarn.lock | 7 ++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index e6261c8..024c8d1 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ }, "dependencies": { "@companion-module/base": "^1.7.0", + "semver": "^7.5.0", "ws": "^8.8.1" }, "devDependencies": { @@ -39,6 +40,7 @@ "lint-staged": "^13.1.2", "prettier": "^2.8.4", "rimraf": "^3.0.2", + "@types/semver": "^7.5.0", "typescript": "~5.3.3" }, "lint-staged": { diff --git a/src/v3/connection.ts b/src/v3/connection.ts index 015db16..d60b32f 100644 --- a/src/v3/connection.ts +++ b/src/v3/connection.ts @@ -7,10 +7,11 @@ import { MessageState, OntimeEvent, Runtime, SimpleTimerState, TimerState } from import { OntimeV3 } from './ontimev3' import { CustomFields } from './ontime-types' import { TimerZone } from './ontime-types' +import * as semver from 'semver' 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 +43,13 @@ 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, 'Version request timed out') + ws?.close() + }, 500) } ws.onclose = (event) => { @@ -165,7 +171,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 +210,16 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void { updateEventNext(payload.eventNext) break } + case 'version': { + clearTimeout(versionTimeout as NodeJS.Timeout) + if (semver.satisfies(semver.coerce(payload) ?? '', '>=3.0.0')) { + self.updateStatus(InstanceStatus.Ok, payload) + } else { + self.updateStatus(InstanceStatus.ConnectionFailure, `Incompatible version ${payload}`) + ws?.close() + } + break + } case 'ontime-refetch': { if (self.config.refetchEvents === false) { break diff --git a/yarn.lock b/yarn.lock index 2716eb2..253f053 100644 --- a/yarn.lock +++ b/yarn.lock @@ -324,6 +324,11 @@ resolved "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz" integrity sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw== +"@types/semver@^7.5.0": + version "7.5.8" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.8.tgz#8268a8c57a3e4abd25c165ecd36237db7948a55e" + integrity sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ== + "@types/which@^3.0.0": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/which/-/which-3.0.3.tgz#41142ed5a4743128f1bc0b69c46890f0453ddb89" @@ -2357,7 +2362,7 @@ schema-utils@^3.2.0: ajv "^6.12.5" ajv-keywords "^3.5.2" -semver@^7.0.0, semver@^7.5.3, semver@^7.5.4: +semver@^7.0.0, semver@^7.5.0, semver@^7.5.3, semver@^7.5.4: version "7.6.0" resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.0.tgz#1a46a4db4bffcccd97b743b5005c8325f23d4e2d" integrity sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg== From de801cd752b82300db4446dc3b33eed0df28a783 Mon Sep 17 00:00:00 2001 From: arc-alex Date: Tue, 30 Apr 2024 13:29:52 +0200 Subject: [PATCH 2/4] remove semver and link to new version --- package.json | 2 -- src/v3/connection.ts | 13 +++++++++---- yarn.lock | 7 +------ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 024c8d1..e6261c8 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ }, "dependencies": { "@companion-module/base": "^1.7.0", - "semver": "^7.5.0", "ws": "^8.8.1" }, "devDependencies": { @@ -40,7 +39,6 @@ "lint-staged": "^13.1.2", "prettier": "^2.8.4", "rimraf": "^3.0.2", - "@types/semver": "^7.5.0", "typescript": "~5.3.3" }, "lint-staged": { diff --git a/src/v3/connection.ts b/src/v3/connection.ts index d60b32f..949d699 100644 --- a/src/v3/connection.ts +++ b/src/v3/connection.ts @@ -7,7 +7,6 @@ import { MessageState, OntimeEvent, Runtime, SimpleTimerState, TimerState } from import { OntimeV3 } from './ontimev3' import { CustomFields } from './ontime-types' import { TimerZone } from './ontime-types' -import * as semver from 'semver' let ws: Websocket | null = null let reconnectionTimeout: NodeJS.Timeout | null = null @@ -47,7 +46,11 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void { self.updateStatus(InstanceStatus.Connecting) socketSendJson('version') versionTimeout = setTimeout(() => { - self.updateStatus(InstanceStatus.ConnectionFailure, 'Version request timed out') + self.updateStatus(InstanceStatus.ConnectionFailure, 'Unsupported version: see log') + self.log( + 'error', + 'The version request timed out, this is mostlily do to an old ontime version. Get the latest here: https://www.getontime.no/' + ) ws?.close() }, 500) } @@ -212,10 +215,12 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void { } case 'version': { clearTimeout(versionTimeout as NodeJS.Timeout) - if (semver.satisfies(semver.coerce(payload) ?? '', '>=3.0.0')) { + const majorVersion = payload.split('.').at(0) + if (majorVersion === '3') { self.updateStatus(InstanceStatus.Ok, payload) } else { - self.updateStatus(InstanceStatus.ConnectionFailure, `Incompatible version ${payload}`) + self.updateStatus(InstanceStatus.ConnectionFailure, 'Unsupported version: see log') + self.log('error', `Unsupported version ${payload}. Get the latest here: https://www.getontime.no/`) ws?.close() } break diff --git a/yarn.lock b/yarn.lock index 253f053..2716eb2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -324,11 +324,6 @@ resolved "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz" integrity sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw== -"@types/semver@^7.5.0": - version "7.5.8" - resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.8.tgz#8268a8c57a3e4abd25c165ecd36237db7948a55e" - integrity sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ== - "@types/which@^3.0.0": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/which/-/which-3.0.3.tgz#41142ed5a4743128f1bc0b69c46890f0453ddb89" @@ -2362,7 +2357,7 @@ schema-utils@^3.2.0: ajv "^6.12.5" ajv-keywords "^3.5.2" -semver@^7.0.0, semver@^7.5.0, semver@^7.5.3, semver@^7.5.4: +semver@^7.0.0, semver@^7.5.3, semver@^7.5.4: version "7.6.0" resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.0.tgz#1a46a4db4bffcccd97b743b5005c8325f23d4e2d" integrity sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg== From af13d410c9635496d85c6c5749a27f0403e1a629 Mon Sep 17 00:00:00 2001 From: arc-alex Date: Tue, 30 Apr 2024 13:47:32 +0200 Subject: [PATCH 3/4] small wording change --- src/v3/connection.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/v3/connection.ts b/src/v3/connection.ts index 949d699..afb73d8 100644 --- a/src/v3/connection.ts +++ b/src/v3/connection.ts @@ -49,7 +49,7 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void { self.updateStatus(InstanceStatus.ConnectionFailure, 'Unsupported version: see log') self.log( 'error', - 'The version request timed out, this is mostlily do to an old ontime version. Get the latest here: https://www.getontime.no/' + '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) @@ -220,7 +220,10 @@ export function connect(self: OnTimeInstance, ontime: OntimeV3): void { self.updateStatus(InstanceStatus.Ok, payload) } else { self.updateStatus(InstanceStatus.ConnectionFailure, 'Unsupported version: see log') - self.log('error', `Unsupported version ${payload}. Get the latest here: https://www.getontime.no/`) + self.log( + 'error', + `Unsupported version "${payload}" You can download the latest version of Ontime through the website https://www.getontime.no/` + ) ws?.close() } break From 9f9ada4606de5dd20b2f1a9548ffe4c6ec77cfc5 Mon Sep 17 00:00:00 2001 From: arc-alex Date: Wed, 1 May 2024 13:15:41 +0200 Subject: [PATCH 4/4] bump to v4 --- companion/manifest.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 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",