@@ -37,6 +37,23 @@ impl ServerMessages {
3737 self . sent_messages . retain ( |& ( entity, ..) | entity != client) ;
3838 }
3939
40+ /// Returns an iterator over received messages from clients on a channel without consuming them.
41+ ///
42+ /// Unlike [`Self::receive`], the messages stay in the resource. Intended for tools
43+ /// that need to observe inbound traffic (e.g. debug overlays or replay recording)
44+ /// alongside Replicon's normal consumption.
45+ pub fn iter_received < I : Into < usize > > (
46+ & self ,
47+ channel_id : I ,
48+ ) -> impl ExactSizeIterator < Item = ( Entity , & Bytes ) > + ' _ {
49+ let channel_id = channel_id. into ( ) ;
50+ self . received_messages
51+ . get ( channel_id)
52+ . unwrap_or_else ( || panic ! ( "server should have a receive channel with id {channel_id}" ) )
53+ . iter ( )
54+ . map ( |( entity, bytes) | ( * entity, bytes) )
55+ }
56+
4057 /// Receives all available messages from clients over a channel.
4158 ///
4259 /// All messages will be drained.
@@ -95,6 +112,17 @@ impl ServerMessages {
95112 self . sent_messages . retain ( f)
96113 }
97114
115+ /// Returns an iterator over sent messages without consuming them.
116+ ///
117+ /// Unlike [`Self::drain_sent`], the messages stay in the resource. Intended for
118+ /// tools that need to observe outbound traffic (e.g. server-side replay recording)
119+ /// before the messaging backend drains them.
120+ pub fn iter_sent ( & self ) -> impl ExactSizeIterator < Item = ( Entity , usize , & Bytes ) > + ' _ {
121+ self . sent_messages
122+ . iter ( )
123+ . map ( |( entity, channel_id, bytes) | ( * entity, * channel_id, bytes) )
124+ }
125+
98126 /// Removes all sent messages, returning them as an iterator with client entity and channel.
99127 ///
100128 /// <div class="warning">
0 commit comments