teleportxr 1.0.28 → 1.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/signaling.js +27 -0
package/package.json
CHANGED
package/signaling.js
CHANGED
|
@@ -52,6 +52,7 @@ var desiredIP = "";
|
|
|
52
52
|
var webRtcConnectionManager = null;
|
|
53
53
|
var newClient=null;
|
|
54
54
|
var disconnectClient=null;
|
|
55
|
+
var clientHostHeader = ""; // Store the first client's host header for resource URLs
|
|
55
56
|
function startStreaming(signalingClient) {
|
|
56
57
|
signalingClient.ChangeSignalingState(SignalingState.ACCEPTED);
|
|
57
58
|
// And we send the WebSockets connect-response.
|
|
@@ -183,6 +184,27 @@ function OnWebSocket(ws, req) {
|
|
|
183
184
|
" connected from " +
|
|
184
185
|
signalingClient.ip_addr_port.toString()
|
|
185
186
|
);
|
|
187
|
+
|
|
188
|
+
// Capture the Host header from the first client connection for resource URLs
|
|
189
|
+
// This allows us to auto-detect the server's public address
|
|
190
|
+
if (!clientHostHeader && req.headers) {
|
|
191
|
+
// Try to get the host from headers, preferring X-Forwarded-Host (for reverse proxies)
|
|
192
|
+
const xForwardedHost = req.headers['x-forwarded-host'];
|
|
193
|
+
const hostHeader = req.headers['host'];
|
|
194
|
+
clientHostHeader = xForwardedHost || hostHeader || '';
|
|
195
|
+
if (clientHostHeader) {
|
|
196
|
+
console.log("Auto-detected resource server host from client connection: " + clientHostHeader);
|
|
197
|
+
if (xForwardedHost) {
|
|
198
|
+
console.log(" (from X-Forwarded-Host: " + xForwardedHost + ")");
|
|
199
|
+
} else if (hostHeader) {
|
|
200
|
+
console.log(" (from Host: " + hostHeader + ")");
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
console.log("WARNING: Could not auto-detect host from request headers");
|
|
204
|
+
console.log(" Available headers: " + JSON.stringify(req.headers));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
186
208
|
//When the server runs behind a proxy like NGINX, the de-facto standard is to use the X-Forwarded-For header.
|
|
187
209
|
//const ip = .headers['x-forwarded-for'].split(',')[0].trim();
|
|
188
210
|
|
|
@@ -273,3 +295,8 @@ exports.sendConfigMessage = function (clientID, msg) {
|
|
|
273
295
|
};
|
|
274
296
|
|
|
275
297
|
exports.signalingClients = signalingClients;
|
|
298
|
+
|
|
299
|
+
// Export function to retrieve the auto-detected client host header for resource URLs
|
|
300
|
+
exports.getClientHostHeader = function () {
|
|
301
|
+
return clientHostHeader;
|
|
302
|
+
};
|