Skip to content

Commit 78cd2ee

Browse files
committed
feat(chrome): Allow manual device connections
1 parent ebfeea1 commit 78cd2ee

File tree

5 files changed

+129
-5
lines changed

5 files changed

+129
-5
lines changed

src/backend/common/infrastructure/config/source/chromecast.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ export interface ChromecastData extends CommonSourceData {
4242
* */
4343
useAvahi?: boolean
4444

45+
/**
46+
* Use mDNS to discovery Google Cast devices on your next automatically?
47+
*
48+
* If not explicitly set then it is TRUE if `devices` is not set
49+
* */
50+
useAutoDiscovery?: boolean | undefined
51+
52+
/**
53+
* A list of Google Cast devices to monitor
54+
*
55+
* If this is used then `useAutoDiscovery` is set to FALSE, if not explicitly set
56+
* */
57+
devices?: {
58+
name: string
59+
address: string
60+
}[]
61+
4562
/**
4663
* Chromecast Apps report a "media type" in the status info returned for whatever is currently playing
4764
*
@@ -63,6 +80,17 @@ export interface ChromecastData extends CommonSourceData {
6380
forceMediaRecognitionOn?: string[]
6481
}
6582

83+
export interface ChromecastDeviceInfo {
84+
/**
85+
* A friendly name to identify this device
86+
* */
87+
name: string
88+
/**
89+
* The IP address of the device
90+
* */
91+
address: string
92+
}
93+
6694
export interface ChromecastSourceConfig extends CommonSourceConfig {
6795
data: ChromecastData
6896
}

src/backend/common/schema/aio-source.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,28 @@
6161
],
6262
"title": "blacklistDevices"
6363
},
64+
"devices": {
65+
"description": "A list of Google Cast devices to monitor\n\nIf this is used then `useAutoDiscovery` is set to FALSE, if not explicitly set",
66+
"items": {
67+
"properties": {
68+
"address": {
69+
"title": "address",
70+
"type": "string"
71+
},
72+
"name": {
73+
"title": "name",
74+
"type": "string"
75+
}
76+
},
77+
"required": [
78+
"address",
79+
"name"
80+
],
81+
"type": "object"
82+
},
83+
"title": "devices",
84+
"type": "array"
85+
},
6486
"forceMediaRecognitionOn": {
6587
"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",
6688
"items": {
@@ -105,6 +127,11 @@
105127
"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.",
106128
"title": "scrobbleThresholds"
107129
},
130+
"useAutoDiscovery": {
131+
"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",
132+
"title": "useAutoDiscovery",
133+
"type": "boolean"
134+
},
108135
"useAvahi": {
109136
"default": false,
110137
"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.",

src/backend/common/schema/aio.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,28 @@
6161
],
6262
"title": "blacklistDevices"
6363
},
64+
"devices": {
65+
"description": "A list of Google Cast devices to monitor\n\nIf this is used then `useAutoDiscovery` is set to FALSE, if not explicitly set",
66+
"items": {
67+
"properties": {
68+
"address": {
69+
"title": "address",
70+
"type": "string"
71+
},
72+
"name": {
73+
"title": "name",
74+
"type": "string"
75+
}
76+
},
77+
"required": [
78+
"address",
79+
"name"
80+
],
81+
"type": "object"
82+
},
83+
"title": "devices",
84+
"type": "array"
85+
},
6486
"forceMediaRecognitionOn": {
6587
"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",
6688
"items": {
@@ -105,6 +127,11 @@
105127
"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.",
106128
"title": "scrobbleThresholds"
107129
},
130+
"useAutoDiscovery": {
131+
"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",
132+
"title": "useAutoDiscovery",
133+
"type": "boolean"
134+
},
108135
"useAvahi": {
109136
"default": false,
110137
"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.",

src/backend/common/schema/source.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,28 @@
108108
],
109109
"title": "blacklistDevices"
110110
},
111+
"devices": {
112+
"description": "A list of Google Cast devices to monitor\n\nIf this is used then `useAutoDiscovery` is set to FALSE, if not explicitly set",
113+
"items": {
114+
"properties": {
115+
"address": {
116+
"title": "address",
117+
"type": "string"
118+
},
119+
"name": {
120+
"title": "name",
121+
"type": "string"
122+
}
123+
},
124+
"required": [
125+
"address",
126+
"name"
127+
],
128+
"type": "object"
129+
},
130+
"title": "devices",
131+
"type": "array"
132+
},
111133
"forceMediaRecognitionOn": {
112134
"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",
113135
"items": {
@@ -152,6 +174,11 @@
152174
"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.",
153175
"title": "scrobbleThresholds"
154176
},
177+
"useAutoDiscovery": {
178+
"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",
179+
"title": "useAutoDiscovery",
180+
"type": "boolean"
181+
},
155182
"useAvahi": {
156183
"default": false,
157184
"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.",

src/backend/sources/ChromecastSource.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,30 @@ export class ChromecastSource extends MemorySource {
9191

9292
const {
9393
data: {
94-
useAvahi = parseBool(process.env.IS_DOCKER)
94+
useAvahi = parseBool(process.env.IS_DOCKER),
95+
useAutoDiscovery,
96+
devices = []
9597
} = {}
9698
} = this.config;
9799

98-
if(useAvahi) {
99-
await this.discoverAvahi();
100-
} else {
101-
await this.discoverNative();
100+
let ad = useAutoDiscovery;
101+
if(ad === undefined) {
102+
ad = devices.length === 0;
103+
}
104+
if(devices.length > 0) {
105+
for(const device of devices) {
106+
await this.initializeDevice({name: device.name, addresses: [device.address], type: 'googlecast'});
107+
}
108+
}
109+
110+
if(ad) {
111+
if(useAvahi) {
112+
await this.discoverAvahi();
113+
} else {
114+
await this.discoverNative();
115+
}
102116
}
117+
103118
this.initialized = true;
104119
return true;
105120
}

0 commit comments

Comments
 (0)