My goal is to make a desktop application with electron. I have already a script in nodejs that works when I run it in Nodejs, but which blocks in electron, and I know that primus is the problem, but I don't know how to solve it.
I want to connect in websocket, therefore I use:
var url = "https://myurl.com"
const PrimusSocket = Primus.createSocket({transformer: "engine.io",});
const primus = new PrimusSocket(url);
but the second line doesn't work, nothing is showing in the console, except a warning which shouldn't block all the script:
[Deprecation] 'window.webkitStorageInfo' is deprecated. Please use 'navigator.webkitTemporaryStorage' or 'navigator.webkitPersistentStorage' instead.
Here is the code in my index.html that doesn't work
<script type="text/javascript" >
async function test() {
var Primus = require("primus")
var url = "https://myurl.com";
console.log("we create the socket");
const PrimusSocket = Primus.createSocket({transformer: "engine.io",});
console.log("new instance"); //this message doesn't show up
const primus = new PrimusSocket(url);
primus.on("open", () => {
console.log("open");
})
primus.on("data", data => {
console.log("message received : " + data._messageType);
})
primus.on("reconnected", () => {
console.log('reconnect');
})
primus.on("error", error => {
logger.error(new Error(error));
})
primus.on("end", () => {
console.log("end");
})
primus.open();
}
test();
</script>
For me it works in this way
Server side
app.js
websockets.js
Client side
index.html
your script