我在我的 laravel 应用程序上运行 socket.io
和 laravel-echo-server
。所以我想知道 privateChannels
和 presenceChannels
之间的区别。我觉得在很多情况下(如果不是全部)它们可以互换使用。
例如在我的应用中:
- 有些情况下我需要通知所有用户 部门。
- 然后在某些情况下我需要通知某些特定的人 在部门内具有特定权限的用户。
- 那么在某些情况下我可能需要提供一些 用户临时访问某些通知等。
最佳答案
Presence channels build on the security of private channels while exposing the additional feature of awareness of who is subscribed to the channel. This makes it easy to build powerful, collaborative application features such as notifying users when another user is viewing the same page.
换句话说,存在 channel 本身也是私有(private) channel ,但允许每个用户看到同一 channel 中的其他用户。常见的示例是带有房间的聊天应用程序,其中每个房间都是一个 channel 。
对于您描述的场景,我希望始终使用私有(private) channel 。您的描述读起来好像该应用程序受身份验证保护,这会自动排除公共(public) channel 。由于您也不要求您的用户查看还有谁收到了通知(至少您没有提到),因此存在 channel 没有意义。这让我们可以选择使用私有(private) channel 。
关于laravel - PresenceChannels 和 PrivateChannels 之间的区别是什么 - LARAVEL 5.8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56970270/