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

Commit

Permalink
Decompose IceCandidate message (#21)
Browse files Browse the repository at this point in the history
- split IceCandidate message into: candidate, sdp_m_line_index, sdp_mid
- update 0002-webrc-client-api RFC
  • Loading branch information
alexlapa authored May 9, 2019
1 parent bc48960 commit a3ad134
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 25 deletions.
78 changes: 68 additions & 10 deletions docs/rfc/0002-webrc-client-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,16 @@ This event is sent during SDP negotiation/re-negotiation.
```rust
struct IceCandidateDiscovered {
peer_id: u64,
candidate: IceCandidate,
}
```

Related objects:
```rust
struct IceCandidate {
candidate: String,
sdp_m_line_index: Option<u16>,
sdp_mid: Option<String>,
}
```

Expand Down Expand Up @@ -895,7 +904,16 @@ struct MakeSdpAnswer {
```rust
struct SetIceCandidate {
peer_id: u64,
candidate: IceCandidate,
}
```

Related objects:
```rust
struct IceCandidate {
candidate: String,
sdp_m_line_index: Option<u16>,
sdp_mid: Option<String>,
}
```

Expand Down Expand Up @@ -1183,7 +1201,11 @@ struct GetMembers {
"command": "SetIceCandidate",
"data": {
"peer_id": 1,
"candidate": "user1_ice_candidate"
"candidate": {
"candidate": "user1_ice_candidate",
"sdp_m_line_index": 0,
"sdp_mid": "0"
}
}
}
```
Expand All @@ -1195,7 +1217,11 @@ struct GetMembers {
"event": "IceCandidateDiscovered",
"data": {
"peer_id": 2,
"candidate": "user1_ice_candidate"
"candidate": {
"candidate": "user1_ice_candidate",
"sdp_m_line_index": 0,
"sdp_mid": "0"
}
}
}
```
Expand All @@ -1207,7 +1233,11 @@ struct GetMembers {
"command": "SetIceCandidate",
"data": {
"peer_id": 2,
"candidate": "user2_ice_candidate"
"candidate": {
"candidate": "user2_ice_candidate",
"sdp_m_line_index": 0,
"sdp_mid": "0"
}
}
}
```
Expand All @@ -1219,7 +1249,11 @@ struct GetMembers {
"event": "IceCandidateDiscovered",
"data": {
"peer_id": 1,
"candidate": "user2_ice_candidate"
"candidate": {
"candidate": "user2_ice_candidate",
"sdp_m_line_index": 0,
"sdp_mid": "0"
}
}
}
```
Expand Down Expand Up @@ -1503,7 +1537,11 @@ struct GetMembers {
"command": "SetIceCandidate",
"data": {
"peer_id": 1,
"candidate": "user1_ice_candidate"
"candidate": {
"candidate": "user1_ice_candidate",
"sdp_m_line_index": 0,
"sdp_mid": "0"
}
}
}
```
Expand All @@ -1515,7 +1553,11 @@ struct GetMembers {
"event": "IceCandidateDiscovered",
"data": {
"peer_id": 1,
"candidate": "server_ice_candidate"
"candidate": {
"candidate": "server_ice_candidate",
"sdp_m_line_index": 0,
"sdp_mid": "0"
}
}
}
```
Expand Down Expand Up @@ -1594,7 +1636,11 @@ struct GetMembers {
"command": "SetIceCandidate",
"data": {
"peer_id": 2,
"candidate": "user2_ice_candidate"
"candidate": {
"candidate": "user2_ice_candidate",
"sdp_m_line_index": 0,
"sdp_mid": "0"
}
}
}
```
Expand All @@ -1606,7 +1652,11 @@ struct GetMembers {
"event": "IceCandidateDiscovered",
"data": {
"peer_id": 2,
"candidate": "server_ice_candidate"
"candidate": {
"candidate": "server_ice_candidate",
"sdp_m_line_index": 0,
"sdp_mid": "0"
}
}
}
```
Expand Down Expand Up @@ -1729,7 +1779,11 @@ struct GetMembers {
"command": "SetIceCandidate",
"data": {
"peer_id": 3,
"candidate": "user3_ice_candidate"
"candidate": {
"candidate": "user3_ice_candidate",
"sdp_m_line_index": 0,
"sdp_mid": "0"
}
}
}
```
Expand All @@ -1741,7 +1795,11 @@ struct GetMembers {
"event": "IceCandidateDiscovered",
"data": {
"peer_id": 3,
"candidate": "server_ice_candidate"
"candidate": {
"candidate": "server_ice_candidate",
"sdp_m_line_index": 0,
"sdp_mid": "0"
}
}
}
```
Expand Down
13 changes: 10 additions & 3 deletions signaling_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@

var pc = pcs[msg.peer_id];
pc.ontrack = function (e) {
console.log("ontrack");
partnervid.srcObject = e.streams[0];
};

Expand Down Expand Up @@ -126,7 +125,11 @@
command: "SetIceCandidate",
data: {
peer_id: msg.peer_id,
candidate: JSON.stringify(e.candidate)
candidate: {
candidate: e.candidate.candidate,
sdp_mid: e.candidate.sdpMid,
sdp_m_line_index: e.candidate.sdpMLineIndex
}
}
}))
}
Expand All @@ -141,7 +144,11 @@

