Skip to content

Commit

Permalink
feat: use unique installation name in mdns
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Aug 9, 2024
1 parent c52f8a0 commit 3958a2f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions satellite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"koa-body": "^6.0.1",
"koa-router": "^12.0.1",
"koa-static": "^5.0.0",
"nanoid": "^5.0.7",
"node-hid": "^3.1.0",
"semver": "^7.6.3",
"tslib": "^2.6.3",
Expand Down
10 changes: 9 additions & 1 deletion satellite/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import Conf, { Schema } from 'conf'
import path from 'path'
import os from 'os'
import { nanoid, customAlphabet } from 'nanoid'

const nanoidHex = customAlphabet('0123456789abcdef')

export interface SatelliteConfig {
remoteIp: string
Expand Down Expand Up @@ -30,7 +34,7 @@ export const satelliteConfigSchema: Schema<SatelliteConfig> = {
installationName: {
type: 'string',
description: 'Name for this Satellite installation',
default: 'TODO - something here',
default: `Satellite ${os.hostname()} (${nanoidHex(8)})`,
},

restEnabled: {
Expand All @@ -53,12 +57,16 @@ export const satelliteConfigSchema: Schema<SatelliteConfig> = {
}

export function ensureFieldsPopulated(store: Conf<SatelliteConfig>): void {
// Note: This doesn't appear to do anything, as Conf is populated with defaults
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)
}
}

// Ensure that the store with the filled in defaults is written to disk
store.store = store.store
}

export function openHeadlessConfig(rawConfigPath: string): Conf<SatelliteConfig> {
Expand Down
4 changes: 2 additions & 2 deletions satellite/src/mdnsAnnouncer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export class MdnsAnnouncer {
try {
const restEnabled = this.#appConfig.get('restEnabled')
const restPort = this.#appConfig.get('restPort')
const installationName = this.#appConfig.get('installationName') || os.hostname() || 'Unnamed Satellite'

this.#bonjourService = this.#bonjour.publish(
{
// TODO - this name needs to be unique for each installation
name: os.hostname(), // TODO - something customisable?
name: installationName,
type: 'companion-satellite',
protocol: 'tcp',
port: restPort || 9999,
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5385,6 +5385,15 @@ __metadata:
languageName: node
linkType: hard

"nanoid@npm:^5.0.7":
version: 5.0.7
resolution: "nanoid@npm:5.0.7"
bin:
nanoid: bin/nanoid.js
checksum: 10c0/a3fb1c157e3e35378f44e5a7130c70f80c9037f66c9a37285e5e3d8298e8405fcb2399baaa420980b0fe5fd9c2e4186a6a31c3526f21de03cf34c1b459871401
languageName: node
linkType: hard

"natural-compare@npm:^1.4.0":
version: 1.4.0
resolution: "natural-compare@npm:1.4.0"
Expand Down Expand Up @@ -6443,6 +6452,7 @@ __metadata:
koa-body: "npm:^6.0.1"
koa-router: "npm:^12.0.1"
koa-static: "npm:^5.0.0"
nanoid: "npm:^5.0.7"
node-hid: "npm:^3.1.0"
rimraf: "npm:^5.0.9"
semver: "npm:^7.6.3"
Expand Down

0 comments on commit 3958a2f

Please sign in to comment.