Open dondragon2 opened 8 years ago
room is the server side feature. Look at the following method, which i add two event listener to the server. once the client side emit signal, and these event catches them, the server will automatically establish a room and let that client in.
/**
* join: participate into a room that could have private chat
* leave: exit from the room
*/
private void addRoomEvents() {
server.addEventListener("join", String.class, new DataListener<String>() {
@Override
public void onData(SocketIOClient socketIOClient, String roomName, AckRequest ackRequest) throws Exception {
log.info("<join room name> " + roomName);
socketIOClient.joinRoom(roomName);
}
});
server.addEventListener("join", String.class, new DataListener<String>() {
@Override
public void onData(SocketIOClient socketIOClient, String roomName, AckRequest ackRequest) throws Exception {
log.info("<leave room name>" + roomName);
socketIOClient.leaveRoom(roomName);
}
});
}
Socket fromUser = ...
Socket toUser=...
.... some other setting of socket client ...
String roomId = "Hello";
fromUser.emit("join", roomId);
toUser.emit("join", roomId);
I want to know If the socket join a room and then it broadcast a message,the message broadcast to the sockets connected to the server or joined the room?
I notice these methods on the SocketIOClient but I cannot find any documentation on how to use them and what there are to be used for. Can someone help me out with this? Is it for a chat room? What exactly are they for?