@@ -64,13 +64,18 @@ export class InterModuleCommunication {
6464 const type = message . type ;
6565
6666 // Return if the channel ID exists but does not match the current channel ID
67- if ( this . channelId !== undefined && channelId !== this . channelId ) {
67+ // (channel ID can be undefined during initial handshake)
68+ if (
69+ this . channelId !== undefined &&
70+ channelId !== undefined &&
71+ channelId !== this . channelId
72+ ) {
6873 return ;
6974 }
7075
7176 if (
7277 this . messageRecords ?. has ( messageId ) &&
73- type !== IMCMessageTypeEnum . SignalGetWindowId
78+ type !== IMCMessageTypeEnum . SignalRequestOtherWindowId
7479 ) {
7580 console . warn (
7681 `[${
@@ -89,7 +94,7 @@ export class InterModuleCommunication {
8994 ) ;
9095 }
9196
92- if ( message . from !== undefined ) {
97+ if ( message . from !== undefined && message . type !== IMCMessageTypeEnum . SignalIgnore ) {
9398 console . log (
9499 `Module ${ this . thisWindowId } received message from module ${
95100 message . from
@@ -122,7 +127,7 @@ export class InterModuleCommunication {
122127 }
123128
124129 const message = event . data ;
125- const otherWindowId = message . windowId ;
130+ const otherWindowId = message . payload ;
126131 this . otherWindowId = otherWindowId ;
127132
128133 const sender = new MessageSender (
@@ -149,7 +154,7 @@ export class InterModuleCommunication {
149154 this . otherWindow = window ;
150155 this . otherWindow . postMessage (
151156 {
152- type : IMCMessageTypeEnum . SignalGetWindowId ,
157+ type : IMCMessageTypeEnum . SignalRequestOtherWindowId ,
153158 from : this . thisWindowId ,
154159 } ,
155160 "*"
@@ -237,7 +242,7 @@ export class InterModuleCommunication {
237242
238243 // Set get window ID handler in the receiver handler map.
239244 this . receiverHandlerMap ?. set (
240- IMCMessageTypeEnum . SignalGetWindowId ,
245+ IMCMessageTypeEnum . SignalRequestOtherWindowId ,
241246 async ( senderWindow : Window , message : IMCMessage ) => {
242247 console . log (
243248 "Received window ID request. Sending current window ID to other window: "
@@ -246,16 +251,8 @@ export class InterModuleCommunication {
246251 if ( ! id ) {
247252 throw new Error ( "This window ID is not defined." ) ;
248253 }
249- const msg : IMCMessage = {
250- messageId : message . messageId ,
251- channelId : message . channelId ,
252- type : IMCMessageTypeEnum . SignalReturnWindowId ,
253- payload : {
254- windowId : id ,
255- } ,
256- from : id ,
257- } ;
258- senderWindow . postMessage ( msg , "*" ) ;
254+
255+ return id ;
259256 }
260257 ) ;
261258
0 commit comments