SignalR,JQuery和Node [英] SignalR, JQuery and Node
问题描述
在我目前正在进行的一个项目中,我们使用Electron作为主机.在电子主进程(这是正常的Node进程)中,我们需要连接到具有SignalR端点的下游后端.
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.
但是,由于SignalR是一个JQuery模块,而Node既不支持SignalR也没有JQuery,因此我们有点卡住了.我看到以下选项:
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:
- 查看 node 中的一些JQuery实现,自 我们使用webpack,而不是普通的JQuery注入 SignalR
- 使用不受支持(较旧)的 SignalR的节点版本
- 具有一个不可见的隐藏浏览器窗口,该窗口将托管SignalR和JQuery位并将它们通过IPC代理到主进程
- 自己编译JQuery,仅包括SignalR所需的模块
- 您需要别人帮助的其他事情. :)
- Look at some of the JQuery implementations in node and since we use webpack, inject that instead of the normal JQuery into SignalR
- Use an unsupported (and old) Node version of SignalR
- Have an invisible hidden browser window which will host the SignalR and JQuery bits and proxy them through to the main process over IPC
- Compile JQuery myself, including only the modules that SignalR require
- Something else, which you kind people will help me with. :)
数字1和2吓到我了,因为我不想调试API差异,或者只是实现中的简单错误.
Number 1 and 2 scare me as I don't want to be debugging API differences or just plain bugs in the implementations.
推荐答案
引入对jsdom的依赖关系并通过它向jquery提供一个dom似乎可以解决问题:
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");
如果以上内容在Signalr脚本之前导入,则可以正常工作.
If the above is imported before the signalr script, it works fine.
更新:需要使WebSocket在窗口对象上可用,以便websockets传输能够正常工作
UPDATE: need to make WebSockets available on window object so websockets transport will work
祝你好运;)
这篇关于SignalR,JQuery和Node的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!