问题描述
来自广播文档
Broadcast::channel('order.{orderId}', function ($user, $orderId) {
return $user->id === Order::findOrNew($orderId)->user_id;
});
句子所有授权回调均将当前经过身份验证的用户作为其第一个参数
对于在网络上广播是正确的,如果我们为移动应用程序构建广播并且来自移动应用程序的用户想要订阅该怎么办频道?然后,此 user
将不再存在.
The sentence All authorization callbacks receive the currently authenticated user as their first argument
is true for broadcasting on web, what if we build broadcasting for mobile application and a user from a mobile application wants to subscribe to a channel? Then this user
wont exist any more.
我们如何授权来自移动应用程序的用户?
How can we authorize users coming from mobile application?
推荐答案
找到了它.服务器和客户端中使用的协议必须相同.尽管Laravel Echo使用Socket.io,但在android应用程序上安装Socket.io不会起作用.我必须在android上安装 LaravelEchoAndroid 程序包,并使用Bearer令牌作为身份验证.
Found it. The protocol used in server and client must be the same. Despite of the fact Laravel Echo uses Socket.io, but installing Socket.io on android application wont work. I have to install LaravelEchoAndroid package on android and use Bearer token as authentication.
提示:该软件包有一个编译错误,通过更改maven可以使用.
Hint: This package has a compile error and by changing maven it will work.
这篇关于Laravel回声:频道授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!