Skip to content

Commit

Permalink
refactor(chrome): Use forked chromecast-client lib
Browse files Browse the repository at this point in the history
* Instead of patching using forked lib with validation fixes and improvements
* Print raw data if validation error is found
  • Loading branch information
FoxxMD committed Jan 12, 2024
1 parent ee7ebb1 commit 758770d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
21 changes: 17 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"better-sse": "^0.8.0",
"body-parser": "^1.19.0",
"bonjour-service": "^1.2.1",
"chromecast-client": "^1.0.1",
"castv2": "^0.1.10",
"chromecast-client": "github:foxxmd/chromecast-client#dist",
"clsx": "^2.0.0",
"common-tags": "^1.8.2",
"compare-versions": "^4.1.2",
Expand Down
File renamed without changes.
11 changes: 10 additions & 1 deletion src/backend/sources/ChromecastSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {EventEmitter} from "events";
import Bonjour, {Service} from "bonjour-service";
import {MediaController, PersistentClient, Media} from "chromecast-client";
import {Client as CastClient} from 'castv2';
import {ErrorWithCause} from "pony-cause";
import {ErrorWithCause, findCauseByReference} from "pony-cause";
import {PlayObject} from "../../core/Atomic";
import dayjs from "dayjs";
import {RecentlyPlayedOptions} from "./AbstractSource";
Expand All @@ -26,6 +26,7 @@ import {
initializeClientPlatform
} from "../common/vendor/chromecast/ChromecastClientUtils";
import {Logger} from "@foxxmd/winston";
import {ContextualValidationError} from "chromecast-client/dist/cjs/src/utils";

interface ChromecastDeviceInfo {
mdns: Service
Expand Down Expand Up @@ -180,6 +181,10 @@ export class ChromecastSource extends MemorySource {
apps = await getCurrentPlatformApplications(v.platform);
} catch (e) {
v.logger.warn(new ErrorWithCause('Could not refresh applications', {cause: e}));
const validationError = findCauseByReference(e, ContextualValidationError);
if(validationError && validationError.data !== undefined) {
v.logger.warn(JSON.stringify(validationError.data));
}
continue;
}

Expand Down Expand Up @@ -339,6 +344,10 @@ export class ChromecastSource extends MemorySource {
}
} catch (e) {
this.logger.warn(new ErrorWithCause(`Could not get Player State for ${k}`, {cause: e}))
const validationError = findCauseByReference(e, ContextualValidationError);
if(validationError && validationError.data !== undefined) {
v.logger.warn(JSON.stringify(validationError.data));
}
}
}

Expand Down

0 comments on commit 758770d

Please sign in to comment.