-
-
Save antonioaguilar/ee5b26aea38ed4f0d4aaabf5939d52c4 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