Skip to content

Commit d5a191a

Browse files
committed
fix how the onMessage is implemented and updated the mock to reflect the change.
1 parent 3b1f0fb commit d5a191a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

app/scripts/services/angular-atmosphere.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ angular.module('ngAtmosphere', [])
2424
request.fallbackTransport = 'long-polling';
2525

2626
function handleResponse(response) {
27-
var data = angular.fromJson(response.responseBody);
27+
var data = response.responseBody;
28+
if (typeof data === 'string'){
29+
data = angular.fromJson(data);
30+
}
2831
if (listeners.hasOwnProperty(data.event)) {
2932
angular.forEach(listeners[data.event], function (listener) {
3033
listener.fn.call(this, data);
@@ -36,9 +39,9 @@ angular.module('ngAtmosphere', [])
3639
return {
3740
init: function (url) {
3841
request.url = url;
42+
request.onMessage = handleResponse;
3943

4044
connection = $.atmosphere.subscribe(request);
41-
connection.onMessage = handleResponse;
4245
},
4346
on: function (event, callbackFn) {
4447

test/mock/jquery.atmosphere.mock.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
var $ = $ || {};
22
$.atmosphere = {
33
AtmosphereRequest: function () {
4-
5-
},
6-
subscribe: function () {
74
return {
85
onError : function(response) {
96
},
@@ -20,9 +17,14 @@ $.atmosphere = {
2017
onTransportFailure : function (reason, request) {
2118
},
2219
onLocalMessage : function (response) {
23-
},
20+
}
21+
}
22+
},
23+
subscribe: function (request) {
24+
var _request = request;
25+
return {
2426
push: function(data){
25-
this.onMessage({responseBody:data});
27+
_request.onMessage({responseBody:data});
2628
}
2729
}
2830
}

0 commit comments

Comments
 (0)