.on(
'connection',
socketjwt.authorize({
secret: config.get('jwtsecret'),
timeout: 15000 // 15 seconds to send the authentication message
})
)
.on('authenticated', (socket) => {
console.log(socket.decoded_token);
})
};
index.js
————-
// imports
const express = require('express');
const config = require('config');
const app = express();
const server = require('http').createServer(app);
const io = require('socket.io')(server);
// routes
require('./startup/routes')(app);
// socket.io
require('./startup/socket')(io);
// port
const port = process.env.PORT || config.get('port');
// start server
module.exports = server.listen(port, () =>
console.log(`Listening on port ${port}...`)
);
routes/index.js
router.get('/someroute', async(req, res) => {
// do something
// how do I emit an event from here?
// io.emit('somedata', 'somedata')
}
@TRGWII @GingerPlusPlus @MKRhere @Sparkenstein
what's the issue
What's the issue with doing as in the comment, io.emit('somedata', 'somedata')?
Обсуждают сегодня