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
use super::{Broadcaster, PathNotification};
use anyhow::Error;
use derive_more::From;
use meio::{Action, ActionHandler, ActionRecipient, Actor, Address};
use rill_protocol::provider::{Description, EntryId, Path};
use std::collections::HashSet;
#[derive(Debug)]
pub struct BroadcasterLinkForClient {
address: Address<Broadcaster>,
active_streams: HashSet<Path>,
}
impl From<Address<Broadcaster>> for BroadcasterLinkForClient {
fn from(address: Address<Broadcaster>) -> Self {
Self {
address,
active_streams: HashSet::new(),
}
}
}
pub(super) struct SubscribeToStructChanges {
pub recipient: Box<dyn ActionRecipient<PathNotification>>,
}
impl Action for SubscribeToStructChanges {}
impl BroadcasterLinkForClient {
pub async fn subscribe_to_struct_changes<A>(&mut self, address: Address<A>) -> Result<(), Error>
where
A: Actor + ActionHandler<PathNotification>,
{
let recipient = Box::new(address);
let msg = SubscribeToStructChanges { recipient };
self.address.act(msg).await
}
}
#[derive(Debug, Clone, From)]
pub struct BroadcasterLinkForProvider {
address: Address<Broadcaster>,
}
pub(super) enum SessionLifetime {
Attached { name: EntryId },
Detached,
}
impl Action for SessionLifetime {}
impl BroadcasterLinkForProvider {
pub async fn session_attached(&mut self, name: EntryId) -> Result<(), Error> {
let msg = SessionLifetime::Attached { name };
self.address.act(msg).await
}
pub async fn session_detached(&mut self) -> Result<(), Error> {
let msg = SessionLifetime::Detached;
self.address.act(msg).await
}
}
pub(super) struct PathDeclared {
pub description: Description,
}
impl Action for PathDeclared {}
impl BroadcasterLinkForProvider {
pub async fn path_declared(&mut self, description: Description) -> Result<(), Error> {
let msg = PathDeclared { description };
self.address.act(msg).await
}
}