@@ -21,16 +21,19 @@ const mustHaveSendError = new Error(`Process must have a \`.send()\` method.`)
2121
2222export default class IPOSMessaging {
2323 private listeners : Map < iposMessagingType | 'any' , Array < iposMessagingCallback > >
24+ private nonIPOSListeners : Set < ( message : any ) => any >
2425 private process : ChildProcess | NodeJS . Process
2526
2627 constructor ( process : ChildProcess | NodeJS . Process ) {
2728 this . listeners = new Map ( )
29+ this . nonIPOSListeners = new Set ( )
2830 if ( ! process . send ) throw mustHaveSendError
2931 this . process = process
3032 this . process . on ( 'message' , ( message : iposMessagingMessage ) => {
3133 try {
3234 if ( message . protocol !== 'ipos' )
33- return
35+ // not a message from ipos
36+ return this . nonIPOSListeners . forEach ( callback => callback ( message ) )
3437
3538 if ( message . type === 'ready' ) {
3639 this . send ( 'register' )
@@ -52,6 +55,7 @@ export default class IPOSMessaging {
5255 }
5356 } catch ( e ) {
5457 // not a message from ipos
58+ this . nonIPOSListeners . forEach ( callback => callback ( message ) )
5559 }
5660 } )
5761
@@ -62,6 +66,10 @@ export default class IPOSMessaging {
6266 }
6367 }
6468
69+ /*getNonIPOSMessages(handler: (message: any) => any) {
70+ this.nonIPOSListeners.add(handler)
71+ }*/
72+
6573 send ( type : iposMessagingType , data ?: { } ) {
6674 if ( ! this . process . send ) throw mustHaveSendError
6775 this . process . send ( {
0 commit comments