gpt4 book ai didi

Laravel Echo 和耳语

转载 作者:行者123 更新时间:2023-12-05 00:48:22 26 4
gpt4 key购买 nike

我正在运行 echo 服务器和 redis。私有(private) channel 完美运行,我为其构建的消息传递也很有效。现在我正试图让耳语也适用于打字状态,但没有运气。耳语需要插入者才能工作吗?

我在 keyup (jquery) 上的尝试

Echo.private(chat- + userid)
.whisper('typing',{e: 'i am is typing...'});
console.log('key up'); // this one works so the keyup is triggered

那么我当然是在收听我正在耳语的 channel :

Echo.private(chat- + userid).listenForWhisper('typing', (e) => {
console.log(e + ' this is typing');
});

但我在任何地方都一无所获。 (在回显服务器上调试,控制台上没有任何东西等)任何帮助如何使它工作将不胜感激。

最佳答案

您的输入事件:

$('input').on('keydown', function(){
let channel = Echo.private('chat')

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

您的收听事件:

Echo.private('chat')
.listenForWhisper('typing', (e) => {
e.typing ? $('.typing').show() : $('.typing').hide()
})

setTimeout( () => {
$('.typing').hide()
}, 1000)

当然,您必须提前为此 channel 设置身份验证,以确保受信任方可以访问:

Broadcast::channel('chat', function ($user) {
return Auth::check();
});

其中 $user 将是我们在前端对象中传递给 user 参数的 userid

关于Laravel Echo 和耳语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51524551/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com