Compare commits

...

9 Commits

11 changed files with 119 additions and 5 deletions

View File

@ -1,7 +1,7 @@
cmake_minimum_required (VERSION 3.7)
project (libdatachannel
DESCRIPTION "WebRTC DataChannels Library"
VERSION 0.4.2
VERSION 0.4.4
LANGUAGES CXX)
option(USE_GNUTLS "Use GnuTLS instead of OpenSSL" OFF)
@ -16,6 +16,12 @@ endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
if(WIN32)
if (MSYS OR MINGW)
add_definitions(-DSCTP_STDINT_INCLUDE=<stdint.h>)
endif()
endif()
set(LIBDATACHANNEL_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/candidate.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/certificate.cpp
@ -59,9 +65,15 @@ target_include_directories(datachannel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/inclu
target_include_directories(datachannel PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(datachannel PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/deps/plog/include)
target_link_libraries(datachannel
Threads::Threads
Usrsctp::UsrsctpStatic
Threads::Threads
Usrsctp::UsrsctpStatic
)
if(WIN32)
target_link_libraries(datachannel
"wsock32" #winsock2
"ws2_32" #winsock2
)
endif()
add_library(datachannel-static STATIC EXCLUDE_FROM_ALL ${LIBDATACHANNEL_SOURCES})
set_target_properties(datachannel-static PROPERTIES
@ -76,6 +88,12 @@ target_link_libraries(datachannel-static
Threads::Threads
Usrsctp::UsrsctpStatic
)
if(WIN32)
target_link_libraries(datachannel-static
"wsock32" #winsock2
"ws2_32" #winsock2
)
endif()
if (USE_GNUTLS)
find_package(GnuTLS REQUIRED)

View File

@ -1,6 +1,6 @@
# libdatachannel - C/C++ WebRTC DataChannels
libdatachannel is a standalone implementation of WebRTC DataChannels in C++17 with C bindings. It enables direct connectivity between native applications and web browsers without the pain of importing the entire WebRTC stack. Its API is modelled as a simplified version of the JavaScript WebRTC API, in order to ease the design of cross-environment applications.
libdatachannel is a standalone implementation of WebRTC DataChannels in C++17 with C bindings for POSIX platforms and Microsoft Windows. It enables direct connectivity between native applications and web browsers without the pain of importing the entire WebRTC stack. Its API is modelled as a simplified version of the JavaScript WebRTC API, in order to ease the design of cross-environment applications.
This projet is originally inspired by [librtcdcpp](https://github.com/chadnickbok/librtcdcpp), however it is a complete rewrite from scratch, because the messy architecture of librtcdcpp made solving its implementation issues difficult.

2
deps/libjuice vendored

View File

@ -19,6 +19,12 @@
#ifndef RTC_INCLUDE_H
#define RTC_INCLUDE_H
#ifdef _WIN32
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0602
#endif
#endif
#include <cstddef>
#include <functional>
#include <memory>

View File

@ -22,8 +22,14 @@
#include <array>
#include <sstream>
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#elif __linux__
#include <netdb.h>
#include <sys/socket.h>
#endif
#include <sys/types.h>
using std::array;

View File

@ -19,9 +19,14 @@
#include "icetransport.hpp"
#include "configuration.hpp"
#ifdef _WIN32
#include <winsock2.h>
#elif __linux__
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#endif
#include <sys/types.h>
#include <iostream>

View File

@ -23,7 +23,9 @@
#include <iostream>
#include <vector>
#ifdef __linux__
#include <arpa/inet.h>
#endif
using namespace std::chrono_literals;
using namespace std::chrono;

View File

@ -29,7 +29,12 @@
#include <map>
#include <mutex>
#ifdef _WIN32
#include <winsock2.h>
#elif __linux__
#include <sys/socket.h>
#endif
#include <sys/types.h>
#include "usrsctp.h"

View File

@ -23,6 +23,10 @@
#include <memory>
#include <thread>
#ifdef _WIN32
#include <winsock2.h>
#endif
using namespace rtc;
using namespace std;
@ -43,6 +47,20 @@ int main(int argc, char **argv) {
auto pc1 = std::make_shared<PeerConnection>(config);
auto pc2 = std::make_shared<PeerConnection>(config);
#ifdef _WIN32
WSADATA wsaData;
int iResult;
// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) {
std::string err("WSAStartup failed. Error:");
err.append(WSAGetLastError() + "");
std::cout << err;
return -1;
}
#endif
pc1->onLocalDescription([wpc2 = make_weak_ptr(pc2)](const Description &sdp) {
auto pc2 = wpc2.lock();
if (!pc2)
@ -127,9 +145,15 @@ int main(int argc, char **argv) {
pc2->close();
cout << "Success" << endl;
#ifdef _WIN32
WSACleanup();
#endif
return 0;
} else {
cout << "Failure" << endl;
#ifdef _WIN32
WSACleanup();
#endif
return 1;
}
}

View File

@ -22,6 +22,10 @@
#include <iostream>
#include <memory>
#ifdef _WIN32
#include <winsock2.h>
#endif
using namespace rtc;
using namespace std;
@ -41,9 +45,24 @@ int main(int argc, char **argv) {
auto pc = std::make_shared<PeerConnection>(config);
#ifdef _WIN32
WSADATA wsaData;
int iResult;
// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) {
std::string err("WSAStartup failed. Error:");
err.append(WSAGetLastError() + "");
std::cout << err;
return -1;
}
#endif
pc->onLocalDescription([](const Description &sdp) {
std::string s(sdp);
std::replace(s.begin(), s.end(), '\n', static_cast<char>(94));
std::replace(s.begin(), s.end(), '\r', static_cast<char>(95));
cout << "Local Description (Paste this to other peer):" << endl << s << endl << endl;
});
@ -102,6 +121,7 @@ int main(int argc, char **argv) {
getline(cin, sdp);
std::replace(sdp.begin(), sdp.end(), static_cast<char>(94), '\n');
std::replace(sdp.begin(), sdp.end(), static_cast<char>(95), '\r');
descPtr = std::make_unique<Description>(sdp, Description::Type::Offer,
Description::Role::Passive);
pc->setRemoteDescription(*descPtr);
@ -141,4 +161,8 @@ int main(int argc, char **argv) {
dc->close();
if (pc)
pc->close();
#ifdef _WIN32
WSACleanup();
#endif
}

View File

@ -22,6 +22,10 @@
#include <iostream>
#include <memory>
#ifdef _WIN32
#include <winsock2.h>
#endif
using namespace rtc;
using namespace std;
@ -41,9 +45,24 @@ int main(int argc, char **argv) {
auto pc = std::make_shared<PeerConnection>(config);
#ifdef _WIN32
WSADATA wsaData;
int iResult;
// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) {
std::string err("WSAStartup failed. Error:");
err.append(WSAGetLastError() + "");
std::cout << err;
return -1;
}
#endif
pc->onLocalDescription([](const Description &sdp) {
std::string s(sdp);
std::replace(s.begin(), s.end(), '\n', static_cast<char>(94));
std::replace(s.begin(), s.end(), '\r', static_cast<char>(95));
cout << "Local Description (Paste this to other peer):" << endl << s << endl << endl;
});
@ -100,6 +119,7 @@ int main(int argc, char **argv) {
getline(cin, sdp);
std::replace(sdp.begin(), sdp.end(), static_cast<char>(94), '\n');
std::replace(sdp.begin(), sdp.end(), static_cast<char>(95), '\r');
descPtr = std::make_unique<Description>(sdp);
pc->setRemoteDescription(*descPtr);
break;
@ -138,4 +158,8 @@ int main(int argc, char **argv) {
dc->close();
if (pc)
pc->close();
#ifdef _WIN32
WSACleanup();
#endif
}