What event should I use for closing client websocket in Electron application?

4255 views javascript
7

I have Electron application. There is websocket connection between server and client side of electron app (another words, I use websocket on index.html).

I need to close websocket connection, when user closes the application. What event should I use for it?

There is mainWindow.on('closed', () => { }); but I have no access to browser code at this point.

answered question

1 Answer

0

You should use IPC (Internal Process Communication). In the electron framework, there are two processes:

  • Main (The main process creates web pages by creating BrowserWindow instances.)
  • Renderer (The main process manages all web pages and their corresponding renderer processes)

These two can communicate together using IPC. For more details see docs

posted this

Have an answer?

JD

Please login first before posting an answer.