Skip to content

Commit

Permalink
Merge pull request #845 from nazar-pc/rust-webrtc-server
Browse files Browse the repository at this point in the history
Add `WebRtcServer` support for Rust
  • Loading branch information
nazar-pc authored Jun 29, 2022
2 parents ca365d9 + b472c18 commit a4c7fec
Show file tree
Hide file tree
Showing 45 changed files with 1,485 additions and 271 deletions.
30 changes: 17 additions & 13 deletions .github/workflows/mediasoup-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ jobs:
ci:
strategy:
matrix:
# Just 1 OS should be fine for TypeScript.
os:
- ubuntu-22.04
# - macos-11.0
# - windows-2019
node:
- 14
- 16
- 18
runs-on: ${{ matrix.os }}
# Different Node versions on Ubuntu, the latest Node on other platforms
ci:
- os: ubuntu-22.04
node: 14
- os: ubuntu-22.04
node: 16
- os: ubuntu-22.04
node: 18
- os: macos-12
node: 18
- os: windows-2022
node: 18
runs-on: ${{ matrix.ci.os }}

steps:
- name: Checkout
Expand All @@ -24,18 +27,19 @@ jobs:
- name: Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
node-version: ${{ matrix.ci.node }}

- name: Configure cache
uses: actions/cache@v2
with:
path: |
~/.npm
key: ${{ matrix.os }}-node-${{ hashFiles('**/package.json') }}
key: ${{ matrix.ci.os }}-node-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ matrix.os }}-node-
${{ matrix.ci.os }}-node-
- run: npm install
- run: npm run lint:node
if: runner.os == 'Linux'
- run: npm run typescript:build
- run: npm run test:node
4 changes: 2 additions & 2 deletions node/tests/test-WebRtcServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ test('worker.createWebRtcServer() with unavailable listenInfos rejects with Erro
},
{
protocol : 'udp',
ip : '0.0.0.0',
ip : '127.0.0.1',
announcedIp : '1.2.3.4',
port : port1
}
Expand All @@ -165,7 +165,7 @@ test('worker.createWebRtcServer() with unavailable listenInfos rejects with Erro
});

