[英]Sails.js WebScoket how to create new channel?
如何在SAILS.js中创建用于发出的新通道?
简单
io.sockets.in('ee').emit('messageName', {thisIs: 'theMessage'});
然后在Angular.js中
io.socket.on("ee", function(data){
console.log(data);
})
不要工作..
您可以使用此代码,我认为它可以完成您想要的工作,但不能达到您提到的方式:
在客户端调用我们在服务器端使用的路由之前,请添加以下代码:
// Use `io.socket.on()` to listen for the 'hello' event: io.socket.on('hello', function (data) { console.log('Socket `' + data.id + '` joined the party!'); });
在所需的路由控制器中,添加以下代码:
// Have the socket which made the request join the "funSockets" room. sails.sockets.join(req, 'funSockets'); // Broadcast a notification to all the sockets who have joined // the "funSockets" room, excluding our newly added socket: sails.sockets.broadcast('funSockets', 'hello', { howdy: 'hi there!'}, req);
请注意,此“嗨!” 刚刚加入的客户端将不会收到该消息。 如果要向所有客户端以及新加入的客户端发送消息,只需从广播参数中删除req参数。
有关更多信息,请检查此链接: http : //sailsjs.com/documentation/concepts/realtime
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.