Skip to content

Add rtti option #343

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

Merged
merged 8 commits into from
Apr 11, 2025
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
37 changes: 28 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Android")
set(CMAKE_C_FLAGS "-Wno-error=unused-but-set-variable -Wno-error=strict-prototypes")
endif()

# Add -frtti only for Linux and macOS
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti")
endif()
Comment on lines +24 to +26

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's working on linux but getting the same error for intel mac architecture.

Screenshot 2025-03-18 at 5 51 18 PM

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, it is saying wrong architecture.
need x86 but have arm64.
It should not be related to this issue.


set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)

Expand All @@ -35,29 +40,43 @@ FetchContent_Declare(
option(NO_MEDIA "Disable media transport support in libdatachannel" OFF)
option(NO_WEBSOCKET "Disable WebSocket support in libdatachannel" OFF)

set(FETCHCONTENT_QUIET OFF)
FetchContent_GetProperties(libdatachannel)

if(NOT libdatachannel)
FetchContent_Populate(libdatachannel)
add_subdirectory(${libdatachannel_SOURCE_DIR} ${libdatachannel_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

add_library(${PROJECT_NAME} SHARED
src/cpp/rtc-wrapper.cpp
src/cpp/media-direction.cpp
src/cpp/media-rtcpreceivingsession-wrapper.cpp
src/cpp/media-track-wrapper.cpp
src/cpp/media-audio-wrapper.cpp
src/cpp/media-video-wrapper.cpp
# Create Source File List
set(SRC_FILES
src/cpp/rtc-wrapper.cpp
src/cpp/data-channel-wrapper.cpp
src/cpp/peer-connection-wrapper.cpp
src/cpp/thread-safe-callback.cpp
src/cpp/web-socket-wrapper.cpp
src/cpp/web-socket-server-wrapper.cpp
src/cpp/main.cpp
${CMAKE_JS_SRC}
)

if(NOT NO_MEDIA)
list(APPEND SRC_FILES
src/cpp/media-direction.cpp
src/cpp/media-rtcpreceivingsession-wrapper.cpp
src/cpp/media-track-wrapper.cpp
src/cpp/media-audio-wrapper.cpp
src/cpp/media-video-wrapper.cpp
)
endif()

if(NOT NO_WEBSOCKET)
list(APPEND SRC_FILES
src/cpp/web-socket-wrapper.cpp
src/cpp/web-socket-server-wrapper.cpp
)
endif()

add_library(${PROJECT_NAME} SHARED ${SRC_FILES})

set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")

Expand Down
226 changes: 113 additions & 113 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,117 +1,117 @@
{
"name": "node-datachannel",
"version": "0.26.0",
"description": "WebRTC For Node.js and Electron. libdatachannel node bindings.",
"main": "./dist/cjs/lib/index.cjs",
"module": "./dist/esm/lib/index.mjs",
"types": "./dist/types/lib/index.d.ts",
"typesVersions": {
"*": {
"*": [
"dist/types/lib/index.d.ts"
],
"polyfill": [
"dist/types/polyfill/index.d.ts"
]
}
},
"exports": {
".": {
"types": "./dist/types/lib/index.d.ts",
"require": "./dist/cjs/lib/index.cjs",
"import": "./dist/esm/lib/index.mjs",
"default": "./dist/lib/esm/index.mjs"
},
"./polyfill": {
"types": "./dist/types/polyfill/index.d.ts",
"require": "./dist/cjs/polyfill/index.cjs",
"import": "./dist/esm/polyfill/index.mjs",
"default": "./dist/polyfill/esm/index.mjs"
}
},
"engines": {
"node": ">=18.20.0"
},
"scripts": {
"install": "prebuild-install -r napi || (npm install --ignore-scripts --production=false && npm run _prebuild)",
"install:nice": "npm run clean && npm install --ignore-scripts --production=false && cmake-js build --CDUSE_NICE=1",
"install:gnu": "npm run clean && npm install --ignore-scripts --production=false && cmake-js build --CDUSE_GNUTLS=1",
"build": "npm run compile && npm run build:tsc",
"compile": "cmake-js build",
"compile:debug": "cmake-js build -D",
"build:tsc": "rimraf dist && rollup -c",
"build:tsc:watch": "rollup -c -w",
"clean": "rimraf dist build",
"lint": "eslint . --ext .ts --ext .mts",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
"test:wpt": "npm run run:wpt:server & (sleep 8 && (npm run run:wpt:test | tee test/wpt-tests/last-test-results.md) )",
"wpt:server": "cd test/wpt-tests/wpt && ./wpt serve",
"wpt:test": "ts-node test/wpt-tests/index.ts",
"_prebuild": "prebuild -r napi --backend cmake-js",
"prepack": "npm run build:tsc"
},
"binary": {
"napi_versions": [
8
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/murat-dogan/node-datachannel.git"
},
"keywords": [
"libdatachannel",
"webrtc",
"p2p",
"peer-to-peer",
"datachannel",
"data channel",
"websocket"
],
"contributors": [
{
"name": "Murat Doğan",
"url": "https://github.com/murat-dogan"
},
{
"name": "Paul-Louis Ageneau",
"url": "https://github.com/paullouisageneau"
}
],
"license": "MPL 2.0",
"bugs": {
"url": "https://github.com/murat-dogan/node-datachannel/issues"
"name": "node-datachannel",
"version": "0.26.0",
"description": "WebRTC For Node.js and Electron. libdatachannel node bindings.",
"main": "./dist/cjs/lib/index.cjs",
"module": "./dist/esm/lib/index.mjs",
"types": "./dist/types/lib/index.d.ts",
"typesVersions": {
"*": {
"*": [
"dist/types/lib/index.d.ts"
],
"polyfill": [
"dist/types/polyfill/index.d.ts"
]
}
},
"exports": {
".": {
"types": "./dist/types/lib/index.d.ts",
"require": "./dist/cjs/lib/index.cjs",
"import": "./dist/esm/lib/index.mjs",
"default": "./dist/lib/esm/index.mjs"
},
"homepage": "https://github.com/murat-dogan/node-datachannel#readme",
"devDependencies": {
"@rollup/plugin-esm-shim": "^0.1.7",
"@rollup/plugin-replace": "^6.0.1",
"@types/jest": "^29.5.12",
"@types/node": "^20.6.1",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"cmake-js": "^7.3.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
"jsdom": "^24.1.1",
"node-addon-api": "^7.0.0",
"prebuild": "^13.0.1",
"prettier": "^3.3.3",
"puppeteer": "^22.14.0",
"rimraf": "^5.0.9",
"rollup": "^4.22.5",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-esbuild": "^6.1.1",
"ts-api-utils": "^1.3.0",
"ts-jest": "^29.2.3",
"ts-node": "^10.9.2",
"typescript": "5.4"
"./polyfill": {
"types": "./dist/types/polyfill/index.d.ts",
"require": "./dist/cjs/polyfill/index.cjs",
"import": "./dist/esm/polyfill/index.mjs",
"default": "./dist/polyfill/esm/index.mjs"
}
},
"engines": {
"node": ">=18.20.0"
},
"scripts": {
"install": "prebuild-install -r napi || (npm install --ignore-scripts --production=false && npm run _prebuild)",
"install:nice": "npm run clean && npm install --ignore-scripts --production=false && cmake-js configure --CDUSE_NICE=1 && cmake-js build",
"install:gnu": "npm run clean && npm install --ignore-scripts --production=false && cmake-js configure --CDUSE_GNUTLS=1 && cmake-js build",
"build": "npm run compile && npm run build:tsc",
"compile": "cmake-js build",
"compile:debug": "cmake-js build -D",
"build:tsc": "rimraf dist && rollup -c",
"build:tsc:watch": "rollup -c -w",
"clean": "rimraf dist build",
"lint": "eslint . --ext .ts --ext .mts",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
"test:wpt": "npm run run:wpt:server & (sleep 8 && (npm run run:wpt:test | tee test/wpt-tests/last-test-results.md) )",
"wpt:server": "cd test/wpt-tests/wpt && ./wpt serve",
"wpt:test": "ts-node test/wpt-tests/index.ts",
"_prebuild": "prebuild -r napi --backend cmake-js",
"prepack": "npm run build:tsc"
},
"binary": {
"napi_versions": [
8
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/murat-dogan/node-datachannel.git"
},
"keywords": [
"libdatachannel",
"webrtc",
"p2p",
"peer-to-peer",
"datachannel",
"data channel",
"websocket"
],
"contributors": [
{
"name": "Murat Doğan",
"url": "https://github.com/murat-dogan"
},
"dependencies": {
"prebuild-install": "^7.1.3"
{
"name": "Paul-Louis Ageneau",
"url": "https://github.com/paullouisageneau"
}
}
],
"license": "MPL 2.0",
"bugs": {
"url": "https://github.com/murat-dogan/node-datachannel/issues"
},
"homepage": "https://github.com/murat-dogan/node-datachannel#readme",
"devDependencies": {
"@rollup/plugin-esm-shim": "^0.1.7",
"@rollup/plugin-replace": "^6.0.1",
"@types/jest": "^29.5.12",
"@types/node": "^20.6.1",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"cmake-js": "^7.3.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
"jsdom": "^24.1.1",
"node-addon-api": "^7.0.0",
"prebuild": "^13.0.1",
"prettier": "^3.3.3",
"puppeteer": "^22.14.0",
"rimraf": "^5.0.9",
"rollup": "^4.22.5",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-esbuild": "^6.1.1",
"ts-api-utils": "^1.3.0",
"ts-jest": "^29.2.3",
"ts-node": "^10.9.2",
"typescript": "5.4"
},
"dependencies": {
"prebuild-install": "^7.1.3"
}
}
14 changes: 14 additions & 0 deletions src/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,38 @@
#include "rtc-wrapper.h"
#include "peer-connection-wrapper.h"
#include "data-channel-wrapper.h"

#if RTC_ENABLE_MEDIA == 1
#include "media-rtcpreceivingsession-wrapper.h"
#include "media-track-wrapper.h"
#include "media-video-wrapper.h"
#include "media-audio-wrapper.h"
#endif

#if RTC_ENABLE_WEBSOCKET == 1
#include "web-socket-wrapper.h"
#include "web-socket-server-wrapper.h"
#endif

Napi::Object InitAll(Napi::Env env, Napi::Object exports)
{
RtcWrapper::Init(env, exports);

#if RTC_ENABLE_MEDIA == 1
RtcpReceivingSessionWrapper::Init(env, exports);
TrackWrapper::Init(env, exports);
VideoWrapper::Init(env, exports);
AudioWrapper::Init(env, exports);
#endif

DataChannelWrapper::Init(env, exports);
PeerConnectionWrapper::Init(env, exports);

#if RTC_ENABLE_WEBSOCKET == 1
WebSocketWrapper::Init(env, exports);
WebSocketServerWrapper::Init(env, exports);
#endif

return exports;
}

Expand Down
10 changes: 9 additions & 1 deletion src/cpp/peer-connection-wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "peer-connection-wrapper.h"
#include "data-channel-wrapper.h"

#if RTC_ENABLE_MEDIA == 1
#include "media-track-wrapper.h"
#include "media-video-wrapper.h"
#include "media-audio-wrapper.h"
#endif

#include "plog/Log.h"

Expand Down Expand Up @@ -43,7 +46,11 @@ Napi::Object PeerConnectionWrapper::Init(Napi::Env env, Napi::Object exports)
InstanceMethod("remoteDescription", &PeerConnectionWrapper::remoteDescription),
InstanceMethod("addRemoteCandidate", &PeerConnectionWrapper::addRemoteCandidate),
InstanceMethod("createDataChannel", &PeerConnectionWrapper::createDataChannel),

#if RTC_ENABLE_MEDIA == 1
InstanceMethod("addTrack", &PeerConnectionWrapper::addTrack),
InstanceMethod("onTrack", &PeerConnectionWrapper::onTrack),
#endif
InstanceMethod("hasMedia", &PeerConnectionWrapper::hasMedia),
InstanceMethod("state", &PeerConnectionWrapper::state),
InstanceMethod("iceState", &PeerConnectionWrapper::iceState),
Expand All @@ -56,7 +63,6 @@ Napi::Object PeerConnectionWrapper::Init(Napi::Env env, Napi::Object exports)
InstanceMethod("onSignalingStateChange", &PeerConnectionWrapper::onSignalingStateChange),
InstanceMethod("onGatheringStateChange", &PeerConnectionWrapper::onGatheringStateChange),
InstanceMethod("onDataChannel", &PeerConnectionWrapper::onDataChannel),
InstanceMethod("onTrack", &PeerConnectionWrapper::onTrack),
InstanceMethod("bytesSent", &PeerConnectionWrapper::bytesSent),
InstanceMethod("bytesReceived", &PeerConnectionWrapper::bytesReceived),
InstanceMethod("rtt", &PeerConnectionWrapper::rtt),
Expand Down Expand Up @@ -1049,6 +1055,7 @@ std::string PeerConnectionWrapper::candidateTransportTypeToString(const rtc::Can
}
}

#if RTC_ENABLE_MEDIA == 1
Napi::Value PeerConnectionWrapper::addTrack(const Napi::CallbackInfo &info)
{
PLOG_DEBUG << "addTrack() called";
Expand Down Expand Up @@ -1132,6 +1139,7 @@ void PeerConnectionWrapper::onTrack(const Napi::CallbackInfo &info)
args = {instance};
}); });
}
#endif

Napi::Value PeerConnectionWrapper::hasMedia(const Napi::CallbackInfo &info)
{
Expand Down
Loading