// Using the same UDP port in a second Worker.
await expect(worker1.createWebRtcServer(
await expect(worker2.createWebRtcServer(
{
listenInfos :
[
Expand Down
4 changes: 2 additions & 2 deletions npm-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ switch (task)
}
else
{
execute('rmdir /s /q node/lib');
execute('rmdir /s /q "node/lib"');
}

execute('tsc --project node');
Expand All @@ -46,7 +46,7 @@ switch (task)
}
else
{
execute('rmdir /s /q node/lib');
execute('rmdir /s /q "node/lib"');
}

const watch = new TscWatchClient();
Expand Down
1 change: 1 addition & 0 deletions rust/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* nlohmann_json 3.10.5.
* usrsctp snapshot 4e06feb01cadcd127d119486b98a4bd3d64aa1e7.
* wingetopt 1.00.
* `WebRtcServer`: A new class that brings to `WebRtcTransports` the ability to listen on a single UDP/TCP port (PR #834, PR #845).

# 0.9.3

Expand Down
3 changes: 2 additions & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.9.3"
description = "Cutting Edge WebRTC Video Conferencing in Rust"
categories = ["api-bindings", "multimedia", "network-programming"]
authors = ["Nazar Mokrynskyi <[email protected]>"]
edition = "2018"
edition = "2021"
license = "ISC"
keywords = ["webrtc", "ortc", "sfu"]
documentation = "https://docs.rs/mediasoup"
Expand Down Expand Up @@ -70,6 +70,7 @@ actix-web-actors = "4.1.0"
async-io = "1.6.0"
criterion = "0.3.5"
env_logger = "0.9.0"
portpicker = "0.1.1"

[dev-dependencies.actix-web]
default-features = false
Expand Down
9 changes: 4 additions & 5 deletions rust/examples/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,10 @@ impl EchoConnection {
// We know that for echo example we'll need 2 transports, so we can create both right away.
// This may not be the case for real-world applications or you may create this at a
// different time and/or in different order.
let transport_options =
WebRtcTransportOptions::new(TransportListenIps::new(TransportListenIp {
ip: "127.0.0.1".parse().unwrap(),
announced_ip: None,
}));
let transport_options = WebRtcTransportOptions::new(TransportListenIps::new(ListenIp {
ip: "127.0.0.1".parse().unwrap(),
announced_ip: None,
}));
let producer_transport = router
.create_webrtc_transport(transport_options.clone())
.await
Expand Down
4 changes: 2 additions & 2 deletions rust/examples/multiopus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl EchoConnection {
// For simplicity we will create plain transport for audio producer right away
let plain_transport = router
.create_plain_transport({
let mut options = PlainTransportOptions::new(TransportListenIp {
let mut options = PlainTransportOptions::new(ListenIp {
ip: "127.0.0.1".parse().unwrap(),
announced_ip: None,
});
Expand Down Expand Up @@ -225,7 +225,7 @@ impl EchoConnection {
// this at a different time and/or in different order.
let consumer_transport = router
.create_webrtc_transport(WebRtcTransportOptions::new(TransportListenIps::new(
TransportListenIp {
ListenIp {
ip: "127.0.0.1".parse().unwrap(),
announced_ip: None,
},
Expand Down
9 changes: 4 additions & 5 deletions rust/examples/svc-simulcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,10 @@ impl SvcSimulcastConnection {
// right away.
// This may not be the case for real-world applications or you may create this at a
// different time and/or in different order.
let transport_options =
WebRtcTransportOptions::new(TransportListenIps::new(TransportListenIp {
ip: "127.0.0.1".parse().unwrap(),
announced_ip: None,
}));
let transport_options = WebRtcTransportOptions::new(TransportListenIps::new(ListenIp {
ip: "127.0.0.1".parse().unwrap(),
announced_ip: None,
}));
let producer_transport = router
.create_webrtc_transport(transport_options.clone())
.await
Expand Down
2 changes: 1 addition & 1 deletion rust/examples/videoroom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ mod participant {
// right away. This may not be the case for real-world applications or you may create
// this at a different time and/or in different order.
let transport_options =
WebRtcTransportOptions::new(TransportListenIps::new(TransportListenIp {
WebRtcTransportOptions::new(TransportListenIps::new(ListenIp {
ip: "127.0.0.1".parse().unwrap(),
announced_ip: None,
}));
Expand Down
12 changes: 6 additions & 6 deletions rust/src/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl AppData {
/// If you use "0.0.0.0" or "::" as ip value, then you need to also provide `announced_ip`.
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TransportListenIp {
pub struct ListenIp {
/// Listening IPv4 or IPv6.
pub ip: IpAddr,
/// Announced IPv4 or IPv6 (useful when running mediasoup behind NAT with private IP).
Expand Down Expand Up @@ -111,7 +111,7 @@ pub enum IceCandidateTcpType {
/// Transport protocol.
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum TransportProtocol {
pub enum Protocol {
/// TCP.
Tcp,
/// UDP.
Expand All @@ -130,7 +130,7 @@ pub struct IceCandidate {
/// The IP address of the candidate.
pub ip: IpAddr,
/// The protocol of the candidate.
pub protocol: TransportProtocol,
pub protocol: Protocol,
/// The port for the candidate.
pub port: u16,
/// The type of candidate (always `Host`).
Expand Down Expand Up @@ -182,7 +182,7 @@ pub enum TransportTuple {
/// Remote port.
remote_port: u16,
/// Protocol
protocol: TransportProtocol,
protocol: Protocol,
},
/// Transport tuple without remote endpoint info.
#[serde(rename_all = "camelCase")]
Expand All @@ -192,7 +192,7 @@ pub enum TransportTuple {
/// Local port.
local_port: u16,
/// Protocol
protocol: TransportProtocol,
protocol: Protocol,
},
}

Expand All @@ -210,7 +210,7 @@ impl TransportTuple {
}

/// Protocol.
pub fn protocol(&self) -> TransportProtocol {
pub fn protocol(&self) -> Protocol {
let (Self::WithRemote { protocol, .. } | Self::LocalOnly { protocol, .. }) = self;
*protocol
}
Expand Down
1 change: 1 addition & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub mod scalability_modes;
pub mod sctp_parameters;
pub mod srtp_parameters;
pub mod supported_rtp_capabilities;
pub mod webrtc_server;
pub mod worker;
pub mod worker_manager;

Expand Down
Loading

0 comments on commit a4c7fec

Please sign in to comment.