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
@@ -58,6 +58,7 @@ export enum IPC {
|
||||
CLOSE_TAB = 'close-tab',
|
||||
START_BOT = 'start-bot',
|
||||
STOP_BOT = 'stop-bot',
|
||||
SET_UPSTREAM_PROXY = 'set-upstream-proxy',
|
||||
EXPORT_COOKIES_ZIP = 'export-cookies-zip',
|
||||
RELAY_LOG = 'relay-log',
|
||||
CREATE_BOT_TAB = 'create-bot-tab',
|
||||
|
||||
@@ -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'],
|
||||
});
|
||||
|
||||
@@ -23,6 +23,9 @@ import { IPC } from '../constants';
|
||||
stopBot() {
|
||||
return ipcRenderer.invoke(IPC.STOP_BOT);
|
||||
},
|
||||
setUpstreamProxy(proxy: any) {
|
||||
return ipcRenderer.invoke(IPC.SET_UPSTREAM_PROXY, proxy);
|
||||
},
|
||||
onCreateBotTab(cb: (data: any) => void) {
|
||||
ipcRenderer.on(IPC.CREATE_BOT_TAB, (_e, data) => cb(data));
|
||||
},
|
||||
|
||||
@@ -85,6 +85,10 @@ function bindSettingsEvents(): void {
|
||||
tm.botSettings.groupId = (document.getElementById('vkGroupId') as HTMLInputElement).value.trim();
|
||||
tm.botSettings.userId = (document.getElementById('vkUserId') as HTMLInputElement).value.trim();
|
||||
tm.saveBotSettings();
|
||||
tm.upstreamProxy.socks = (document.getElementById('upstreamSocks') as HTMLInputElement).value.trim();
|
||||
tm.upstreamProxy.user = (document.getElementById('upstreamUser') as HTMLInputElement).value.trim();
|
||||
tm.upstreamProxy.pass = (document.getElementById('upstreamPass') as HTMLInputElement).value.trim();
|
||||
tm.saveUpstreamProxy();
|
||||
closeSettings();
|
||||
});
|
||||
}
|
||||
@@ -154,6 +158,9 @@ function openSettings(): void {
|
||||
(document.getElementById('vkToken') as HTMLInputElement).value = tm.botSettings.token;
|
||||
(document.getElementById('vkGroupId') as HTMLInputElement).value = tm.botSettings.groupId;
|
||||
(document.getElementById('vkUserId') as HTMLInputElement).value = tm.botSettings.userId;
|
||||
(document.getElementById('upstreamSocks') as HTMLInputElement).value = tm.upstreamProxy.socks;
|
||||
(document.getElementById('upstreamUser') as HTMLInputElement).value = tm.upstreamProxy.user;
|
||||
(document.getElementById('upstreamPass') as HTMLInputElement).value = tm.upstreamProxy.pass;
|
||||
}
|
||||
|
||||
function closeSettings(): void {
|
||||
@@ -169,6 +176,8 @@ function init(): void {
|
||||
bindLogEvents();
|
||||
bindHeadlessEvents();
|
||||
|
||||
window.bridge.setUpstreamProxy(tm.upstreamProxy);
|
||||
|
||||
window.bridge.onRelayLog((tabId: string, msg: string) => {
|
||||
tm.appendRelayLog(tabId, msg);
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
RendererTab,
|
||||
BotTabData,
|
||||
BotSettings,
|
||||
UpstreamProxy,
|
||||
TunnelMode,
|
||||
Platform,
|
||||
Bridge,
|
||||
@@ -18,6 +19,7 @@ export class RendererTabManager {
|
||||
private nextId = 1;
|
||||
botRunning = false;
|
||||
botSettings: BotSettings;
|
||||
upstreamProxy: UpstreamProxy;
|
||||
private onRender: () => void;
|
||||
|
||||
constructor(onRender: () => void) {
|
||||
@@ -26,6 +28,10 @@ export class RendererTabManager {
|
||||
this.botSettings = saved
|
||||
? JSON.parse(saved)
|
||||
: { token: '', groupId: '', userId: '' };
|
||||
const savedProxy = localStorage.getItem('upstreamProxy');
|
||||
this.upstreamProxy = savedProxy
|
||||
? JSON.parse(savedProxy)
|
||||
: { socks: '', user: '', pass: '' };
|
||||
}
|
||||
|
||||
createTab(): string {
|
||||
@@ -236,6 +242,11 @@ export class RendererTabManager {
|
||||
localStorage.setItem('botSettings', JSON.stringify(this.botSettings));
|
||||
}
|
||||
|
||||
saveUpstreamProxy(): void {
|
||||
localStorage.setItem('upstreamProxy', JSON.stringify(this.upstreamProxy));
|
||||
window.bridge.setUpstreamProxy(this.upstreamProxy);
|
||||
}
|
||||
|
||||
toggleBot(): void {
|
||||
if (!this.botSettings.token || !this.botSettings.groupId) return;
|
||||
this.botRunning = !this.botRunning;
|
||||
|
||||
@@ -65,6 +65,12 @@ export interface BotSettings {
|
||||
userId: string;
|
||||
}
|
||||
|
||||
export interface UpstreamProxy {
|
||||
socks: string;
|
||||
user: string;
|
||||
pass: string;
|
||||
}
|
||||
|
||||
export interface TabConfig {
|
||||
mode: TunnelMode;
|
||||
peerId: number;
|
||||
@@ -144,6 +150,7 @@ export interface Bridge {
|
||||
closeTab(tabId: string): Promise<void>;
|
||||
startBot(settings: BotSettings): Promise<void>;
|
||||
stopBot(): Promise<void>;
|
||||
setUpstreamProxy(proxy: UpstreamProxy): Promise<void>;
|
||||
onCreateBotTab(cb: (data: BotTabData) => void): void;
|
||||
getCallCreatorCode(scriptFile: string): Promise<string>;
|
||||
onBotError(cb: (msg: string) => void): void;
|
||||
|
||||
Reference in new issue
Block a user