Package org.atmosphere.room.protocol
Class RoomProtocolCodec
java.lang.Object
org.atmosphere.room.protocol.RoomProtocolCodec
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 Summary
Modifier and TypeMethodDescriptionstatic RoomProtocolMessageDecode a JSON string into a protocol message.static StringencodeError(String room, String message) Encode an error response.static StringencodeJoinAck(String room, Collection<RoomMember> members) Encode a join acknowledgement with the current member list.static StringencodeMessage(String room, long id, String fromMemberId, Object data) Encode a room message with a server-assigned monotonic id.static StringencodeMessage(String room, String fromMemberId, Object data) Encode a room message for delivery to clients.static StringencodePresence(String room, String action, RoomMember member) Encode a presence event (join or leave) for broadcast to other members.static StringencodeTyping(String room, String memberId, boolean typing) Encode a typing indicator for broadcast to other room members.
-
Method Details
-
decode
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
Encode a join acknowledgement with the current member list. -
encodePresence
Encode a presence event (join or leave) for broadcast to other members. -
encodeMessage
Encode a room message for delivery to clients. Backward-compatible variant that does not include a server-assigned monotonic id. -
encodeMessage
Encode a room message with a server-assigned monotonic id. Clients use the id to drive history-sync on reconnect: the nextjoinframe carriessinceId = lastSeenIdso the server skips messages the client already has.id <= 0omits 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
Encode an error response. -
encodeTyping
Encode a typing indicator for broadcast to other room members.
-