diff --git a/01.md b/01.md index a38ac1d..5823119 100644 --- a/01.md +++ b/01.md @@ -124,17 +124,22 @@ Subscriptions stay indefinitely open until either side closes the subscription o ### Subscription Requests -To open and update, and close subscriptions, Clients MUST use the following formats: - * `["REQ", , , , ...]`, - * `["CLOSE", ]` +To request or update a subscription, send a `REQ` message with the format -`REQ` requests events and subscribes to new updates. A `REQ` message on an existing subscription overrides the previous subscription. +```js +["REQ", , , , ...] +``` -`CLOSE` stops the respective subscription. +To stop receiving events from a subscription: +```js +["CLOSE", ] +``` -`` is a non-empty string with a maximum length of 64 chars. Relays MUST manage ``s independently for each WebSocket connection. ``s are not globally unique. + A `REQ` message on an existing subscription overrides the previous subscription. -`` is a JSON object that determines what events will be sent in that subscription, it can have the following attributes: +`subscription_id` is a non-empty string with a maximum length of 64 chars. Relays MUST manage ``s independently for each WebSocket connection. ``s are not globally unique. + +`filterX` is a stringified JSON object that determines what events will be sent in that subscription, it can have the following attributes: ```js { @@ -164,27 +169,39 @@ The `limit` attribute informs the maximum number of events to return, sorted by ### Subscription Responses -Relays send 3 types of messages during a subscription: +The `EVENT` message is used to send events requested by clients: - * `["EVENT", , ]` - * `["EOSE", ]`, - * `["CLOSED", , :]` +```js +["EVENT", , ] +``` -The `EVENT` message is used to send events requested by clients. +Once all matching events are sent, an `EOSE` message follows to indicate the _end of stored events_ and the beginning of events newly received in real-time. -`EOSE` indicates the _end of stored events_ and the beginning of events newly received in real-time. +```js +["EOSE", ] +``` -`CLOSED` messages MUST be sent in response to a `REQ` when the relay refuses to fulfill it. It can also be sent when a relay decides to kill a subscription on its side before a client has disconnected or sent a `CLOSE`. The message MUST be a string formed by a machine-readable single-word prefix followed by a `:` and then a human-readable message. +`CLOSED` messages can be when the relay refuses to fulfill a `REQ` or when it decides to kill a subscription before a client has disconnected or sent a `CLOSE`, a `CLOSED` message is sent: + +```js +["CLOSED", , ] +``` + +The message MUST be a string formed by a machine-readable single-word prefix followed by a `:` and then a human-readable message. ## Publishing To send an event to the Relay, Clients send a broadcast message in the format: - * `["EVENT", ]` +```js +["EVENT", ] +``` Relays reply with an ACK message in the format of: - * `["OK", , , :]` +```js +["OK", , , ] +``` `OK` messages MUST be sent in response to `EVENT` messages received from clients, they must have the 3rd parameter set to `true` when an event has been accepted by the relay, `false` otherwise. The 4th parameter MUST always be present, but MAY be an empty string when the 3rd is `true`. @@ -194,7 +211,9 @@ If present, the message MUST be a string formed by a machine-readable single-wor Notices are human-readable warnings that might help explain or debug the behavior of a given relay or filter. - * `["NOTICE", ]` +```js +["NOTICE", ] +``` ## Message Prefixes