允许访客连接到状态频道

允许访客连接到状态频道

本文介绍了Laravel Echo-允许访客连接到状态频道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用laravel-echo-server运行Laravel Echo广播事件.

I am using laravel-echo-server to run Laravel Echo to broadcast events.

我有一个用户计数器频道,其中显示了该应用程序上的所有用户.为此,我正在使用一个在线渠道.对于已登录的用户来说,这很好用,但访客永远都无法建立连接.

I have a user counter channel which shows all the users on the app. For this I am using a presence channel. This works fine for logged in users, but guests just never get connected.

我已经在BroadcastServiceProvider中设置了以下内容:

I've setup the below in the BroadcastServiceProvider:

Broadcast :: channel('global',function(){return ['name'=>'来宾'];});

据我所知,应该允许每个人都作为客人".我猜测在此之前需要禁用一些中间件或auth,而我需要为此频道禁用它.

Which from what I can tell, should allow everyone in as 'guests'. I'm guessing there's some middleware or auth that's being checked before this that I need to disable for this channel.

在帮助所有客户加入此状态渠道方面的任何帮助将不胜感激!

Any help on getting all clients joining this presence channel would be much appreciated!

推荐答案

适用于任何寻求答案的人.确实可以将来宾身份验证到状态通道,而您只需要使用您自己的通道来覆盖服务提供商的Broadcast :: routes().

For anyone looking for answers to this. It is indeed possible to auth guests into presence channels you just need to override the Broadcast::routes() from the service provider with your own.

例如,我的状态频道"global"接受来宾:

As an example my presence channel 'global' accepts guests:

Route :: post('/broadcasting/auth',function(Illuminate \ Http \ Request $ req){if($ req-> channel_name =='presence-global'){返回'global';}返回abort(403);});

这可以扩展到各个方向,或者可以继续将其他状态和专用频道传递给默认的Broadcast :: auth方法

This could be extended in various directions, or could continue to pass other presence and private channels through to the default Broadcast::auth method

这篇关于Laravel Echo-允许访客连接到状态频道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 04:03