Skip to content

Commit

Permalink
fix: add version property to API /status
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Jan 27, 2025
1 parent a8bef36 commit ee7e3b4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"author": {
"name": "NRK"
},
"main": "dist/main.js",
"main": "dist/src/main.js",
"scripts": {
"build": "tsc",
"watch:build": "tsc -w",
"watch:electron": "nodemon --exec npm start",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"start": "electron ./dist/main.js",
"start": "electron ./dist/src/main.js",
"build:binary": "electron-builder",
"dev": "yarn && yarn build && concurrently --kill-others \"yarn watch:build\" \"yarn watch:electron\"",
"release:release": "sofie-version",
Expand Down
17 changes: 13 additions & 4 deletions src/helpers/APIHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '../lib/api'
import { rateLimitAndDoLater } from '../lib/lib'
import { Config } from '../lib/config'
import packageJson = require('../../package.json')

// How long to wait for status changes to settle before broadcasting
const STATUS_SETTLE_TIME = 3000
Expand All @@ -30,7 +31,7 @@ export class APIHelper {

private config: Config | undefined = undefined

private status: SendWSMessageStatus['status'] = {
private _status: InternalStatus = {
app: {
statusCode: StatusCode.GOOD,
message: '',
Expand All @@ -51,12 +52,18 @@ export class APIHelper {
this.setupHTTPServer()
this.setupWSServer()
}
public setStatus(status: SendWSMessageStatus['status']): void {
this.status = status
public setStatus(status: InternalStatus): void {
this._status = status

this.broadcastStatusToClients()
}

get status(): SendWSMessageStatus['status'] {
console.log('packageJson', packageJson)

Check warning on line 61 in src/helpers/APIHelper.ts

View workflow job for this annotation

GitHub Actions / Typecheck and Lint

Unexpected console statement
return {
...this._status,
version: packageJson.version,
}
}
private setupHTTPServer(): void {
if (this.httpServer) return
if (!this.config) throw new Error('this.config not set, call init() first!')
Expand Down Expand Up @@ -389,3 +396,5 @@ function firstInArray<T>(v: T | T[]): T {
if (Array.isArray(v)) return v[0]
else return v
}

type InternalStatus = Omit<SendWSMessageStatus['status'], 'version'>
1 change: 1 addition & 0 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export interface SendWSMessageStatus extends SendWSMessageBase {
type: SendWSMessageType.STATUS

status: {
version: string
app: StatusObject
windows: {
[index: string]: StatusObject
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"types": [
"node"
],
"skipLibCheck": true
"skipLibCheck": true,
"resolveJsonModule": true,
}
}

0 comments on commit ee7e3b4

Please sign in to comment.