@@ -102,24 +102,31 @@ impl Subscribed {
102102 }
103103
104104 async fn serve_inner ( & mut self , track : serve:: TrackReader ) -> Result < ( ) , SessionError > {
105- let latest = track. latest ( ) ;
105+ // Update largest location before sending SubscribeOk
106+ let largest_location = track. largest ( ) ;
106107 self . state
107108 . lock_mut ( )
108109 . ok_or ( ServeError :: Cancel ) ?
109- . largest_location = latest;
110-
111- self . publisher . send_message ( message:: SubscribeOk {
112- id : self . msg . id ,
113- track_alias : self . msg . id , // TODO SLG - use subscription id for now, needs fixing
114- expires : 0 , // TODO SLG
115- group_order : message:: GroupOrder :: Descending , // TODO: resolve correct value from publisher / subscriber prefs
116- content_exists : latest. is_some ( ) ,
117- largest_location : latest,
118- params : Default :: default ( ) ,
119- } ) ;
110+ . largest_location = largest_location;
111+
112+ // Send SubscribeOk using send_message_and_wait to ensure it is sent at least to the QUIC stack before
113+ // we start serving the track. If a subscriber gets the stream before SubscribeOk
114+ // then they won't recognize the track_alias in the stream header.
115+ self . publisher
116+ . send_message_and_wait ( message:: SubscribeOk {
117+ id : self . msg . id ,
118+ track_alias : self . msg . id , // use subscription id as track alias
119+ expires : 0 , // TODO SLG
120+ group_order : message:: GroupOrder :: Descending , // TODO: resolve correct value from publisher / subscriber prefs
121+ content_exists : largest_location. is_some ( ) ,
122+ largest_location,
123+ params : Default :: default ( ) ,
124+ } )
125+ . await ;
120126
121127 self . ok = true ; // So we send SubscribeDone on drop
122128
129+ // Serve based on track mode
123130 match track. mode ( ) . await ? {
124131 // TODO cancel track/datagrams on closed
125132 TrackReaderMode :: Stream ( _stream) => panic ! ( "deprecated" ) ,
@@ -204,7 +211,7 @@ impl Subscribed {
204211 Ok ( Some ( subgroup) ) => {
205212 let header = data:: SubgroupHeader {
206213 header_type: data:: StreamHeaderType :: SubgroupIdExt , // SubGroupId = Yes, Extensions = Yes, ContainsEndOfGroup = No
207- track_alias: self . msg. id, // TODO SLG - use subscription id for now, needs fixing
214+ track_alias: self . msg. id, // use subscription id as track_alias
208215 group_id: subgroup. group_id,
209216 subgroup_id: Some ( subgroup. subgroup_id) ,
210217 publisher_priority: subgroup. priority,
@@ -367,7 +374,7 @@ impl Subscribed {
367374 while let Some ( datagram) = datagrams. read ( ) . await ? {
368375 let encoded_datagram = data:: Datagram {
369376 datagram_type : data:: DatagramType :: ObjectIdPayload , // TODO SLG
370- track_alias : self . msg . id , // TODO SLG - use subscription id for now
377+ track_alias : self . msg . id , // use subscription id as track_alias
371378 group_id : datagram. group_id ,
372379 object_id : Some ( datagram. object_id ) ,
373380 publisher_priority : datagram. priority ,
@@ -403,7 +410,6 @@ impl Subscribed {
403410 encoded_datagram. group_id ,
404411 encoded_datagram. object_id . unwrap ( ) ,
405412 ) ?;
406- // TODO SLG - fix up safety of unwrap()
407413
408414 datagram_count += 1 ;
409415 }
0 commit comments