UNPKG

homebridge-homeconnect

Version:

A Homebridge plugin that connects Home Connect appliances to Apple HomeKit

39 lines 1.52 kB
// Homebridge plugin for Home Connect home appliances // Copyright © 2023-2025 Alexander Thoukydides import { RequestError } from '@homebridge/plugin-ui-utils'; import { logError } from '../log-error.js'; // Server-side IPC implementation export class ServerIPC { // Create a new server IPC instance constructor(log, server) { this.log = log; this.server = server; } // Register a new request handler for a given route onRequest(path, fn) { this.server.onRequest(path, async (data) => { const prefix = `onRequest("${path}")`; try { this.log.debug(`${prefix} request`, data); const result = await fn(data); this.log.debug(`${prefix} response`, result); return result; } catch (err) { // All errors should be reported as RequestError to the client if (err instanceof RequestError) throw err; logError(this.log, prefix, err); const message = err instanceof Error ? err.message : String(err); throw new RequestError(`Unexpected ${path} error: ${message}`, { status: 500 }); } }); } // Push an event or stream data to the client pushEvent(event, data) { if (event !== 'log') this.log.debug(`pushEvent("${event}")`, data); this.server.pushEvent(event, data); } } //# sourceMappingURL=server-ipc.js.map