微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么laravel-echo-server不订阅侦听器OpenServer?

如何解决为什么laravel-echo-server不订阅侦听器OpenServer?

Windows 10。 (OpenServer,Redis,laravel)。 PC上的6001端口已打开。

侦听器未在laravel-echo-server中显示。 但是显示出Ajax-request是在laravel-echo-server中发送的。

enter image description here

JavaScript文件

import Echo from 'laravel-echo';
window.io = require('socket.io-client');

window.Echo = new Echo({
    broadcaster: 'socket.io',host: window.location.hostname + ':6001'
  });

window.Echo.channel('test')
      .listen('PublicChat',(e) => {
console.log(e);
})

.env

broADCAST_DRIVER=redis
REdis_PREFIX=

REdis_HOST=127.0.0.1
REdis_PASSWORD=null
REdis_PORT=6379

laravel-echo-server.json

{
  "authHost": "localhost","authEndpoint": "/broadcasting/auth","clients": [
    {
      "appId": "14f75b628608563b","key": "65214843e1ba27e2269b40416af6a9ce"
    }
  ],"database": "redis","databaseConfig": {
    "redis": {
      "port": 6379,"host":"127.0.0.1","keyPrefix":null
    },"sqlite": {
      "databasePath": "/database/laravel-echo-server.sqlite"
    }
  },"devMode": true,"host": null,"port": "6001","protocol": "http","socketio": {},"secureOptions": 67108864,"sslCertPath": "","sslKeyPath": "","sslCertChainPath": "","sslPassphrase": "","subscribers": {
    "http": true,"redis": true
  },"apiOriginAllow": {
    "allowCors": true,"allowOrigin": "http://localhost:80","allowMethods": "GET,POST","allowHeaders": "application,json"
  }
}

公共聊天(事件)

<?PHP

namespace App\Events;

use Illuminate\broadcasting\Channel;
use Illuminate\broadcasting\InteractsWithSockets;
use Illuminate\broadcasting\PresenceChannel;
use Illuminate\broadcasting\PrivateChannel;
use Illuminate\Contracts\broadcasting\Shouldbroadcast;
use Illuminate\Foundation\Events\dispatchable;
use Illuminate\Queue\SerializesModels;

class PublicChat implements Shouldbroadcast
{
    use dispatchable,InteractsWithSockets,SerializesModels;

    public $message;
    public $id_user;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($message,$id_user)
    {
        $this->message = $message;
        $this->id_user = $id_user;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('test');
    }
}

为什么它没有收听特定频道?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。