Merge pull request #14287 from electron/miniak/ipc-refactoring

refactor: move common logic to handleRemoteCommand (rpc-server.js)
This commit is contained in:
John Kleinschmidt 2018-08-28 17:06:38 -04:00 committed by GitHub
commit 865435c491
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 108 additions and 138 deletions

View file

@ -275,21 +275,21 @@ function metaToException (meta) {
return error
}
function handleMessage (channel, handler) {
ipcRenderer.on(channel, (event, passedContextId, ...args) => {
if (passedContextId === contextId) {
handler(...args)
}
})
}
// Browser calls a callback in renderer.
ipcRenderer.on('ELECTRON_RENDERER_CALLBACK', (event, passedContextId, id, args) => {
if (passedContextId !== contextId) {
// The invoked callback belongs to an old page in this renderer.
return
}
handleMessage('ELECTRON_RENDERER_CALLBACK', (id, args) => {
callbacksRegistry.apply(id, metaToValue(args))
})
// A callback in browser is released.
ipcRenderer.on('ELECTRON_RENDERER_RELEASE_CALLBACK', (event, passedContextId, id) => {
if (passedContextId !== contextId) {
// The freed callback belongs to an old page in this renderer.
return
}
handleMessage('ELECTRON_RENDERER_RELEASE_CALLBACK', (id) => {
callbacksRegistry.remove(id)
})