Class RoomProtocolCodec

java.lang.Object
org.atmosphere.room.protocol.RoomProtocolCodec

public final class RoomProtocolCodec extends Object
JSON encoder/decoder for the room protocol, backed by Jackson 3 (tools.jackson.databind). Jackson is the project's single JSON dependency; a legacy third-party JSON backend was retired to avoid the periodic CVE churn that library carried.

Wire format (client → server)


 { "type": "join",      "room": "lobby", "memberId": "alice", "metadata": { "avatar": "..." } }
 { "type": "leave",     "room": "lobby" }
 { "type": "broadcast", "room": "lobby", "data": "hello" }
 { "type": "direct",    "room": "lobby", "targetId": "bob", "data": "hi bob" }
 

Wire format (server → client)


 { "type": "join_ack",  "room": "lobby", "members": [...] }
 { "type": "presence",  "room": "lobby", "action": "join|leave", "memberId": "alice", "metadata": {...} }
 { "type": "message",   "room": "lobby", "from": "alice", "data": "hello" }
 { "type": "error",     "room": "lobby", "data": "Unauthorized" }
 
Since:
4.0
  • Method Details

    • decode

      public static RoomProtocolMessage decode(String json)
      Decode a JSON string into a protocol message.
      Parameters:
      json - the raw JSON string
      Returns:
      the decoded message
      Throws:
      IllegalArgumentException - if the JSON is malformed or has an unknown type
    • encodeJoinAck

      public static String encodeJoinAck(String room, Collection<RoomMember> members)
      Encode a join acknowledgement with the current member list.
    • encodePresence

      public static String encodePresence(String room, String action, RoomMember member)
      Encode a presence event (join or leave) for broadcast to other members.
    • encodeMessage

      public static String encodeMessage(String room, String fromMemberId, Object data)
      Encode a room message for delivery to clients. Backward-compatible variant that does not include a server-assigned monotonic id.
    • encodeMessage

      public static String encodeMessage(String room, long id, String fromMemberId, Object data)
      Encode a room message with a server-assigned monotonic id. Clients use the id to drive history-sync on reconnect: the next join frame carries sinceId = lastSeenId so the server skips messages the client already has. id <= 0 omits the field entirely so consumers of the legacy 3-arg overload aren't surprised by a new field appearing in their on-the-wire payloads.
    • encodeError

      public static String encodeError(String room, String message)
      Encode an error response.
    • encodeTyping

      public static String encodeTyping(String room, String memberId, boolean typing)
      Encode a typing indicator for broadcast to other room members.