fix(classes.ipcchannel): Normalize heartbeatThrowOnTimeout option parsing and allow registering heartbeatTimeout via IpcChannel.on
This commit is contained in:
@@ -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.'
|
||||
}
|
||||
|
@@ -82,6 +82,18 @@ export class IpcChannel<TRequest = any, TResponse = any> 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<TRequest = any, TResponse = any> extends plugins.EventEm
|
||||
* Register a message handler
|
||||
*/
|
||||
public on(event: string, handler: (payload: any) => any | Promise<any>): 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 {
|
||||
|
Reference in New Issue
Block a user