Last active
December 11, 2015 07:08
-
-
Save patelm5/4564224 to your computer and use it in GitHub Desktop.
subscribe object example.
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
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