Websocket callback not being called


this is not really an ionic question, but more likely a web socket question for mobiles.
I am using angular-websockets (https://github.com/angular-class/angular-websocket) to implement a web socket client in my app (iOS and Android). 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:

[  '$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));

     /*  dataStream.onClose(function(message) {
            ZMDataModel.zmLog("GOT CLOSE:" + JSON.parse(message.data));



I did some more debugging - if I add this code directly to the controller that is running, I get notifications at onMessage. But the callback in my service is not working - how do I make sure my service callback is called? I’m probably misunderstanding how services work - but my understanding was once the service starts, it always receive notifications no matter which controller I am in my app. (Yes, angular question, not ionic - but hopefully folks here can advise)


FYI, the problem was solved. The problem was in the library (or maybe I wasn’t using it correctly, who knows). switched from angular-websocket to ng-websocket and things started working