Creates a WebSocket Subject with a given URL, protocol and an optional observer for the open event.
url
(String): The URL of the WebSocket.protocol
(String): The protocol of the WebSocket.[observerOrOnNext]
(Rx.Observer|Function): An optional Observer or onNext function to capture the open event.
(Subject): A Subject which wraps a WebSocket.
// Using a function for the open
var socket = Rx.DOM.fromWebSocket(
'http://localhost:8080',
'protocol',
function (e) {
console.log('Opening');
})
socket.subscribe(function (next) {
console.log('Received data: ' + next);
});
socket.onNext('data');
// Using an observer for the open
var observer = Rx.Observer.create(function (e) {
console.log('Opening');
});
var socket = Rx.DOM.fromWebSocket(
'http://localhost:8080', 'protocol', observer)
socket.subscribe(function (next) {
console.log('Received data: ' + next);
});
socket.onNext('data');