Laravel 5.1 Session和Socket.IO + Redis-向登录(已知)用户和用户组发送通知 [英] Laravel 5.1 Session and Socket.IO + Redis - Sending Notifications to Logged In (Known) Users and Group Of Users

查看:94
本文介绍了Laravel 5.1 Session和Socket.IO + Redis-向登录(已知)用户和用户组发送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,我想为特定的用户组(具有Admin的角色)实施实时通知,并且经过研究后,我了解到需要进行会话才能知道哪些用户登录(默认情况下,它们是匿名的).

I am working on a project where I want to implement real-time notifications for a specific group of users (with role of Admin) and after some research, I understood that I'll need the session in order to know which users are logged in (by default they are anonymous).

此外,我只需要向特定用户实施通知. (只有一个用户,例如:John Doe)

Also, I'll need to implement notifications to specific users only. (only one user, example: John Doe)

所以,我的问题是:

  1. 如何通过Redis将会话/cookie转移到NodeJS端,然后发出通知?

  1. How can I transfer the session/cookie over to the NodeJS side through Redis and then emit the notification?

我应该怎么做?

是否进行了加密/解密?

Any encryption / decryption?

任何人都有机会实施这样的事情吗?

Anyone ever had any chance to implement anything like this?

在互联网上几乎没有关于此的信息,并且大多数教程对于我的用例来说都太基础了.

There's almost no info about this on the internet and most of the tutorials are way too basic for my use case.

我正在使用Laravel 5.1 Broadcasting功能发布一些通知,并使用Socket.io(版本1.3.7)实时显示它们.我还使用Redis(版本3),NodeJS(版本5)和Express(版本4.13).

I am using Laravel 5.1 Broadcasting features to publish some notifications and display them in real-time with Socket.io (version 1.3.7). I also use Redis (version 3), NodeJS (version 5) and Express (version 4.13).

感谢您的阅读!

推荐答案

我一直在(缓慢地)使用 WAMP ,它是相关的协议和路由器.我目前有大约五种不同的服务(有些是用PHP编写的,有些是用NodeJS编写的),还有所有的客户端都可以实时通信.

I've been implementing (slowly) something similar for a web app using Autobahn and WAMP, it's associated protocol and router. I currently have about five different services (some written in PHP, some in NodeJS) plus the clients all communicating in real time.

WAMP的优点在于,它封装了远程过程调用(RPC)和发布/订阅(PubSub)模型以进行通信.

The nice thing about WAMP is that it encapsulates both remote procedure calls (RPC) and publish/subscribe (PubSub) models for communication.

我的身份验证方案有点麻烦:在Laravel Web应用程序的每个页面上,都有一个令牌值,该值对于用户是唯一的,并且是在登录Laravel应用程序时生成的.当客户端连接到WAMP路由器时,Javascript将使用此令牌值进行身份验证-如果它是无效(或陈旧)的令牌,则拒绝连接.

My authentication scheme is a bit of a kludge: on each page of the Laravel web app, there is a token value which is unique to the user and generated upon log in to the Laravel app. The Javascript uses this token value to authenticate when the client connects to the WAMP router - if it's an invalid (or stale) token, the connection is refused.

对于将通知限制为特定用户或组,一种简单的方法是将适当的JS代码包装在仅当用户(或仅在刀片模板中输出到客户端)的函数中具有适当的权限.

As for limiting notifications to specific users or groups, one simple way to do it would be to wrap the appropriate JS code in a function that is only called (or is only output to the client in the blade template) if the user has the appropriate permissions.

最后,我的应用程序只能在防火墙内部使用,因此我没有研究使用加密/解密的方法.

Finally, my application is strictly for use inside our firewall, so I haven't investigated using encryption/decryption.

这篇关于Laravel 5.1 Session和Socket.IO + Redis-向登录(已知)用户和用户组发送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