rtsp-relay icon indicating copy to clipboard operation
rtsp-relay copied to clipboard

Web socket does not work in build for electron

Open na-613c opened this issue 4 years ago • 11 comments

I have a project on electron + react js + local node js server (use rtsp-relay to convert RTSP stream to web socket). In the dev version it works, in the prod version the web socket does not work (the server is working, it was processing a get request)

I'm sorry for the bad english ☺

na-613c avatar Sep 22 '21 13:09 na-613c

Hi, do you have a example of this bug, perhaps a basic repository where I can test this? It's difficult to help without seeing any code.

k-yle avatar Sep 22 '21 21:09 k-yle

Hi. https://github.com/na-613c/web-rtsp-relay-electron - repo. In electron you can write mainWindow.webContents.openDevTools() (35 line) for open dev tools.

na-613c avatar Sep 23 '21 07:09 na-613c

There is a memory leak, if you run a lot of streams in good quality, then you can see in the task dispatcher how RAM is spent over time.

na-613c avatar Sep 23 '21 14:09 na-613c

Is there any way of opening the dev tools in production? Pretty difficult to debug the issue otherwise

k-yle avatar Sep 23 '21 23:09 k-yle

I just started learning electron. I don't know how to get the logs from the local server. :disappointed: p.s. added devtools (similar to browser) in prod.

na-613c avatar Sep 24 '21 07:09 na-613c

for some reason mainWindow.webContents.openDevTools() seems to have no effect in production.

Perhaps the issue is that in production, you're serving the react app from a file:// url, rather than from localhost...

k-yle avatar Sep 24 '21 23:09 k-yle

You can delete process.env.NODE_ENV === 'development' in process.env.NODE_ENV === 'development' && mainWindow.webContents.openDevTools();
or download last version https://github.com/na-613c/web-rtsp-relay-electron/tree/2cb2e67f3beaa6121deb22328cd5ab07beadcab0.

Or something I didn't understand

na-613c avatar Sep 25 '21 13:09 na-613c

This may be caused by '@ffmpeg-installer/ffmpeg' package, It's a known issue that Asar breaks native paths. As a workaround, if you use Asar, you can do something like this:

const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path.replace('app.asar', 'app.asar.unpacked');

Since the relevant code is in this package, I cannot change it. Look here, I can only use translation tools to reply this issues. Forgive me for my poor English.

evalor avatar Jul 18 '22 19:07 evalor

Thanks for the suggestion @evalor, are you experiencing the same issue? I just tried the reproduction example from @na-613c (https://github.com/na-613c/web-rtsp-relay-electron), and it seems to work fine in production. Not sure why it didn't work 10 months ago...

k-yle avatar Jul 19 '22 05:07 k-yle

I use vite+vue3 to build electron application and encounter the same problem.

I try to change the following code( in index.js line 42 ):

    this.stream = spawn(
      ffmpegPath.replace('app.asar', 'app.asar.unpacked'),  // [!!!] It's changed here
      [
        ...(transport ? ['-rtsp_transport', transport] : []), // this must come before `-i [url]`, see #82
        '-i',
        url,
        '-f', // force format
        'mpegts',
        '-codec:v', // specify video codec (MPEG1 required for jsmpeg)
        'mpeg1video',
        '-r',
        '30', // 30 fps. any lower and the client can't decode it
        ...additionalFlags,
        '-',
      ],
      { detached: false, windowsHide },
    );

Now my application can work after it is built. Due to my busy work, I can't follow up this problem immediately. Later, I will try to provide a "minimal" problem recurrence code to help solve this problem.

By the way, you can enable the electron menu to open the developer tools. Please do not hide the menu bar. After starting the application, click 'View - > toggle developer tools' in the menu bar, the developer tool will open.

evalor avatar Jul 21 '22 19:07 evalor

Potential memory leaks may come from jsmpeg, on large (4K) RSTP streams, memory stack growth can be significantly observed, and applications will soon crash due to memory exhaustion. When I destroy instances of jsmpeg and recreate them every 10 minutes, this situation is suppressed. I'm trying to trace the source of memory leaks.

evalor avatar Jul 25 '22 12:07 evalor