mirror of
https://github.com/godotengine/webrtc-native.git
synced 2026-01-01 05:48:15 +03:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eeabf0a844 | ||
|
|
04fbae6ce3 | ||
|
|
ce3f086ec4 | ||
|
|
00ac03c8e7 | ||
|
|
fa5296a4e4 | ||
|
|
189c353264 | ||
|
|
e44c42fde8 | ||
|
|
524fdde8f2 | ||
|
|
673a4c1a1c | ||
|
|
cf98eb2e7a |
51
.github/actions/webrtc-download/action.yml
vendored
Normal file
51
.github/actions/webrtc-download/action.yml
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
name: 'Get WebRTC Library'
|
||||
description: 'Get pre-build statically linked WebRTC library from Faless/webrtc-builds'
|
||||
inputs:
|
||||
repo:
|
||||
description: 'Base repository'
|
||||
required: true
|
||||
default: "godotengine/webrtc-actions"
|
||||
release:
|
||||
description: 'Release tag'
|
||||
required: true
|
||||
default: '4472-33644-92ba70c'
|
||||
webrtc-base-name:
|
||||
description: 'The WebRTC version'
|
||||
required: true
|
||||
default: "webrtc-33644-92ba70c"
|
||||
out-dir:
|
||||
description: 'Directory where to extract the library'
|
||||
required: true
|
||||
default: "webrtc"
|
||||
platform:
|
||||
description: 'Platform to download'
|
||||
required: true
|
||||
archs:
|
||||
description: 'Space separated list of architecture to fetch'
|
||||
required: true
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- shell: bash
|
||||
env:
|
||||
RTC_BASE_URL: https://github.com/${{ inputs.repo }}/releases/download/${{ inputs.release }}/${{ inputs.webrtc-base-name }}
|
||||
run: |
|
||||
cd ${{ inputs.out-dir }}
|
||||
|
||||
libplat=${{ inputs.platform }}
|
||||
if [ "${{ inputs.platform }}" = "windows" ]; then
|
||||
libplat=win
|
||||
elif [ "${{ inputs.platform }}" = "osx" ]; then
|
||||
libplat=mac
|
||||
fi
|
||||
|
||||
for arch in ${{ inputs.archs }}
|
||||
do
|
||||
echo "Downloading ${{ env.RTC_BASE_URL }}-${{ inputs.platform }}-${arch}.tar.gz"
|
||||
curl -L ${{ env.RTC_BASE_URL }}-${libplat}-${arch}.tar.gz -o ${arch}.tar.gz
|
||||
tar -xzf ${arch}.tar.gz
|
||||
done
|
||||
|
||||
mv lib ${{ inputs.platform }}
|
||||
ls -l
|
||||
ls -l *
|
||||
180
.github/workflows/build_release.yml
vendored
Normal file
180
.github/workflows/build_release.yml
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
name: 🔧 Build -> Package 📦
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
name: 🔧 Build
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
# Android
|
||||
- platform: android
|
||||
arch: 'x86'
|
||||
sconsflags: 'android_arch=x86'
|
||||
os: 'ubuntu-20.04'
|
||||
- platform: android
|
||||
arch: 'x64'
|
||||
sconsflags: 'android_arch=x86_64'
|
||||
os: 'ubuntu-20.04'
|
||||
- platform: android
|
||||
arch: 'arm'
|
||||
sconsflags: 'android_arch=armv7'
|
||||
os: 'ubuntu-20.04'
|
||||
- platform: android
|
||||
arch: 'arm64'
|
||||
sconsflags: 'android_arch=arm64v8'
|
||||
os: 'ubuntu-20.04'
|
||||
|
||||
# iOS
|
||||
- platform: ios
|
||||
arch: 'x64'
|
||||
sconsflags: 'ios_arch=x86_64 ios_simulator=true'
|
||||
os: 'macos-latest'
|
||||
- platform: ios
|
||||
arch: 'arm'
|
||||
sconsflags: 'ios_arch=armv7'
|
||||
os: 'macos-latest'
|
||||
- platform: ios
|
||||
arch: 'arm64'
|
||||
sconsflags: 'ios_arch=arm64'
|
||||
os: 'macos-latest'
|
||||
|
||||
# Linux
|
||||
- platform: linux
|
||||
arch: 'x86'
|
||||
sconsflags: 'bits=32'
|
||||
os: 'ubuntu-20.04'
|
||||
- platform: linux
|
||||
arch: 'x64'
|
||||
sconsflags: 'bits=64'
|
||||
os: 'ubuntu-20.04'
|
||||
|
||||
# macOS
|
||||
- platform: osx
|
||||
arch: 'x64'
|
||||
sconsflags: 'bits=64'
|
||||
os: 'macos-latest'
|
||||
|
||||
# Windows
|
||||
- platform: windows
|
||||
arch: 'x86'
|
||||
sconsflags: 'bits=32'
|
||||
os: 'windows-latest'
|
||||
msvc_arch: amd64_x86
|
||||
- platform: windows
|
||||
arch: 'x64'
|
||||
sconsflags: 'bits=64'
|
||||
os: 'windows-latest'
|
||||
msvc_arch: amd64
|
||||
|
||||
env:
|
||||
SCONSFLAGS: ${{ matrix.sconsflags }} platform=${{ matrix.platform }} --jobs=2
|
||||
NDK_VERSION: 22b
|
||||
ANDROID_NDK_ROOT: ${{github.workspace}}/android-ndk-r22b
|
||||
MSVC_VARS: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat'
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Cache NDK
|
||||
id: cache-ndk
|
||||
if: ${{ matrix.platform == 'android' }}
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ env.ANDROID_NDK_ROOT }}
|
||||
key: ndk-${{ env.NDK_VERSION }}
|
||||
|
||||
- name: Download NDK
|
||||
if: ${{ matrix.platform == 'android' && steps.cache-ndk.outputs.cache-hit != 'true' }}
|
||||
id: setup-ndk
|
||||
run: |
|
||||
cd ${{ github.workspace }}
|
||||
curl -L https://dl.google.com/android/repository/android-ndk-r${{ env.NDK_VERSION }}-linux-x86_64.zip -o ndk.zip
|
||||
unzip ndk.zip
|
||||
ls
|
||||
|
||||
- name: Setup MSVC build environment for ${{ matrix.msvc_arch }}
|
||||
if: ${{ matrix.platform == 'windows' }}
|
||||
run: "'${{ env.MSVC_VARS }}' ${{ matrix.msvc_arch }}"
|
||||
|
||||
- name: Install Linux build dependencies
|
||||
if: ${{ matrix.platform == 'linux' }}
|
||||
run: |
|
||||
sudo apt-get install build-essential gcc-multilib wget g++-multilib
|
||||
|
||||
- name: Set up Python 3.x
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '3.x'
|
||||
architecture: 'x64'
|
||||
|
||||
- name: Configuring Python packages
|
||||
run: |
|
||||
python -c "import sys; print(sys.version)"
|
||||
python -m pip install scons
|
||||
python --version
|
||||
scons --version
|
||||
|
||||
- name: Get WebRTC package for ${{ matrix.platform }} - ${{ matrix.arch }}
|
||||
uses: ./.github/actions/webrtc-download
|
||||
with:
|
||||
platform: ${{ matrix.platform }}
|
||||
archs: ${{ matrix.arch }}
|
||||
|
||||
- name: Compilation ${{ matrix.platform }} - ${{ matrix.arch }} - godot-cpp
|
||||
run: |
|
||||
scons -C godot-cpp target=debug generate_bindings=yes
|
||||
scons -C godot-cpp target=release
|
||||
|
||||
- name: Compilation ${{ matrix.platform }} - ${{ matrix.arch }} - webrtc-native
|
||||
run: |
|
||||
scons target=debug
|
||||
scons target=release
|
||||
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: ${{ github.job }}-${{ matrix.platform }}-${{ matrix.arch }}
|
||||
path: bin/*
|
||||
|
||||
package:
|
||||
name: 📦 Package
|
||||
needs: build
|
||||
runs-on: "ubuntu-latest"
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
path: artifacts
|
||||
|
||||
- name: Package artifacts for release
|
||||
run: |
|
||||
mkdir release
|
||||
cd release
|
||||
for name in webrtc webrtc_debug
|
||||
do
|
||||
mkdir -p ${name}/lib/
|
||||
find ../artifacts -wholename "*/${name}/lib/*" | xargs cp -t ${name}/lib/
|
||||
find ../artifacts -wholename "*/${name}/${name}.tres" | head -n 1 | xargs cp -t ${name}/
|
||||
done
|
||||
|
||||
zip -r godot-webrtc-native-release.zip webrtc
|
||||
zip -r godot-webrtc-native-debug.zip webrtc_debug
|
||||
ls -R
|
||||
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: godot-webrtc-native-debug.zip
|
||||
path: release/godot-webrtc-native-debug.zip
|
||||
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: godot-webrtc-native-release.zip
|
||||
path: release/godot-webrtc-native-release.zip
|
||||
17
README.md
17
README.md
@@ -7,15 +7,15 @@
|
||||
|
||||
### Compiling
|
||||
|
||||
Clone this repository with the following command to checkout both [godot-cpp](https://github.com/GodotNativeTools/godot-cpp) and [godot_headers](https://github.com/GodotNativeTools/godot_headers) dependencies.
|
||||
Clone this repository with the following command to checkout both [godot-cpp](https://github.com/godotengine/godot-cpp) and [godot-headers](https://github.com/godotengine/godot-headers) dependencies.
|
||||
|
||||
```
|
||||
$ git clone --recurse-submodules git@github.com:godotengine/webrtc-native.git
|
||||
$ git clone --recurse-submodules https://github.com/godotengine/webrtc-native.git
|
||||
```
|
||||
|
||||
Note that if you wish to use a specific branch, add the -b option to the clone command:
|
||||
```
|
||||
$ git clone --recurse-submodules -b 3.2 git@github.com:godotengine/webrtc-native.git
|
||||
$ git clone --recurse-submodules -b 3.2 https://github.com/godotengine/webrtc-native.git
|
||||
```
|
||||
|
||||
If you already checked out the branch use the following commands to update the dependencies:
|
||||
@@ -29,7 +29,7 @@ Right now our directory structure should look like this:
|
||||
webrtc-native/
|
||||
├─bin/
|
||||
├─godot-cpp/
|
||||
| └─godot_headers/
|
||||
| └─godot-headers/
|
||||
├─src/
|
||||
└─webrtc/
|
||||
```
|
||||
@@ -54,7 +54,12 @@ $ cd ..
|
||||
|
||||
### Building WebRTC
|
||||
|
||||
Use [this script](https://github.com/Faless/webrtc-builds) to build and package the WebRTCLibrary (`branch-heads/68`), or [**download latest pre-compiled binaries**](https://github.com/Faless/webrtc-builds/releases)
|
||||
Building WebRTC is quite a complex task, involves huge downloads and long build times, and produces multiple output libraries that needs to bundled together.
|
||||
|
||||
To make things easier, a set of [GitHub Actions](https://docs.github.com/en/actions) are used to generate the library for this plugin, [available in this repository](https://github.com/godotengine/webrtc-actions).
|
||||
|
||||
Alternatively, [**download the latest pre-compiled libraries**](https://github.com/godotengine/webrtc-actions/releases).
|
||||
|
||||
Extract content of `include` into `webrtc/include` and content of `bin` into `webrtc/<your platform>`
|
||||
|
||||
### Compiling the plugin.
|
||||
@@ -63,4 +68,4 @@ Extract content of `include` into `webrtc/include` and content of `bin` into `we
|
||||
$ scons platform=<your platform> target=<your target>
|
||||
```
|
||||
|
||||
The generated library and associated `gdns` will be placed in `bin/webrtc/` or `bin/webrtc_debug/` according to the desired target. You simply need to copy that folder into your project.
|
||||
The generated library and associated `tres` will be placed in `bin/webrtc/` or `bin/webrtc_debug/` according to the desired target. You simply need to copy that folder to the root folder of your project.
|
||||
|
||||
14
SConstruct
14
SConstruct
@@ -141,7 +141,12 @@ elif target_platform == 'windows':
|
||||
elif target_arch == '64':
|
||||
env['CXX']='x86_64-w64-mingw32-g++'
|
||||
|
||||
env.Append(CCFLAGS = [ '-g', '-O3', '-std=c++14', '-Wwrite-strings' ])
|
||||
if env['target'] == 'debug':
|
||||
env.Append(CCFLAGS=['-Og', '-g'])
|
||||
elif env['target'] == 'release':
|
||||
env.Append(CCFLAGS=['-O3'])
|
||||
|
||||
env.Append(CCFLAGS = [ '-std=c++14', '-Wwrite-strings' ])
|
||||
env.Append(LINKFLAGS = [ '--static', '-Wl,--no-undefined', '-static-libgcc', '-static-libstdc++' ])
|
||||
|
||||
elif target_platform == 'osx':
|
||||
@@ -151,7 +156,7 @@ elif target_platform == 'osx':
|
||||
# Only 64-bits is supported for OS X
|
||||
target_arch = '64'
|
||||
|
||||
env.Append(CCFLAGS = [ '-g','-O3', '-std=c++14', '-arch', 'x86_64' ])
|
||||
env.Append(CCFLAGS = [ '-std=c++14', '-arch', 'x86_64' ])
|
||||
env.Append(LINKFLAGS = [ '-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup' ])
|
||||
|
||||
if env['target'] == 'debug':
|
||||
@@ -248,6 +253,11 @@ elif target_platform == 'android':
|
||||
env.Append(CCFLAGS=arch_info['ccflags'])
|
||||
env.Append(LINKFLAGS=['--target=' + arch_info['target'] + env['android_api_level'], '-march=' + arch_info['march']])
|
||||
|
||||
if env['target'] == 'debug':
|
||||
env.Append(CCFLAGS=['-Og', '-g'])
|
||||
elif env['target'] == 'release':
|
||||
env.Append(CCFLAGS=['-O3'])
|
||||
|
||||
else:
|
||||
print("No valid target platform selected.")
|
||||
sys.exit(1)
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
#include "WebRTCLibDataChannel.hpp"
|
||||
#include "WebRTCLibPeerConnection.hpp"
|
||||
|
||||
using namespace godot_webrtc;
|
||||
|
||||
// CreateSessionObseerver
|
||||
WebRTCLibPeerConnection::GodotCSDO::GodotCSDO(WebRTCLibPeerConnection *parent) {
|
||||
this->parent = parent;
|
||||
}
|
||||
|
||||
void WebRTCLibPeerConnection::GodotCSDO::OnSuccess(webrtc::SessionDescriptionInterface *desc) {
|
||||
// serialize this offer and send it to the remote peer:
|
||||
std::string sdp; // sdp = session description protocol
|
||||
desc->ToString(&sdp);
|
||||
parent->queue_signal("session_description_created", 2, desc->type().c_str(), sdp.c_str());
|
||||
};
|
||||
|
||||
void WebRTCLibPeerConnection::GodotCSDO::OnFailure(webrtc::RTCError error){};
|
||||
|
||||
// SetSessionObseerver
|
||||
WebRTCLibPeerConnection::GodotSSDO::GodotSSDO(WebRTCLibPeerConnection *parent) {
|
||||
this->parent = parent;
|
||||
}
|
||||
|
||||
void WebRTCLibPeerConnection::GodotSSDO::OnSuccess(){};
|
||||
void WebRTCLibPeerConnection::GodotSSDO::OnFailure(webrtc::RTCError error){};
|
||||
|
||||
// PeerConnectionObserver
|
||||
WebRTCLibPeerConnection::GodotPCO::GodotPCO(WebRTCLibPeerConnection *parent) {
|
||||
this->parent = parent;
|
||||
}
|
||||
|
||||
void WebRTCLibPeerConnection::GodotPCO::OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) {
|
||||
parent->queue_signal("data_channel_received", 1, WebRTCLibDataChannel::new_data_channel(data_channel));
|
||||
}
|
||||
|
||||
void WebRTCLibPeerConnection::GodotPCO::OnIceCandidate(const webrtc::IceCandidateInterface *candidate) {
|
||||
godot::Dictionary candidateSDP;
|
||||
godot::String candidateSdpMidName = candidate->sdp_mid().c_str();
|
||||
int candidateSdpMlineIndexName = candidate->sdp_mline_index();
|
||||
std::string sdp;
|
||||
candidate->ToString(&sdp);
|
||||
godot::String candidateSdpName = sdp.c_str();
|
||||
|
||||
parent->queue_signal("ice_candidate_created", 3, candidateSdpMidName, candidateSdpMlineIndexName, candidateSdpName);
|
||||
}
|
||||
|
||||
void WebRTCLibPeerConnection::GodotPCO::OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) {}
|
||||
void WebRTCLibPeerConnection::GodotPCO::OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {}
|
||||
void WebRTCLibPeerConnection::GodotPCO::OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {}
|
||||
void WebRTCLibPeerConnection::GodotPCO::OnRenegotiationNeeded() {}
|
||||
void WebRTCLibPeerConnection::GodotPCO::OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) {}
|
||||
void WebRTCLibPeerConnection::GodotPCO::OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) {}
|
||||
@@ -7,6 +7,33 @@ using namespace godot_webrtc;
|
||||
|
||||
std::unique_ptr<rtc::Thread> WebRTCLibPeerConnection::signaling_thread = nullptr;
|
||||
|
||||
// PeerConnectionObserver
|
||||
void WebRTCLibPeerConnection::GodotPCO::OnIceCandidate(const webrtc::IceCandidateInterface *candidate) {
|
||||
godot::Dictionary candidateSDP;
|
||||
godot::String candidateSdpMidName = candidate->sdp_mid().c_str();
|
||||
int candidateSdpMlineIndexName = candidate->sdp_mline_index();
|
||||
std::string sdp;
|
||||
candidate->ToString(&sdp);
|
||||
godot::String candidateSdpName = sdp.c_str();
|
||||
parent->queue_signal("ice_candidate_created", 3, candidateSdpMidName, candidateSdpMlineIndexName, candidateSdpName);
|
||||
}
|
||||
|
||||
// SetSessionDescriptionObserver
|
||||
void WebRTCLibPeerConnection::GodotSSDO::OnSuccess() {
|
||||
if (make_offer) {
|
||||
make_offer = false;
|
||||
parent->peer_connection->CreateAnswer(parent->ptr_csdo, webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
|
||||
}
|
||||
}
|
||||
|
||||
// CreateSessionDescriptionObserver
|
||||
void WebRTCLibPeerConnection::GodotCSDO::OnSuccess(webrtc::SessionDescriptionInterface *desc) {
|
||||
// serialize this offer and send it to the remote peer:
|
||||
std::string sdp;
|
||||
desc->ToString(&sdp);
|
||||
parent->queue_signal("session_description_created", 2, desc->type().c_str(), sdp.c_str());
|
||||
}
|
||||
|
||||
void WebRTCLibPeerConnection::initialize_signaling() {
|
||||
if (signaling_thread.get() == nullptr) {
|
||||
signaling_thread = rtc::Thread::Create();
|
||||
@@ -142,8 +169,10 @@ godot_error WebRTCLibPeerConnection::create_offer() {
|
||||
godot_error WebRTCLibPeerConnection::set_remote_description(const char *type, const char *sdp) {
|
||||
ERR_FAIL_COND_V(peer_connection.get() == nullptr, GODOT_ERR_UNCONFIGURED);
|
||||
std::unique_ptr<webrtc::SessionDescriptionInterface> desc = _MAKE_DESC(type, sdp);
|
||||
if (desc->GetType() == webrtc::SdpType::kOffer) {
|
||||
ptr_ssdo->make_offer = true;
|
||||
}
|
||||
peer_connection->SetRemoteDescription(ptr_ssdo, desc.release());
|
||||
peer_connection->CreateAnswer(ptr_csdo, webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
|
||||
return GODOT_OK;
|
||||
}
|
||||
|
||||
@@ -174,14 +203,12 @@ godot_error WebRTCLibPeerConnection::add_ice_candidate(const char *sdpMidName, i
|
||||
godot_error WebRTCLibPeerConnection::poll() {
|
||||
ERR_FAIL_COND_V(peer_connection.get() == nullptr, GODOT_ERR_UNCONFIGURED);
|
||||
|
||||
std::function<void()> signal;
|
||||
while (!signal_queue.empty()) {
|
||||
mutex_signal_queue->lock();
|
||||
signal = signal_queue.front();
|
||||
Signal signal = signal_queue.front();
|
||||
signal_queue.pop();
|
||||
mutex_signal_queue->unlock();
|
||||
|
||||
signal();
|
||||
signal.emit(this);
|
||||
}
|
||||
return GODOT_OK;
|
||||
}
|
||||
@@ -244,15 +271,7 @@ WebRTCLibPeerConnection::~WebRTCLibPeerConnection() {
|
||||
|
||||
void WebRTCLibPeerConnection::queue_signal(godot::String p_name, int p_argc, const godot::Variant &p_arg1, const godot::Variant &p_arg2, const godot::Variant &p_arg3) {
|
||||
mutex_signal_queue->lock();
|
||||
signal_queue.push(
|
||||
[this, p_name, p_argc, p_arg1, p_arg2, p_arg3] {
|
||||
if (p_argc == 1) {
|
||||
emit_signal(p_name, p_arg1);
|
||||
} else if (p_argc == 2) {
|
||||
emit_signal(p_name, p_arg1, p_arg2);
|
||||
} else {
|
||||
emit_signal(p_name, p_arg1, p_arg2, p_arg3);
|
||||
}
|
||||
});
|
||||
const godot::Variant argv[3] = { p_arg1, p_arg2, p_arg3 };
|
||||
signal_queue.push(Signal(p_name, p_argc, argv));
|
||||
mutex_signal_queue->unlock();
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
|
||||
#include "api/peer_connection_interface.h" // interface for all things needed from WebRTC
|
||||
#include "media/base/media_engine.h" // needed for CreateModularPeerConnectionFactory
|
||||
#include <functional> // std::function
|
||||
#include <mutex> // mutex @TODO replace std::mutex with Godot mutex
|
||||
#include <mutex>
|
||||
|
||||
#include "net/WebRTCPeerConnectionNative.hpp"
|
||||
|
||||
@@ -41,9 +40,8 @@ public:
|
||||
~WebRTCLibPeerConnection();
|
||||
|
||||
/* helper functions */
|
||||
|
||||
private:
|
||||
void queue_signal(godot::String p_name, int p_argc, const godot::Variant &p_arg1 = godot::Variant(), const godot::Variant &p_arg2 = godot::Variant(), const godot::Variant &p_arg3 = godot::Variant());
|
||||
// void queue_signal(godot::StringName p_name, Variant_ARG_LIST);
|
||||
void queue_packet(uint8_t *, int);
|
||||
|
||||
/** PeerConnectionObserver callback functions **/
|
||||
@@ -51,35 +49,74 @@ public:
|
||||
public:
|
||||
WebRTCLibPeerConnection *parent;
|
||||
|
||||
GodotPCO(WebRTCLibPeerConnection *parent);
|
||||
void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) override;
|
||||
void OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override;
|
||||
void OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override;
|
||||
void OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override;
|
||||
void OnRenegotiationNeeded() override;
|
||||
void OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) override;
|
||||
void OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) override;
|
||||
GodotPCO(WebRTCLibPeerConnection *p_parent) {
|
||||
parent = p_parent;
|
||||
}
|
||||
void OnIceCandidate(const webrtc::IceCandidateInterface *candidate) override;
|
||||
|
||||
void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) override {}
|
||||
void OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override {}
|
||||
void OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override {}
|
||||
void OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override {}
|
||||
void OnRenegotiationNeeded() override {}
|
||||
void OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) override {}
|
||||
void OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) override {}
|
||||
};
|
||||
|
||||
/** CreateSessionDescriptionObserver callback functions **/
|
||||
class GodotCSDO : public webrtc::CreateSessionDescriptionObserver {
|
||||
public:
|
||||
WebRTCLibPeerConnection *parent;
|
||||
WebRTCLibPeerConnection *parent = nullptr;
|
||||
|
||||
GodotCSDO(WebRTCLibPeerConnection *parent);
|
||||
GodotCSDO(WebRTCLibPeerConnection *p_parent) {
|
||||
parent = p_parent;
|
||||
}
|
||||
void OnSuccess(webrtc::SessionDescriptionInterface *desc) override;
|
||||
void OnFailure(webrtc::RTCError error) override;
|
||||
void OnFailure(webrtc::RTCError error) override {
|
||||
ERR_PRINT(godot::String(error.message()));
|
||||
}
|
||||
};
|
||||
|
||||
/** SetSessionDescriptionObserver callback functions **/
|
||||
class GodotSSDO : public webrtc::SetSessionDescriptionObserver {
|
||||
public:
|
||||
WebRTCLibPeerConnection *parent;
|
||||
WebRTCLibPeerConnection *parent = nullptr;
|
||||
bool make_offer = false;
|
||||
|
||||
GodotSSDO(WebRTCLibPeerConnection *parent);
|
||||
GodotSSDO(WebRTCLibPeerConnection *p_parent) {
|
||||
parent = p_parent;
|
||||
}
|
||||
void OnSuccess() override;
|
||||
void OnFailure(webrtc::RTCError error) override;
|
||||
void OnFailure(webrtc::RTCError error) override {
|
||||
make_offer = false;
|
||||
ERR_PRINT(godot::String(error.message()));
|
||||
}
|
||||
};
|
||||
|
||||
class Signal {
|
||||
godot::String method;
|
||||
godot::Variant argv[3];
|
||||
int argc = 0;
|
||||
public:
|
||||
Signal(godot::String p_method, int p_argc, const godot::Variant *p_argv) {
|
||||
method = p_method;
|
||||
argc = p_argc;
|
||||
for (int i = 0; i < argc; i++) {
|
||||
argv[i] = p_argv[i];
|
||||
}
|
||||
}
|
||||
|
||||
void emit(godot::Object *p_object) {
|
||||
if (argc == 0) {
|
||||
p_object->emit_signal(method);
|
||||
} else if (argc == 1) {
|
||||
p_object->emit_signal(method, argv[0]);
|
||||
} else if (argc == 2) {
|
||||
p_object->emit_signal(method, argv[0], argv[1]);
|
||||
} else if (argc == 3) {
|
||||
p_object->emit_signal(method, argv[0], argv[1], argv[2]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GodotPCO pco;
|
||||
@@ -87,7 +124,7 @@ public:
|
||||
rtc::scoped_refptr<GodotCSDO> ptr_csdo;
|
||||
|
||||
std::mutex *mutex_signal_queue = nullptr;
|
||||
std::queue<std::function<void()> > signal_queue;
|
||||
std::queue<Signal> signal_queue;
|
||||
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory;
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection;
|
||||
|
||||
3
webrtc/.gitignore
vendored
3
webrtc/.gitignore
vendored
@@ -1 +1,2 @@
|
||||
include/
|
||||
*
|
||||
!.gitignore
|
||||
|
||||
2
webrtc/linux/.gitignore
vendored
2
webrtc/linux/.gitignore
vendored
@@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
||||
2
webrtc/windows/.gitignore
vendored
2
webrtc/windows/.gitignore
vendored
@@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
||||
Reference in New Issue
Block a user