Skip to content

Instantly share code, notes, and snippets.

@patelm5
Last active December 11, 2015 07:08
Show Gist options
  • Save patelm5/4564224 to your computer and use it in GitHub Desktop.
Save patelm5/4564224 to your computer and use it in GitHub Desktop.
subscribe object example.
function subscriber(){
var socket = $.atmosphere;
var subSocket;
var model = [] ;
var obj = {
getModel : function(){ return model ; },
subscribe : function(){
var request = { url : document.location.toString()+'atmosphere/?channelId=12351',
transport : 'websocket' ,
fallbackTransport: 'long-polling',
'enableXDR': true,
'withCredentials': true,
'transport' : 'long-polling'
};
request.onMessage = function (response) {
detectedTransport = response.transport;
if (response.status == 200) {
var data = response.responseBody;
try {
var result = $.parseJSON(data);
model.push(result);
} catch (err) {
alert("Exception: " + err)
}
}
};
subSocket = socket.subscribe(request);
}
}
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment