T1.5: Migrate emit/parse sites to v2 wire format
This commit is contained in:
@@ -25,16 +25,13 @@ pub struct Event {
|
||||
pub src: Option<String>,
|
||||
/// Packet sequence number.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub seq: Option<u16>,
|
||||
pub seq: Option<u32>,
|
||||
/// Codec identifier.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub codec: Option<String>,
|
||||
/// FEC block ID.
|
||||
/// FEC block ID (low byte) and symbol index (high byte).
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub fec_block: Option<u8>,
|
||||
/// FEC symbol index.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub fec_sym: Option<u8>,
|
||||
pub fec_block: Option<u16>,
|
||||
/// Is FEC repair packet.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub repair: Option<bool>,
|
||||
@@ -60,7 +57,9 @@ pub struct Event {
|
||||
|
||||
impl Event {
|
||||
fn now() -> String {
|
||||
chrono::Utc::now().format("%Y-%m-%dT%H:%M:%S%.6fZ").to_string()
|
||||
chrono::Utc::now()
|
||||
.format("%Y-%m-%dT%H:%M:%S%.6fZ")
|
||||
.to_string()
|
||||
}
|
||||
|
||||
/// Create a minimal event with just type and timestamp.
|
||||
@@ -73,7 +72,6 @@ impl Event {
|
||||
seq: None,
|
||||
codec: None,
|
||||
fec_block: None,
|
||||
fec_sym: None,
|
||||
repair: None,
|
||||
len: None,
|
||||
to_count: None,
|
||||
@@ -85,33 +83,59 @@ impl Event {
|
||||
}
|
||||
|
||||
/// Set room.
|
||||
pub fn room(mut self, room: &str) -> Self { self.room = Some(room.to_string()); self }
|
||||
pub fn room(mut self, room: &str) -> Self {
|
||||
self.room = Some(room.to_string());
|
||||
self
|
||||
}
|
||||
/// Set source.
|
||||
pub fn src(mut self, src: &str) -> Self { self.src = Some(src.to_string()); self }
|
||||
pub fn src(mut self, src: &str) -> Self {
|
||||
self.src = Some(src.to_string());
|
||||
self
|
||||
}
|
||||
/// Set packet header fields from a MediaPacket.
|
||||
pub fn packet(mut self, pkt: &wzp_proto::MediaPacket) -> Self {
|
||||
self.seq = Some(pkt.header.seq);
|
||||
self.codec = Some(format!("{:?}", pkt.header.codec_id));
|
||||
self.fec_block = Some(pkt.header.fec_block);
|
||||
self.fec_sym = Some(pkt.header.fec_symbol);
|
||||
self.repair = Some(pkt.header.is_repair);
|
||||
self.repair = Some(pkt.header.is_repair());
|
||||
self.len = Some(pkt.payload.len());
|
||||
self
|
||||
}
|
||||
/// Set seq only (when full packet not available).
|
||||
pub fn seq(mut self, seq: u16) -> Self { self.seq = Some(seq); self }
|
||||
pub fn seq(mut self, seq: u32) -> Self {
|
||||
self.seq = Some(seq);
|
||||
self
|
||||
}
|
||||
/// Set payload length.
|
||||
pub fn len(mut self, len: usize) -> Self { self.len = Some(len); self }
|
||||
pub fn len(mut self, len: usize) -> Self {
|
||||
self.len = Some(len);
|
||||
self
|
||||
}
|
||||
/// Set recipient count.
|
||||
pub fn to_count(mut self, n: usize) -> Self { self.to_count = Some(n); self }
|
||||
pub fn to_count(mut self, n: usize) -> Self {
|
||||
self.to_count = Some(n);
|
||||
self
|
||||
}
|
||||
/// Set peer label.
|
||||
pub fn peer(mut self, peer: &str) -> Self { self.peer = Some(peer.to_string()); self }
|
||||
pub fn peer(mut self, peer: &str) -> Self {
|
||||
self.peer = Some(peer.to_string());
|
||||
self
|
||||
}
|
||||
/// Set drop reason.
|
||||
pub fn reason(mut self, reason: &str) -> Self { self.reason = Some(reason.to_string()); self }
|
||||
pub fn reason(mut self, reason: &str) -> Self {
|
||||
self.reason = Some(reason.to_string());
|
||||
self
|
||||
}
|
||||
/// Set presence action.
|
||||
pub fn action(mut self, action: &str) -> Self { self.action = Some(action.to_string()); self }
|
||||
pub fn action(mut self, action: &str) -> Self {
|
||||
self.action = Some(action.to_string());
|
||||
self
|
||||
}
|
||||
/// Set participant count.
|
||||
pub fn participants(mut self, n: usize) -> Self { self.participants = Some(n); self }
|
||||
pub fn participants(mut self, n: usize) -> Self {
|
||||
self.participants = Some(n);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle for emitting events. Cheap to clone.
|
||||
@@ -181,8 +205,12 @@ async fn writer_task(path: PathBuf, mut rx: mpsc::UnboundedReceiver<Event>) {
|
||||
while let Some(event) = rx.recv().await {
|
||||
match serde_json::to_string(&event) {
|
||||
Ok(json) => {
|
||||
if writer.write_all(json.as_bytes()).await.is_err() { break; }
|
||||
if writer.write_all(b"\n").await.is_err() { break; }
|
||||
if writer.write_all(json.as_bytes()).await.is_err() {
|
||||
break;
|
||||
}
|
||||
if writer.write_all(b"\n").await.is_err() {
|
||||
break;
|
||||
}
|
||||
count += 1;
|
||||
// Flush every 100 events
|
||||
if count % 100 == 0 {
|
||||
|
||||
Reference in New Issue
Block a user