I just started with socket.io, and I want some function which will broadcast somethink from one client throuh server to all clients.
For example I will have game, when I will need handle a lot of things.
There is two option: 1. Every call handle on server and client side, for every call create socket.on('call');
But I think there is better solution 2. On client call emit when I get payload and name of socket which will be called from server to other clients.
Like this: SERVER
// Broadcast specific emit to all clisnts expect sender
socket.on('broadcast', function(data){
socket.broadcast.emit(data.emitName, {id: socket.id, payload: data.payload});
});
and client:
// Call to server
socket.emit('broadcast', {emitName: 'playerMove', payload: {....}});
// Handle called from server
socket.on('playerMove', function(data){
....
});
Second solution can save a lot of time, but is it safe solution ? And is there any better solution how call from client broadcast throuht server and call to other clients ?