From 1b462e3a350e9e5125dafce33a73f3b69f9aab68 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Thu, 28 Aug 2025 20:12:40 +0000 Subject: [PATCH] fix(classes.ipcchannel): Normalize heartbeatThrowOnTimeout option parsing and allow registering heartbeatTimeout via IpcChannel.on --- changelog.md | 6 ++++++ ts/00_commitinfo_data.ts | 2 +- ts/classes.ipcchannel.ts | 14 +++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index fdb2667..49e7c77 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2025-08-28 - 2.1.3 - fix(classes.ipcchannel) +Normalize heartbeatThrowOnTimeout option parsing and allow registering 'heartbeatTimeout' via IpcChannel.on + +- Normalize heartbeatThrowOnTimeout to boolean (accepts 'true'/'false' strings and other truthy/falsey values) to be defensive for JS consumers +- Expose 'heartbeatTimeout' as a special channel event so handlers registered via IpcChannel.on('heartbeatTimeout', ...) will be called + ## 2025-08-26 - 2.1.2 - fix(core) Improve heartbeat handling and transport routing; forward heartbeat timeout events; include clientId routing and probe improvements diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index c504b35..a03eb16 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartipc', - version: '2.1.2', + version: '2.1.3', description: 'A library for node inter process communication, providing an easy-to-use API for IPC.' } diff --git a/ts/classes.ipcchannel.ts b/ts/classes.ipcchannel.ts index d620877..ebd2a09 100644 --- a/ts/classes.ipcchannel.ts +++ b/ts/classes.ipcchannel.ts @@ -82,6 +82,18 @@ export class IpcChannel extends plugins.EventEm ...options }; + // Normalize heartbeatThrowOnTimeout to boolean (defensive for JS consumers) + const throwOnTimeout = (this.options as any).heartbeatThrowOnTimeout; + if (throwOnTimeout !== undefined) { + if (throwOnTimeout === 'false') { + this.options.heartbeatThrowOnTimeout = false; + } else if (throwOnTimeout === 'true') { + this.options.heartbeatThrowOnTimeout = true; + } else if (typeof throwOnTimeout !== 'boolean') { + this.options.heartbeatThrowOnTimeout = Boolean(throwOnTimeout); + } + } + this.transport = createTransport(this.options); this.setupTransportHandlers(); } @@ -449,7 +461,7 @@ export class IpcChannel extends plugins.EventEm * Register a message handler */ public on(event: string, handler: (payload: any) => any | Promise): this { - if (event === 'message' || event === 'connect' || event === 'disconnect' || event === 'error' || event === 'reconnecting' || event === 'drain') { + if (event === 'message' || event === 'connect' || event === 'disconnect' || event === 'error' || event === 'reconnecting' || event === 'drain' || event === 'heartbeatTimeout') { // Special handling for channel events super.on(event, handler); } else {