livekit_data_stream/outgoing/
mod.rs1use livekit_common::ParticipantIdentity;
18use std::collections::HashMap;
19
20use crate::types::OperationType;
21
22pub(crate) mod manager;
23
24mod constants;
25mod raw_stream;
26mod stream_writer;
27
28pub use stream_writer::{ByteStreamWriter, StreamWriter, TextStreamWriter};
29
30#[derive(Clone, Debug, Eq, PartialEq)]
32pub struct StreamByteOptions {
33 pub topic: String,
34 pub attributes: HashMap<String, String>,
35 pub destination_identities: Vec<ParticipantIdentity>,
36 pub id: Option<String>,
39 pub mime_type: Option<String>,
40 pub name: Option<String>,
41 pub total_length: Option<u64>,
42 pub compress: Option<bool>,
45 pub sender_identity: Option<ParticipantIdentity>,
50}
51
52impl StreamByteOptions {
53 pub fn new_with_topic(topic: impl Into<String>) -> Self {
54 Self {
55 topic: topic.into(),
56 attributes: HashMap::new(),
57 destination_identities: vec![],
58 id: None,
59 mime_type: None,
60 name: None,
61 total_length: None,
62 compress: None,
63 sender_identity: None,
64 }
65 }
66
67 pub fn with_topic(mut self, topic: String) -> Self {
69 self.topic = topic;
70 self
71 }
72 pub fn with_attributes(mut self, attributes: HashMap<String, String>) -> Self {
74 self.attributes = attributes;
75 self
76 }
77 pub fn with_attribute(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
79 self.attributes.insert(key.into(), value.into());
80 self
81 }
82 pub fn with_destination_identities(
85 mut self,
86 destination_identities: Vec<ParticipantIdentity>,
87 ) -> Self {
88 self.destination_identities = destination_identities;
89 self
90 }
91 pub fn with_destination_identity(mut self, identity: impl Into<ParticipantIdentity>) -> Self {
93 self.destination_identities.push(identity.into());
94 self
95 }
96 pub fn with_id(mut self, id: impl Into<String>) -> Self {
98 self.id = Some(id.into());
99 self
100 }
101 pub fn with_mime_type(mut self, mime_type: impl Into<String>) -> Self {
103 self.mime_type = Some(mime_type.into());
104 self
105 }
106 pub fn with_name(mut self, name: impl Into<String>) -> Self {
108 self.name = Some(name.into());
109 self
110 }
111 pub fn with_total_length(mut self, total_length: u64) -> Self {
113 self.total_length = Some(total_length);
114 self
115 }
116 pub fn with_compress(mut self, compress: bool) -> Self {
119 self.compress = Some(compress);
120 self
121 }
122 pub fn with_sender_identity(mut self, identity: impl Into<ParticipantIdentity>) -> Self {
125 self.sender_identity = Some(identity.into());
126 self
127 }
128}
129
130#[derive(Clone, Debug, Eq, PartialEq)]
132pub struct StreamTextOptions {
133 pub topic: String,
134 pub attributes: HashMap<String, String>,
135 pub destination_identities: Vec<ParticipantIdentity>,
136 pub id: Option<String>,
139 pub operation_type: Option<OperationType>,
140 pub version: Option<i32>,
141 pub reply_to_stream_id: Option<String>,
142 pub attached_stream_ids: Vec<String>,
143 pub generated: Option<bool>,
144 pub compress: Option<bool>,
147 pub sender_identity: Option<ParticipantIdentity>,
152}
153
154impl StreamTextOptions {
155 pub fn new_with_topic(topic: impl Into<String>) -> Self {
156 Self {
157 topic: topic.into(),
158 attributes: HashMap::new(),
159 destination_identities: vec![],
160 id: None,
161 operation_type: None,
162 version: None,
163 reply_to_stream_id: None,
164 attached_stream_ids: vec![],
165 generated: None,
166 compress: None,
167 sender_identity: None,
168 }
169 }
170
171 pub fn with_topic(mut self, topic: String) -> Self {
173 self.topic = topic;
174 self
175 }
176 pub fn with_attributes(mut self, attributes: HashMap<String, String>) -> Self {
178 self.attributes = attributes;
179 self
180 }
181 pub fn with_attribute(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
183 self.attributes.insert(key.into(), value.into());
184 self
185 }
186 pub fn with_destination_identities(
189 mut self,
190 destination_identities: Vec<ParticipantIdentity>,
191 ) -> Self {
192 self.destination_identities = destination_identities;
193 self
194 }
195 pub fn with_destination_identity(mut self, identity: impl Into<ParticipantIdentity>) -> Self {
197 self.destination_identities.push(identity.into());
198 self
199 }
200 pub fn with_id(mut self, id: impl Into<String>) -> Self {
202 self.id = Some(id.into());
203 self
204 }
205 pub fn with_operation_type(mut self, operation_type: OperationType) -> Self {
207 self.operation_type = Some(operation_type);
208 self
209 }
210 pub fn with_version(mut self, version: i32) -> Self {
212 self.version = Some(version);
213 self
214 }
215 pub fn with_reply_to_stream_id(mut self, reply_to_stream_id: impl Into<String>) -> Self {
217 self.reply_to_stream_id = Some(reply_to_stream_id.into());
218 self
219 }
220 pub fn with_attached_stream_ids(mut self, attached_stream_ids: Vec<String>) -> Self {
222 self.attached_stream_ids = attached_stream_ids;
223 self
224 }
225 pub fn with_attached_stream_id(mut self, attached_stream_id: impl Into<String>) -> Self {
227 self.attached_stream_ids.push(attached_stream_id.into());
228 self
229 }
230 pub fn with_generated(mut self, generated: bool) -> Self {
232 self.generated = Some(generated);
233 self
234 }
235 pub fn with_compress(mut self, compress: bool) -> Self {
238 self.compress = Some(compress);
239 self
240 }
241 pub fn with_sender_identity(mut self, identity: impl Into<ParticipantIdentity>) -> Self {
244 self.sender_identity = Some(identity.into());
245 self
246 }
247}