laracasts / Laravel-Redis-and-Socket.io

https://laracasts.com/series/real-time-laravel-with-socket-io/episodes/3
56 stars 32 forks source link

Can you explain how to adapt this project for the server which was provisioned with the Forge and uses Let's encrypt? #1

Closed zvermafia closed 7 years ago

zvermafia commented 7 years ago

I saw the lessons Real-time Laravel with Socket.io and made a little different project and it works fine on homestead (local machine). But on production server wich was provisioned with the Forge and works via HTTPS protocol it doesn't work!

To the moment I tried:

sudo ufw enable
sudo ufw allow 3000

sudo chown forge /etc/nginx/ssl/example.com/748234/server.key
sudo chown forge /etc/nginx/ssl/example.com/748234/server.crt

socket.js is:

var fs = require('fs');

var options = {
    key:    fs.readFileSync('/etc/nginx/ssl/example.com/748234/server.key'), // 748234 is a random number
    cert:   fs.readFileSync('/etc/nginx/ssl/example.com/748234/server.crt')
}

var server = require('https').createServer(options);
var io     = require('socket.io')(server);
var Redis  = require('ioredis');
var redis  = new Redis();

redis.subscribe('login-via-telegram');

redis.on('message', function (channel, response) {
    response = JSON.parse(response);
    console.log(response); // Outputs nothing

    io.emit(channel + ':' + response.data.login_token, response.data.login_token);
});

server.listen(3000);

The client side script is:

var socket = io('//{{ Request::getHost() }}:3000', {secure: true});

socket.on("login-via-telegram:{{ session('login_token') }}", function (token) {
    if (token === "{{ session('login_token') }}") {
        location.reload();
    }
});
zvermafia commented 7 years ago

There were not problems with node.js, socket.io or HTTPS. There is problem with the Laravel or Redis... I required the predis/predis package to work with Redis and set redis as broadcast driver (and cache driver is file). But broadcasting works like the broadcast driver parameter was set log...

P.S. I also tried artisan config:clear, but unseccessful...

zvermafia commented 7 years ago

Solved the problem with clearing all data in redis redis-cli flushall. Because I was use redis for caching before using for broadcasting.