SignalR,JQuery和Node [英] SignalR, JQuery and Node

查看:146
本文介绍了SignalR,JQuery和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:

  1. 查看 node 中的一些JQuery实现,自 我们使用webpack,而不是普通的JQuery注入 SignalR
  2. 使用不受支持(较旧)的 SignalR的节点版本
  3. 具有一个不可见的隐藏浏览器窗口,该窗口将托管SignalR和JQuery位并将它们通过IPC代理到主进程
  4. 自己编译JQuery,仅包括SignalR所需的模块
  5. 您需要别人帮助的其他事情. :)
  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. :)

数字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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