Reputation: 3339
I'm trying to do something basic, but it's completely eluding me. I'm trying to create an Observable
from rxjx/observable/dom/webSocket
in RxJS5, but I'm not using typescript, or es6 modules... just plain 'ole good commonJS. I've managed to patch the Observable properly according to the docs, but whenever I try to pass in the string expected for the subject, I get the error:
no WebSocket constructor can be found
, [source].
I haven't had time to dig into TypeScript yet, but from what I can tell, I've satisfied the conditions of the constructor, and I've also taken a look at the test spec, and they use the function in the same way Observable.webSocket('ws://host:port');
I'm trying to, but I still get an error.
I've tried:
var Rx = require('rxjs/Rx');
require('rxjs/Rx.dom').webSocketSubject; //also tried just using `.webSocket`
var source = Rx.Observable.webSocket('ws://localhost:53311');
source.subscribe();
I've also tried passing an object to Rx.Observable.webSocket
:
var source = Rx.Observable.webSocket({
url: 'ws://host:port'
});
Can anyone help me figure out how to use the webSocket
Observable that's available via rxjs5, when consuming from commonJS? (node v5.11)
Upvotes: 2
Views: 991
Reputation: 4641
This isn't about TypeScript, you may need provide constructor to websocket to WebSocketSubject.
In test case, https://github.com/ReactiveX/rxjs/blob/fd0823b99db92d1e214052ad506904b0d744d494/spec/observables/dom/webSocket-spec.ts#L14 specifies it in root to globally override websocket, while it's also possible to provide it as config object like
var ws = require('websocket');
socket = new WebSocketSubject({
url: 'ws://....',
WebSocketCtor: ws.w3cwebsocket
});
Even required in TypeScript or ES15 RxJS module as well.
Upvotes: 2