Last active
August 22, 2018 20:54
-
-
Save bleathem/50b4dd2fd4377503eaad to your computer and use it in GitHub Desktop.
Creating an Rx.js Observable from a STOMP over Websocket source (with error handling)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see: https://github.com/jmesnil/stomp-websocket | |
var client = Stomp.client('ws://...'); | |
client.debug = undefined; | |
var live = Rx.Observable.create(function (observer) { | |
console.log('Connecting...') | |
client.connect(username, password, function(frame) { | |
console.log(frame.toString()); | |
observer.onNext(frame); | |
}, function(error) { | |
observer.onError(new Error(error)); | |
}); | |
}) | |
.flatMap(function() { | |
return Rx.Observable.create(function (observer) { | |
client.subscribe('/queue/some_queue', function(message) { | |
observer.onNext(event); | |
return function() { | |
client.disconnect(function() { | |
console.log('Disconnected.'); | |
}); | |
}; | |
}, function(error) { | |
observer.onError(new Error(error)); | |
}) | |
}) | |
}) | |
.map(function(message) { | |
... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment