Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

Phone link WebRTC: one fixed UDP port (the link's port, ICE UDP mux), SCULPTFORGE_RTC_LOG

islandmed7a2349ced7cd
diff --git a/docs/guide/phone-capture.md b/docs/guide/phone-capture.md
index 1bb75584..d394201b 100644
--- a/docs/guide/phone-capture.md
+++ b/docs/guide/phone-capture.md
@@ -33,14 +33,15 @@ camera's QR links open there.
### Linux firewall
Many Linux desktops (Omarchy, Ubuntu with ufw enabled, Fedora with firewalld) block incoming connections, so the
-phone's request never arrives. Allow SculptForge's port from your home network only, for example with ufw:
+phone's request never arrives. Allow SculptForge's port from your home network only, TCP for the page and UDP for
+the direct link that AR on Android and face capture use, for example with ufw:
```
-sudo ufw allow from 10.0.0.0/24 to any port 8765 proto tcp comment 'SculptForge phone capture'
+sudo ufw allow from 10.0.0.0/24 to any port 8765 comment 'SculptForge phone capture'
```
Use your own network's range (the first three numbers of the address under the QR code, then `.0/24`). With
-firewalld: `sudo firewall-cmd --add-port=8765/tcp` (add `--permanent` to keep it).
+firewalld: `sudo firewall-cmd --add-port=8765/tcp --add-port=8765/udp` (add `--permanent` to keep it).
## Scan an object
diff --git a/src/app/PanelPhone.cpp b/src/app/PanelPhone.cpp
index cdecb14e..8f26600b 100644
--- a/src/app/PanelPhone.cpp
+++ b/src/app/PanelPhone.cpp
@@ -461,7 +461,7 @@ void App::drawPhoneWindow() {
ImGui::BulletText("Android Chrome says \"This site can't be reached\"\n(ERR_TOO_MANY_RETRIES)? Recent Chrome versions can\n"
"block every home-network address, even your router.\nUse Firefox on the phone instead and allow it to\n"
"reach local devices when it asks.");
- ImGui::BulletText("Linux: allow port %d through the firewall, e.g.\nsudo ufw allow from <your network>/24 to any\nport %d proto tcp",
+ ImGui::BulletText("Linux: allow port %d (TCP and UDP) through the\nfirewall, e.g. sudo ufw allow from\n<your network>/24 to any port %d",
int(phone_->port()), int(phone_->port()));
ImGui::TreePop();
}
diff --git a/src/link/PhoneLink.cpp b/src/link/PhoneLink.cpp
index 81be1813..d2bd796e 100644
--- a/src/link/PhoneLink.cpp
+++ b/src/link/PhoneLink.cpp
@@ -1032,7 +1032,7 @@ bool PhoneLink::createFaceLink(std::string& faceUrl, std::string& error, bool ar
stopRelay(); // (outside rtcMutex_: the relay thread takes it to answer)
std::lock_guard rtcLock(rtcMutex_);
if (rtc_) rtc_->close();
- rtc_ = std::make_unique<FaceRtc>(ar ? FaceRtc::Mode::Ar : FaceRtc::Mode::Face);
+ rtc_ = std::make_unique<FaceRtc>(ar ? FaceRtc::Mode::Ar : FaceRtc::Mode::Face, uint16_t(port()));
arSentVersion_ = 0;
if (ar) {
rtc_->onMessage = [this](const std::string& text) {
diff --git a/src/link/PhoneRtc.cpp b/src/link/PhoneRtc.cpp
index d2e1f5aa..8d05340d 100644
--- a/src/link/PhoneRtc.cpp
+++ b/src/link/PhoneRtc.cpp
@@ -1,5 +1,6 @@
// SculptForge - open source digital sculpting
// SPDX-License-Identifier: GPL-3.0-or-later
+#include <cstdlib>
#include "link/PhoneRtc.h"
#include <condition_variable>
@@ -175,15 +176,24 @@ rtc::DataChannelInit channelInit(FaceRtc::Mode mode) {
const char* channelLabel(FaceRtc::Mode mode) { return mode == FaceRtc::Mode::Ar ? "ar" : "face"; }
-rtc::Configuration localConfiguration() {
- return rtc::Configuration(); // no STUN or TURN servers: the phone and this computer share a network
+rtc::Configuration localConfiguration(uint16_t port = 0) {
+ rtc::Configuration config; // no STUN or TURN servers: the phone and this computer share a network
+ if (port) {
+ config.portRangeBegin = config.portRangeEnd = port;
+ config.enableIceUdpMux = true;
+ }
+ return config;
}
} // namespace
-FaceRtc::FaceRtc(Mode mode) : impl_(std::make_unique<Impl>()), mode_(mode) {
+FaceRtc::FaceRtc(Mode mode, uint16_t icePort) : impl_(std::make_unique<Impl>()), mode_(mode), icePort_(icePort) {
static std::once_flag logging;
- std::call_once(logging, [] { rtc::InitLogger(rtc::LogLevel::None); });
+ // SCULPTFORGE_RTC_LOG=1: WebRTC's own log (ICE candidates and checks) on stderr, for connection problems.
+ std::call_once(logging, [] {
+ const char* log = std::getenv("SCULPTFORGE_RTC_LOG");
+ rtc::InitLogger(log && *log && *log != '0' ? rtc::LogLevel::Debug : rtc::LogLevel::None);
+ });
}
FaceRtc::~FaceRtc() { close(); }
@@ -196,7 +206,13 @@ FaceRtc::State FaceRtc::state() const {
bool FaceRtc::createOffer(std::string& sdp, std::string& error, int timeoutMs) {
close();
try {
- auto pc = std::make_shared<rtc::PeerConnection>(localConfiguration());
+ std::shared_ptr<rtc::PeerConnection> pc;
+ try {
+ pc = std::make_shared<rtc::PeerConnection>(localConfiguration(icePort_));
+ } catch (const std::exception&) {
+ if (!icePort_) throw;
+ pc = std::make_shared<rtc::PeerConnection>(localConfiguration()); // the port is taken: any port
+ }
Impl* impl = impl_.get();
auto setState = [this, impl](State s) {
{
@@ -382,7 +398,7 @@ bool webrtcAvailable() { return false; }
struct FaceRtc::Impl {};
-FaceRtc::FaceRtc(Mode mode) : impl_(std::make_unique<Impl>()), mode_(mode) {}
+FaceRtc::FaceRtc(Mode mode, uint16_t icePort) : impl_(std::make_unique<Impl>()), mode_(mode), icePort_(icePort) {}
FaceRtc::~FaceRtc() = default;
FaceRtc::State FaceRtc::state() const { return State::Idle; }
diff --git a/src/link/PhoneRtc.h b/src/link/PhoneRtc.h
index bdfbdd66..9502c41e 100644
--- a/src/link/PhoneRtc.h
+++ b/src/link/PhoneRtc.h
@@ -32,7 +32,9 @@ public:
enum class State { Idle, Offered, Connecting, Connected, Closed, Failed };
enum class Mode { Face, Ar }; // Face: the "face" channel, unordered and lossy; Ar: the "ar" channel, reliable
- explicit FaceRtc(Mode mode = Mode::Face);
+ // `icePort`: the local UDP port for every link (0 = any), shared through ICE UDP multiplexing, so a firewall
+ // needs one rule (the phone link uses its HTTP port number). Falls back to any port if it is taken.
+ explicit FaceRtc(Mode mode = Mode::Face, uint16_t icePort = 0);
~FaceRtc();
FaceRtc(const FaceRtc&) = delete;
FaceRtc& operator=(const FaceRtc&) = delete;
@@ -62,6 +64,7 @@ public:
private:
struct Impl;
Mode mode_;
+ uint16_t icePort_;
std::unique_ptr<Impl> impl_;
};