livekit_data_stream/incoming/events.rs
1// Copyright 2026 LiveKit, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use from_variants::FromVariants;
16use livekit_common::ParticipantIdentity;
17
18use crate::{
19 incoming::AnyStreamReader,
20 types::{Chunk, Packet, Trailer},
21};
22
23pub struct PacketReceived {
24 pub packet: Packet,
25 pub participant_identity: ParticipantIdentity,
26}
27
28impl PacketReceived {
29 pub fn new(packet: Packet, participant_identity: ParticipantIdentity) -> Self {
30 Self { packet, participant_identity }
31 }
32}
33
34/// An event fed into [`IncomingStreamManager::run`] by the host crate. Each corresponds to an
35/// inbound data-stream packet (or a lifecycle signal) and carries everything the manager needs to
36/// process it without reaching back into room state.
37#[derive(FromVariants)]
38pub enum InputEvent {
39 PacketReceived(PacketReceived),
40 /// Abort every open stream sent by this participant (they disconnected mid-send).
41 AbortStreamsFrom(ParticipantIdentity),
42 /// Stop the run loop.
43 Shutdown,
44}
45
46/// A new stream was opened; its reader should be delivered to the application (or routed
47/// internally for reserved topics). Carries the sender's identity.
48pub struct StreamOpened {
49 pub stream_reader: AnyStreamReader,
50 pub participant_identity: ParticipantIdentity,
51}
52
53/// A "raw chunk received" notification, which is used to trigger
54/// the deprecated [RoomEvent:::StreamChunkReceived] event.
55pub struct ChunkReceived {
56 pub chunk: Chunk,
57 pub participant_identity: ParticipantIdentity,
58
59 /// Topic of the stream this chunk belongs to, or `None` if the associated stream id could
60 /// not be mapped to a topic.
61 pub topic: Option<String>,
62}
63
64/// A "raw trailer received" notification, which is used to trigger
65/// the deprecated [RoomEvent:::StreamTrailerReceived] event.
66pub struct TrailerReceived {
67 pub trailer: Trailer,
68 pub participant_identity: ParticipantIdentity,
69
70 /// Topic of the stream this chunk belongs to, or `None` if the associated stream id could
71 /// not be mapped to a topic.
72 ///
73 /// See [`ChunkReceived::topic`].
74 pub topic: Option<String>,
75}
76
77/// An event emitted by [`IncomingStreamManager::run`] for the host crate to surface. The manager
78/// stays decoupled from `RoomEvent`; the host maps these onto its own event types.
79#[derive(FromVariants)]
80pub enum OutputEvent {
81 StreamOpened(StreamOpened),
82 ChunkReceived(ChunkReceived),
83 TrailerReceived(TrailerReceived),
84}