Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#69253 Add additional message types to cast…
Browse files Browse the repository at this point in the history
…v2 by @joeyparrish
  • Loading branch information
joeyparrish authored Apr 15, 2024
1 parent da49c53 commit 7edaa7d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions types/castv2/castv2-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Client,
ClientOptions,
LaunchRequestMessage,
MediaStatusMessage,
ReceiverLaunchErrorMessage,
ReceiverLaunchStatusMessage,
ReceiverMessage,
Expand Down Expand Up @@ -111,6 +112,11 @@ function handleStatusMessages(channel: Channel): void {
}
console.log(`isActiveInput: ${status.isActiveInput}`);
console.log(`isStandBy: ${status.isStandBy}`);
} else if (message.type == "MEDIA_STATUS") {
const status = (message as MediaStatusMessage).status[0];
console.log(`mediaSessionId: ${status.mediaSessionId}`);
console.log(`playerState: ${status.playerState}`);
console.log(`currentTime: ${status.currentTime}`);
}
});
}
Expand Down
17 changes: 15 additions & 2 deletions types/castv2/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="node" />

import { MediaInformation, MediaStatus } from "chromecast-caf-receiver/cast.framework.messages";
import { EventEmitter } from "node:events";

// To start a new client.
Expand Down Expand Up @@ -60,10 +61,10 @@ export interface ApplicationInfo {
}

export interface VolumeInfo {
controlType: string;
controlType?: string;
level: number;
muted: boolean;
stepInterval: number;
stepInterval?: number;
}

// A status message from the receiver.
Expand All @@ -89,6 +90,11 @@ export interface ReceiverLaunchStatusMessage extends ReceiverMessage {
status: "USER_PENDING_AUTHORIZATION" | "USER_ALLOWED";
}

export interface MediaStatusMessage extends ReceiverMessage {
type: "MEDIA_STATUS";
status: MediaStatus[];
}

export type MessageHandler = (data: ReceiverMessage, broadcast: boolean) => void;

export type ErrorHandler = (error: Error) => void;
Expand All @@ -105,6 +111,7 @@ export interface Channel extends EventEmitter {
close(): void;

on(eventName: "message", callback: MessageHandler): this;
on(eventName: "close", callback: () => void): this;
}

export class Client extends EventEmitter {
Expand All @@ -114,5 +121,11 @@ export class Client extends EventEmitter {

createChannel(sourceId: string, destinationId: string, namespace: string, encoding: string): Channel;

on(
eventName: "message",
callback: (sourceId: string, destinationId: string, namespace: string, message: string) => void,
): this;
on(eventName: "connect", callback: () => void): this;
on(eventName: "error", callback: ErrorHandler): this;
on(eventName: "close", callback: () => void): this;
}
2 changes: 1 addition & 1 deletion types/castv2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"https://github.com/thibauts/node-castv2#readme"
],
"dependencies": {
"@types/chromecast-caf-receiver": "*",
"@types/events": "*",
"@types/mdns": "*",
"@types/node": "*"
},
"devDependencies": {
Expand Down

0 comments on commit 7edaa7d

Please sign in to comment.