aboutsummaryrefslogtreecommitdiff
path: root/client-native-lib/src/lib.rs
blob: bb88b9fbd59e6b6f6dff9d57c7d257bd77ec47e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
    This file is part of keks-meet (https://codeberg.org/metamuffin/keks-meet)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2022 metamuffin <metamuffin@disroot.org>
*/
#![feature(async_closure)]
#![feature(box_syntax)]
#![feature(async_fn_in_trait)]

use std::{pin::Pin, sync::Arc};

use futures_util::Future;
use peer::Peer;
use protocol::ProvideInfo;
use state::State;
use tokio::sync::RwLock;
use webrtc::{
    api::{
        interceptor_registry::register_default_interceptors, media_engine::MediaEngine, APIBuilder,
    },
    interceptor::registry::Registry,
};

pub mod crypto;
pub mod peer;
pub mod protocol;
pub mod signaling;
pub mod state;

pub use webrtc;

pub struct Config {
    pub signaling_uri: String,
    pub secret: String,
    pub username: String,
}

pub(crate) fn build_api() -> webrtc::api::API {
    let mut media_engine = MediaEngine::default();
    media_engine.register_default_codecs().unwrap();
    let mut registry = Registry::new();
    registry = register_default_interceptors(registry, &mut media_engine).unwrap();
    APIBuilder::new()
        .with_media_engine(media_engine)
        .with_interceptor_registry(registry)
        .build()
}

pub trait LocalResource: Send + Sync + 'static {
    fn info(&self) -> ProvideInfo;
    fn on_request(&self, peer: Arc<Peer>) -> Box<dyn Future<Output = ()>>;
}

pub trait EventHandler: Send + Sync + 'static {
    fn remote_resource_added(
        &self,
        peer: &Peer,
        info: ProvideInfo,
    ) -> Pin<Box<dyn Future<Output = ()>>>;
    fn remote_resource_removed(&self, peer: &Peer, id: String)
        -> Pin<Box<dyn Future<Output = ()>>>;
}