简体   繁体   中英

Laravel 5.1 Session and Socket.IO + Redis - Sending Notifications to Logged In (Known) Users and Group Of Users

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).

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

So, my questions are:

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

  2. What should I do exactly?

  3. 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.

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).

Thanks for reading!

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.

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM