Skip to content

Instantly share code, notes, and snippets.

@datafatmunger
Created August 18, 2012 13:09
Show Gist options
  • Save datafatmunger/3386775 to your computer and use it in GitHub Desktop.
Save datafatmunger/3386775 to your computer and use it in GitHub Desktop.
WebSocketStompMock = SockJS;
var guid = function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}();
var stream = 'dev.ideedock.com';
var stomp = Stomp.client('http://'+stream+':55674/stomp');
stomp.connect('guest', 'guest', function(x) {
stomp.subscribe('/topic/'+guid, function(d) {
var data = JSON.parse(d.body);
if(data.user) {
//Signup or login complete! - Do something fun!
} else {
//Server knows you're here! - Login or signup!
}
});
var message = JSON.stringify({ url: stream});
stomp.send('/topic/'+guid, {}, message);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment