Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sails.io.js - nodejs - Resourceful PubSub not receiving model events

I am trying to subscribe a nodejs application to model events in sails. Here is my code:

var socketIOClient = require('socket.io-client'),
    sailsIOClient = require('sails.io.js');

var io = sailsIOClient(socketIOClient);

io.sails.url = 'http://localhost:1337';

io.socket.on("agent", function(event) {
  console.log(event);
})

io.socket.get("/agent", function(resData, jwres) {})

Here is a link to all of the output on the sails server when the client(nodejs) connects:

https://gist.github.com/CiscoKidxx/e5af93ebcc24702ba4f8

My understanding is that when I create a new agent it should trigger a console.log(event) which lists the changes. This is not happening. I do get a "now connected to sails" upon script start up. Any thoughts?

Here is my call to create a new agent in my UserController:

Agent.create({
  syncToken: token,
  owner: user.id
}).exec(function (err, newAgent) {
  Agent.publishUpdate(newAgent.id, {syncToken: newAgent.syncToken});
like image 751
CiscoKidx Avatar asked Nov 25 '15 21:11

CiscoKidx


1 Answers

The server side code snippet above doesn't show a call to Agent.publishCreate in the callback, but rather a publishUpdate.

From what I understand, the publishCreate is only automatically triggered when using the blueprints - but not for programatic calls like your Agent.create above.

So changing it from publishUpdate to publishCreate might fix it in your context.

like image 169
marco4net Avatar answered Nov 13 '22 10:11

marco4net