@@ -25,6 +25,10 @@ pub struct Origin {
2525 /// Active origin producers for publishing and consuming broadcasts.
2626 active : NonZeroSlab < moq_net:: OriginProducer > ,
2727
28+ /// Announcement guards from `publish`. Removing an entry (via `unpublish`) drops the
29+ /// guard, which unannounces the broadcast.
30+ published : NonZeroSlab < moq_net:: OriginPublish > ,
31+
2832 /// Broadcast announcement information (path, active status).
2933 announced : NonZeroSlab < ( String , bool ) > ,
3034
@@ -185,14 +189,25 @@ impl Origin {
185189 Ok ( ( ) )
186190 }
187191
192+ /// Announce `broadcast` under `path`, returning a publish handle. The announcement stays
193+ /// live until [`Self::unpublish`] is called with that handle (independent of the broadcast's
194+ /// own lifetime). Errors with [`Error::Moq`] if the path is outside the origin's scope.
188195 pub fn publish < P : moq_net:: AsPath > (
189196 & mut self ,
190197 origin : Id ,
191198 path : P ,
192199 broadcast : moq_net:: BroadcastConsumer ,
193- ) -> Result < ( ) , Error > {
194- let origin = self . active . get_mut ( origin) . ok_or ( Error :: OriginNotFound ) ?;
195- origin. publish_broadcast ( path, broadcast) ;
200+ ) -> Result < Id , Error > {
201+ let origin = self . active . get ( origin) . ok_or ( Error :: OriginNotFound ) ?;
202+ let publish = origin. publish_broadcast ( path, broadcast) ?;
203+ self . published . insert ( publish)
204+ }
205+
206+ /// Drop a publish handle from [`Self::publish`], unannouncing the broadcast.
207+ pub fn unpublish ( & mut self , publish : Id ) -> Result < ( ) , Error > {
208+ // Dropping the removed guard is what unannounces the broadcast.
209+ let publish = self . published . remove ( publish) . ok_or ( Error :: BroadcastNotFound ) ?;
210+ drop ( publish) ;
196211 Ok ( ( ) )
197212 }
198213
0 commit comments