Skip to content

Commit

Permalink
Merge pull request #35 from phillipivan/main
Browse files Browse the repository at this point in the history
Add bonjour device discovery
  • Loading branch information
phillipivan authored Sep 20, 2024
2 parents 95998de + 41cb74b commit b041c8a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
10 changes: 9 additions & 1 deletion companion/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,13 @@
},
"manufacturer": "Generic",
"products": ["Ember+"],
"keywords": ["ember", "emberplus"]
"keywords": ["ember", "emberplus"],
"bonjourQueries": {
"bonjourHost": [
{
"type": "ember",
"protocol": "tcp"
}
]
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generic-emberplus",
"version": "2.3.2",
"version": "2.3.3",
"main": "dist/index.js",
"scripts": {
"prepare": "husky",
Expand Down
25 changes: 25 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { SomeCompanionConfigField } from '@companion-module/base'
export const portDefault = 9000

export interface EmberPlusConfig {
bonjourHost?: string
host?: string
port?: number
take?: boolean
Expand All @@ -15,13 +16,28 @@ export interface EmberPlusConfig {

export function GetConfigFields(): SomeCompanionConfigField[] {
return [
{
type: 'bonjour-device',
id: 'bonjourHost',
label: 'Device',
width: 6,
},
{
type: 'textinput',
id: 'host',
label: 'Target IP',
tooltip: 'The IP of the ember+ provider',
width: 6,
regex: Regex.IP,
isVisible: (options) => !options['bonjourHost'],
},
{
type: 'static-text',
id: 'host-filler',
width: 6,
label: '',
isVisible: (options) => !!options['bonjourHost'],
value: '',
},
{
type: 'number',
Expand All @@ -33,6 +49,15 @@ export function GetConfigFields(): SomeCompanionConfigField[] {
max: 0xffff,
step: 1,
default: portDefault,
isVisible: (options) => !options['bonjourHost'],
},
{
type: 'static-text',
id: 'port-filler',
width: 6,
label: '',
isVisible: (options) => !!options['bonjourHost'],
value: '',
},
{
type: 'checkbox',
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class EmberPlusInstance extends InstanceBase<EmberPlusConfig> {
*/
public async init(config: EmberPlusConfig): Promise<void> {
this.config = config
if (this.config.bonjourHost) {
this.config.host = config.bonjourHost?.split(':')[0]
this.config.port = Number(config.bonjourHost?.split(':')[1])
}
this.state = new EmberPlusState()
this.emberQueue = new PQueue({ concurrency: 1 })
this.setupEmberConnection()
Expand All @@ -49,7 +53,10 @@ class EmberPlusInstance extends InstanceBase<EmberPlusConfig> {
*/
public async configUpdated(config: EmberPlusConfig): Promise<void> {
this.config = config

if (this.config.bonjourHost) {
this.config.host = config.bonjourHost?.split(':')[0]
this.config.port = Number(config.bonjourHost?.split(':')[1])
}
//this.emberClient.discard()
//this.emberClient.removeAllListeners()

Expand Down

0 comments on commit b041c8a

Please sign in to comment.