Skip to content

Commit

Permalink
Merge pull request #247 from paullouisageneau/update-deprecated
Browse files Browse the repository at this point in the history
Update wrapper for deprecated methods in libdatachannel
  • Loading branch information
murat-dogan authored May 6, 2024
2 parents 6b0af89 + ac1dc62 commit 368a740
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 31 deletions.
11 changes: 5 additions & 6 deletions src/media-audio-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,8 @@ void AudioWrapper::setBitrate(const Napi::CallbackInfo &info)
return;
}

int bitRate = static_cast<int>(info[0].As<Napi::Number>().ToNumber());

mAudioPtr->setBitrate(bitRate);
unsigned int bitrate = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
mAudioPtr->setBitrate(bitrate);
}

Napi::Value AudioWrapper::getBitrate(const Napi::CallbackInfo &info)
Expand Down Expand Up @@ -428,9 +427,9 @@ void AudioWrapper::addRTXCodec(const Napi::CallbackInfo &info)
return;
}

unsigned int payloadType = static_cast<unsigned int>(info[0].As<Napi::Number>().ToNumber());
unsigned int originalPayloadType = static_cast<unsigned int>(info[1].As<Napi::Number>().ToNumber());
unsigned int clockRate = static_cast<unsigned int>(info[2].As<Napi::Number>().ToNumber());
int payloadType = static_cast<int32_t>(info[0].As<Napi::Number>().ToNumber());
int originalPayloadType = static_cast<int32_t>(info[1].As<Napi::Number>().ToNumber());
unsigned int clockRate = static_cast<uint32_t>(info[2].As<Napi::Number>().ToNumber());

mAudioPtr->addRtxCodec(payloadType, originalPayloadType, clockRate);
}
Expand Down
7 changes: 3 additions & 4 deletions src/media-rtcpreceivingsession-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ void RtcpReceivingSessionWrapper::requestBitrate(const Napi::CallbackInfo &info)
return;
}

unsigned int bitRate = static_cast<unsigned int>(info[0].As<Napi::Number>().ToNumber());

mSessionPtr->requestBitrate(bitRate);
unsigned int bitrate = static_cast<uint32_t>(info[0].As<Napi::Number>().ToNumber());
mSessionPtr->requestBitrate(bitrate);
}

Napi::Value RtcpReceivingSessionWrapper::requestKeyframe(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
return Napi::Boolean::New(env, mSessionPtr->requestKeyframe());
}
}
22 changes: 22 additions & 0 deletions src/media-track-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Napi::Object TrackWrapper::Init(Napi::Env env, Napi::Object exports)
InstanceMethod("isOpen", &TrackWrapper::isOpen),
InstanceMethod("isClosed", &TrackWrapper::isClosed),
InstanceMethod("maxMessageSize", &TrackWrapper::maxMessageSize),
InstanceMethod("requestBitrate", &TrackWrapper::requestBitrate),
InstanceMethod("requestKeyframe", &TrackWrapper::requestKeyframe),
InstanceMethod("setMediaHandler", &TrackWrapper::setMediaHandler),
InstanceMethod("onOpen", &TrackWrapper::onOpen),
Expand Down Expand Up @@ -237,6 +238,27 @@ Napi::Value TrackWrapper::maxMessageSize(const Napi::CallbackInfo &info)
}
}

Napi::Value TrackWrapper::requestBitrate(const Napi::CallbackInfo &info)
{
if (!mTrackPtr)
{
Napi::Error::New(info.Env(), "requestBitrate() called on destroyed track").ThrowAsJavaScriptException();
return info.Env().Null();
}

Napi::Env env = info.Env();
int length = info.Length();

if (length < 1 || !info[0].IsNumber())
{
Napi::TypeError::New(env, "Number expected").ThrowAsJavaScriptException();
return info.Env().Null();
}

unsigned int bitrate = static_cast<uint32_t>(info[0].As<Napi::Number>());
return Napi::Boolean::New(env, mTrackPtr->requestBitrate(bitrate));
}

Napi::Value TrackWrapper::requestKeyframe(const Napi::CallbackInfo &info)
{
if (!mTrackPtr)
Expand Down
1 change: 1 addition & 0 deletions src/media-track-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TrackWrapper : public Napi::ObjectWrap<TrackWrapper>
Napi::Value isOpen(const Napi::CallbackInfo &info);
Napi::Value isClosed(const Napi::CallbackInfo &info);
Napi::Value maxMessageSize(const Napi::CallbackInfo &info);
Napi::Value requestBitrate(const Napi::CallbackInfo &info);
Napi::Value requestKeyframe(const Napi::CallbackInfo &info);
void setMediaHandler(const Napi::CallbackInfo &info);

Expand Down
14 changes: 6 additions & 8 deletions src/media-video-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,12 @@ void VideoWrapper::setBitrate(const Napi::CallbackInfo &info)
return;
}

int bitRate = static_cast<int>(info[0].As<Napi::Number>().ToNumber());

