Experimental Sans-I/O WebRTC stack for MoonBit
Dependencies
///|
test "inject a deterministic clock sample" {
let monotonic = @rtc.Instant::from_milliseconds(42L)
let wall = @rtc.WallTime::from_unix_nanoseconds(1700000000000000000L)
let sample = @rtc.ClockSample::new(monotonic~, wall~)
assert_eq(sample.monotonic().as_milliseconds(), 42L)
assert_eq(sample.wall().as_unix_nanoseconds(), 1700000000000000000L)
}moon run --target native examples/sans_io_datachannelmoon fmt --check
moon check --target native --warn-list +73
moon test --target native
scripts/test-rust-interop
scripts/test-chromium-interop
scripts/test-coturn-interop
scripts/audit-upstream.mjs \
--upstream /path/to/webrtc-rs-rtc \
--write-ledger docs/upstream-coverage.json
moon bench --release --target native --no-parallelize
moon infopub(all) suberror RtcError {
InvalidConfiguration(String)
InvalidState(String)
BackpressureExceeded
CryptoUnavailable(String)
Sdp(SdpError)
Stun(StunError)
Turn(TurnError)
Mdns(MdnsError)
Ice(IceError)
Dtls(DtlsError)
Srtp(SrtpError)
Sctp(SctpError)
DataChannel(DataChannelError)
Interceptor(InterceptorError)
Closed
} derive(Eq, Debug)pub(all) struct CandidatePairStats {
id : String
local_candidate : IceCandidate
remote_candidate : IceCandidate
priority : UInt64
state : CandidatePairState
nominated : Bool
selected : Bool
} derive(Eq, Debug)pub struct Configuration {
ice_servers : Array[IceServer]
ice_transport_policy : IceTransportPolicy
mdns_mode : Mode
host_candidates : Array[IceCandidate]
sctp_port : UInt16
max_message_size : UInt64
command_capacity : Int
event_capacity : Int
message_capacity : Int
settings : Settings
interceptor_pipeline : Pipeline
encoded_transform_pipeline : EncodedTransformPipeline
}fn Configuration::new(ice_servers? : Array[IceServer], ice_transport_policy? : IceTransportPolicy, mdns_mode? : Mode, host_candidates? : Array[IceCandidate], sctp_port? : UInt16, max_message_size? : UInt64, command_capacity? : Int, event_capacity? : Int, message_capacity? : Int, settings? : Settings, interceptor_pipeline? : Pipeline, encoded_transform_pipeline? : EncodedTransformPipeline) -> Configuration raise RtcErrorpub(all) struct DataChannelStats {
id : String
stream_id : StreamId
label : String
protocol : String
state : DataChannelState
buffered_amount : UInt64
} derive(Eq, Debug)pub(all) struct DetailedStatsReport {
timestamp : WallTime
codecs : Array[CodecStats]
outbound_rtp : Array[RtpStreamStats]
inbound_rtp : Array[RtpStreamStats]
candidate_pairs : Array[CandidatePairStats]
data_channels : Array[DataChannelStats]
transport : TransportStats
} derive(Eq, Debug)pub struct PeerConnection {
configuration : Configuration
clock_sample : ClockSample
signaling : SignalingStateMachine
identity : CertificateIdentity
local_credentials : IceCredentials
session_id : UInt64
session_version : UInt64
tie_breaker : UInt64
events : Queue[PeerEvent]
messages : Queue[RtcMessage]
outbound : Queue[OutboundDatagram]
io_actions : Queue[IoAction]
pending_streams : Array[PendingRtcStream]
active_streams : Array[ActiveRtcStream]
active_listeners : Array[ActiveRtcListener]
next_connection_id : UInt64
next_listener_id : UInt64
local_transport_candidates : Array[IceCandidate]
local_advertised_candidates : Array[IceCandidate]
srflx_gatherers : Array[SrflxGatherer]
turn_allocations : Array[Allocation]
pending_relay_datagrams : Array[PendingRelayDatagram]
remote_candidates : Array[IceCandidate]
mdns_resolver : Resolver
pending_mdns_candidates : Map[QueryId, IceCandidate]
state : PeerConnectionState
gathering_state : IceGatheringState
data_manager : Manager?
ice_agent : IceAgent?
dtls_endpoint : Endpoint?
data_transport : Transport?
local_media_sections : Array[LocalMediaSection]
remote_media_sections : Array[RemoteMediaSection]
outbound_srtp : Context?
inbound_srtp : Context?
media_started : Bool
rtcp_sender_ssrc : UInt
next_rtcp_report : Instant?
next_transport_sequence : UInt16
remote_twcc_recorder : TwccRecorder?
data_channel_buffered_amount_low_thresholds : Map[StreamId, UInt64]
transport_started : Bool
ice_restart_pending : Bool
dtls_started : Bool
data_started : Bool
closing : Bool
bytes_sent : UInt64
bytes_received : UInt64
packets_sent : UInt64
packets_received : UInt64
data_channels_opened : UInt
data_channels_closed : UInt
}fn PeerConnection::add_ice_candidate(self : PeerConnection, candidate : IceCandidate, now : Instant) -> Unit raise RtcErrorfn PeerConnection::add_track(self : PeerConnection, track : MediaTrack, now : Instant) -> RtpTransceiver raise RtcErrorfn PeerConnection::add_transceiver(self : PeerConnection, kind : MediaKind, direction? : TransceiverDirection, now~ : Instant) -> RtpTransceiver raise RtcErrorfn PeerConnection::close_data_channel(self : PeerConnection, channel_id : StreamId, now : Instant) -> Unit raise RtcErrorfn PeerConnection::create_answer(self : PeerConnection, now : Instant) -> SessionDescription raise RtcErrorfn PeerConnection::create_data_channel(self : PeerConnection, config : DataChannelConfig, now : Instant) -> DataChannel raise RtcErrorfn PeerConnection::create_offer(self : PeerConnection, now : Instant) -> SessionDescription raise RtcErrorfn PeerConnection::create_pranswer(self : PeerConnection, now : Instant) -> SessionDescription raise RtcErrorfn PeerConnection::data_channel_buffered_amount(self : PeerConnection, channel_id : StreamId) -> UInt64fn PeerConnection::data_channel_buffered_amount_low_threshold(self : PeerConnection, channel_id : StreamId) -> UInt64fn PeerConnection::handle_datagram(self : PeerConnection, datagram : InboundDatagram) -> Unit raise RtcErrorfn PeerConnection::handle_mdns_datagram(self : PeerConnection, datagram : InboundDatagram) -> Unit raise RtcErrorfn PeerConnection::handle_message(self : PeerConnection, message : RtcMessage, now : Instant) -> Unit raise RtcErrorfn PeerConnection::local_track_encodings(self : PeerConnection, track_id : String) -> Array[RtpEncodingParameters]fn PeerConnection::new(configuration : Configuration, clock_sample : ClockSample) -> PeerConnection raise RtcErrorfn PeerConnection::remove_track(self : PeerConnection, track_id : String, now : Instant) -> Unit raise RtcErrorfn PeerConnection::set_data_channel_buffered_amount_low_threshold(self : PeerConnection, channel_id : StreamId, threshold : UInt64) -> Unit raise RtcErrorfn PeerConnection::set_local_description(self : PeerConnection, description : SessionDescription, now : Instant) -> Unit raise RtcErrorfn PeerConnection::set_remote_description(self : PeerConnection, description : SessionDescription, now : Instant) -> Unit raise RtcErrorfn PeerConnection::set_remote_description_perfect(self : PeerConnection, description : SessionDescription, policy : OfferCollisionPolicy, now : Instant) -> Unit raise RtcErrorfn PeerConnection::set_sender_encodings(self : PeerConnection, track_id : String, encodings : Array[RtpEncodingParameters], now : Instant) -> Unit raise RtcErrorpub(all) enum PeerEvent {
SignalingStateChanged(SignalingState)
IceGatheringStateChanged(IceGatheringState)
IceConnectionStateChanged(IceConnectionState)
ConnectionStateChanged(PeerConnectionState)
IceCandidateDiscovered(IceCandidate)
TrackOpened(MediaTrack)
TrackClosed(String)
DataChannelOpened(DataChannel)
DataChannelClosed(StreamId)
BufferedAmountLow(StreamId)
NegotiationNeeded
Closed
} derive(Debug)pub(all) struct RtpStreamStats {
id : String
track_id : String
kind : MediaKind
outbound : Bool
ssrc : UInt
rid : String?
codec_id : String
packets : UInt64
bytes : UInt64
packets_lost : UInt64
jitter : UInt64
retransmitted_packets : UInt64
retransmitted_bytes : UInt64
active : Bool
} derive(Eq, Debug)pub struct Settings {
ice_credentials : IceCredentials?
ice_check_interval : Duration
ice_initial_rto : Duration
ice_reliable_timeout : Duration
ice_max_retransmissions : Int
ice_disconnected_timeout : Duration
ice_failed_timeout : Duration
ice_keepalive_interval : Duration
mdns_retry_interval : Duration
mdns_query_timeout : Duration
mdns_local_name : String?
answering_dtls_role : Role?
verify_peer_fingerprint : Bool
dtls_certificate_key_type : CertificateKeyType
dtls_cipher_suites : Array[CipherSuite]
dtls_psk : Bytes?
dtls_psk_identity : Bytes?
dtls_srtp_profiles : Array[SrtpProtectionProfile]
dtls_flight_interval : Duration
dtls_mtu : Int
dtls_replay_window : Int
srtp_replay_window : Int
srtcp_replay_window : Int
sctp_max_payload_size : Int
sctp_send_buffer_size : UInt64
sctp_receive_buffer_size : UInt
sctp_initial_rto : Duration
receive_mtu : Int
ignore_rid_pause_for_recv : Bool
write_ssrc_attributes_for_simulcast : Bool
}fn Settings::new(ice_credentials? : IceCredentials, ice_check_interval? : Duration, ice_initial_rto? : Duration, ice_reliable_timeout? : Duration, ice_max_retransmissions? : Int, ice_disconnected_timeout? : Duration, ice_failed_timeout? : Duration, ice_keepalive_interval? : Duration, mdns_retry_interval? : Duration, mdns_query_timeout? : Duration, mdns_local_name? : String, answering_dtls_role? : Role, verify_peer_fingerprint? : Bool, dtls_certificate_key_type? : CertificateKeyType, dtls_cipher_suites? : Array[CipherSuite], dtls_psk? : Bytes, dtls_psk_identity? : Bytes, dtls_srtp_profiles? : Array[SrtpProtectionProfile], dtls_flight_interval? : Duration, dtls_mtu? : Int, dtls_replay_window? : Int, srtp_replay_window? : Int, srtcp_replay_window? : Int, sctp_max_payload_size? : Int, sctp_send_buffer_size? : UInt64, sctp_receive_buffer_size? : UInt, sctp_initial_rto? : Duration, receive_mtu? : Int, ignore_rid_pause_for_recv? : Bool, write_ssrc_attributes_for_simulcast? : Bool) -> Settings raise RtcErrorpub(all) struct TransportStats {
id : String
ice_state : IceConnectionState
dtls_state : State?
selected_candidate_pair_id : String?
bytes_sent : UInt64
bytes_received : UInt64
packets_sent : UInt64
packets_received : UInt64
} derive(Eq, Debug)Install
Download zipExperimental Sans-I/O WebRTC stack for MoonBit
Dependencies