Reputation: 920
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});
Upvotes: 8
Views: 212
Reputation: 175
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.
Upvotes: 6