If the subscriber is aware of a namespace of interest, it can send SUBSCRIBE_NAMESPACE to publishers/relays it has established a session with. The Track Namespace Prefix it carries is compared against the namespaces known to the receiver using Namespace Prefix Matching (Section 2.4.2).
SUBSCRIBE_NAMESPACE requests namespace discovery: the publisher responds with NAMESPACE and NAMESPACE_DONE messages.
A SUBSCRIBE_NAMESPACE with zero Track Namespace fields indicates the sender is interested in all namespaces from the receiver.
The subscriber sends SUBSCRIBE_NAMESPACE on a new bidirectional stream. The publisher MUST send a single SUBSCRIBE_NAMESPACE_OK or SUBSCRIBE_NAMESPACE_ERROR as the first message on the response half of the stream; if the subscriber receives any other message first, it MUST close the session with a PROTOCOL_VIOLATION.
On success, the publisher MUST send a NAMESPACE message for each namespace it knows that matches the Track Namespace Prefix, and further NAMESPACE or NAMESPACE_DONE messages as that set changes. A publisher knows a namespace if it is an Original Publisher for one or more tracks in that Namespace Prefix, or is a relay that has received an authorized PUBLISH_NAMESPACE for the Namespace. On error, the stream is immediately closed via FIN.
The namespace in a NAMESPACE message is itself a prefix; tracks can exist in namespaces matching it. A NAMESPACE_DONE indicates the publisher intends to stop serving new subscriptions for tracks within that namespace.
Within a session, if a publisher receives a SUBSCRIBE_NAMESPACE with a
Track Namespace Prefix that shares a common prefix with an established
SUBSCRIBE_NAMESPACE, it MUST respond with SUBSCRIBE_NAMESPACE_ERROR with
error code PREFIX_OVERLAP.
The publisher MUST NOT send NAMESPACE_DONE for a namespace suffix before the corresponding NAMESPACE. If a subscriber receives a NAMESPACE_DONE before the corresponding NAMESPACE, it MUST close the session with a 'PROTOCOL_VIOLATION'.
A subscriber can receive a PUBLISH_NAMESPACE on a request stream for a namespace that falls within an active SUBSCRIBE_NAMESPACE prefix. This occurs when SUBSCRIBE_NAMESPACE or its response is in flight at the same time as a PUBLISH_NAMESPACE, or when an original publisher sends PUBLISH_NAMESPACE to advertise namespaces within the prefix being discovered. Such a PUBLISH_NAMESPACE is valid and MAY carry an AUTHORIZATION TOKEN parameter. Its lifetime is independent of the SUBSCRIBE_NAMESPACE stream.
A SUBSCRIBE_NAMESPACE is cancelled as described in Section 6.4.2.3, by resetting or sending STOP_SENDING on the stream.
4.2.2. Namespace Subscription State Management
If the publisher is unable to send NAMESPACE or NAMESPACE_DONE messages in a timely manner because the SUBSCRIBE_NAMESPACE response stream is blocked by flow control, the publisher MAY reset the SUBSCRIBE_NAMESPACE response stream. When a subscriber receives a stream reset or FIN on a SUBSCRIBE_NAMESPACE response stream, it SHOULD treat this as though each active namespace received a NAMESPACE_DONE. Subscriptions established via PUBLISH on separate bidi streams are not affected by closure of the SUBSCRIBE_NAMESPACE stream.