Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Add coturn integration #20

Merged
merged 48 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
4865a0f
Dockerize application
Kirguir Apr 11, 2019
48468c1
Remove medea container
Kirguir Apr 15, 2019
bd5fdaa
Fix docs
Kirguir Apr 17, 2019
2b70f97
Merge branch 'master' into dockerize
Kirguir May 8, 2019
9489194
Impl COTURN auth service
Kirguir May 13, 2019
5785514
Merge branch 'master' into dockerize
Kirguir May 14, 2019
a20cec3
Impl IceUsersRepository
Kirguir May 14, 2019
9546d4b
refactor
alexlapa May 15, 2019
cdfdf19
refactor
alexlapa May 20, 2019
fbd2abe
fix config
alexlapa May 20, 2019
cd3bd63
fix config
alexlapa May 20, 2019
a4dc292
fix tests
alexlapa May 21, 2019
a7d2812
Merge branch 'master' into dockerize
alexlapa May 22, 2019
da70a95
fix merge
alexlapa May 22, 2019
82b28c0
Merge branch 'master' into dockerize
alexlapa May 22, 2019
83f7d5b
fix merge
alexlapa May 22, 2019
ba6f653
return derive debug
alexlapa May 22, 2019
d8d70be
refactoring
alexlapa May 23, 2019
c9456ae
Merge branch 'master' into dockerize
alexlapa May 23, 2019
adce23b
refactor
alexlapa May 23, 2019
cab7db3
refactor
alexlapa May 23, 2019
73df128
run coturn in host
alexlapa May 24, 2019
fb30d72
Corrections
tyranron May 24, 2019
daf1653
fix config
alexlapa May 24, 2019
eea2a45
fix rand usage
alexlapa May 24, 2019
cc87ec9
getters naming
alexlapa May 24, 2019
b171d5e
minor fixes
alexlapa May 24, 2019
8b76505
add trait TurnAuthService
alexlapa May 26, 2019
d543ee2
refactor
alexlapa May 26, 2019
de40a38
add reauth todo
alexlapa May 26, 2019
d5d6b13
Merge remote-tracking branch 'origin/dockerize' into dockerize
tyranron May 28, 2019
862303f
Add Coturn integration (#20)
nWacky Jun 5, 2019
fa984f6
Merge branch 'master' into dockerize
alexlapa Jun 6, 2019
952fa07
Optimize, fix bugs
nWacky Jun 6, 2019
0dd9c82
review
alexlapa Jun 7, 2019
51e59bc
fix bugs
nWacky Jun 7, 2019
6b376a9
documentation, refactor
alexlapa Jun 9, 2019
440273c
do not create/delete static IceUsers
alexlapa Jun 9, 2019
4cf81fe
poll delete_ice_user, use delete_batch instead of delete
alexlapa Jun 9, 2019
09c62a5
fix test
alexlapa Jun 9, 2019
a0905c7
add MEDEA_TURN.DB.REDIS.CONNECTION_TIMEOUT
alexlapa Jun 9, 2019
91c5dbc
log err
alexlapa Jun 9, 2019
8d68d3f
refactor
alexlapa Jun 9, 2019
b8da19e
add todo
alexlapa Jun 9, 2019
868907a
fix deps
alexlapa Jun 9, 2019
c5cbb84
Merge remote-tracking branch 'origin/dockerize' into dockerize
tyranron Jun 12, 2019
9f3a12e
Correct 'jason' and 'medea-client-api' changes
tyranron Jun 12, 2019
44bc7e6
Correct config defaults
tyranron Jun 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
RUST_LOG=debug
MEDEA_CONF=config.toml

COMPOSE_PROJECT_NAME=medea
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
/*.iml
.DS_Store

/.cache/

/target/
**/*.rs.bk
130 changes: 124 additions & 6 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ lto = "thin"
[dependencies]
actix = "0.7"
actix-web = "0.7"
bb8 = "0.3"
bb8-redis = "0.3"
config = "0.9"
chrono = "0.4"
dotenv = "0.13"
Expand All @@ -33,7 +35,10 @@ macro-attr = "0.2"
medea-client-api-proto = { path = "proto/client-api", features = ["medea"] }
medea-macro = { path = "crates/medea-macro" }
newtype_derive = "0.1"
serde = { version = "1.0", features = ['derive'] }
rand = "0.6"
redis = "0.10"
rust-crypto = "0.2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
slog = "2.4"
slog-envlogger = "2.1"
Expand All @@ -42,6 +47,7 @@ slog-async = "2.3"
slog-json = "2.3"
slog-scope = "4.1"
smart-default = "0.5"
tokio = "0.1"
toml = "0.4"
[dependencies.serde-humantime]
git = "https://github.com/tailhook/serde-humantime"
Expand All @@ -50,4 +56,3 @@ toml = "0.4"
[dev-dependencies]
serial_test = "0.2"
serial_test_derive = "0.2"
tokio = "0.1"
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fmt: cargo.fmt
# make up

up:
$(MAKE) -j2 up.jason up.medea
$(MAKE) -j3 up.coturn up.jason up.medea


test: test.unit
Expand Down Expand Up @@ -152,6 +152,15 @@ endif
# Running commands #
####################

# Run Coturn STUN/TURN server.
#
# Usage:
# make up.coturn

up.coturn:
docker-compose up


# Run Jason E2E demo in development mode.
#
# Usage:
Expand Down Expand Up @@ -179,6 +188,6 @@ up.medea:
.PHONY: cargo cargo.fmt cargo.lint \
docs docs.rust \
test test.unit \
up up.jason up.medea \
up up.coturn up.jason up.medea \
yarn

50 changes: 50 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,53 @@
#
# Default:
# reconnect_timeout = "10s"




[turn]
# Turn server IP address.
#
# Default:
# ip = "127.0.0.1"

# Turn server port.
#
# Default:
# port = 3478

# Static user on Turn server.
#
# Default:
# user = "USER"

# Static user password on Turn server.
#
# Default:
# pass = "PASS"

[turn.db.redis]
# Host of Coturn's Redis database.
#
# Default:
# host = "127.0.0.1"

# Port of Coturn's Redis database for client connections.
#
# Default:
# port = 6379

# Password to connect to Coturn's Redis database with.
#
# Default:
# pass = "turn"

# Number of Coturn's database in Redis.
#
# Default:
# db_number = 0

# Timeout for establishing connection with Coturn's Redis database.
#
# Default:
# connection_timeout = "5s"
3 changes: 3 additions & 0 deletions dev/coturn/redis.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
requirepass turn
timeout 0
tcp-keepalive 60
10 changes: 10 additions & 0 deletions dev/coturn/turnserver.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
lt-cred-mech
fingerprint
no-cli
no-tls
no-dtls
min-port=49160
max-port=49200
realm=medea
redis-userdb="ip=127.0.0.1 port=6379 dbname=0 password=turn"
user=USER:PASS
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: 2

services:
coturn:
container_name: ${COMPOSE_PROJECT_NAME}-coturn
image: instrumentisto/coturn:4.5
depends_on: ["coturn-db"]
command:
- --log-file=stdout
#- --Verbose
volumes:
- ./dev/coturn/turnserver.conf:/etc/coturn/turnserver.conf:ro
- ./.cache/coturn/data:/var/lib/coturn
network_mode: host
coturn-db:
container_name: ${COMPOSE_PROJECT_NAME}-coturn-db
image: redis:alpine
command: ["redis-server", "/etc/redis.conf"]
ports:
- "6379:6379" # coturn redis
volumes:
- ./dev/coturn/redis.conf:/etc/redis.conf:ro
19 changes: 8 additions & 11 deletions jason/src/api/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use futures::{
future::{Future as _, IntoFuture},
stream::Stream as _,
};
use medea_client_api_proto::{EventHandler, IceCandidate, Track};
use medea_client_api_proto::{EventHandler, IceCandidate, IceServer, Track};
use wasm_bindgen::{prelude::*, JsValue};
use wasm_bindgen_futures::spawn_local;
use web_sys::console;
Expand Down Expand Up @@ -83,31 +83,28 @@ impl EventHandler for InnerRoom {
/// Creates RTCPeerConnection with provided ID.
fn on_peer_created(
&mut self,
_peer_id: u64,
_sdp_offer: Option<String>,
_tracks: Vec<Track>,
_: u64,
_: Option<String>,
_: Vec<Track>,
_: Vec<IceServer>,
) {
console::log_1(&JsValue::from_str("on_peer_created invoked"));
}

/// Applies specified SDP Answer to specified RTCPeerConnection.
fn on_sdp_answer_made(&mut self, _peer_id: u64, _sdp_answer: String) {
fn on_sdp_answer_made(&mut self, _: u64, _: String) {
console::log_1(&JsValue::from_str("on_sdp_answer invoked"));
}

/// Applies specified ICE Candidate to specified RTCPeerConnection.
fn on_ice_candidate_discovered(
&mut self,
_peer_id: u64,
_candidate: IceCandidate,
) {
fn on_ice_candidate_discovered(&mut self, _: u64, _: IceCandidate) {
console::log_1(&JsValue::from_str(
"on_ice_candidate_discovered invoked",
));
}

/// Disposes specified RTCPeerConnection's.
fn on_peers_removed(&mut self, _peer_ids: Vec<u64>) {
fn on_peers_removed(&mut self, _: Vec<u64>) {
console::log_1(&JsValue::from_str("on_peers_removed invoked"));
}
}
Expand Down
18 changes: 18 additions & 0 deletions proto/client-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub enum Event {
peer_id: u64,
sdp_offer: Option<String>,
tracks: Vec<Track>,
ice_servers: Vec<IceServer>,
},
/// Media Server notifies Web Client about necessity to apply specified SDP
/// Answer to Web Client's RTCPeerConnection.
Expand Down Expand Up @@ -92,6 +93,23 @@ pub struct Track {
pub media_type: MediaType,
}

/// Representation of [RTCIceServer][1] (item of `iceServers` field
/// from [RTCConfiguration][2]).
///
/// [1]: https://developer.mozilla.org/en-US/docs/Web/API/RTCIceServer
/// [2]: https://developer.mozilla.org/en-US/docs/Web/API/RTCConfiguration
#[derive(Clone, Debug)]
#[cfg_attr(feature = "medea", derive(Serialize))]
#[cfg_attr(feature = "jason", derive(Deserialize))]
#[cfg_attr(test, derive(PartialEq))]
pub struct IceServer {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nWacky ,

Требуется использовать conditional компиляцию по аналогии с другими структурами.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexlapa,

Я так понял что при feature = "medea", derive(Serialize);
При "jason" - Deserialize

pub urls: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub username: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub credential: Option<String>,
}

/// Direction of [`Track`].
#[cfg_attr(feature = "medea", derive(Serialize))]
#[cfg_attr(feature = "jason", derive(Deserialize))]
Expand Down
3 changes: 2 additions & 1 deletion signaling_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
}
});

pcs[msg.peer_id] = new RTCPeerConnection();
var configuration = { iceServers: msg.ice_servers };
pcs[msg.peer_id] = new RTCPeerConnection(configuration);

var pc = pcs[msg.peer_id];
pc.ontrack = function (e) {
Expand Down
3 changes: 2 additions & 1 deletion src/api/client/rpc_connection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! [`RpcConnection`] with related messages.

use std::fmt;
use core::fmt;

use actix::Message;
use futures::Future;
Expand Down Expand Up @@ -162,6 +162,7 @@ pub mod test {
peer_id,
sdp_offer,
tracks: _,
ice_servers: _,
} => {
match sdp_offer {
Some(_) => self.room.do_send(CommandMessage::from(
Expand Down
26 changes: 21 additions & 5 deletions src/api/client/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub struct Context {

/// Starts HTTP server for handling WebSocket connections of Client API.
pub fn run(rooms: RoomsRepository, config: Conf) {
let server_addr = config.server.get_bind_addr();
let server_addr = config.server.bind_addr();

server::new(move || {
App::with_state(Context {
Expand Down Expand Up @@ -110,21 +110,36 @@ mod test {

use crate::{
api::control::Member,
conf::{Conf, Server},
conf::{Conf, Server, Turn},
media::create_peers,
signalling::Room,
turn::new_turn_auth_service_mock,
};

use super::*;

/// Creates [`RoomsRepository`] for tests filled with a single [`Room`].
fn room(conf: Rpc) -> RoomsRepository {
let members = hashmap! {
1 => Member{id: 1, credentials: "caller_credentials".into()},
2 => Member{id: 2, credentials: "responder_credentials".into()},
1 => Member{
id: 1,
credentials: "caller_credentials".into(),
ice_user: None
},
2 => Member{
id: 2,
credentials: "responder_credentials".into(),
ice_user: None
},
};
let room = Arbiter::start(move |_| {
Room::new(1, members, create_peers(1, 2), conf.reconnect_timeout)
Room::new(
1,
members,
create_peers(1, 2),
conf.reconnect_timeout,
new_turn_auth_service_mock(),
)
});
let rooms = hashmap! {1 => room};
RoomsRepository::new(rooms)
Expand Down Expand Up @@ -161,6 +176,7 @@ mod test {
idle_timeout: Duration::new(2, 0),
reconnect_timeout: Default::default(),
},
turn: Turn::default(),
server: Server::default(),
};

Expand Down
16 changes: 16 additions & 0 deletions src/api/control/member.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Member definitions and implementations.

use crate::media::IceUser;

/// ID of [`Member`].
pub type Id = u64;

Expand All @@ -11,4 +13,18 @@ pub struct Member {

/// Credentials to authorize [`Member`] with.
pub credentials: String,

/// Turn server credentials.
pub ice_user: Option<IceUser>,
}

impl Member {
/// Returns new instance of [`Memebr`] with given credentials.
pub fn new(id: Id, credentials: String) -> Self {
Self {
id,
credentials,
ice_user: None,
}
}
}
Loading