Technology: Socket.io, Redis, Express and Nodejs, Laravel Web Framework, MySQL.
We will install nodejs if we did not install before. So, make sure you can check if nodejs is not install then you can fire following command and install nodejs easily.
sudo apt-get update
sudo apt-get install nodejs
we have to also need to install npm because we will install more socket.io, redis and express package using npm command, so if you not installed this command before then install by following command.
sudo apt-get install npm
we also require to install redis server because we will manage redis token, so if you not installed this command before then install by following command.
sudo apt-get install redis-server
we also require to install redis express redis socket.io, so if you not installed this command before then install by following command.
npm install express redis socket.io --save
ok, now we are ready to install laravel 5 application, so if you want to start from scratch then fire following command for laravel new application.
composer create-project --prefer-dist laravel/laravel blog
Now, open laravel application root directory and create folder nodejs and also create new file server.js inside nodejs folder, so put bellow code in server.js file.
nodejs/server.js
var app = require('express')(); var server = require('http').Server(app); var io = require('socket.io')(server); var redis = require('redis');
server.listen(3000); io.on('connection', function(socket) { console.log("connected"); var redisClient = redis.createClient(); redisClient.subscribe('message'); redisClient.on("message", function(channel, data) { console.log("new message add in queue " + channel + " channel"); socket.emit(channel, data); });
socket.on('disconnect', function() {
redisClient.quit();
});
});
In this step we have to install predis package off laravel. this package through we can assign message in redis. so first fire following command: sudo composer require predis/predis now we have to add aliase of predis package so open config/app.php and replace following line: 'Redis' => Illuminate\Support\Facades\Redis::class, Replace Into 'LRedis' => 'Illuminate\Support\Facades\Redis'
$ git clone https://github.com/glokesh94/Laravel-Real-Time-Chat-Application
$ cd Laravel-Real-Time-Chat-Application
Run the server using the following command: Laravel-Real-Time-Chat-Application$ sudo node server.js The server starts running on local server. Go to the browser and type the following url: http://localhost/Laravel-Real-Time-Chat-Application
The Laravel framework is open-sourced software licensed under the MIT license.