@denis_21321321

Laravel-echo-server не подписывает слушателей?

В laravel-echo-server не показывает, подключившихся слушателей.
Хотя Ajax-запрос на сервер показывает, что пришел.
5f79a48199973950030840.png

Хотя он должен подключиться.

Js файл
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"
	}
}


PublicChat ( Event)

<?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');
    }
}
  • Вопрос задан
  • 437 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы