TrackHandler with a TrackMux for each broadcast path. When a subscription request is received for a given track name, the handler is invoked and is responsible for sending the appropriate track data.
Publish and Announce Broadcasts
To make a broadcast available for subscription, use one of the following methods on aTrackMux:
Publish: Registers aTrackHandlerfor a specific path. Internally, it creates an activeAnnouncementand delegates toAnnounce.PublishFunc: Registers a function as a handler for a specific path (convenience wrapper forPublish).Announce: Registers a handler and an explicitAnnouncementobject. TheAnnouncementmust be active, otherwise the handler is not registered and no announcement is sent.
Handle Track Subscriptions
When the other side (client or server) subscribes to a broadcast path, the registeredTrackHandler is invoked to serve the subscription. The handler receives a TrackWriter and is responsible for sending the appropriate track data for the requested track name.
Registering a TrackHandler with Publish:
PublishFunc:
- Context: The context is used to manage the lifecycle of the publication and can be cancelled to stop the broadcast.
- Broadcast Path: The broadcast path is a unique identifier for the broadcast stream.
- Track Handler: The track handler is a function that processes incoming track data for a specific broadcast path.
Announcements and Track Discovery
When you callPublish, PublishFunc, or Announce, a moqt.Announcement is initialized (or provided), and the announcement is sent to all registered channels in the announcement tree.
This ensures that all participants are aware of available broadcasts and their status. If the announcement ends (for example, if the context is cancelled), the mux cleans up the handler and announcement.
For more details, see the Announce & Discover documentation.
Producing a Track
Produce a Track
How to produce a track.