Skip to content

Commit

Permalink
feat(chrome): Allow manual device connections
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxMD committed Jan 15, 2024
1 parent ebfeea1 commit 78cd2ee
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 5 deletions.
28 changes: 28 additions & 0 deletions src/backend/common/infrastructure/config/source/chromecast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ export interface ChromecastData extends CommonSourceData {
* */
useAvahi?: boolean

/**
* Use mDNS to discovery Google Cast devices on your next automatically?
*
* If not explicitly set then it is TRUE if `devices` is not set
* */
useAutoDiscovery?: boolean | undefined

/**
* A list of Google Cast devices to monitor
*
* If this is used then `useAutoDiscovery` is set to FALSE, if not explicitly set
* */
devices?: {
name: string
address: string
}[]

/**
* Chromecast Apps report a "media type" in the status info returned for whatever is currently playing
*
Expand All @@ -63,6 +80,17 @@ export interface ChromecastData extends CommonSourceData {
forceMediaRecognitionOn?: string[]
}

export interface ChromecastDeviceInfo {
/**
* A friendly name to identify this device
* */
name: string
/**
* The IP address of the device
* */
address: string
}

export interface ChromecastSourceConfig extends CommonSourceConfig {
data: ChromecastData
}
Expand Down
27 changes: 27 additions & 0 deletions src/backend/common/schema/aio-source.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@
],
"title": "blacklistDevices"
},
"devices": {
"description": "A list of Google Cast devices to monitor\n\nIf this is used then `useAutoDiscovery` is set to FALSE, if not explicitly set",
"items": {
"properties": {
"address": {
"title": "address",
"type": "string"
},
"name": {
"title": "name",
"type": "string"
}
},
"required": [
"address",
"name"
],
"type": "object"
},
"title": "devices",
"type": "array"
},
"forceMediaRecognitionOn": {
"description": "Media provided by any App whose name is listed here will ALWAYS be tracked, regardless of the \"media type\" reported\n\nApps will be recognized if they CONTAIN any of these values, case-insensitive",
"items": {
Expand Down Expand Up @@ -105,6 +127,11 @@
"description": "Set thresholds for when multi-scrobbler should consider a tracked play to be \"scrobbable\". If both duration and percent are defined then if either condition is met the track is scrobbled.",
"title": "scrobbleThresholds"
},
"useAutoDiscovery": {
"description": "Use mDNS to discovery Google Cast devices on your next automatically?\n\nIf not explicitly set then it is TRUE if `devices` is not set",
"title": "useAutoDiscovery",
"type": "boolean"
},
"useAvahi": {
"default": false,
"description": "Try to use Avahi and avahi-browse to resolve mDNS devices instead of native mDNS querying\n\nUseful for docker (alpine) container where mDNS resolution is not yet supported. Avahi socket must be exposed to the container and avahi-tools must be installed.",
Expand Down
27 changes: 27 additions & 0 deletions src/backend/common/schema/aio.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@
],
"title": "blacklistDevices"
},
"devices": {
"description": "A list of Google Cast devices to monitor\n\nIf this is used then `useAutoDiscovery` is set to FALSE, if not explicitly set",
"items": {
"properties": {
"address": {
"title": "address",
"type": "string"
},
"name": {
"title": "name",
"type": "string"
}
},
"required": [
"address",
"name"
],
"type": "object"
},
"title": "devices",
"type": "array"
},
"forceMediaRecognitionOn": {
"description": "Media provided by any App whose name is listed here will ALWAYS be tracked, regardless of the \"media type\" reported\n\nApps will be recognized if they CONTAIN any of these values, case-insensitive",
"items": {
Expand Down Expand Up @@ -105,6 +127,11 @@
"description": "Set thresholds for when multi-scrobbler should consider a tracked play to be \"scrobbable\". If both duration and percent are defined then if either condition is met the track is scrobbled.",
"title": "scrobbleThresholds"
},
"useAutoDiscovery": {
"description": "Use mDNS to discovery Google Cast devices on your next automatically?\n\nIf not explicitly set then it is TRUE if `devices` is not set",
"title": "useAutoDiscovery",
"type": "boolean"
},
"useAvahi": {
"default": false,
"description": "Try to use Avahi and avahi-browse to resolve mDNS devices instead of native mDNS querying\n\nUseful for docker (alpine) container where mDNS resolution is not yet supported. Avahi socket must be exposed to the container and avahi-tools must be installed.",
Expand Down
27 changes: 27 additions & 0 deletions src/backend/common/schema/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@
],
"title": "blacklistDevices"
},
"devices": {
"description": "A list of Google Cast devices to monitor\n\nIf this is used then `useAutoDiscovery` is set to FALSE, if not explicitly set",
"items": {
"properties": {
"address": {
"title": "address",
"type": "string"
},
"name": {
"title": "name",
"type": "string"
}
},
"required": [
"address",
"name"
],
"type": "object"
},
"title": "devices",
"type": "array"
},
"forceMediaRecognitionOn": {
"description": "Media provided by any App whose name is listed here will ALWAYS be tracked, regardless of the \"media type\" reported\n\nApps will be recognized if they CONTAIN any of these values, case-insensitive",
"items": {
Expand Down Expand Up @@ -152,6 +174,11 @@
"description": "Set thresholds for when multi-scrobbler should consider a tracked play to be \"scrobbable\". If both duration and percent are defined then if either condition is met the track is scrobbled.",
"title": "scrobbleThresholds"
},
"useAutoDiscovery": {
"description": "Use mDNS to discovery Google Cast devices on your next automatically?\n\nIf not explicitly set then it is TRUE if `devices` is not set",
"title": "useAutoDiscovery",
"type": "boolean"
},
"useAvahi": {
"default": false,
"description": "Try to use Avahi and avahi-browse to resolve mDNS devices instead of native mDNS querying\n\nUseful for docker (alpine) container where mDNS resolution is not yet supported. Avahi socket must be exposed to the container and avahi-tools must be installed.",
Expand Down
25 changes: 20 additions & 5 deletions src/backend/sources/ChromecastSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,30 @@ export class ChromecastSource extends MemorySource {

const {
data: {
useAvahi = parseBool(process.env.IS_DOCKER)
useAvahi = parseBool(process.env.IS_DOCKER),
useAutoDiscovery,
devices = []
} = {}
} = this.config;

if(useAvahi) {
await this.discoverAvahi();
} else {
await this.discoverNative();
let ad = useAutoDiscovery;
if(ad === undefined) {
ad = devices.length === 0;
}
if(devices.length > 0) {
for(const device of devices) {
await this.initializeDevice({name: device.name, addresses: [device.address], type: 'googlecast'});
}
}

if(ad) {
if(useAvahi) {
await this.discoverAvahi();
} else {
await this.discoverNative();
}
}

this.initialized = true;
return true;
}
Expand Down

0 comments on commit 78cd2ee

Please sign in to comment.