简体   繁体   English

rxjs5-WebSocketSubject不是构造函数

[英]rxjs5 - WebSocketSubject is not a constructor

So I am trying to utilize rxjs's Observable.webSocket in a node.js environment. 所以我试图在node.js环境中利用rxjs的Observable.webSocket I saw from the docs and this stack overflow post that it is required that I provide my own version of websocket. 我从文档和堆栈溢出帖子中看到,要求我提供自己的websocket版本。 The problem I'm coming across is that both of the examples provided indicate a WebSocketSubject , but they do not mention where this comes from. 我遇到的问题是,提供的两个示例都指示了WebSocketSubject ,但是它们没有提及其来源。

const ws = require('nodejs-websocket');
const Rx = require('rxjs/Rx');
const WebSocketSubject = require('rxjs/observable/dom/WebSocketSubject');

socket = new WebSocketSubject({url: 'ws://....', WebSocketCtor: ws.w3cwebsocket});

const marketSocket$ = Rx.Observable.webSocket('ws://....');

This was my attempt at retrieving the necessary WebSocketSubject, but I just get an error telling me that "WebSocketSubject is not a constructor". 这是我尝试检索必要的WebSocketSubject的尝试,但是我只是收到一条错误消息,告诉我“ WebSocketSubject不是构造函数”。 Is there something painfully obvious I'm missing? 有什么令人痛苦的明显我丢失了吗? If you could share a working solution providing a valid websocket constructor(with all needed references provided) along with an explanation as to what I'm doing wrong that would be wonderful! 如果您可以共享一个有效的websocket构造函数(提供所有必需的引用)并提供有关我做错了的解释的工作解决方案,那就太好了!

The call to require will return the module that contains the WebSocketSubject , so your require call should look like this: require的调用将返回包含WebSocketSubject的模块,因此您的require调用应如下所示:

const WebSocketSubject = require('rxjs/observable/dom/WebSocketSubject').WebSocketSubject;

Or like this: 或像这样:

const { WebSocketSubject } = require('rxjs/observable/dom/WebSocketSubject');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM