feat(companion): add filtered runtime event subscription helper
This commit is contained in:
@@ -42,6 +42,7 @@ export interface CompanionRuntimeClientOptions {
|
||||
}
|
||||
|
||||
export type CompanionEventHandler = (event: string, data: unknown) => void;
|
||||
export type CompanionTypedEventHandler<TData = unknown> = (data: TData) => void;
|
||||
|
||||
export interface RegisterNodeInput {
|
||||
nodeId: string;
|
||||
@@ -352,6 +353,18 @@ export class CompanionRuntimeClient {
|
||||
};
|
||||
}
|
||||
|
||||
subscribeEvent<TData = unknown>(
|
||||
eventName: string,
|
||||
handler: CompanionTypedEventHandler<TData>,
|
||||
): () => void {
|
||||
return this.subscribeEvents((event, data) => {
|
||||
if (event !== eventName) {
|
||||
return;
|
||||
}
|
||||
handler(data as TData);
|
||||
});
|
||||
}
|
||||
|
||||
async call<T>(method: string, params?: Record<string, unknown>): Promise<T> {
|
||||
if (!this.connected) {
|
||||
if (!this.autoConnect) {
|
||||
|
||||
Reference in New Issue
Block a user