Add native self-hosted instance connection to fluxer_desktop

Trimmed monorepo checkout (fluxer_desktop + packages/voice_engine_v2 +
tools/ci) with a "Connect to a Different Server" menu item and popout
that lets the desktop app switch to any self-hosted Fluxer instance,
plus fixes for well-known discovery on single-domain self-hosted
deployments and a false-positive ERR_ABORTED on same-origin client
redirects during the switch. Defaults to chat.fluxr.chat and uses an
isolated userData directory from the official build.
This commit is contained in:
2026-07-01 18:22:43 -04:00
commit 682afacd30
1763 changed files with 613720 additions and 0 deletions
@@ -0,0 +1,208 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "cpu_linux.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
namespace webrtc {
CpuLinux::CpuLinux()
: m_oldBusyTime(0),
m_oldIdleTime(0),
m_oldBusyTimeMulti(NULL),
m_oldIdleTimeMulti(NULL),
m_idleArray(NULL),
m_busyArray(NULL),
m_resultArray(NULL),
m_numCores(0) {
const int result = GetNumCores();
if (result != -1) {
m_numCores = result;
m_oldBusyTimeMulti = new long long[m_numCores];
memset(m_oldBusyTimeMulti, 0, sizeof(long long) * m_numCores);
m_oldIdleTimeMulti = new long long[m_numCores];
memset(m_oldIdleTimeMulti, 0, sizeof(long long) * m_numCores);
m_idleArray = new long long[m_numCores];
memset(m_idleArray, 0, sizeof(long long) * m_numCores);
m_busyArray = new long long[m_numCores];
memset(m_busyArray, 0, sizeof(long long) * m_numCores);
m_resultArray = new uint32_t[m_numCores];
GetData(m_oldBusyTime, m_oldIdleTime, m_busyArray, m_idleArray);
}
}
CpuLinux::~CpuLinux()
{
delete [] m_oldBusyTimeMulti;
delete [] m_oldIdleTimeMulti;
delete [] m_idleArray;
delete [] m_busyArray;
delete [] m_resultArray;
}
int32_t CpuLinux::CpuUsage()
{
uint32_t dummy = 0;
uint32_t* dummyArray = NULL;
return CpuUsageMultiCore(dummy, dummyArray);
}
int32_t CpuLinux::CpuUsageMultiCore(uint32_t& numCores,
uint32_t*& coreArray)
{
coreArray = m_resultArray;
numCores = m_numCores;
long long busy = 0;
long long idle = 0;
if (GetData(busy, idle, m_busyArray, m_idleArray) != 0)
return -1;
long long deltaBusy = busy - m_oldBusyTime;
long long deltaIdle = idle - m_oldIdleTime;
m_oldBusyTime = busy;
m_oldIdleTime = idle;
int retVal = -1;
if (deltaBusy + deltaIdle == 0)
{
retVal = 0;
}
else
{
retVal = (int)(100 * (deltaBusy) / (deltaBusy + deltaIdle));
}
if (coreArray == NULL)
{
return retVal;
}
for (int32_t i = 0; i < m_numCores; i++)
{
deltaBusy = m_busyArray[i] - m_oldBusyTimeMulti[i];
deltaIdle = m_idleArray[i] - m_oldIdleTimeMulti[i];
m_oldBusyTimeMulti[i] = m_busyArray[i];
m_oldIdleTimeMulti[i] = m_idleArray[i];
if(deltaBusy + deltaIdle == 0)
{
coreArray[i] = 0;
}
else
{
coreArray[i] = (int)(100 * (deltaBusy) / (deltaBusy+deltaIdle));
}
}
return retVal;
}
int CpuLinux::GetData(long long& busy, long long& idle, long long*& busyArray,
long long*& idleArray)
{
FILE* fp = fopen("/proc/stat", "r");
if (!fp)
{
return -1;
}
char line[100];
if (fgets(line, 100, fp) == NULL) {
fclose(fp);
return -1;
}
char firstWord[100];
if (sscanf(line, "%s ", firstWord) != 1) {
fclose(fp);
return -1;
}
if (strncmp(firstWord, "cpu", 3) != 0) {
fclose(fp);
return -1;
}
char sUser[100];
char sNice[100];
char sSystem[100];
char sIdle[100];
if (sscanf(line, "%s %s %s %s %s ",
firstWord, sUser, sNice, sSystem, sIdle) != 5) {
fclose(fp);
return -1;
}
long long luser = atoll(sUser);
long long lnice = atoll(sNice);
long long lsystem = atoll(sSystem);
long long lidle = atoll (sIdle);
busy = luser + lnice + lsystem;
idle = lidle;
for (int32_t i = 0; i < m_numCores; i++)
{
if (fgets(line, 100, fp) == NULL) {
fclose(fp);
return -1;
}
if (sscanf(line, "%s %s %s %s %s ", firstWord, sUser, sNice, sSystem,
sIdle) != 5) {
fclose(fp);
return -1;
}
luser = atoll(sUser);
lnice = atoll(sNice);
lsystem = atoll(sSystem);
lidle = atoll (sIdle);
busyArray[i] = luser + lnice + lsystem;
idleArray[i] = lidle;
}
fclose(fp);
return 0;
}
int CpuLinux::GetNumCores()
{
FILE* fp = fopen("/proc/stat", "r");
if (!fp)
{
return -1;
}
// Skip first line
char line[100];
if (!fgets(line, 100, fp))
{
fclose(fp);
return -1;
}
int numCores = -1;
char firstWord[100];
do
{
numCores++;
if (fgets(line, 100, fp))
{
if (sscanf(line, "%s ", firstWord) != 1) {
firstWord[0] = '\0';
}
} else {
break;
}
} while (strncmp(firstWord, "cpu", 3) == 0);
fclose(fp);
return numCores;
}
CpuWrapper* CpuWrapper::CreateCpu()
{
return new CpuLinux();
}
} // namespace webrtc
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_CPU_LINUX_H_
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_CPU_LINUX_H_
#include "cpu_wrapper.h"
namespace webrtc {
class CpuLinux : public CpuWrapper {
public:
CpuLinux();
virtual ~CpuLinux();
int32_t CpuUsage() override;
int32_t CpuUsage(int8_t* pProcessName, uint32_t length) override { return 0; }
int32_t CpuUsage(uint32_t dwProcessID) override { return 0; }
int32_t CpuUsageMultiCore(uint32_t& numCores, uint32_t*& array) override;
void Reset() override { return; }
void Stop() override { return; }
int GetNumCores() override;
private:
int GetData(long long& busy,
long long& idle,
long long*& busyArray,
long long*& idleArray);
long long m_oldBusyTime;
long long m_oldIdleTime;
long long* m_oldBusyTimeMulti;
long long* m_oldIdleTimeMulti;
long long* m_idleArray;
long long* m_busyArray;
uint32_t* m_resultArray;
uint32_t m_numCores;
};
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_CPU_LINUX_H_
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_WRAPPER_H_
#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_WRAPPER_H_
#include <stdint.h>
namespace webrtc {
class CpuWrapper
{
public:
static CpuWrapper* CreateCpu();
virtual ~CpuWrapper() {}
// Returns the average CPU usage for all processors. The CPU usage can be
// between and including 0 to 100 (%)
virtual int32_t CpuUsage() = 0;
virtual int32_t CpuUsage(int8_t* processName,
uint32_t length) = 0;
virtual int32_t CpuUsage(uint32_t dwProcessID) = 0;
// The CPU usage per core is returned in cpu_usage. The CPU can be between
// and including 0 to 100 (%)
// Note that the pointer passed as cpu_usage is redirected to a local member
// of the CPU wrapper.
// numCores is the number of cores in the cpu_usage array.
// The return value is -1 for failure or 0-100, indicating the average
// CPU usage across all cores.
// Note: on some OSs this class is initialized lazy. This means that it
// might not yet be possible to retrieve any CPU metrics. When this happens
// the return value will be zero (indicating that there is not a failure),
// numCores will be 0 and cpu_usage will be set to NULL (indicating that
// no metrics are available yet). Once the initialization is completed,
// which can take in the order of seconds, CPU metrics can be retrieved.
virtual int32_t CpuUsageMultiCore(uint32_t& numCores,
uint32_t*& cpu_usage) = 0;
virtual void Reset() = 0;
virtual void Stop() = 0;
virtual int GetNumCores() = 0;
protected:
CpuWrapper() {}
};
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_CPU_WRAPPER_H_