sails.io.js - nodejs - 资源丰富的 PubSub 未接收模型事件

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

我正在尝试订阅一个 nodejs 应用程序来模拟 sails 中的事件。这是我的代码:

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) {})

这是客户端 (nodejs) 连接时 sails 服务器上所有输出的 link:

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

我的理解是,当我创建一个新代理时,它应该触发一个 console.log(event),其中列出了更改。这没有发生。我确实在脚本启动时得到 "now connected to sails"。有什么想法吗?

这是我在 UserController 中创建新代理的调用:

Agent.create({
  syncToken: token,
  owner: user.id
}).exec(function (err, newAgent) {
  Agent.publishUpdate(newAgent.id, {syncToken: newAgent.syncToken});

上面的服务器端代码片段在回调中没有显示对 Agent.publishCreate 的调用,而是 publishUpdate.

据我了解,publishCreate 只会在使用蓝图时自动触发 - 但不会像上面的 Agent.create 这样的程序调用。

因此,将其从 publishUpdate 更改为 publishCreate 可能会在您的上下文中修复它。