php - Socket.io Node Laravel Redis and saving chat messages to database -


i have laravel project uses node laravel , redis make real time chat. have followed many tuturials lost on how save data chat messages database(mysql). i've seen tuturial can use redis broadcast events laracasts, , youtube video uses mongodb https://www.youtube.com/watch?v=c01ohdupdmu.i havent been able find clear answer on saving methods socket. need send ajax request outside of socket??

here tried make test httprequest, maybe there someway send data on post request laravel route?

can provide advice?

var app = require('express')(); var server = require('http').server(app); var io = require('socket.io')(server);  server.listen(3000, function(){     console.log('listening on *:3000'); });  console.log('chat has booted...');  io.on('connection', function(socket){     socket.on('join', function (data) {         socket.userid = data.user_id;         socket.username = data.user_name;         socket.class_group = data.class_group;         console.log('user ' + socket.username + ' available');     });      //notify connected users availability      socket.on('notify', function (notice) {         console.log( notice + ' from' + ' user ' + socket.username );         io.emit('receive note.' + notice[0], 'hello');     })      socket.on('subscribe', function (room) {         console.log('joining room', room);         socket.join(room);     })      socket.on('send', function(data){         console.log(socket.username + ': ' + data.message + ' room' + '[' + data.room + ']');             io.to(data.room).emit('message', data);         var xhr = new xmlhttprequest();         xhr.open('get', "http://google.com", true); //here tried make test httprequest, maybe there someway send data on post request laravel route?     });     socket.on('disconnect', function(){         console.log('user disconnected');     }); }); 

as understand, script posted node.js script executed on server side.

in order save mongodb can use mongodb driver: https://github.com/mongodb/node-mongodb-native


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -