Asked Dec 27th, 2021 11:25 a.m. 80 0 1
  • 80 0 1
0

Laravel echo không chạy ở client

Share
  • 80 0 1

Mọi người cho e hỏi, nó báo như này là lỗi hay sao ạ ? nếu là lỗi gì xem log như nào vậy a ?

Nó vẫn tạo :

Config e như này

const lEcho = new Echo({
      broadcaster: 'socket.io',
      host: 'http://localhost/socket.io',
      client: SocketIO,
      transports: ['websocket', 'polling']
    })
    lEcho.listen('laravel_database_channel', '.server.created', e => {
      console.log('asdasdasdasd')
    })
    lEcho.listen('laravel_database_channel', 'server.created', e => {
      console.log('asdasdasdasd')
    })

config.json

{
    "authHost": "http://nginx",
    "authEndpoint": "/api/broadcasting/auth",
    "clients": [],
    "database": "redis",
    "databaseConfig": {
        "redis": {
            "port": 6379,
            "host": "127.0.0.1",
            "password": "",
            "tls": false,
            "keyPrefix": ""
        }
    },
    "devMode": true,
    "host": null,
    "port": "6001",
    "protocol": "http",
    "socketio": {},
    "secureOptions": 67108864,
    "sslCertPath": "",
    "sslKeyPath": "",
    "sslCertChainPath": "",
    "sslPassphrase": "",
    "subscribers": {
        "http": true,
        "redis": true
    },
    "apiOriginAllow": {
        "allowCors": true,
        "allowOrigin": "*",
        "allowMethods": "GET, POST",
        "allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id, X-ACCESS-TOKEN",
        "Allow-Credentials": true
    }
}

docker-compose

version: "3"

services:
    workspace:
        container_name: laravel_workspace
        build:
            context: .
            dockerfile: ./Dockerfile
        restart: always
        volumes:
            - ./:/var/www/html:cached
            - ./.docker/nginx/sites-enabled:/etc/nginx/sites-enabled
        tty: true
        ports:
            - "9002:9000"
            - "80:80"
        depends_on:
            - mysql
            - redis
            - laravel_echo_server
        networks:
            - app-network
    mysql:
        container_name: laravel_db
        image: mysql:5.7
        restart: always
        volumes:
            - ./.docker/mysql:/var/lib/mysql
        ports:
            - "3306:3306"
        environment:
            MYSQL_DATABASE: laravel
            MYSQL_ROOT_PASSWORD: [email protected]
        networks:
            - app-network
    #
    mailhog:
        container_name: mailhog
        build: ./.docker/mailhog
        restart: always
        command: ["-storage=maildir", "-maildir-path=/maildir"]
        volumes:
            - ./.docker/mailhog/maildir:/maildir
        ports:
            - "1025:1025"
            - "8025:8025"
        networks:
            - app-network
        ## Redis ################################################
    redis:
        container_name: laravel_redis
        image: redis:5-alpine
        volumes:
            - .docker/redis/data:/data
        restart: unless-stopped
        ports:
            - "6379:6379"
        networks:
            - app-network

    laravel_echo_server:
        build:
            context: .docker/laravel-echo-server
            dockerfile: Dockerfile
        volumes:
            - .env:/app/.env
        restart: unless-stopped
        networks:
            - app-network
networks:
    app-network:
        driver: bridge
    location /socket.io {
        proxy_pass http://laravel_echo_server:6001;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header Host $host;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header X-Real-Ip $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

Nhờ mn chỉ giáo với (bow)

1 ANSWERS


Answered Dec 28th, 2021 5:02 a.m.
0

Coi lại code đi bạn.

Sau khi connect socket xong thì hãy join channel rồi mới listen event

Echo.join(`chat.${roomId}`)
    .here(...)
    .joining(...)
    .leaving(...)
    .listen('NewMessage', (e) => {
        //
    });
Share
Dec 30th, 2021 11:07 a.m.

à mình làm được rồi, hình như client: SocketIO, nó ko nhận được

phải import link script tỉnh của thằng socker-io vô mới đc á

0
| Reply
Share
Viblo
Let's register a Viblo Account to get more interesting posts.