videocall_types/
lib.rs

1/*
2 * Copyright 2025 Security Union LLC
3 *
4 * Licensed under either of
5 *
6 * * Apache License, Version 2.0
7 *   (http://www.apache.org/licenses/LICENSE-2.0)
8 * * MIT license
9 *   (http://opensource.org/licenses/MIT)
10 *
11 * at your option.
12 *
13 * Unless you explicitly state otherwise, any contribution intentionally
14 * submitted for inclusion in the work by you, as defined in the Apache-2.0
15 * license, shall be dual licensed as above, without any additional terms or
16 * conditions.
17 */
18
19pub mod protos;
20
21use protobuf::Message;
22use yew_websocket::websocket::{Binary, Text};
23
24impl std::fmt::Display for protos::media_packet::media_packet::MediaType {
25    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
26        match self {
27            protos::media_packet::media_packet::MediaType::AUDIO => write!(f, "audio"),
28            protos::media_packet::media_packet::MediaType::VIDEO => write!(f, "video"),
29            protos::media_packet::media_packet::MediaType::SCREEN => write!(f, "screen"),
30            protos::media_packet::media_packet::MediaType::HEARTBEAT => write!(f, "heartbeat"),
31            protos::media_packet::media_packet::MediaType::RTT => write!(f, "rtt"),
32        }
33    }
34}
35
36impl std::fmt::Display for protos::packet_wrapper::packet_wrapper::PacketType {
37    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
38        match self {
39            protos::packet_wrapper::packet_wrapper::PacketType::AES_KEY => write!(f, "AES_KEY"),
40            protos::packet_wrapper::packet_wrapper::PacketType::RSA_PUB_KEY => {
41                write!(f, "RSA_PUB_KEY")
42            }
43            protos::packet_wrapper::packet_wrapper::PacketType::MEDIA => write!(f, "MEDIA"),
44            protos::packet_wrapper::packet_wrapper::PacketType::CONNECTION => {
45                write!(f, "CONNECTION")
46            }
47            protos::packet_wrapper::packet_wrapper::PacketType::DIAGNOSTICS => {
48                write!(f, "DIAGNOSTICS")
49            }
50            protos::packet_wrapper::packet_wrapper::PacketType::HEALTH => {
51                write!(f, "HEALTH")
52            }
53        }
54    }
55}
56
57impl From<Text> for protos::packet_wrapper::PacketWrapper {
58    fn from(t: Text) -> Self {
59        protos::packet_wrapper::PacketWrapper::parse_from_bytes(&t.unwrap().into_bytes()).unwrap()
60    }
61}
62
63impl From<Binary> for protos::packet_wrapper::PacketWrapper {
64    fn from(bin: Binary) -> Self {
65        protos::packet_wrapper::PacketWrapper::parse_from_bytes(&bin.unwrap()).unwrap()
66    }
67}
68
69pub fn truthy(s: Option<&str>) -> bool {
70    if let Some(s) = s {
71        ["true".to_string(), "1".to_string()].contains(&s.to_lowercase())
72    } else {
73        false
74    }
75}