Skip to content

Commit

Permalink
feat: add mdns and installname to api and webui
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Aug 9, 2024
1 parent f21095f commit 6b9b4a1
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 5 deletions.
11 changes: 11 additions & 0 deletions satellite/src/apiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ export interface ApiConfigData {
host: string
port: number

installationName: string

httpEnabled: boolean
httpPort: number

mdnsEnabled: boolean
}

export function compileStatus(client: CompanionSatelliteClient): ApiStatusResponse {
Expand All @@ -29,8 +33,12 @@ export function compileConfig(appConfig: Conf<SatelliteConfig>): ApiConfigData {
host: appConfig.get('remoteIp'),
port: appConfig.get('remotePort'),

installationName: appConfig.get('installationName'),

httpEnabled: appConfig.get('restEnabled'),
httpPort: appConfig.get('restPort'),

mdnsEnabled: appConfig.get('mdnsEnabled'),
}
}

Expand All @@ -40,4 +48,7 @@ export function updateConfig(appConfig: Conf<SatelliteConfig>, newConfig: Partia

if (newConfig.httpEnabled !== undefined) appConfig.set('restEnabled', newConfig.httpEnabled)
if (newConfig.httpPort !== undefined) appConfig.set('restPort', newConfig.httpPort)

if (newConfig.mdnsEnabled !== undefined) appConfig.set('mdnsEnabled', newConfig.mdnsEnabled)
if (newConfig.installationName !== undefined) appConfig.set('installationName', newConfig.installationName)
}
8 changes: 8 additions & 0 deletions satellite/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export interface SatelliteConfig {
remoteIp: string
remotePort: number

installationName: string

restEnabled: boolean
restPort: number

Expand All @@ -25,6 +27,12 @@ export const satelliteConfigSchema: Schema<SatelliteConfig> = {
default: 16622,
},

installationName: {
type: 'string',
description: 'Name for this Satellite installation',
default: 'TODO - something here',
},

restEnabled: {
type: 'boolean',
description: 'Enable HTTP api',
Expand Down
20 changes: 20 additions & 0 deletions satellite/src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ export class RestServer {
partialConfig.port = port
}

const installationName = body.installationName
if (installationName !== undefined) {
if (typeof installationName === 'string') {
partialConfig.installationName = installationName
} else {
ctx.status = 400
ctx.body = 'Invalid installationName'
}
}

const mdnsEnabled = body.mdnsEnabled
if (mdnsEnabled !== undefined) {
if (typeof mdnsEnabled === 'boolean') {
partialConfig.mdnsEnabled = mdnsEnabled
} else {
ctx.status = 400
ctx.body = 'Invalid mdnsEnabled'
}
}

// Ensure some fields cannot be changed
delete partialConfig.httpEnabled
delete partialConfig.httpPort
Expand Down
51 changes: 46 additions & 5 deletions webui/src/SettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function SettingsFormInner({
host: value,
}))
},
[setModifiedConfig]
[setModifiedConfig],
)
const setPort = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -81,7 +81,7 @@ function SettingsFormInner({
port: value,
}))
},
[setModifiedConfig]
[setModifiedConfig],
)
const setHttpEnabled = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -92,7 +92,7 @@ function SettingsFormInner({
httpEnabled: value,
}))
},
[setModifiedConfig]
[setModifiedConfig],
)

const setHttpPort = useCallback(
Expand All @@ -104,7 +104,29 @@ function SettingsFormInner({
httpPort: value,
}))
},
[setModifiedConfig]
[setModifiedConfig],
)
const setMdnsEnabled = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
const value = !!e.currentTarget.checked

setModifiedConfig((oldConfig) => ({
...oldConfig,
mdnsEnabled: value,
}))
},
[setModifiedConfig],
)
const setInstallationName = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.currentTarget.value

setModifiedConfig((oldConfig) => ({
...oldConfig,
installationName: value,
}))
},
[setModifiedConfig],
)

const saveConfigFull = useCallback(
Expand All @@ -113,7 +135,7 @@ function SettingsFormInner({

saveConfig()
},
[saveConfig]
[saveConfig],
)

return (
Expand Down Expand Up @@ -145,6 +167,25 @@ function SettingsFormInner({
</Form.Text>
</Form.Group>

<Form.Group className="mb-3" controlId="formCompanionPort">
<Form.Label>MDNS Announce</Form.Label>
<Form.Check type="switch" label="Enabled" checked={fullConfig.mdnsEnabled} onChange={setMdnsEnabled} />
<Form.Text className="text-muted">
Announce this Satellite installation to the network. This allows for easy setup from inside Companion.
</Form.Text>
</Form.Group>

<Form.Group className="mb-3" controlId="formCompanionAddress">
<Form.Label>Installation name</Form.Label>
<Form.Control
type="text"
placeholder="Installation name"
value={fullConfig.installationName}
onChange={setInstallationName}
/>
<Form.Text className="text-muted">Name to use for this installation in MDNS announcements</Form.Text>
</Form.Group>

{includeApiEnable && (
<>
<legend>HTTP Interface & API</legend>
Expand Down

0 comments on commit 6b9b4a1

Please sign in to comment.