Skip to content

Commit

Permalink
Merge pull request #33 from paullouisageneau/reliability-timed
Browse files Browse the repository at this point in the history
Implement Timed reliability
  • Loading branch information
paullouisageneau authored May 16, 2022
2 parents 9f2458b + 51ba4a0 commit aab0e67
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
12 changes: 8 additions & 4 deletions wasm/include/rtc/reliability.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@
#ifndef RTC_RELIABILITY_H
#define RTC_RELIABILITY_H

#include "common.hpp"

#include <chrono>

namespace rtc {
// TODO: Support Type::Timed

struct Reliability {
enum class Type { Reliable = 0, Rexmit };
enum class Type { Reliable = 0, Rexmit, Timed };

Type type = Type::Reliable;
bool unordered = false;
int rexmit = 0;
variant<int, std::chrono::milliseconds> rexmit = 0;
};

} // namespace rtc

#endif // RTC_PEERCONNECTION_H
#endif // RTC_RELIABILITY_H
12 changes: 6 additions & 6 deletions wasm/js/webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@
return type;
},

rtcCreateDataChannel: function(pc, pLabel, unreliable, unordered, rexmit) {
rtcCreateDataChannel: function(pc, pLabel, unordered, maxRetransmits, maxPacketLifeTime) {
if(!pc) return 0;
var label = UTF8ToString(pLabel);
var peerConnection = WEBRTC.peerConnectionsMap[pc];
var datachannelInit = {};
if (unordered)
datachannelInit['ordered'] = false;
if (unreliable)
datachannelInit['maxRetransmits'] = rexmit;
var datachannelInit = {
ordered: !unordered,
maxRetransmits: maxRetransmits >= 0 ? maxRetransmits : null,
maxPacketLifeTime: maxPacketLifeTime >= 0 ? maxPacketLifeTime : null,
};
var channel = peerConnection.createDataChannel(label, datachannelInit);
return WEBRTC.registerDataChannel(channel);
},
Expand Down
14 changes: 10 additions & 4 deletions wasm/src/peerconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ extern char *rtcGetLocalDescription(int pc);
extern char *rtcGetLocalDescriptionType(int pc);
extern char *rtcGetRemoteDescription(int pc);
extern char *rtcGetRemoteDescriptionType(int pc);
extern int rtcCreateDataChannel(int pc, const char *label, bool unreliable, bool unordered,
int rexmit);
extern int rtcCreateDataChannel(int pc, const char *label, bool unordered, int maxRetransmits,
int maxPacketLifeTime);
extern void rtcSetDataChannelCallback(int pc, void (*dataChannelCallback)(int, void *));
extern void rtcSetLocalDescriptionCallback(int pc,
void (*descriptionCallback)(const char *, const char *,
Expand Down Expand Up @@ -180,9 +180,15 @@ optional<Description> PeerConnection::remoteDescription() const {

shared_ptr<DataChannel> PeerConnection::createDataChannel(const string &label,
DataChannelInit init) {
int maxRetransmits = init.reliability.type == Reliability::Type::Rexmit
? std::get<int>(init.reliability.rexmit)
: -1;
int maxPacketLifeTime =
init.reliability.type == Reliability::Type::Timed
? int(std::get<std::chrono::milliseconds>(init.reliability.rexmit).count())
: -1;
return std::make_shared<DataChannel>(rtcCreateDataChannel(
mId, label.c_str(), init.reliability.type != Reliability::Type::Reliable,
init.reliability.unordered, init.reliability.rexmit));
mId, label.c_str(), init.reliability.unordered, maxRetransmits, maxPacketLifeTime));
}

void PeerConnection::setRemoteDescription(const Description &description) {
Expand Down

0 comments on commit aab0e67

Please sign in to comment.