async function handleIceCandidateDiscovered(msg) {
var pc = pcs[msg.peer_id];
pc.addIceCandidate(JSON.parse(msg.candidate));
pc.addIceCandidate( {
candidate:msg.candidate.candidate,
sdpMid:msg.candidate.sdp_mid,
sdpMLineIndex: msg.candidate.sdp_m_line_index,
});
}

</script>
Expand Down
7 changes: 6 additions & 1 deletion src/api/client/rpc_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub mod test {
};
use futures::future::Future;

use crate::api::protocol::IceCandidate;
use crate::{
api::{
client::rpc_connection::{
Expand Down Expand Up @@ -158,7 +159,11 @@ pub mod test {
}
self.room.do_send(Command::SetIceCandidate {
peer_id,
candidate: "ice_candidate".into(),
candidate: IceCandidate {
candidate: "ice_candidate".to_owned(),
sdp_m_line_index: None,
sdp_mid: None,
},
})
}
Event::IceCandidateDiscovered {
Expand Down
20 changes: 17 additions & 3 deletions src/api/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ pub enum Command {
/// Web Client sends SDP Answer.
MakeSdpAnswer { peer_id: u64, sdp_answer: String },
/// Web Client sends Ice Candidate.
SetIceCandidate { peer_id: u64, candidate: String },
SetIceCandidate {
peer_id: u64,
candidate: IceCandidate,
},
}

/// WebSocket message from Medea to Jason.
Expand All @@ -60,14 +63,25 @@ pub enum Event {

/// Media Server notifies Web Client about necessity to apply specified
/// ICE Candidate.
IceCandidateDiscovered { peer_id: u64, candidate: String },
IceCandidateDiscovered {
peer_id: u64,
candidate: IceCandidate,
},

/// Media Server notifies Web Client about necessity of RTCPeerConnection
/// close.
PeersRemoved { peer_ids: Vec<u64> },
}

/// [`Track] with specified direction.
/// Represents [`RtcIceCandidateInit`] object.
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
pub struct IceCandidate {
pub candidate: String,
pub sdp_m_line_index: Option<u16>,
pub sdp_mid: Option<String>,
}

/// [`Track`] with specified direction.
#[derive(Deserialize, Serialize, Debug)]
#[cfg_attr(test, derive(PartialEq))]
pub struct Directional {
Expand Down
2 changes: 2 additions & 0 deletions src/conf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ mod conf_parse_spec {
assert_ne!(new_config.rpc.idle_timeout, defaults.rpc.idle_timeout);
}

// TODO: This test seems to pollute environment and might
// fail from time to time.
#[test]
#[serial]
fn env_overrides_defaults() {
Expand Down
21 changes: 13 additions & 8 deletions src/signalling/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
RpcConnectionEstablished,
},
control::{Member, MemberId},
protocol::{Command, Event},
protocol::{Command, Event, IceCandidate},
},
log::prelude::*,
media::{
Expand Down Expand Up @@ -193,7 +193,7 @@ impl Room {
fn handle_set_ice_candidate(
&mut self,
from_peer_id: PeerId,
candidate: String,
candidate: IceCandidate,
) -> Result<ActFuture<(), RoomError>, RoomError> {
let from_peer = self.peers.get_peer(from_peer_id)?;
if let PeerStateMachine::New(_) = from_peer {
Expand Down Expand Up @@ -412,10 +412,7 @@ impl Handler<RpcConnectionClosed> for Room {

#[cfg(test)]
mod test {
use std::sync::{
atomic::{AtomicUsize, Ordering},
Arc, Mutex,
};
use std::sync::{atomic::AtomicUsize, Arc, Mutex};

use actix::{Addr, Arbiter, System};

Expand Down Expand Up @@ -494,7 +491,11 @@ mod test {
.unwrap(),
serde_json::to_string(&Event::IceCandidateDiscovered {
peer_id: 1,
candidate: "ice_candidate".into(),
candidate: IceCandidate {
candidate: "ice_candidate".to_owned(),
sdp_m_line_index: None,
sdp_mid: None
},
})
.unwrap(),
]
Expand Down Expand Up @@ -522,7 +523,11 @@ mod test {
.unwrap(),
serde_json::to_string(&Event::IceCandidateDiscovered {
peer_id: 2,
candidate: "ice_candidate".into(),
candidate: IceCandidate {
candidate: "ice_candidate".to_owned(),
sdp_m_line_index: None,
sdp_mid: None
},
})
.unwrap(),
]
Expand Down

0 comments on commit a3ad134

Please sign in to comment.