angularjsnode.jssocketssails.jssails.io.js

Sailsjs websocket not working in the call of io.socket.on()


My angular controller waits for the create signal of the web socket over a model to refresh the data im using on the view. The name of the sails model is Noticia, so the identifier is noticia.

Here is my angular control

io.socket.on('noticia', function (msg) {

    switch(msg.verb) {

      case 'created':

      $scope.last6Items.pop();
      console.log("socket create");
      $scope.last6Items.push(msg.data);
      $scope.$apply(); 
      break;

      default: return; 
    }
});

Then thing is that when I create a register with a POST petition using the rest API generated by sails, the web socket is not working.

I'm using the lastest sails.io.js in my client side https://github.com/balderdashy/sails.io.js/tree/master/dist

Also my model have a connection with mysql


Solution

  • Make sure you are connected to the socket by calling io.socket.get('/noticia') before io.socket.on(...).

    You can check if the socket is connected with io.socket.isConnected().