kelibra
kelibra

Reputation: 173

rxjs5 - WebSocketSubject is not a constructor

So I am trying to utilize rxjs's Observable.webSocket in a node.js environment. I saw from the docs and this stack overflow post that it is required that I provide my own version of 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.

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". 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!

Upvotes: 1

Views: 836

Answers (1)

cartant
cartant

Reputation: 58400

The call to require will return the module that contains the WebSocketSubject, so your require call should look like this:

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

Or like this:

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

Upvotes: 2

Related Questions