I still have a question. Everything works fine at the moment. Send data from the client to the server isn't a problem now.
But how can I emit a event to all connected clients serverside?
Something e.g
myPlugin.emit('plugins.publishMessage', {data: "Some data"}, function(err, result) {
console.log(result);
});
After one hour spending searching different topics and some code I found the solution.
Besides the custom clientside Sockets
const myPluginSockets = require.main.require('./src/socket.io/plugins');
you have to define the Server Sockets too
const myPluginSockets = require.main.require('./src/socket.io/plugins');
const serverSockets = require.main.require('./src/socket.io');
Now you can emit events from server side to the clients:
serverSockets.server.sockets.emit('messageReceive', data);
to receive the event clientside, you can use following in ur main.js file:
socket.on('messageReceive', function(data){
console.log(data);
});
Client console output:
{msg: "my message"}
Maybe I'll write a little Tutorial on this because I am probably not the only one who does not understand it so easily.