Skip to content

Commit

Permalink
Merge pull request #10 from murat-dogan/0.0.11-dev
Browse files Browse the repository at this point in the history
0.0.11
  • Loading branch information
murat-dogan authored Nov 12, 2020
2 parents e3d4834 + 963b6ed commit add338a
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.14)
project(node_datachannel VERSION 0.0.10)
project(node_datachannel VERSION 0.0.11)

include_directories(${CMAKE_JS_INC})

Expand All @@ -11,7 +11,7 @@ include(FetchContent)
FetchContent_Declare(
libdatachannel
GIT_REPOSITORY https://github.com/paullouisageneau/libdatachannel.git
GIT_TAG "v0.8.0"
GIT_TAG "v0.9.4"
)
FetchContent_MakeAvailable(libdatachannel)

Expand Down
2 changes: 2 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum LogLevel {

// Functions
export function initLogger(level: LogLevel): void;
export function cleanup(): void;

export enum ProxyServerType {
None = 'None',
Expand Down Expand Up @@ -48,6 +49,7 @@ export class DataChannel {
availableAmount: () => Number;
bufferedAmount: () => Number;
maxMessageSize: () => Number;
setBufferedAmountLowThreshold: (newSize: Number) => void;
onOpen: (cb: () => void) => void;
onClosed: (cb: () => void) => void;
onError: (cb: (err: string) => void) => void;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@
"dependencies": {
"prebuild-install": "^5.3.5"
}
}
}
21 changes: 21 additions & 0 deletions src/data-channel-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Napi::Object DataChannelWrapper::Init(Napi::Env env, Napi::Object exports)
InstanceMethod("availableAmount", &DataChannelWrapper::availableAmount),
InstanceMethod("bufferedAmount", &DataChannelWrapper::bufferedAmount),
InstanceMethod("maxMessageSize", &DataChannelWrapper::maxMessageSize),
InstanceMethod("setBufferedAmountLowThreshold", &DataChannelWrapper::setBufferedAmountLowThreshold),
InstanceMethod("onOpen", &DataChannelWrapper::onOpen),
InstanceMethod("onClosed", &DataChannelWrapper::onClosed),
InstanceMethod("onError", &DataChannelWrapper::onError),
Expand Down Expand Up @@ -182,6 +183,26 @@ Napi::Value DataChannelWrapper::maxMessageSize(const Napi::CallbackInfo &info)
return Napi::Number::New(info.Env(), mDataChannelPtr->maxMessageSize());
}

void DataChannelWrapper::setBufferedAmountLowThreshold(const Napi::CallbackInfo &info)
{
if (!mDataChannelPtr)
{
Napi::TypeError::New(info.Env(), "It seems data-channel is destroyed!").ThrowAsJavaScriptException();
return;
}

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

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

mDataChannelPtr->setBufferedAmountLowThreshold(info[0].ToNumber().Uint32Value());
}

void DataChannelWrapper::onOpen(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Expand Down
1 change: 1 addition & 0 deletions src/data-channel-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class DataChannelWrapper : public Napi::ObjectWrap<DataChannelWrapper>
Napi::Value availableAmount(const Napi::CallbackInfo &info);
Napi::Value bufferedAmount(const Napi::CallbackInfo &info);
Napi::Value maxMessageSize(const Napi::CallbackInfo &info);
void setBufferedAmountLowThreshold(const Napi::CallbackInfo &info);

// Callbacks
void onOpen(const Napi::CallbackInfo &info);
Expand Down
6 changes: 6 additions & 0 deletions src/rtc-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Napi::Object RtcWrapper::Init(Napi::Env env, Napi::Object exports)
Napi::HandleScope scope(env);

exports.Set("initLogger", Napi::Function::New(env, &RtcWrapper::initLogger));
exports.Set("cleanup", Napi::Function::New(env, &RtcWrapper::cleanup));
return exports;
}

Expand Down Expand Up @@ -37,4 +38,9 @@ void RtcWrapper::initLogger(const Napi::CallbackInfo &info)
logLevel = rtc::LogLevel::Fatal;

rtc::InitLogger(logLevel);
}

void RtcWrapper::cleanup(const Napi::CallbackInfo &info)
{
rtc::Cleanup();
}
1 change: 1 addition & 0 deletions src/rtc-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class RtcWrapper
public:
static Napi::Object Init(Napi::Env env, Napi::Object exports);
static void initLogger(const Napi::CallbackInfo &info);
static void cleanup(const Napi::CallbackInfo &info);
};

#endif // RTC_WRAPPER_H
6 changes: 6 additions & 0 deletions test/connectivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,10 @@ setTimeout(() => {
dc2.close();
peer1.close();
peer2.close();
dc1 = null;
dc2 = null;
peer1 = null;
peer2 = null;
nodeDataChannel.cleanup();

}, 10 * 1000);
7 changes: 6 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ describe('P2P', () => {
peer1 = null;
peer2 = null;

// Cleanup Threads
nodeDataChannel.cleanup();
}, 5 * 1000);

setTimeout(() => {
// State Callbacks
expect(p1StateMock.mock.calls.length).toBeGreaterThanOrEqual(1);
expect(p1GatheringStateMock.mock.calls.length).toBeGreaterThanOrEqual(1);
Expand All @@ -136,7 +141,7 @@ describe('P2P', () => {
expect(p2DCMessageMock.mock.calls[0][0]).toEqual("Hello From Peer1");

done();
}, 10 * 1000);
}, 15 * 1000);

});
});

0 comments on commit add338a

Please sign in to comment.