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

WebRTC relay mode configuration #79

Merged
merged 16 commits into from
Jan 21, 2020
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ All user visible changes to this project will be documented in this file. This p
- Filter `SetIceCandidate` messages without `candidate` ([#50](/../../pull/50));
- Send reason of closing WebSocket connection as [Close](https://tools.ietf.org/html/rfc4566#section-5.14) frame's description ([#58](/../../pull/58));
- Send `Event::RpcSettingsUpdated` when `Member` connects ([#75]);
- Send relay mode in `Event::PeerCreated` which is used for configuring client's `RtcIceTransportPolicy` ([#79](/../../pull/79)).
- Configuration:
- `[server.control.grpc]` section to configure Control API gRPC server ([#33]);
- `server.client.http.public_url` option to configure public URL of Client API HTTP server ([#33]);
Expand Down
263 changes: 134 additions & 129 deletions Cargo.lock

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions _dev/specs/relay-pub-pub-video-call.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
kind: Room
id: relay-pub-pub-video-call
spec:
pipeline:
caller:
kind: Member
credentials: test
on_join: "grpc://127.0.0.1:9099"
on_leave: "grpc://127.0.0.1:9099"
spec:
pipeline:
publish:
kind: WebRtcPublishEndpoint
spec:
p2p: Always
force_relay: true
play-responder:
kind: WebRtcPlayEndpoint
spec:
src: "local://relay-pub-pub-video-call/responder/publish"
force_relay: true
responder:
kind: Member
credentials: test
on_join: "grpc://127.0.0.1:9099"
on_leave: "grpc://127.0.0.1:9099"
spec:
pipeline:
publish:
kind: WebRtcPublishEndpoint
spec:
p2p: Always
force_relay: true
play-caller:
kind: WebRtcPlayEndpoint
spec:
src: "local://relay-pub-pub-video-call/caller/publish"
force_relay: true
3 changes: 3 additions & 0 deletions docs/rfc/0001-control-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ spec:
on_start: "http://127.0.0.1:8080/publish/started"
# Fires when "caller" client stops publishing media data.
on_stop: "http://127.0.0.1:8080/publish/stopped"
# All media will be relayed through TURN server.
force_relay: false
# Media element which is able to play media data for client via WebRTC.
play:
kind: WebRtcPlayEndpoint
Expand Down Expand Up @@ -796,6 +798,7 @@ message WebRtcPublishEndpoint {
optional string dst = 2;
optional string on_start = 3;
optional string on_stop = 4;
optional bool force_relay = 5;

enum P2P {
NEVER = 0;
Expand Down
219 changes: 110 additions & 109 deletions docs/rfc/0002-webrc-client-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,17 @@ Where:

```rust
struct PeerCreated {
peer: Peer,
peer_id: PeerId,
sdp_offer: Option<String>,
ice_servers: Vec<ICEServer>,
tracks: Vec<Track>,
ice_servers: Vec<IceServer>,
force_relay: bool,
}
```

Related objects:
```rust
struct ICEServer {
struct IceServer {
urls: Vec<String>,
username: String,
credential: String,
Expand All @@ -231,9 +233,11 @@ struct ICEServer {
`Media Server` notifies about necessity of [RTCPeerConnection] creation.

Params:
1. `peer`: peer connection settings.
1. `peer_id`: created `Peer`'s ID.
2. `sdp_offer`: if `None`, client should create [SDP Offer] and pass it to the server; if `Some`, client should set it as remote description, then create [SDP Answer], set it as local description, and pass it to the server.
3. `ice_servers`: list of [ICE server]s that should be used to construct [RTCPeerConnection].
3. `tracks`: tracks of this `Peer`.
4. `ice_servers`: list of [ICE server]s that should be used to construct [RTCPeerConnection].
5. `force_relay`: if `true` then all media will be relayed through [TURN] server.

The most important part of `Peer` object is a list of `Track`s.
- All `TrackDirection::Send` `Track`s must be created according to their settings and added to the `Peer`.
Expand All @@ -246,54 +250,52 @@ The most important part of `Peer` object is a list of `Track`s.

```json
{
"peer": {
"peer_id": 1,
"tracks": [{
"id": 1,
"media_type": {
"Audio": {}
},
"direction": {
"Send": {
"receivers": [2],
"mid": null
}
"peer_id": 1,
"tracks": [{
"id": 1,
"media_type": {
"Audio": {}
},
"direction": {
"Send": {
"receivers": [2],
"mid": null
}
}, {
"id": 2,
"media_type": {
"Video": {}
},
"direction": {
"Send": {
"receivers": [2],
"mid": null
}
}
}, {
"id": 2,
"media_type": {
"Video": {}
},
"direction": {
"Send": {
"receivers": [2],
"mid": null
}
}, {
"id": 3,
"media_type": {
"Audio": {}
},
"direction": {
"Recv": {
"sender": 2,
"mid": null
}
}
}, {
"id": 3,
"media_type": {
"Audio": {}
},
"direction": {
"Recv": {
"sender": 2,
"mid": null
}
}, {
"id": 4,
"media_type": {
"Video": {}
},
"direction": {
"Recv": {
"sender": 2,
"mid": null
}
}
}, {
"id": 4,
"media_type": {
"Video": {}
},
"direction": {
"Recv": {
"sender": 2,
"mid": null
}
}
]},
}],
"sdp_offer": null,
"ice_servers": [{
"urls": [
Expand All @@ -302,7 +304,8 @@ The most important part of `Peer` object is a list of `Track`s.
],
"username": "turn_user",
"credential": "turn_credential"
}]
}],
"force_relay": false
}
```

Expand All @@ -323,21 +326,19 @@ After negotiation is done and media starts flowing, `Web Client` might receive n

```json
{
"peer": {
"peer_id": 1,
"tracks": [{
"id": 1,
"media_type": {
"Audio": {}
},
"direction": {
"Send": {
"receivers": [],
"mid": null
}
"peer_id": 1,
"tracks": [{
"id": 1,
"media_type":{
"Audio":{}
},
"direction": {
"Send": {
"receivers": [],
"mid": null
}
}]
},
}
}],
"sdp_offer": "server_user1_recvonly_offer",
"ice_servers": [{
"urls": [
Expand All @@ -346,7 +347,8 @@ After negotiation is done and media starts flowing, `Web Client` might receive n
],
"username": "turn_user",
"credential": "turn_credential"
}]
}],
"force_relay": false
}
```

Expand Down Expand Up @@ -1086,54 +1088,52 @@ Metrics list will be extended as needed.
{
"event": "PeerCreated",
"data": {
"peer": {
"peer_id": 1,
"tracks": [{
"id": 1,
"media_type": {
"Audio": {}
},
"direction": {
"Send": {
"receivers": [2],
"mid": null
}
"peer_id": 1,
"tracks": [{
"id": 1,
"media_type": {
"Audio": {}
},
"direction": {
"Send": {
"receivers": [2],
"mid": null
}
}, {
"id": 2,
"media_type": {
"Video": {}
},
"direction": {
"Send": {
"receivers": [2],
"mid": null
}
}
}, {
"id": 2,
"media_type": {
"Video": {}
},
"direction": {
"Send": {
"receivers": [2],
"mid": null
}
}, {
"id": 3,
"media_type": {
"Audio": {}
},
"direction": {
"Recv": {
"sender": 2,
"mid": null
}
}
}, {
"id": 3,
"media_type": {
"Audio": {}
},
"direction": {
"Recv": {
"sender": 2,
"mid": null
}
}, {
"id": 4,
"media_type": {
"Video": {}
},
"direction": {
"Recv": {
"sender": 2,
"mid": null
}
}
}, {
"id": 4,
"media_type": {
"Video": {}
},
"direction": {
"Recv": {
"sender": 2,
"mid": null
}
}]
},
}
}],
"sdp_offer": null,
"ice_servers": [{
"urls": [
Expand All @@ -1142,7 +1142,8 @@ Metrics list will be extended as needed.
],
"username": "turn_user",
"credential": "turn_credential"
}]
}],
"force_relay": false
}
}
```
Expand Down
2 changes: 2 additions & 0 deletions jason/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ All user visible changes to this project will be documented in this file. This p
- `Room.join()`;
- Ability to inject local video/audio stream into `Room` via `Room.inject_local_stream()` ([#54]);
- `Room.on_failed_local_stream` callback ([#54]);
- `Room.on_close` callback for WebSocket close initiated by server ([#55]);
- `RtcIceTransportPolicy` configuration ([#79](/../../pull/79)).
- Room management:
- Library API:
- `Room.on_connection_loss` callback that JS side can start Jason reconnection on connection loss with ([#75]);
Expand Down
1 change: 1 addition & 0 deletions jason/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ wee_alloc = { version = "0.4", optional = true }
"RtcIceCandidate", "RtcIceCandidateInit",
"RtcIceConnectionState",
"RtcIceServer",
"RtcIceTransportPolicy",
"RtcPeerConnection", "RtcPeerConnectionIceEvent",
"RtcRtpReceiver", "RtcRtpSender",
"RtcRtpTransceiver", "RtcRtpTransceiverDirection",
Expand Down
1 change: 1 addition & 0 deletions jason/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
publish: {
kind: 'WebRtcPublishEndpoint',
p2p: 'Always',
force_relay: false,
},
};

Expand Down
Loading