Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Xenon
Vortex
Commits
3c965472
Verified
Commit
3c965472
authored
Jul 27, 2021
by
Martin Löffler
Browse files
Refactor ProduceType, WebSocket produce events
parent
6aca9252
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
36 deletions
+52
-36
src/state/room/mod.rs
src/state/room/mod.rs
+3
-1
src/state/user.rs
src/state/user.rs
+30
-2
src/ws/mod.rs
src/ws/mod.rs
+18
-2
src/ws/types.rs
src/ws/types.rs
+1
-31
No files found.
src/state/room/mod.rs
View file @
3c965472
...
...
@@ -10,7 +10,7 @@ use tokio::sync::{
RwLock
,
};
use
super
::
user
::
User
;
use
super
::
user
::
{
ProduceType
,
User
}
;
use
crate
::{
api
::
ApiError
,
rtc
::
get_worker_pool
};
pub
mod
users
;
...
...
@@ -20,6 +20,8 @@ pub use users::RoomUsers;
pub
enum
RoomEvent
{
UserJoined
(
String
),
UserLeft
(
String
),
UserStartProduce
(
String
,
ProduceType
),
UserStopProduce
(
String
,
ProduceType
),
RoomDelete
,
}
...
...
src/state/user.rs
View file @
3c965472
use
serde
::
Serialize
;
use
serde
::
{
Deserialize
,
Serialize
}
;
use
std
::{
str
::
FromStr
,
sync
::
Arc
};
use
mediasoup
::
producer
::
Producer
;
use
mediasoup
::
rtp_parameters
::
MediaKind
;
use
super
::
room
::{
Room
,
RoomEvent
};
#[
non_exhaustive
]
#[
derive(Serialize,
Deserialize,
Clone,
Copy,
Debug)
]
pub
enum
ProduceType
{
#[serde(rename
=
"audio"
)]
Audio
,
#[serde(rename
=
"video"
)]
Video
,
#[serde(rename
=
"saudio"
)]
#[serde(alias
=
"screenshareaudio"
)]
ScreenshareAudio
,
#[serde(rename
=
"svideo"
)]
#[serde(alias
=
"screensharevideo"
)]
ScreenshareVideo
,
}
impl
ProduceType
{
pub
fn
into_kind
(
self
)
->
MediaKind
{
match
self
{
ProduceType
::
Audio
|
ProduceType
::
ScreenshareAudio
=>
MediaKind
::
Audio
,
ProduceType
::
Video
|
ProduceType
::
ScreenshareVideo
=>
MediaKind
::
Video
,
}
}
}
impl
From
<
ProduceType
>
for
MediaKind
{
fn
from
(
produce_type
:
ProduceType
)
->
MediaKind
{
produce_type
.into_kind
()
}
}
impl
FromStr
for
ProduceType
{
...
...
@@ -63,6 +89,7 @@ impl User {
pub
fn
get_producer
(
&
self
,
produce_type
:
ProduceType
)
->
Option
<&
Producer
>
{
let
producer
=
match
produce_type
{
ProduceType
::
Audio
=>
&
self
.audio
,
_
=>
todo!
(),
};
producer
.as_ref
()
...
...
@@ -78,6 +105,7 @@ impl User {
}
let
producer
=
match
produce_type
{
ProduceType
::
Audio
=>
&
mut
self
.audio
,
_
=>
todo!
(),
};
*
producer
=
Some
(
new_producer
);
...
...
src/ws/mod.rs
View file @
3c965472
...
...
@@ -14,7 +14,7 @@ mod error;
mod
types
;
use
error
::
WSCloseType
;
use
types
::{
WSCommand
,
WSCommandType
,
WSReply
,
WSReplyType
,
WSEvent
};
use
types
::{
WSCommand
,
WSCommandType
,
WSEvent
,
WSReply
,
WSReplyType
};
pub
fn
route
()
->
impl
Filter
<
Extract
=
(
impl
Reply
,),
Error
=
Rejection
>
+
Copy
{
warp
::
ws
::
ws
()
.map
(|
ws
:
Ws
|
ws
.on_upgrade
(
on_connection
))
...
...
@@ -129,12 +129,28 @@ async fn event_loop(
if
id
==
user_id
{
return
Err
(
WSCloseType
::
Kicked
);
}
let
event
=
WSEvent
::
UserLeft
{
id
};
ws_sink
.send
(
Message
::
text
(
serde_json
::
to_string
(
&
event
)
?
))
.await
?
;
},
RoomEvent
::
UserStartProduce
(
id
,
produce_type
)
=>
{
if
id
!=
user_id
{
let
event
=
WSEvent
::
UserStartProduce
{
id
,
produce_type
};
ws_sink
.send
(
Message
::
text
(
serde_json
::
to_string
(
&
event
)
?
))
.await
?
;
}
},
RoomEvent
::
UserStopProduce
(
id
,
produce_type
)
=>
{
if
id
!=
user_id
{
let
event
=
WSEvent
::
UserStopProduce
{
id
,
produce_type
};
ws_sink
.send
(
Message
::
text
(
serde_json
::
to_string
(
&
event
)
?
))
.await
?
;
}
}
RoomEvent
::
RoomDelete
=>
{
return
Err
(
WSCloseType
::
RoomClosed
);
},
...
...
src/ws/types.rs
View file @
3c965472
...
...
@@ -9,37 +9,7 @@ use mediasoup::{
srtp_parameters
::{
SrtpCryptoSuite
,
SrtpParameters
},
};
use
crate
::
state
::
user
::
UserInfo
;
#[derive(Serialize,
Deserialize,
Clone,
Copy)]
pub
enum
ProduceType
{
#[serde(rename
=
"audio"
)]
Audio
,
#[serde(rename
=
"video"
)]
Video
,
#[serde(rename
=
"saudio"
)]
#[serde(alias
=
"screenshareaudio"
)]
ScreenshareAudio
,
#[serde(rename
=
"svideo"
)]
#[serde(alias
=
"screensharevideo"
)]
ScreenshareVideo
,
}
impl
ProduceType
{
pub
fn
into_kind
(
self
)
->
MediaKind
{
match
self
{
ProduceType
::
Audio
|
ProduceType
::
ScreenshareAudio
=>
MediaKind
::
Audio
,
ProduceType
::
Video
|
ProduceType
::
ScreenshareVideo
=>
MediaKind
::
Video
,
}
}
}
impl
From
<
ProduceType
>
for
MediaKind
{
fn
from
(
produce_type
:
ProduceType
)
->
MediaKind
{
produce_type
.into_kind
()
}
}
use
crate
::
state
::
user
::{
ProduceType
,
UserInfo
};
#[derive(Deserialize,
IntoStaticStr)]
#[serde(tag
=
"type"
,
content
=
"data"
)]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment