Receive the next message from WebSocket. Message is a dict
containing the following keys:
- opcode:OpCode
- OpCode of the message. This is an atom for known opcodes
and an integer for unknown ones. If the peer closed the
stream, OpCode is bound to
close
and data to the atom
end_of_file
.
- data:String
- The data, represented as a string. This field is always
present. String is the empty string if there is no data
in the message.
- rsv:RSV
- Present if the WebSocket RSV header is not 0. RSV is an
integer in the range [1..7].
If ping
message is received and WebSocket is a stream pair,
ws_receive/1 replies with a pong
and waits for the next
message.
The predicate ws_receive/3 processes the following options:
- format(+Format)
- Defines how text messages are parsed. Format is one of
- string
- Data is returned as a Prolog string (default)
- json
- Data is parsed using json_read_dict/3, which also receives
Options.
- prolog
- Data is parsed using read_term/3, which also receives
Options.
- To be done
- - Add a hook to allow for more data formats?