Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Socket IO、Laravel、Redis、Angularjs向特定用户发送数据_Angularjs_Node.js_Laravel_Redis_Socket.io - Fatal编程技术网

使用Socket IO、Laravel、Redis、Angularjs向特定用户发送数据

使用Socket IO、Laravel、Redis、Angularjs向特定用户发送数据,angularjs,node.js,laravel,redis,socket.io,Angularjs,Node.js,Laravel,Redis,Socket.io,我正在建立一个应用程序,让学生能够看到他们的时间表是由管理员创建的。现在每个学生都有一个组id。 我想让时间表实时更新,所以我应用了本教程。这是我到目前为止所做的 事件处理程序: namespace echooly\Handlers; use Redis; use Response; class StudentScheduleUpdatedEventHandler { CONST EVENT = 'schedule.update'; CONST CHANNEL = 'sch

我正在建立一个应用程序,让学生能够看到他们的时间表是由管理员创建的。现在每个学生都有一个组id。 我想让时间表实时更新,所以我应用了本教程。这是我到目前为止所做的

事件处理程序

namespace echooly\Handlers;
use Redis;
use Response;

class StudentScheduleUpdatedEventHandler 
{

    CONST EVENT = 'schedule.update';
    CONST CHANNEL = 'schedule.update';

    public function handle($data)
    {
        $redis = Redis::connection();
        $redis->publish(self::CHANNEL, $data);

    }

}
var express  = require('express'),
       http  = require('http'),
     server  = http.createServer(app);
var app      = express();
const redis  = require('redis');
const io     = require('socket.io');
const client = redis.createClient();

server.listen(3000, 'localhost');
console.log("Listening.....");

io.listen(server).on('connection', function(client) {
     const redisClient = redis.createClient();

     redisClient.subscribe('schedule.update');

     console.log("Redis server running.....");

     redisClient.on("message", function(channel, message) {
         client.emit(channel, message);
     });
     client.on("getGroup", function(groupId) {
         console.log(groupId);
     });

    client.on('disconnect', function() {
         redisClient.quit();
    });
});
  studentSocket.on('schedule.update', function (data) {
        $scope.events.length = 0;
        $scope.populatePlan(JSON.parse(data));
        inform.add('New Course Added');
  });
管理控制器(事件积垢法)

因此,基本上我正在推动最新创建的事件

节点服务器

namespace echooly\Handlers;
use Redis;
use Response;

class StudentScheduleUpdatedEventHandler 
{

    CONST EVENT = 'schedule.update';
    CONST CHANNEL = 'schedule.update';

    public function handle($data)
    {
        $redis = Redis::connection();
        $redis->publish(self::CHANNEL, $data);

    }

}
var express  = require('express'),
       http  = require('http'),
     server  = http.createServer(app);
var app      = express();
const redis  = require('redis');
const io     = require('socket.io');
const client = redis.createClient();

server.listen(3000, 'localhost');
console.log("Listening.....");

io.listen(server).on('connection', function(client) {
     const redisClient = redis.createClient();

     redisClient.subscribe('schedule.update');

     console.log("Redis server running.....");

     redisClient.on("message", function(channel, message) {
         client.emit(channel, message);
     });
     client.on("getGroup", function(groupId) {
         console.log(groupId);
     });

    client.on('disconnect', function() {
         redisClient.quit();
    });
});
  studentSocket.on('schedule.update', function (data) {
        $scope.events.length = 0;
        $scope.populatePlan(JSON.parse(data));
        inform.add('New Course Added');
  });
角度控制器

namespace echooly\Handlers;
use Redis;
use Response;

class StudentScheduleUpdatedEventHandler 
{

    CONST EVENT = 'schedule.update';
    CONST CHANNEL = 'schedule.update';

    public function handle($data)
    {
        $redis = Redis::connection();
        $redis->publish(self::CHANNEL, $data);

    }

}
var express  = require('express'),
       http  = require('http'),
     server  = http.createServer(app);
var app      = express();
const redis  = require('redis');
const io     = require('socket.io');
const client = redis.createClient();

server.listen(3000, 'localhost');
console.log("Listening.....");

io.listen(server).on('connection', function(client) {
     const redisClient = redis.createClient();

     redisClient.subscribe('schedule.update');

     console.log("Redis server running.....");

     redisClient.on("message", function(channel, message) {
         client.emit(channel, message);
     });
     client.on("getGroup", function(groupId) {
         console.log(groupId);
     });

    client.on('disconnect', function() {
         redisClient.quit();
    });
});
  studentSocket.on('schedule.update', function (data) {
        $scope.events.length = 0;
        $scope.populatePlan(JSON.parse(data));
        inform.add('New Course Added');
  });
问题是如何过滤发送给特定学生的数据

  • 有东西告诉我我们可以用redis制作一个动态频道?遗憾的是,我没有这方面的经验
  • 我试图在通过学生组id获取数据时触发事件 这最终会使学生在组id更改时看到新的计划

    我希望我足够清楚我真的希望得到一些答案谢谢

    您需要通过单独的通道将数据发送给每个学生

    例如:

    public function broadcastOn()
    {
        return ['Student.' . $this->student->Id];
    }
    

    我也想知道这个问题的解决方法……我想知道你是如何解决的?可惜文档没有透露太多信息。。。。