mirror of
https://github.com/mii443/libdatachannel.git
synced 2025-08-23 15:48:03 +00:00
Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
24e9e06c5a | |||
443a19d8e7 | |||
83de743924 | |||
1dc1de4b86 | |||
8ca7722d48 | |||
3079072e63 | |||
982d1c10e1 | |||
50b22bbf3c | |||
93e153398f | |||
be6470d8bc | |||
8a92c97058 | |||
93da605230 |
2
.gitmodules
vendored
2
.gitmodules
vendored
@ -3,7 +3,7 @@
|
||||
url = https://github.com/SergiusTheBest/plog
|
||||
[submodule "usrsctp"]
|
||||
path = deps/usrsctp
|
||||
url = https://github.com/paullouisageneau/usrsctp.git
|
||||
url = https://github.com/sctplab/usrsctp.git
|
||||
[submodule "deps/libjuice"]
|
||||
path = deps/libjuice
|
||||
url = https://github.com/paullouisageneau/libjuice
|
||||
|
@ -1,7 +1,7 @@
|
||||
cmake_minimum_required (VERSION 3.7)
|
||||
project (libdatachannel
|
||||
DESCRIPTION "WebRTC Data Channels Library"
|
||||
VERSION 0.4.1
|
||||
DESCRIPTION "WebRTC DataChannels Library"
|
||||
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)
|
||||
|
2
Makefile
2
Makefile
@ -4,8 +4,8 @@ NAME=libdatachannel
|
||||
CXX=$(CROSS)g++
|
||||
AR=$(CROSS)ar
|
||||
RM=rm -f
|
||||
CPPFLAGS=-O2 -pthread -fPIC -Wall -Wno-address-of-packed-member
|
||||
CXXFLAGS=-std=c++17
|
||||
CPPFLAGS=-O2 -pthread -fPIC -Wall -Wno-address-of-packed-member
|
||||
LDFLAGS=-pthread
|
||||
LIBS=
|
||||
LOCALLIBS=libusrsctp.a
|
||||
|
@ -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
2
deps/libjuice
vendored
Submodule deps/libjuice updated: 25b71f18dc...6ac73257b6
2
deps/usrsctp
vendored
2
deps/usrsctp
vendored
Submodule deps/usrsctp updated: 8768f70504...aa10d60bc2
@ -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>
|
||||
|
@ -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;
|
||||
|
@ -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>
|
||||
|
@ -23,7 +23,9 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using namespace std::chrono;
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user