-
Notifications
You must be signed in to change notification settings - Fork 0
docs(events): document Event::SentFrame and the with_stats → with_observers rename #502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
a25944c
c2a3d09
9ddbddb
f803956
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2038,6 +2038,39 @@ while let Ok(event) = event_rx.recv().await { | |
| // Drop `_lease` to stop forwarding. | ||
| ``` | ||
|
|
||
| ### acquire_sent_frame_forwarding | ||
|
|
||
| ```rust | ||
| pub fn acquire_sent_frame_forwarding(self: &Arc<Self>) -> SentFrameLease | ||
| ``` | ||
|
|
||
| Acquire a lease that keeps [`Event::SentFrame`](/concepts/events#sentframe) enabled for one consumer. The lease is necessary but not sufficient: a handler that has narrowed its `interest()` away from the default `EventInterest::ALL` also needs `EventKind::SentFrame` added back in, or it won't see the event even while a lease is held. This is the outbound counterpart of [`acquire_decrypted_payload_forwarding`](#acquire_decrypted_payload_forwarding): the event carries the marshaled plaintext of every frame the transport accepted, and — unlike [`wait_for_sent_node`](#wait_for_sent_node) — it is neither filtered nor one-shot, and covers every send path, including acks, delivery receipts, and direct-encoded IQs that never build a `Node` at all. | ||
|
|
||
| <ResponseField name="SentFrameLease" type="SentFrameLease"> | ||
| RAII lease. `Event::SentFrame` stays enabled until every acquired lease is dropped — hold it for as long as you want the event forwarded. The lease holds only a weak client reference, so it cannot keep the client alive. | ||
| </ResponseField> | ||
|
|
||
| <Note> | ||
| While no lease is held, nothing is emitted and nothing is cloned — the path costs one relaxed atomic load on the noise sender task. Under a lease, the forwarded frame is the same `bytes::Bytes` the caller handed to the socket, so forwarding it is a refcount bump rather than a copy. | ||
| </Note> | ||
|
|
||
| **Example:** | ||
| ```rust | ||
| use wacore::types::events::{ChannelEventHandler, Event}; | ||
|
|
||
| let _lease = client.acquire_sent_frame_forwarding(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the connected client can send concurrently—for example, from a keepalive, acknowledgement worker, or another task—acquiring the lease here activates publication before the handler is registered. Any frame sent between these statements is dispatched without this consumer and is lost, which undermines the documented session-recording use case. Register the handler first, then acquire the lease so every frame produced after activation has a receiver. Useful? React with 👍 / 👎. |
||
|
|
||
| let (handler, event_rx) = ChannelEventHandler::new(); | ||
| client.register_handler(handler); | ||
|
|
||
| while let Ok(event) = event_rx.recv().await { | ||
| if let Event::SentFrame(frame) = &*event { | ||
| println!("sent {} bytes", frame.plaintext.len()); | ||
| } | ||
| } | ||
| // Drop `_lease` to stop forwarding. | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Call management | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.