mVideoPtr->setBitrate(bitRate);
unsigned int bitrate = info[0].As<Napi::Number>().ToNumber().Uint32Value();
mVideoPtr->setBitrate(bitrate);
}

Napi::Value VideoWrapper::getBitrate(const Napi::CallbackInfo &info)
{

return Napi::Number::New(info.Env(), mVideoPtr->bitrate());
}

Expand All @@ -445,7 +443,7 @@ Napi::Value VideoWrapper::hasPayloadType(const Napi::CallbackInfo &info)
return env.Null();
}

int payloadType = static_cast<int>(info[0].As<Napi::Number>().ToNumber());
int payloadType = static_cast<int32_t>(info[0].As<Napi::Number>().ToNumber());

return Napi::Boolean::New(env, mVideoPtr->hasPayloadType(payloadType));
}
Expand All @@ -461,9 +459,9 @@ void VideoWrapper::addRTXCodec(const Napi::CallbackInfo &info)
return;
}

unsigned int payloadType = static_cast<unsigned int>(info[0].As<Napi::Number>().ToNumber());
unsigned int originalPayloadType = static_cast<unsigned int>(info[1].As<Napi::Number>().ToNumber());
unsigned int clockRate = static_cast<unsigned int>(info[2].As<Napi::Number>().ToNumber());
int payloadType = static_cast<int32_t>(info[0].As<Napi::Number>().ToNumber());
int originalPayloadType = static_cast<int32_t>(info[1].As<Napi::Number>().ToNumber());
unsigned int clockRate = static_cast<uint32_t>(info[2].As<Napi::Number>().ToNumber());

mVideoPtr->addRtxCodec(payloadType, originalPayloadType, clockRate);
}
Expand Down
32 changes: 19 additions & 13 deletions src/peer-connection-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,10 @@ Napi::Value PeerConnectionWrapper::createDataChannel(const Napi::CallbackInfo &i
switch (reliability.Get("type").As<Napi::Number>().Uint32Value())
{
case 1:
init.reliability.rexmit = static_cast<int>(reliability.Get("rexmit").As<Napi::Number>().ToNumber());
init.reliability.rexmit = int(reliability.Get("rexmit").As<Napi::Number>().ToNumber().Uint32Value());
break;
case 2:
init.reliability.rexmit = std::chrono::milliseconds(reliability.Get("rexmit").As<Napi::Number>().Uint32Value());
init.reliability.rexmit = std::chrono::milliseconds(reliability.Get("rexmit").As<Napi::Number>().Int32Value());
break;
}
}
Expand All @@ -572,25 +572,31 @@ Napi::Value PeerConnectionWrapper::createDataChannel(const Napi::CallbackInfo &i
init.reliability.unordered = !initConfig.Get("ordered").As<Napi::Boolean>();
}

if (initConfig.Get("maxPacketLifeTime").IsNumber() && initConfig.Get("maxRetransmits").IsNumber())

if (!initConfig.Get("maxPacketLifeTime").IsUndefined() && !initConfig.Get("maxPacketLifeTime").IsNull() &&
!initConfig.Get("maxRetransmits").IsUndefined() && !initConfig.Get("maxRetransmits").IsNull())
{
Napi::TypeError::New(env, "Wrong DataChannel Init Config, maxPacketLifeTime and maxRetransmits are exclusive").ThrowAsJavaScriptException();
return info.Env().Null();
}

if (initConfig.Get("maxPacketLifeTime").IsNumber())
{
init.reliability.type = rtc::Reliability::Type::Timed;
init.reliability.rexmit = std::chrono::milliseconds(initConfig.Get("maxPacketLifeTime").As<Napi::Number>().Uint32Value());
}
else if (initConfig.Get("maxRetransmits").IsNumber())
if (!initConfig.Get("maxPacketLifeTime").IsUndefined() && !initConfig.Get("maxPacketLifeTime").IsNull())
{
init.reliability.type = rtc::Reliability::Type::Rexmit;
init.reliability.rexmit = int(initConfig.Get("maxRetransmits").As<Napi::Number>().Uint32Value());
if (!initConfig.Get("maxPacketLifeTime").IsNumber())
{
Napi::TypeError::New(env, "Wrong DataChannel Init Config (maxPacketLifeTime)").ThrowAsJavaScriptException();
return info.Env().Null();
}
init.reliability.maxPacketLifeTime = std::chrono::milliseconds(initConfig.Get("maxPacketLifeTime").As<Napi::Number>().Uint32Value());
}
else
else if (!initConfig.Get("maxRetransmits").IsUndefined() && !initConfig.Get("maxRetransmits").IsNull())
{
init.reliability.type = rtc::Reliability::Type::Reliable;
if (!initConfig.Get("maxRetransmits").IsNumber())
{
Napi::TypeError::New(env, "Wrong DataChannel Init Config (maxRetransmits)").ThrowAsJavaScriptException();
return info.Env().Null();
}
init.reliability.maxRetransmits = int(initConfig.Get("maxRetransmits").As<Napi::Number>().Int32Value());
}
}

Expand Down

0 comments on commit 368a740

Please sign in to comment.