Laravel Echo没有在听 [英] Laravel Echo is not listening

查看:253
本文介绍了Laravel Echo没有在听的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了一个活动和新频道:

I set up an event and new channel :

class TaskCreated implements shouldBroadcast
 {
use Dispatchable, InteractsWithSockets, SerializesModels;
public $task;

public function __construct(Task $task)
{
    $this->task = $task;
}

}

并安装Echo并进行设置

and installed Echo and set it up

 import Echo from "laravel-echo"
window.Pusher = require('pusher-js');
window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'pusher-key',
    cluster: 'ap2',
    encrypted: true
});

然后我在发布任务时调用TaskCreated事件

then I call the TaskCreated event when a task is posted

event(new TaskCreated($task));

但是,问题是Echo不收听推送日志或其他任何内容.即使在laravel-websockets中,该事件也是作为api消息创建的.

However, the issue is Echo doesn't listen to pusher logs or ANYTHING. even though in laravel-websockets the event was created as an api-message.

这是vue js Echo实现:

here is vue js Echo implementation :

 mounted () {
        axios.get('/tasks').then(response => (this.tasks = response.data));

       Echo.channel('taskCreated').listen('TaskCreated', (e) => {
            console.log(e);
            this.tasks.push(task.body)
        });

在仪表板中:

api-message Channel: taskCreated, Event: App\Events\TaskCreated 19:01:55

更新

现在,当我尝试与WS连接时,连接状态将挂起10秒钟,然后在建立连接之前关闭WebSocket的错误结束. AND连接建立错误:net :: ERR_CERT_AUTHORITY_INVALID.

Now when I tried to connect with WS the connection status is pending for 10 seconds then finished with an error WebSocket is closed before the connection is established. AND Error in connection establishment: net::ERR_CERT_AUTHORITY_INVALID.

请求网址:wss://127.0.0.1/app/local?protocol = 7& client = js& version = 6.0.2& flash = false

Request URL: wss://127.0.0.1/app/local?protocol=7&client=js&version=6.0.2&flash=false

import Echo from "laravel-echo"
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
 key: process.env.MIX_PUSHER_APP_KEY,
 wsHost: window.location.hostname,
 wssPort: 6001,
 disableStats: true,
 enabledTransports: ['ws', 'wss']

推荐答案

如果您的代码中包含broadcastOn方法,我在TaskCreated事件中看不到该方法,也可以使用broadcastAs方法,如下所示:

i dont see broadcastOn method in TaskCreated event if you have it in your code just use broadcastAs method too like this:

public function broadcastAs()
{
    return 'task.created';
}

在vue组件中侦听这样的事件:

and in vue component listen for event like this:

Echo.channel('taskCreated').listen('.task.created', (e) => {
            this.tasks.push(task.body)
        });

更多信息: https://laravel.com/docs/broadcasting 但是关于laravel-websockets我最近使用它,并且有类似的问题,并检查他们的github回购,原来他们对于此错误有一些未解决的未解决的问题.我喜欢Spatie软件包,但对于这台tlaverdure/laravel-echo-server来说,这是我的第一选择,更易于使用.

more info: https://laravel.com/docs/broadcasting but about laravel-websockets i use it recently and have similar problem and check their github repo turned out they have some open issues for this error that they didnt fix. i love spatie packages but for this one tlaverdure/laravel-echo-server is my first choise and easier to work with.

这篇关于Laravel Echo没有在听的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