简体   繁体   English

Laravel Echo 和 Whisper,listenForWhisper 不起作用

[英]Laravel Echo and Whisper, listenForWhisper not work

I'm running Echo server and Beyondcode (Pusher).我正在运行 Echo 服务器和 Beyondcode (Pusher)。 Presence channels work perfectly, and messaging I have built for it works.状态通道完美运行,我为它构建的消息传递也有效。 Now I'm trying to get the whisper to work for the typing status as well but no luck.现在我试图让耳语也适用于打字状态,但没有运气。

Sending whisper:发送耳语:

let channel = Echo.join('chat')

setTimeout( () => {
    channel.whisper('typing', {
    user: Laravel.user.id,
    typing: true
    })
}, 300)

Listen whisper:听耳语:

Echo.join('chat')
.listenForWhisper('typing', (e) => {
    console.log(e)
});

In my echo server log, when i'm typing message:在我的回显服务器日志中,当我输入消息时:

testapp: connection id 332742863.966987392 received message: 
{
    "event":"client-typing",
    "data":{
        "user":2,
        "typing":true
    },
    "channel":"presence-chat"
}

Broadcast channel (routes/channels.php)广播频道(routes/channels.php)

Broadcast::channel('chat', function ($user) {
    return [
        'id' => $user->id,
        'name' => $user->name
    ];
});

Connection id 332742863.966987392 is second user (not the one from which I typed the message).连接 ID 332742863.966987392 是第二个用户(不是我输入消息的那个用户)。

But nothing appears in browser console.但是浏览器控制台中什么也没有出现。

我知道这很旧,但我的问题是我没有从推送应用程序设置中启用一个名为“启用客户端事件”的选项。

Just leaving this here for future user who might be facing issue with receiving events in只是把这个留在这里给未来的用户,他们可能会遇到接收事件的问题

.listenForWhisper(..)

If you are using laravel-websockets , make sure you enable 'enable_client_messages'如果您使用laravel-websockets ,请确保启用“enable_client_messages”

The problem was solved after adding the listenForWhisper to created() method (creating the Vue application) 在将listenForWhisper添加到created()方法(创建Vue应用程序)后,该问题得以解决。

const app = new Vue({
    el: '#app',
    created() {
        Echo.join('chat').listenForWhisper('typing', ({id, name}) => {
            //....
        }
    }
}

I'm running Echo server and Beyondcode (Pusher).我正在运行Echo服务器和Beyondcode(Pusher)。 Presence channels work perfectly, and messaging I have built for it works.存在通道可以完美运行,而我为此创建的消息传递也可以正常工作。 Now I'm trying to get the whisper to work for the typing status as well but no luck.现在,我正在尝试使耳语也可以用于打字状态,但是没有运气。

Sending whisper:发送悄悄话:

let channel = Echo.join('chat')

setTimeout( () => {
    channel.whisper('typing', {
    user: Laravel.user.id,
    typing: true
    })
}, 300)

Listen whisper:听耳语:

Echo.join('chat')
.listenForWhisper('typing', (e) => {
    console.log(e)
});

In my echo server log, when i'm typing message:在我的回显服务器日志中,当我键入消息时:

testapp: connection id 332742863.966987392 received message: 
{
    "event":"client-typing",
    "data":{
        "user":2,
        "typing":true
    },
    "channel":"presence-chat"
}

Broadcast channel (routes/channels.php)广播频道(routes / channels.php)

Broadcast::channel('chat', function ($user) {
    return [
        'id' => $user->id,
        'name' => $user->name
    ];
});

Connection id 332742863.966987392 is second user (not the one from which I typed the message).连接ID 332742863.966987392是第二个用户(不是我键入消息的那个用户)。

But nothing appears in browser console.但是浏览器控制台中没有任何内容。

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

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