7

i have an event SomeEvent.php

like so:

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class SomeEvent  implements ShouldBroadcast
{


    use InteractsWithSockets, SerializesModels;

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

    /**
     * Get the channels the event should broadcast on.
     *
     * @return Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('channel-name');
    }
}

i have included the following in my bootstrap.js and compiled it with gulp

import Echo from "laravel-echo"

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: 'http://site.dev:6001'

});

window.Echo.private('channel-name')
    .listen('SomeEvent', (e) => {
        console.log(e);
});

then i have installed tlaverdure/laravel-echo-server and here is my laravel-echo-server.json

{
    "appKey": "[generated]",
    "authHost": "http://site.dev",
    "authEndpoint": "/broadcasting/auth",
    "database": "redis",
    "databaseConfig": {
        "redis": {},
        "sqlite": {
            "databasePath": "/database/laravel-echo-server.sqlite"
        }
    },
    "devMode": false,
    "host": "sitei.dev",
    "port": "6001",
    "referrers": [],
    "socketio": {},
    "sslCertPath": "",
    "sslKeyPath": ""
}

now when i fire up laravel echo server with laravel-echo-server start it starts up very well however when i fire up the above event like so

event(new SomeEvent(json_encode(['name' => 'some-name'])));

i can see the event published to redis however nothing is loged to my client console: i am also including socket io in my master.blade.php

the above also happens with notifications

any help will be highly appreciated. Thanks guys

2
  • Are you able to solve this ? I had similar issue still open stackoverflow.com/questions/41120789/… any idea? Commented Dec 13, 2016 at 12:25
  • There is a typo in your host setting, no? "sitei.dev" vs "site.dev". Could that be it? If not, are you sure a redis worker process is running? Commented Dec 16, 2016 at 3:10

1 Answer 1

1

Have you defined an authentication rule for your channel in BroadcastServiceProvider?

Do you see any information about connecting and leaving the channel if you put on devMode in the laravel-echo-server.json?

I had a lot of troubles trying to set up my websocket connection, but a finally figured it out and my code looks pretty much like yours.

Good luck!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.