SignalR, JQuery and Node

依然范特西╮ 提交于 2019-12-02 05:26:32

问题


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:

  1. Look at some of the JQuery implementations in node and since we use webpack, inject that instead of the normal JQuery into SignalR
  2. Use an unsupported (and old) Node version of SignalR
  3. Have an invisible hidden browser window which will host the SignalR and JQuery bits and proxy them through to the main process over IPC
  4. Compile JQuery myself, including only the modules that SignalR require
  5. Something else, which you kind people will help me with. :)

Number 1 and 2 scare me as I don't want to be debugging API differences or just plain bugs in the implementations.


回答1:


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 ;)



来源:https://stackoverflow.com/questions/36234624/signalr-jquery-and-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!