Doubt with socket.emit

0

I have the following code in a small notification application that I'm doing.

var express = require('express')
, app = express()
, server = require('http').createServer(app).listen(4555)
, io = require('socket.io').listen(server)
, bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
var port = process.env.PORT || 8080;
var router = express.Router();
/* Socket irá aqui depois */
var emitir = function(req, res, next){
var notificar = req.query.titulo || '';


    if(notificar != '')  {
    io.emit('titulo', notificar);


    next();
} else {
        next();
    }
}
app.use(emitir);
app.use('/api', router);
app.use(express.static('public'));
router.route('/notificar')
.get(function(req, res){
//aqui vamos receber a mensagem
res.json({message: "testando essa rota"})
})
app.listen(port);
console.log('conectado a porta ' + port);

In this part below is where I add the field I want as a url parameter

var notificar = req.query.titulo || '';


if(notificar != '')  {
io.emit('titulo', notificar);


next();

So when I access the url link notification the notification is sent and on the client's page I normally receive.

My question is how to add more than one parameter eg link notification & content = blablabla & image = xxxxxx

I tried to follow the base but I did not succeed.

The code in the client part that I get the parameter is this:

socket.on('titulo', function (title) {

So I play the function title where I want and I get the title value.

How would I go about getting all the parameters I mentioned above?

    
asked by anonymous 30.05.2018 / 19:55

0 answers