D
D
denis_213213212020-10-04 13:39:39
Laravel
denis_21321321, 2020-10-04 13:39:39

Laravel-echo-server not subscribing listeners?

In laravel-echo-server it doesn't show connected listeners.
Although the Ajax request to the server shows that it came.
5f79a48199973950030840.png

Although it should connect.

js file

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');
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question