I've made Electron app which uses Socket.IO to communicate between back-end (NodeJS) and front-end (Jquery).
I've already sent data from
io.on('connection', (socket) => { socket.emit (.....) })
My problem is that I am not able to send data from API call.
Let me tell you the example.
const express = require('express')
const app = express()
const http = require('http')
const server = http.createServer(app)
const { Server } = require("socket.io");
const io = new Server(server);
app.set('socketIo', io);
app.get('/api/run', (req, res) => {
const ioEmitter = req.app.get("socketIo");
ioEmitter.emit('data', 'some data'); // not working
// ioEmitter.to(~some socket id~).emit('data', 'some-data')
// not working either. I can't get anything to client side
})
Client side code
socket.on('data', (msg) => {
console.log(msg)
})
It's mandatory for me (the project) to get that data from API call.