New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sending data from easyrtc server to a specific connected client #340
Comments
Good question, I will need that as well if I want to continue my example #328 |
The server is using a socket connection, so you use socket.emit, not easyrtc. I have done this on an older version on an app of mine. some quick old example cold that might help: socketServer.on("connection", socket => {
console.log("user connected", socket.id);
let curRoom = null;
socket.on("joinRoom", data => {
console.log('socket join', data)
const { room } = data;
if (!rooms[room]) {
rooms[room] = {
from: 'socketio',
name: room,
occupants: {},
};
}
const joinedTime = Date.now();
rooms[room].occupants[socket.id] = joinedTime;
curRoom = room;
console.log(`${socket.id} joined room ${room}`);
socket.join(room);
socket.emit("connectSuccess", { joinedTime });
const occupants = rooms[room].occupants;
socketServer.in(curRoom).emit("occupantsChanged", { occupants });
});
socket.on("send", data => {
console.log('socket send', data)
socketServer.to(data.to).emit("send", data);
}); |
This code looks similar to |
Listen to data type VR: // arguments: callback, type
easyrtc.setPeerListener((socketId, type, data) => {
console.log(socketId, type, data);
}, 'vr'); Send data type VR to given user // arguments: socketId, type, data
easyrtc.sendData('PSpPpqz5aVJq3Pzz', 'vr', {test: new Date()}) Will send data via P2P if connected to peer, otherwise via server. |
In the demos and tutorial, we can have the client communicate with each other by using
NAF.connection.sendData(clientId, dataType, data)
, which is an extension toeasyrtc.sendData()
from client side.Is there a way for the server (for example, using the demo server file
easyrtc-server.js
) to do that usingeasyrtc.sendData()
? There seems to be no documentations that specifically address how to do this.So far I'm doing this but nothing happened:
easyrtc-server.js
index.html (client-side)
The text was updated successfully, but these errors were encountered: