使用sails js和twilio节点编写一个简单的调用跟踪器,但publishUpdate似乎没有向我的前端客户端发送消息。 Model.publish有效,但Model.publishUpdate不是。我做的任何事情显然都是错的,还是我有什么不对的?
这是我的代码。 在我的主控制器中,我有一个特定的路由来订阅客户端到我的模型
MainController.js中的
calls: function(req,res){
Calls.find(function foundCalls(err, calls) {
if (err) return next(err);
// subscribe this socket to the Calls classroom
Calls.subscribe(req.socket);
// subscribe this socket to the Calls instance rooms
Calls.subscribe(req.socket, calls);
// This will avoid a warning from the socket for trying to render
// html over the socket.
res.send(calls,200);
});
},
在我的app.js文件中,我有
socket.on('connect', function socketConnected() {
socket.get('/main/calls', function(response){console.log(response)});
socket.on('message', function(message) {
console.log(message);
});
});
在另一个控制器中我有这个: CallController.js
takecall: function(req,res) {
Calls.findOneByCallSid(req.body.CallSid).done(function(err, thiscall) {
if(err){
return next(err);
} else {
// 1a. Save additional parameters
thiscall.DialCallDuration=req.body.DialCallDuration
thiscall.DialCallSid=req.body.DialCallSid
thiscall.RecordingUrl=req.body.RecordingUrl
thiscall.DialCallStatus=req.body.DialCallStatus
thiscall.RecordingDuration=req.body.RecordingDuration
thiscall.RecordingSid=req.body.RecordingSid
thiscall.save(function(err,call) {
if (err) return next(err);
console.log(call.id);
Calls.publishUpdate(call.id,{message:'hello'});
});
// 3. Display twiml that tells twilio we are done with call workflow
var twilio = require('twilio');
var resp = new twilio.TwimlResponse();
res.send(resp.toString(), 200);
}
});
}