Envek / obs-studio-node-example

Learn how to use OBS Studio from your Electron app for screen video recording
GNU General Public License v2.0
99 stars 19 forks source link

Electron Error: Failed to host and connect. #50

Open stephen-ip opened 1 year ago

stephen-ip commented 1 year ago

I followed the example code provided, but my code is failing on the first step when I try to run osn.NodeObs.IPC.host("example"); I have the obsRecorder.js file imported into my main.ts file using const obsRecorder = require("./obsRecorder"); and I have set up ipcMain handlers to handle the actions just like in the example. I suspect it might be something with the updated version of electron or something in the example being out of date. Could someone please help me solve this?

hrueger commented 1 year ago

Hi @stephen-ip, could this be a duplicate of #27 ?

stephen-ip commented 1 year ago

I saw that and followed their solution to add { test: /\.node$/, use: "node-loader" } to the webpack config (I'm using typescript and react). When I try running the app, I then get the error: App threw an error during load: Error: \\?\electron\.webpack\main\native_modules\obs_studio_client.node is not a valid Win32 application. I used electron forge to start my project and in the config I saw it already has this in the rules: // Add support for native node modules { // We're specifying native_modules in the test because the asset relocator loader generates a // "fake" .node file which is really a cjs file. test: /native_modules[/\\].+\.node$/, use: "node-loader", },... With this, I assume that it's not a duplicate

hrueger commented 1 year ago

Very strange. Are you you're running it in the main thread and not the renderer process? According to your first post it looks like that which should be fine.

hrueger commented 1 year ago

You could swap the electron version with an older one to check if it is caused by a change in the recent electron versions.

stephen-ip commented 1 year ago

I have tried upgrading all the packages in your demo electron obs app, and it still works, so I guess it's not a electron version issue. I am running it in the main thread the same way the example does. I copied the obsRecorder.js file into the same directory as my main.ts file and import it there. I then copy over the same ipcMain handlers as in the example. A difference is that the updated version of electron wants you to use preload scripts to expose the API and I have did that, which is essentially the same as using remote. I use the electron API to invoke start recording and then main should run it. I am also using npm if that matters, but I'm pretty lost as to what's causing this issue.