我无法处理私人和在线渠道上的授权(或其他事情)。常规渠道运行良好。
我正在使用带有 Auth-next (v5) 的最新 Larvel 和 NuxtJS。 我在 SPA 模式下使用 Laravel Sanctum。
// nuxt.config.js
echo: {
broadcaster: 'pusher',
key: 'mykey',
authEndpoint: 'https://example.com/broadcasting/auth',
wsHost: 'example.com',
wssPort: 6001,
disableStats: true,
encrypted: true,
},
页面:
mounted() {
this.$echo.join("user.test").listen("UserTest", (e) => {
console.log("UserTest:");
console.log(e);
});
},
routes/channels.php
Broadcast::channel('user.test', function ($user) {
\Illuminate\Support\Facades\Log::debug('user test.'); -- log not working. As if it was not triggered at all
return true; -- not working
// return ['name' => $user->name]; -- not working
});
BroadcastServiceProvider.php
public function boot()
{
\Illuminate\Support\Facades\Log::debug('broadcast routes.'); -- works correctly
Broadcast::routes(['middleware' => ['auth:sanctum']]);
// Broadcast::routes();
require base_path('routes/channels.php');
}
事件/UserTest.php
class UserTest implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $user;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
// return new PrivateChannel('channel-name');
\Illuminate\Support\Facades\Log::debug('PERSENCE.'); -- works correctly
return new PresenceChannel('user.test');
}
}
也许有人遇到了类似的问题 - 我正在寻求帮助或一些提示。