add upstream proxy support for creator
This commit is contained in:
1 parent
48dcb04c77
commit
000447b77c
21 files changed
+713
-84
No files matched your search
@@ -4,7 +4,7 @@ import * as fs from 'fs/promises';
|
||||
import { TabManager } from './tab-manager';
|
||||
import { BotManager } from '../bot/bot-manager';
|
||||
import { IPC } from '../constants';
|
||||
import { TunnelMode, Platform, BotSettings, HeadlessStartArgs } from '../types';
|
||||
import { TunnelMode, Platform, BotSettings, HeadlessStartArgs, UpstreamProxy } from '../types';
|
||||
|
||||
export function registerIpcHandlers(tabManager: TabManager): void {
|
||||
ipcMain.handle(IPC.GET_HOOK_CODE, async (_e, tabId: string, url: string) => {
|
||||
@@ -86,6 +86,10 @@ export function registerIpcHandlers(tabManager: TabManager): void {
|
||||
return { success: true };
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC.SET_UPSTREAM_PROXY, (_e, proxy: UpstreamProxy) => {
|
||||
tabManager.setUpstreamProxy(proxy);
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC.SEND_BOT_CALL_LINK, (_e, tabId: string, link: string) => {
|
||||
tabManager.sendBotCallLink(tabId, link);
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
CallStatus,
|
||||
HeadlessStartArgs,
|
||||
HeadlessMode,
|
||||
UpstreamProxy,
|
||||
} from '../types';
|
||||
import {
|
||||
INITIAL_PORT_BASE,
|
||||
@@ -51,6 +52,7 @@ export class TabManager {
|
||||
private headlessWBStreamPath: string;
|
||||
private headlessDionPath: string;
|
||||
private hooksDir: string;
|
||||
private upstreamProxy: UpstreamProxy = { socks: '', user: '', pass: '' };
|
||||
|
||||
constructor() {
|
||||
this.relayPath = resolveResourcePath(
|
||||
@@ -213,6 +215,21 @@ export class TabManager {
|
||||
this._botManager.sendMessage(tab.peerId, link);
|
||||
}
|
||||
|
||||
setUpstreamProxy(proxy: UpstreamProxy): void {
|
||||
this.upstreamProxy = {
|
||||
socks: (proxy?.socks || '').trim(),
|
||||
user: (proxy?.user || '').trim(),
|
||||
pass: (proxy?.pass || '').trim(),
|
||||
};
|
||||
}
|
||||
|
||||
private appendUpstreamArgs(args: string[]): void {
|
||||
if (!this.upstreamProxy.socks) return;
|
||||
args.push('--upstream-socks', this.upstreamProxy.socks);
|
||||
if (this.upstreamProxy.user) args.push('--upstream-user', this.upstreamProxy.user);
|
||||
if (this.upstreamProxy.pass) args.push('--upstream-pass', this.upstreamProxy.pass);
|
||||
}
|
||||
|
||||
startRelay(tabId: string, tab: TabState): void {
|
||||
this.killRelay(tabId, tab);
|
||||
const port = tab.tunnelMode === TunnelMode.PionVideo ? tab.pionPort : tab.dcPort;
|
||||
@@ -222,7 +239,9 @@ export class TabManager {
|
||||
? RelayMode.TelemostVideoCreator
|
||||
: RelayMode.VKVideoCreator;
|
||||
}
|
||||
const proc = spawn(this.relayPath, ['--mode', relayMode, '--ws-port', String(port)], {
|
||||
const relayArgs = ['--mode', relayMode, '--ws-port', String(port)];
|
||||
this.appendUpstreamArgs(relayArgs);
|
||||
const proc = spawn(this.relayPath, relayArgs, {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
tab.relay = proc;
|
||||
@@ -351,6 +370,7 @@ export class TabManager {
|
||||
const flag = this.joinFlagFor(platform);
|
||||
if (flag) spawnArgs.push(flag, joinTarget);
|
||||
}
|
||||
this.appendUpstreamArgs(spawnArgs);
|
||||
const proc = spawn(config.binaryPath, spawnArgs, {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user