Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FBS Transport::Tuple everywhere #1148

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 25 additions & 1 deletion node/src/Transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1310,14 +1310,38 @@ export function parseSctpState(fbsSctpState: FbsSctpState): SctpState
}
}

export function parseProtocol(protocol: FbsTransport.Protocol): TransportProtocol
{
switch (protocol)
{
case FbsTransport.Protocol.UDP:
return 'udp';

case FbsTransport.Protocol.TCP:
return 'tcp';
}
}

export function serializeProtocol(protocol: TransportProtocol): FbsTransport.Protocol
{
switch (protocol)
{
case 'udp':
return FbsTransport.Protocol.UDP;

case 'tcp':
return FbsTransport.Protocol.TCP;
}
}

export function parseTuple(binary: FbsTransport.Tuple): TransportTuple
{
return {
localIp : binary.localIp()!,
localPort : binary.localPort(),
remoteIp : binary.remoteIp() ?? undefined,
remotePort : binary.remotePort(),
protocol : binary.protocol()! as TransportProtocol
protocol : parseProtocol(binary.protocol())
};
}

Expand Down
3 changes: 2 additions & 1 deletion node/src/WebRtcTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
parseSctpState,
parseBaseTransportDump,
parseBaseTransportStats,
parseProtocol,
parseTransportTraceEventData,
parseTuple,
BaseTransportDump,
Expand Down Expand Up @@ -741,7 +742,7 @@ function parseIceCandidate(binary: FbsWebRtcTransport.IceCandidate): IceCandidat
foundation : binary.foundation()!,
priority : binary.priority(),
ip : binary.ip()!,
protocol : binary.protocol() as TransportProtocol,
protocol : parseProtocol(binary.protocol()),
port : binary.port(),
type : 'host',
tcpType : binary.tcpType() === 'passive' ? 'passive' : undefined
Expand Down
5 changes: 3 additions & 2 deletions node/src/tests/test-WebRtcTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as mediasoup from '../';
import { Notification, Body as NotificationBody, Event } from '../fbs/notification';
import * as FbsTransport from '../fbs/transport';
import * as FbsWebRtcTransport from '../fbs/web-rtc-transport';
import { serializeProtocol, TransportTuple } from '../Transport';

const { createWorker } = mediasoup;

Expand Down Expand Up @@ -517,7 +518,7 @@ test('WebRtcTransport events succeed', async () =>
builder.clear();

const onIceSelectedTuple = jest.fn();
const iceSelectedTuple =
const iceSelectedTuple: TransportTuple =
{
localIp : '1.1.1.1',
localPort : 1111,
Expand All @@ -536,7 +537,7 @@ test('WebRtcTransport events succeed', async () =>
iceSelectedTuple.localPort,
iceSelectedTuple.remoteIp,
iceSelectedTuple.remotePort,
iceSelectedTuple.protocol)
serializeProtocol(iceSelectedTuple.protocol))
);

notificationOffset = Notification.createNotification(
Expand Down
12 changes: 5 additions & 7 deletions rust/src/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,10 @@ pub enum Protocol {
}

impl Protocol {
// TODO: Use the Protocol FBS type.
pub(crate) fn from_fbs(protocol: &str) -> Self {
pub(crate) fn from_fbs(protocol: transport::Protocol) -> Self {
match protocol {
"tcp" => Protocol::Tcp,
"udp" => Protocol::Udp,
_ => todo!(),
transport::Protocol::Tcp => Protocol::Tcp,
transport::Protocol::Udp => Protocol::Udp,
}
}
}
Expand Down Expand Up @@ -284,12 +282,12 @@ impl TransportTuple {
.parse()
.expect("Error parsing IP address"),
remote_port: tuple.remote_port,
protocol: Protocol::from_fbs(tuple.protocol.as_str()),
protocol: Protocol::from_fbs(tuple.protocol),
},
None => TransportTuple::LocalOnly {
local_ip: tuple.local_ip.parse().expect("Error parsing IP address"),
local_port: tuple.local_port,
protocol: Protocol::from_fbs(tuple.protocol.as_str()),
protocol: Protocol::from_fbs(tuple.protocol),
},
}
}
Expand Down
Loading
Loading