简体   繁体   English

Laravel echo listenForWhisper 不适用于 laravel-websockets

[英]Laravel echo listenForWhisper not working with laravel-websockets

I'm trying to create a room where we will broadcast changes made to a document.我正在尝试创建一个房间,我们将在其中广播对文档所做的更改。

Currently, I have the following code:目前,我有以下代码:

const channel = window.Echo.private('some-channel');


setInterval(() => {
  channel.whisper('something', { payload: 'foo' });
}, 1000);

window.Echo.private('some-channel').listenForWhisper('something', (e) => {
  console.log('someone whispered');
  console.log(e);
  console.log('-------');
})

With the full payload being:完整的有效载荷是:

{"event":"client-something","data":{"payload":"foo"},"channel":"private-some-channel"}

I login into my application from two different browsers (Chrome and Chrome in incognito mode) but I do not see any console.log in my browser's console.我从两个不同的浏览器(Chrome 和隐身模式下的 Chrome)登录到我的应用程序,但我在浏览器的控制台中看不到任何console.log

I can see the messages are being sent:我可以看到正在发送消息:

在此处输入图像描述

I have enabled enable_client_messages in my config/websockets.php file:我在我的config/websockets.php文件中启用了 enable_client_messages

'apps' => [
  [
    'id' => env('PUSHER_APP_ID'),
    'name' => env('APP_NAME'),
    'key' => env('PUSHER_APP_KEY'),
    'secret' => env('PUSHER_APP_SECRET'),
    'path' => env('PUSHER_APP_PATH'),
    'capacity' => null,
    'enable_client_messages' => true,
    'enable_statistics' => true,
  ],
],

What am I doing wrong?我究竟做错了什么? Why am I not being able to see the console.log in user A or user B browser consoles?为什么我无法在user Auser B浏览器控制台中看到console.log

I forgot to add the route authentication in routes/channels.php我忘记在routes/channels.php添加路由认证

Broadcast::channel('some-channel', function ($user) {
    return $user;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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