Skip to content

Commit

Permalink
add version check (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-Arc authored May 2, 2024
1 parent 7e7b8c9 commit 6ed6b36
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion companion/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
31 changes: 27 additions & 4 deletions src/v3/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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': {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6ed6b36

Please sign in to comment.