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.

AR page: ask Chrome's Local Network Access permission before connecting

islandmed812cd4b86f21
diff --git a/src/link/PhoneRtc.cpp b/src/link/PhoneRtc.cpp
index 8d05340d..17dd4e7f 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 <cstdio>
#include <cstdlib>
#include "link/PhoneRtc.h"
@@ -189,10 +190,12 @@ rtc::Configuration localConfiguration(uint16_t port = 0) {
FaceRtc::FaceRtc(Mode mode, uint16_t icePort) : impl_(std::make_unique<Impl>()), mode_(mode), icePort_(icePort) {
static std::once_flag logging;
- // SCULPTFORGE_RTC_LOG=1: WebRTC's own log (ICE candidates and checks) on stderr, for connection problems.
+ // SCULPTFORGE_RTC_LOG=1 (2: every packet): 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);
+ rtc::InitLogger(!log || !*log || *log == '0' ? rtc::LogLevel::None
+ : *log == '2' ? rtc::LogLevel::Verbose
+ : rtc::LogLevel::Debug);
});
}
@@ -257,6 +260,8 @@ bool FaceRtc::createOffer(std::string& sdp, std::string& error, int timeoutMs) {
return false;
}
sdp = std::string(*description);
+ if (const char* log = std::getenv("SCULPTFORGE_RTC_LOG"); log && *log && *log != '0')
+ std::fprintf(stderr, "Offer:\n%s\n", sdp.c_str());
if (sdp.find("a=candidate:") == std::string::npos) {
error = "This computer has no network address the phone could reach";
return false;
@@ -280,6 +285,8 @@ bool FaceRtc::setAnswer(const std::string& sdp, std::string& error) {
}
impl_->state = State::Connecting;
}
+ if (const char* log = std::getenv("SCULPTFORGE_RTC_LOG"); log && *log && *log != '0')
+ std::fprintf(stderr, "Phone's answer:\n%s\n", sdp.c_str());
try {
pc->setRemoteDescription(rtc::Description(sdp, rtc::Description::Type::Answer));
return true;
diff --git a/website/link/ar.html b/website/link/ar.html
index 696976d7..212769da 100644
--- a/website/link/ar.html
+++ b/website/link/ar.html
@@ -272,6 +272,13 @@ if (!token || !frag.get("o")) {
const stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: "environment" }, audio: false });
for (const t of stream.getTracks()) t.stop();
} catch (e) { /* refused: try anyway (works when the computer has no firewall) */ }
+ // Chrome's Local Network Access: a website may only reach home-network devices once the person allows it.
+ // A request to the computer (its address is private, so Chrome lets this https page make it) brings up
+ // Chrome's "access devices on your local network" prompt; the direct link below needs that permission too.
+ $("waitText").textContent = "If Chrome asks to let this page reach devices on your local network, tap Allow.";
+ try {
+ await fetch(`${desktop}/api/hello`, { mode: "no-cors", cache: "no-store", targetAddressSpace: "local" });
+ } catch (e) { /* refused or unreachable: the direct link may still work */ }
$("waitText").textContent = "Connecting to your computer...";
connectRtc().catch((e) => note($("liveMsg"), "Couldn't connect: " + esc(e.message || e), "bad"));
}