Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add version check #52

Merged
merged 4 commits into from
May 2, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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': {
Expand Down Expand Up @@ -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
Expand Down