1

I'd like to broadcast a message to everyone that listen to this room, not only who join the room.

I do receive another call from server but I didn't get any call for this 'room' listener.

Server: Node.js

io.on('connection', function(socket){

    console.log('connected');

    socket.on('register', function(match) {
        console.log(match);
        var resultJSON = JSON.parse(match);
        socket.join(resultJSON['roomId'], function() {
            socket.broadcast.emit(resultJSON['roomId'], match);
        });
    });

});

Client: Java

mSocket.on(roomSelected.getId()), onSelectedRoom);
private Emitter.Listener onSelectedRoom = new Emitter.Listener() {
        @Override
        public void call(final Object... args) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {

                    try {
                        JsonObject obj = new JsonParser().parse(args[0].toString()).getAsJsonObject();
                        System.err.println(obj);
                        Match match = new Gson().fromJson(obj, Match.class);
                        updateRoomWith(match);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }

            });
        }
    };
Marckaraujo
  • 7,422
  • 11
  • 59
  • 97

1 Answers1

1

As best I know, socket.io does not have a concept of listen to a room, but don't join the room. If you want to receive messages sent to those in a room, you join the room. That's the only purpose of joining so there is no subset of joining that is just listening.

If you are trying to accomplish something that works differently than joining a room, then please describe exactly what you're trying to accomplish so we can help you solve that particular problem.

jfriend00
  • 683,504
  • 96
  • 985
  • 979