-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expand rest api to serve minimal interface (#103)
- Loading branch information
Showing
41 changed files
with
4,728 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
# | ||
# Since v1.7.0 of satellite this is no longer the main config file. | ||
# It is read at startup to import configuration to the main config file. | ||
# After it has been read, it gets reset back to defaults. | ||
# | ||
# More options are available in the web interface. | ||
# | ||
|
||
# Set this to the ip address or hostname of your companion installation | ||
# examples: | ||
# - COMPANION_IP=192.168.100.1 | ||
# - COMPANION_IP=companion.example.org | ||
COMPANION_IP=127.0.0.1 | ||
# COMPANION_IP=127.0.0.1 | ||
|
||
# If you are connecting through a router or firewall which has remapped the port, you will need to change that here to match | ||
COMPANION_PORT=16622 | ||
# COMPANION_PORT=16622 | ||
|
||
# Port for the REST server (0 to disable) | ||
REST_PORT=9999 | ||
# REST_PORT=9999 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Conf from 'conf' | ||
import { CompanionSatelliteClient } from './client' | ||
import { SatelliteConfig } from './config' | ||
|
||
export interface ApiStatusResponse { | ||
connected: boolean | ||
companionVersion: string | null | ||
companionApiVersion: string | null | ||
} | ||
|
||
export interface ApiConfigData { | ||
host: string | ||
port: number | ||
|
||
httpEnabled: boolean | ||
httpPort: number | ||
} | ||
|
||
export function compileStatus(client: CompanionSatelliteClient): ApiStatusResponse { | ||
return { | ||
connected: client.connected, | ||
companionVersion: client.companionVersion, | ||
companionApiVersion: client.companionApiVersion, | ||
} | ||
} | ||
|
||
export function compileConfig(appConfig: Conf<SatelliteConfig>): ApiConfigData { | ||
return { | ||
host: appConfig.get('remoteIp'), | ||
port: appConfig.get('remotePort'), | ||
|
||
httpEnabled: appConfig.get('restEnabled'), | ||
httpPort: appConfig.get('restPort'), | ||
} | ||
} | ||
|
||
export function updateConfig(appConfig: Conf<SatelliteConfig>, newConfig: Partial<ApiConfigData>): void { | ||
if (newConfig.host !== undefined) appConfig.set('remoteIp', newConfig.host) | ||
if (newConfig.port !== undefined) appConfig.set('remotePort', newConfig.port) | ||
|
||
if (newConfig.httpEnabled !== undefined) appConfig.set('restEnabled', newConfig.httpEnabled) | ||
if (newConfig.httpPort !== undefined) appConfig.set('restPort', newConfig.httpPort) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Conf, { Schema } from 'conf' | ||
import path from 'path' | ||
|
||
export interface SatelliteConfig { | ||
remoteIp: string | ||
remotePort: number | ||
|
||
restEnabled: boolean | ||
restPort: number | ||
} | ||
|
||
export const satelliteConfigSchema: Schema<SatelliteConfig> = { | ||
remoteIp: { | ||
type: 'string', | ||
description: 'Address of Companion installation', | ||
default: '127.0.0.1', | ||
}, | ||
remotePort: { | ||
type: 'integer', | ||
description: 'Port number of Companion installation', | ||
minimum: 1, | ||
maximum: 65535, | ||
default: 16622, | ||
}, | ||
|
||
restEnabled: { | ||
type: 'boolean', | ||
description: 'Enable HTTP api', | ||
default: true, | ||
}, | ||
restPort: { | ||
type: 'integer', | ||
description: 'Port number of run HTTP server on', | ||
minimum: 1, | ||
maximum: 65535, | ||
default: 9999, | ||
}, | ||
} | ||
|
||
export function ensureFieldsPopulated(store: Conf<SatelliteConfig>): void { | ||
for (const [key, schema] of Object.entries<any>(satelliteConfigSchema)) { | ||
if (store.get(key) === undefined && schema.default !== undefined) { | ||
// Ensure values are written to disk | ||
store.set(key, schema.default) | ||
} | ||
} | ||
} | ||
|
||
export function openHeadlessConfig(rawConfigPath: string): Conf<SatelliteConfig> { | ||
const absoluteConfigPath = path.isAbsolute(rawConfigPath) ? rawConfigPath : path.join(process.cwd(), rawConfigPath) | ||
|
||
const appConfig = new Conf<SatelliteConfig>({ | ||
schema: satelliteConfigSchema, | ||
configName: path.parse(absoluteConfigPath).name, | ||
projectName: 'companion-satellite', | ||
cwd: path.dirname(absoluteConfigPath), | ||
}) | ||
ensureFieldsPopulated(appConfig) | ||
return appConfig | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.