0

I'm a newbie in Laravel. I have a problem when I tried to built a realtime message with Laravel & ReactJS, Socket.io , Redis Errors when I start laravel-echo server

enter image description here

file laravel-echo-server.json

{
"authHost": "http://localhost:8000",
"authEndpoint": "/broadcasting/auth",
"clients": [
    {
        "appId": "XXXXXXXXXX",
        "key": "XXXXXXXXXXXXXXXXXXXXX"
    }
],
"database": "redis",
"databaseConfig": {
    "redis": {},
    "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": false,
    "allowOrigin": "",
    "allowMethods": "",
    "allowHeaders": ""
}

}

file channels.php

Broadcast::channel('App.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});

Broadcast::channel('online', function ($user) {
return $user;
});

In client-side use ReactJS, file index.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.join(`online`)
  .here((users) => {
    console.log(users)
  })
  .joining((user) => {
    console.log(user.name);
  })
  .leaving((user) => {
    console.log(user.name);
  });

Need some help ... Thanks so much !

Humayun Ahmad Rajib
  • 1,502
  • 1
  • 10
  • 22
Thảo Phương
  • 1
  • 1
  • 1
  • 1
  • 1
    Xin Chao em. When using Stack overflow, we need to get as much information as possible about the problem. Please tell us what you are trying to do and what is not working –  Oct 22 '20 at 13:19
  • Sorry because this is the first time I asked on Stack overflow, I'm trying to build a chat app by using laravel (back-end) and ReactJS (front-end), after learning on google I decided to choose socket.io and redis to do this. This is just the beginning when I want console.log out of users who are online on the system. But when running laravel-echo server, an error occurs "Client can not be authenticated, got HTTP status 404" . If you have any questions, please ask more – Thảo Phương Oct 22 '20 at 14:18
  • in `config/app.php` there is a providers array, look for `// App\Providers\BroadcastServiceProvider::class` and make sure it is uncommented –  Oct 22 '20 at 14:21
  • yah I did that, it still doesn't work :( – Thảo Phương Oct 22 '20 at 14:28
  • Is redis running? –  Oct 22 '20 at 14:32
  • Yahh I've already started the redis server – Thảo Phương Oct 22 '20 at 14:50
  • My http://localhost:8000/broadcasting/auth is 404 not found, I think the problem is here and I don't know how to fix it – Thảo Phương Oct 22 '20 at 15:03
  • https://stackoverflow.com/questions/41704428/http-localhost8000-broadcasting-auth-404-not-found –  Oct 22 '20 at 15:30
  • See here for same issue –  Oct 22 '20 at 15:30
  • Thank you, let me see : – Thảo Phương Oct 22 '20 at 15:51

0 Answers0