Reputation: 30031
In a project I'm currently working on, we are using Electron as a host. In the Electron main process, which is a normal Node process we need to connect to a downstream back-end that has SignalR endpoints.
However, since SignalR is a JQuery module and neither SignalR nor JQuery are supported on Node, we're a bit stuck. I see the following options:
Number 1 and 2 scare me as I don't want to be debugging API differences or just plain bugs in the implementations.
Upvotes: 2
Views: 2042
Reputation: 581
Introducing a dependency on jsdom and providing a dom to jquery via that seems to do the trick:
var jsdom = require('jsdom').jsdom, document = jsdom('<html></html>');
global.window = document.defaultView;
global.window.WebSocket = require("ws");
If the above is imported before the signalr script, it works fine.
UPDATE: need to make WebSockets available on window object so websockets transport will work
Good luck with it ;)
Upvotes: 2