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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#![feature(async_closure)]
use std::{sync::Arc, time::Duration};
use signaling::signaling_connect;
use webrtc::{
api::{
interceptor_registry::register_default_interceptors, media_engine::MediaEngine, APIBuilder,
},
data_channel::data_channel_message::DataChannelMessage,
ice_transport::ice_server::RTCIceServer,
interceptor::registry::Registry,
peer_connection::{
configuration::RTCConfiguration, math_rand_alpha,
peer_connection_state::RTCPeerConnectionState,
},
};
pub mod crypto;
pub mod protocol;
pub mod signaling;
fn main() {
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.block_on(run())
}
async fn run() {
let (send, recv) = signaling_connect("meet.metamuffin.org", "hunter2").await;
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();
let api = APIBuilder::new()
.with_media_engine(media_engine)
.with_interceptor_registry(registry)
.build();
let config = RTCConfiguration {
ice_servers: vec![RTCIceServer {
urls: vec!["stun:metamuffin.org:16900".to_owned()],
..Default::default()
}],
..Default::default()
};
let peer_connection = Arc::new(api.new_peer_connection(config).await.unwrap());
let data_channel = peer_connection
.create_data_channel("data", None)
.await
.unwrap();
let (done_tx, mut done_rx) = tokio::sync::mpsc::channel::<()>(1);
peer_connection
.on_peer_connection_state_change(Box::new(move |s: RTCPeerConnectionState| {
println!("conn state: {s}");
Box::pin(async {})
}))
.await;
let d_label = data_channel.label().to_owned();
data_channel
.on_message(Box::new(move |msg: DataChannelMessage| {
let msg_str = String::from_utf8(msg.data.to_vec()).unwrap();
println!("Message from DataChannel '{}': '{}'", d_label, msg_str);
Box::pin(async {})
}))
.await;
let offer = peer_connection.create_offer(None).await.unwrap();
peer_connection
.set_local_description(offer.clone())
.await
.unwrap();
println!("{offer:?}");
tokio::time::sleep(Duration::from_secs(5)).await;
// // Wait for the answer to be pasted
// let line = signal::must_read_stdin().unwrap();
// let desc_data = signal::decode(line.as_str()).unwrap();
// let answer = serde_json::from_str::<RTCSessionDescription>(&desc_data)?;
// // Apply the answer as the remote description
// peer_connection.set_remote_description(answer).await?;
}
|