P
P
potap_2212020-11-20 22:10:06
Socket.io
potap_221, 2020-11-20 22:10:06

larvel+vue chat (laravel-echo-server [socket.io])?

Kind.
I want to write a chat, I use laravel-echo-server (socket.io)

In vue via axios, I send a message
to the controller, in the controller I call ChatEvent::dispatch( $request->input('message') )
in the event I write to a variable and call Chanel('chat')
in vue I'm listening to port 6001 and when the event fires, the code inside should work, but it doesn't work

EVENT

public $message;
    public function __construct($message)
    {
    	$this->message = $message;
    }
    public function broadcastOn()
    {
    return new Channel('chat');
    }
  public function broadcastAs()
  {
    return 'ChatEvent';
  }


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

if (typeof io !== 'undefined') {
    window.Echo = new Echo({
        broadcaster: 'socket.io',
        host: window.location.hostname + ':6001',
    });
} else{
    console.log('errors socket.io, => bootstrap.js line 33')
}


vue
mounted()
            window.Echo.channel('chat')
      .listen('ChatEvent', (e) => 
             {

                    console.log(123)		
  })
},


after sending a message to the Laravel-echo-server console,
Channel: chat
Event: ChatEvent
-------------------------
seems to be OK from the server side, probably Echo not subscribed to event ?

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