diff --git a/src/Client.js b/src/Client.js index d9a30ea..a5dbbd5 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1020,8 +1020,7 @@ class Client extends EventEmitter { ); await this.pupPage.evaluate(() => { - const { Msg, Chat, WAWebCallCollection } = - window.require('WAWebCollections'); + const { Msg, Chat } = window.require('WAWebCollections'); const AppState = window.require('WAWebSocketModel').Socket; // Enable placeholder message resend (recovery for ciphertext messages) @@ -1069,13 +1068,31 @@ class Client extends EventEmitter { .Conn.on('change:battery', (state) => { window.onBatteryStateChangedEvent(state); }); + const WAWebCallCollection = window.require('WAWebCallCollection'); if ( WAWebCallCollection && typeof WAWebCallCollection.on === 'function' ) { - WAWebCallCollection.on('add', (call) => { - window.onIncomingCall(call); - }); + const mapKey = Object.keys(WAWebCallCollection).find( + (k) => WAWebCallCollection[k] instanceof Map, + ); + const internalCallMap = WAWebCallCollection[mapKey]; + const originalMapSet = + internalCallMap.set.bind(internalCallMap); + + internalCallMap.set = function (key, value) { + window.onIncomingCall({ + id: value.id, + peerJid: value.peerJid, + isVideo: value.isVideo, + isGroup: value.isGroup, + canHandleLocally: value.canHandleLocally, + outgoing: value.outgoing, + webClientShouldHandle: value.webClientShouldHandle, + participants: value.participants, + }); + return originalMapSet(key, value); + }; } Chat.on('remove', async (chat) => { window.onRemoveChatEvent(