use livekit_common::ParticipantIdentity;
use std::collections::HashMap;
use crate::types::OperationType;
pub(crate) mod manager;
mod constants;
mod raw_stream;
mod stream_writer;
pub use stream_writer::{ByteStreamWriter, StreamWriter, TextStreamWriter};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct StreamByteOptions {
pub topic: String,
pub attributes: HashMap<String, String>,
pub destination_identities: Vec<ParticipantIdentity>,
pub id: Option<String>,
pub mime_type: Option<String>,
pub name: Option<String>,
pub total_length: Option<u64>,
pub compress: Option<bool>,
pub sender_identity: Option<ParticipantIdentity>,
}
impl StreamByteOptions {
pub fn new_with_topic(topic: impl Into<String>) -> Self {
Self {
topic: topic.into(),
attributes: HashMap::new(),
destination_identities: vec![],
id: None,
mime_type: None,
name: None,
total_length: None,
compress: None,
sender_identity: None,
}
}
pub fn with_topic(mut self, topic: String) -> Self {
self.topic = topic;
self
}
pub fn with_attributes(mut self, attributes: HashMap<String, String>) -> Self {
self.attributes = attributes;
self
}
pub fn with_attribute(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.attributes.insert(key.into(), value.into());
self
}
pub fn with_destination_identities(
mut self,
destination_identities: Vec<ParticipantIdentity>,
) -> Self {
self.destination_identities = destination_identities;
self
}
pub fn with_destination_identity(mut self, identity: impl Into<ParticipantIdentity>) -> Self {
self.destination_identities.push(identity.into());
self
}
pub fn with_id(mut self, id: impl Into<String>) -> Self {
self.id = Some(id.into());
self
}
pub fn with_mime_type(mut self, mime_type: impl Into<String>) -> Self {
self.mime_type = Some(mime_type.into());
self
}
pub fn with_name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}
pub fn with_total_length(mut self, total_length: u64) -> Self {
self.total_length = Some(total_length);
self
}
pub fn with_compress(mut self, compress: bool) -> Self {
self.compress = Some(compress);
self
}
pub fn with_sender_identity(mut self, identity: impl Into<ParticipantIdentity>) -> Self {
self.sender_identity = Some(identity.into());
self
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct StreamTextOptions {
pub topic: String,
pub attributes: HashMap<String, String>,
pub destination_identities: Vec<ParticipantIdentity>,
pub id: Option<String>,
pub operation_type: Option<OperationType>,
pub version: Option<i32>,
pub reply_to_stream_id: Option<String>,
pub attached_stream_ids: Vec<String>,
pub generated: Option<bool>,
pub compress: Option<bool>,
pub sender_identity: Option<ParticipantIdentity>,
}
impl StreamTextOptions {
pub fn new_with_topic(topic: impl Into<String>) -> Self {
Self {
topic: topic.into(),
attributes: HashMap::new(),
destination_identities: vec![],
id: None,
operation_type: None,
version: None,
reply_to_stream_id: None,
attached_stream_ids: vec![],
generated: None,
compress: None,
sender_identity: None,
}
}
pub fn with_topic(mut self, topic: String) -> Self {
self.topic = topic;
self
}
pub fn with_attributes(mut self, attributes: HashMap<String, String>) -> Self {
self.attributes = attributes;
self
}
pub fn with_attribute(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
self.attributes.insert(key.into(), value.into());
self
}
pub fn with_destination_identities(
mut self,
destination_identities: Vec<ParticipantIdentity>,
) -> Self {
self.destination_identities = destination_identities;
self
}
pub fn with_destination_identity(mut self, identity: impl Into<ParticipantIdentity>) -> Self {
self.destination_identities.push(identity.into());
self
}
pub fn with_id(mut self, id: impl Into<String>) -> Self {
self.id = Some(id.into());
self
}
pub fn with_operation_type(mut self, operation_type: OperationType) -> Self {
self.operation_type = Some(operation_type);
self
}
pub fn with_version(mut self, version: i32) -> Self {
self.version = Some(version);
self
}
pub fn with_reply_to_stream_id(mut self, reply_to_stream_id: impl Into<String>) -> Self {
self.reply_to_stream_id = Some(reply_to_stream_id.into());
self
}
pub fn with_attached_stream_ids(mut self, attached_stream_ids: Vec<String>) -> Self {
self.attached_stream_ids = attached_stream_ids;
self
}
pub fn with_attached_stream_id(mut self, attached_stream_id: impl Into<String>) -> Self {
self.attached_stream_ids.push(attached_stream_id.into());
self
}
pub fn with_generated(mut self, generated: bool) -> Self {
self.generated = Some(generated);
self
}
pub fn with_compress(mut self, compress: bool) -> Self {
self.compress = Some(compress);
self
}
pub fn with_sender_identity(mut self, identity: impl Into<ParticipantIdentity>) -> Self {
self.sender_identity = Some(identity.into());
self
}
}