angular-websocket
angular-websocket copied to clipboard
onMessage not being called when server sends arbitrary data
Hi I am using this library for an iOS app. The problem I am facing is I can see the web socket being initialized and when I am running my app and I bring down the web socket server, I see my app trying to reconnect, so I know the socket is alive, but when the server is sending any message (I am sending "test" every 5 seconds from the server) my onMessage callback is never called. I know the server works because I am running a web socket client in Chrome as well and it receives it, but not my app.
Can someone tell me if they see something wrong in my app code:
angular.module('zmApp.controllers').service('EventServer',
[ '$websocket', 'ZMDataModel', '$rootScope',function
( $websocket, ZMDataModel, $rootScope) {
ZMDataModel.zmLog("*************EVENT SERVER*************");
var dataStream;
var loginData = ZMDataModel.getLogin();
ZMDataModel.zmLog ("webSocketStart: attempting to start a WSS connection");
dataStream = $websocket( "wss://<server name removed>", {reconnectIfNotNormalClose: true});
dataStream.onMessage(function(message) {
ZMDataModel.zmLog("GOT WEBSOCKET MESSAGE:" + JSON.parse(message.data));
});
dataStream.onError(function(message) {
ZMDataModel.zmLog("GOT WEBSOCKET ERROR:" + JSON.parse(message.data));
});
}]);
You may be assigning a function to an undefined object (onOpen).