Newer
Older
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
// Copyright (C) 2020 Sebastian Dröge <sebastian@centricular.com>
//
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
use crate::config::Config;
use crate::rooms::{Room, Rooms};
use std::sync::{Arc, Mutex};
use actix::{Actor, Addr, Handler, Message, StreamHandler};
use actix_web_actors::ws;
use log::debug;
/// Actor that represents a WebRTC subscriber.
#[derive(Debug)]
pub struct Subscriber {
cfg: Arc<Config>,
rooms: Addr<Rooms>,
room: Mutex<Option<Addr<Room>>>,
}
impl Subscriber {
/// Create a new `Subscriber` actor.
pub fn new(cfg: Arc<Config>, rooms: Addr<Rooms>) -> Self {
Subscriber {
cfg,
rooms,
room: Mutex::new(None),
}
}
}
impl Actor for Subscriber {
type Context = ws::WebsocketContext<Self>;
}
impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for Subscriber {
fn handle(&mut self, _msg: Result<ws::Message, ws::ProtocolError>, _ctx: &mut Self::Context) {
// TODO
}
}
/// Leave a `Room` by a `Subscriber`.
#[derive(Debug)]
pub struct RoomDeletedMessage;
impl Message for RoomDeletedMessage {
type Result = ();
}
impl Handler<RoomDeletedMessage> for Subscriber {
type Result = ();
fn handle(
&mut self,
_msg: RoomDeletedMessage,
_ctx: &mut ws::WebsocketContext<Self>,
) -> Self::Result {
debug!("Room deleted");
// TODO
}
}