Skip to content

Commit 6cf553e

Browse files
authored
feat(chromecast): Support Google Pixel Tablet (#77)
The new Pixel tablet behaves a little differently than older devices. This expands the tool to recognize the different home screen behavior and new status messages.
1 parent f799205 commit 6cf553e

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

backends/chromecast/cast-utils.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,24 @@ function cast(flags, log, mode, url) {
116116
receiver.on('message', (data, broadcast) => {
117117
// Certain messages may contain a list of running apps.
118118
// Look for those to indicate a change in what's running.
119-
let appIds = [];
120-
if (data.type == 'RECEIVER_STATUS' && data.status.applications) {
121-
appIds = data.status.applications.map((app) => app.appId);
119+
let appLaunched = false;
120+
let homeLaunched = false;
121+
if (data.type == 'RECEIVER_STATUS') {
122+
const applications = data.status.applications || [];
123+
const appIds = applications.map((app) => app.appId);
124+
appLaunched = appIds.includes(request.appId);
125+
// On traditional Cast devices, there's a home screen app to run.
126+
// On the new Google Pixel tablet (2023), the list becomes empty.
127+
homeLaunched = appIds.includes(HOME_SCREEN_APP_ID) ||
128+
appIds.length == 0;
122129
}
123130

124-
if (request.type == 'LAUNCH' && appIds.includes(request.appId)) {
131+
if (request.type == 'LAUNCH' && appLaunched) {
125132
// The request was fulfilled.
126133
log.info('Cast successful.');
127134
clearTimeout(connectionTimer);
128135
resolve();
129-
} else if (request.type == 'STOP' &&
130-
appIds.includes(HOME_SCREEN_APP_ID)) {
136+
} else if (request.type == 'STOP' && homeLaunched) {
131137
// The home screen is showing.
132138
log.info('Return to home screen successful.');
133139
clearTimeout(connectionTimer);
@@ -138,6 +144,14 @@ function cast(flags, log, mode, url) {
138144
} else if (data.type == 'RECEIVER_STATUS' && data.status.volume) {
139145
// Ignore updates on audio volume. These occur frequently, are not
140146
// useful, and should not be logged below.
147+
} else if (data.type == 'LAUNCH_STATUS' &&
148+
data.status == 'USER_PENDING_AUTHORIZATION') {
149+
log.info('Waiting for user authorization to run the receiver...');
150+
} else if (data.type == 'LAUNCH_STATUS' &&
151+
data.status == 'USER_ALLOWED') {
152+
// This occurs when the user has chosen "always allow" for a previous
153+
// launch. The launch is happening, and there is no need to log this
154+
// status.
141155
} else {
142156
// TODO: are there other common errors we need to check for?
143157
log.debug('Unrecognized data from castv2:', data);

0 commit comments

Comments
 (0)