Saltar al contenido principal

MessageChannelMain

MessageChannelMain is the main-process-side equivalent of the DOM MessageChannel object. Its singular function is to create a pair of connected MessagePortMain objects.

Ve la documentacion de Channel Messaging API para mas información sobre el uso de channel messaging.

Clase: MessageChannelMain

Interfaz para la mensajería de canales del proceso principal.

Proceso: principal

Ejemplo:

// Main process
const { BrowserWindow, MessageChannelMain } = require('electron')
const w = new BrowserWindow()
const { port1, port2 } = new MessageChannelMain()
w.webContents.postMessage('port', null, [port2])
port1.postMessage({ some: 'message' })

// Renderer process
const { ipcRenderer } = require('electron')
ipcRenderer.on('port', (e) => {
// e.ports is a list of ports sent along with this message
e.ports[0].onmessage = (messageEvent) => {
console.log(messageEvent.data)
}
})

Propiedades de la instancia

channel.port1

A MessagePortMain property.

channel.port2

A MessagePortMain property.