add bitrix support
This commit is contained in:
1 parent
747f8f2312
commit
5690cf58a9
62 files changed
+4098
-1053
No files matched your search
@@ -19,6 +19,7 @@
|
||||
<button class="btn-headless-tm" id="btnHeadlessTM">Telemost</button>
|
||||
<button class="btn-headless-wb" id="btnHeadlessWB">WBStream</button>
|
||||
<button class="btn-headless-dion" id="btnHeadlessDion">DION</button>
|
||||
<button class="btn-headless-bitrix" id="btnHeadlessBitrix">Bitrix</button>
|
||||
<button class="btn-vk" id="btnVk">VK (legacy)</button>
|
||||
<button class="btn-telemost" id="btnTelemost">Telemost (legacy)</button>
|
||||
<span class="toolbar-spacer"></span>
|
||||
@@ -54,6 +55,11 @@
|
||||
<div class="headless-start-card-desc">Store an email and password so the session renews itself and never asks for a browser login.</div>
|
||||
<button class="headless-start-btn" id="btnDionAccount">Edit credentials</button>
|
||||
</div>
|
||||
<div class="headless-start-card" id="headlessBitrixAccountCard" style="display:none">
|
||||
<div class="headless-start-card-title">Bitrix account (optional)</div>
|
||||
<div class="headless-start-card-desc">Create or Join opens the Bitrix login, you pick your portal there and the app captures the cookies. Optionally store portal, email and password here so the session renews itself without a browser login.</div>
|
||||
<button class="headless-start-btn" id="btnBitrixAccount">Edit credentials</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="headless-status" id="headlessStatus">Starting...</div>
|
||||
<div class="headless-call-info" id="headlessCallInfo">
|
||||
@@ -71,6 +77,9 @@
|
||||
<div class="headless-call-info" id="headlessCallInfoDion">
|
||||
<div class="headless-row"><span class="headless-label">Join link:</span> <a id="headlessDionJoinLink" href="#" class="headless-link"></a><img class="headless-copy" src="resources/icons8-copy-50.png" data-copy="headlessDionJoinLink" title="Copy"></div>
|
||||
</div>
|
||||
<div class="headless-call-info" id="headlessCallInfoBitrix">
|
||||
<div class="headless-row"><span class="headless-label">Join link:</span> <a id="headlessBitrixJoinLink" href="#" class="headless-link"></a><img class="headless-copy" src="resources/icons8-copy-50.png" data-copy="headlessBitrixJoinLink" title="Copy"></div>
|
||||
</div>
|
||||
<div class="headless-qr" id="headlessQrWrap" style="display:none">
|
||||
<img id="headlessQr" alt="Join link QR code">
|
||||
<div class="headless-qr-hint">Scan in the Android app</div>
|
||||
@@ -111,6 +120,7 @@
|
||||
<button type="button" class="btn-clear-cookies" data-platform="telemost">Telemost</button>
|
||||
<button type="button" class="btn-clear-cookies" data-platform="wbstream">WBStream</button>
|
||||
<button type="button" class="btn-clear-cookies" data-platform="dion">DION</button>
|
||||
<button type="button" class="btn-clear-cookies" data-platform="bitrix">Bitrix</button>
|
||||
</div>
|
||||
<div class="clear-cookies-status" id="clearCookiesStatus"></div>
|
||||
<div class="popup-buttons">
|
||||
@@ -133,6 +143,22 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="popup-overlay" id="bitrixAccountPopup">
|
||||
<div class="popup">
|
||||
<h2>Bitrix account</h2>
|
||||
<label for="bitrixPortal">Portal</label>
|
||||
<input type="text" id="bitrixPortal" placeholder="https://your-portal.bitrix24.ru">
|
||||
<label for="bitrixEmail">Email</label>
|
||||
<input type="text" id="bitrixEmail" placeholder="you@example.com">
|
||||
<label for="bitrixPassword">Password</label>
|
||||
<input type="text" id="bitrixPassword" placeholder="">
|
||||
<div class="clear-cookies-status" id="bitrixAccountStatus"></div>
|
||||
<div class="popup-buttons">
|
||||
<button class="btn-cancel" id="btnBitrixAccountCancel">Cancel</button>
|
||||
<button class="btn-save" id="btnBitrixAccountSave">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="popup-overlay" id="errorPopup">
|
||||
<div class="popup" style="padding:16px">
|
||||
<h2 class="error-title">Bot error</h2>
|
||||
|
||||
@@ -70,6 +70,10 @@
|
||||
{
|
||||
"from": "../headless/headless-dion-darwin",
|
||||
"to": "headless-dion-creator"
|
||||
},
|
||||
{
|
||||
"from": "../headless/headless-bitrix-darwin",
|
||||
"to": "headless-bitrix-creator"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -97,6 +101,10 @@
|
||||
{
|
||||
"from": "../headless/headless-dion-bundle.exe",
|
||||
"to": "headless-dion-creator.exe"
|
||||
},
|
||||
{
|
||||
"from": "../headless/headless-bitrix-bundle.exe",
|
||||
"to": "headless-bitrix-creator.exe"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -124,6 +132,10 @@
|
||||
{
|
||||
"from": "../headless/headless-dion-bundle",
|
||||
"to": "headless-dion-creator"
|
||||
},
|
||||
{
|
||||
"from": "../headless/headless-bitrix-bundle",
|
||||
"to": "headless-bitrix-creator"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -18,10 +18,13 @@ export const VK_LOGIN_URL = 'https://vk.ru/';
|
||||
export const YANDEX_LOGIN_URL = 'https://passport.yandex.ru/auth?retpath=https%3A%2F%2Ftelemost.yandex.ru%2F';
|
||||
export const DION_LOGIN_URL = 'https://dion.vc/login';
|
||||
export const WBSTREAM_LOGIN_URL = 'https://stream.wb.ru/login';
|
||||
export const BITRIX_LOGIN_URL = 'https://www.bitrix24.ru/';
|
||||
export const VK_AUTH_COOKIE = 'remixsid';
|
||||
export const YANDEX_AUTH_COOKIE = 'Session_id';
|
||||
export const DION_AUTH_COOKIE = 'vc-refresh-token';
|
||||
export const WBSTREAM_AUTH_COOKIE = 'x_wbaas_token';
|
||||
export const BITRIX_SESSION_COOKIE = 'BITRIX_SM_UIDH';
|
||||
export const BITRIX_AUTH_NET_HOST = 'https://auth2.bitrix24.net';
|
||||
|
||||
export const SESSION_PARTITION = 'persist:creator';
|
||||
export const WINDOW_WIDTH = 1200;
|
||||
@@ -35,6 +38,7 @@ export const VK_COOKIE_DOMAINS = ['vk.ru'];
|
||||
export const YANDEX_COOKIE_DOMAINS = ['yandex.ru', 'yandex.net', 'ya.ru'];
|
||||
export const DION_COOKIE_DOMAINS = ['dion.vc'];
|
||||
export const WBSTREAM_COOKIE_DOMAINS = ['stream.wb.ru', 'wb.ru', 'wildberries.ru'];
|
||||
export const BITRIX_COOKIE_DOMAINS = ['bitrix24.ru', 'bitrix24.net', 'bitrix24.com'];
|
||||
|
||||
export enum Selector {
|
||||
VK_ADMIT = '[data-testid="calls_waiting_hall_promote"]',
|
||||
@@ -63,6 +67,8 @@ export enum IPC {
|
||||
CLEAR_COOKIES = 'clear-cookies',
|
||||
GET_DION_CREDENTIALS = 'get-dion-credentials',
|
||||
SET_DION_CREDENTIALS = 'set-dion-credentials',
|
||||
GET_BITRIX_CREDENTIALS = 'get-bitrix-credentials',
|
||||
SET_BITRIX_CREDENTIALS = 'set-bitrix-credentials',
|
||||
EXPORT_COOKIES_ZIP = 'export-cookies-zip',
|
||||
RENDER_QR = 'render-qr',
|
||||
RELAY_LOG = 'relay-log',
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import * as fs from 'fs/promises';
|
||||
import { BitrixCredentials } from '../types';
|
||||
|
||||
export interface BitrixCookie {
|
||||
name: string;
|
||||
value: string;
|
||||
host: string;
|
||||
}
|
||||
|
||||
export class BitrixCookieFile {
|
||||
private filePath: string;
|
||||
|
||||
constructor(filePath: string) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
async readCredentials(): Promise<BitrixCredentials> {
|
||||
const content = await this.read();
|
||||
return {
|
||||
portal: content?.portal || '',
|
||||
email: content?.email || '',
|
||||
password: content?.password || '',
|
||||
};
|
||||
}
|
||||
|
||||
async writeCredentials(portal: string, email: string, password: string): Promise<void> {
|
||||
const content = {
|
||||
portal: portal || undefined,
|
||||
email: email || undefined,
|
||||
password: password || undefined,
|
||||
cookies: [] as unknown[],
|
||||
};
|
||||
await fs.writeFile(this.filePath, JSON.stringify(content));
|
||||
}
|
||||
|
||||
async writeSession(portal: string, cookies: BitrixCookie[]): Promise<void> {
|
||||
const existing = await this.read();
|
||||
const content = {
|
||||
portal: portal || existing?.portal || undefined,
|
||||
email: existing?.email || undefined,
|
||||
password: existing?.password || undefined,
|
||||
cookies,
|
||||
};
|
||||
await fs.writeFile(this.filePath, JSON.stringify(content));
|
||||
}
|
||||
|
||||
private async read(): Promise<BitrixCredentials | null> {
|
||||
try {
|
||||
const raw = await fs.readFile(this.filePath, 'utf8');
|
||||
const parsed = JSON.parse(raw);
|
||||
return {
|
||||
portal: typeof parsed.portal === 'string' ? parsed.portal : '',
|
||||
email: typeof parsed.email === 'string' ? parsed.email : '',
|
||||
password: typeof parsed.password === 'string' ? parsed.password : '',
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
import { app, session } from 'electron';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs/promises';
|
||||
import { Platform, DionCredentials, BitrixCredentials } from '../types';
|
||||
import {
|
||||
SESSION_PARTITION,
|
||||
VK_COOKIE_DOMAINS,
|
||||
YANDEX_COOKIE_DOMAINS,
|
||||
DION_COOKIE_DOMAINS,
|
||||
WBSTREAM_COOKIE_DOMAINS,
|
||||
BITRIX_COOKIE_DOMAINS,
|
||||
BITRIX_SESSION_COOKIE,
|
||||
BITRIX_AUTH_NET_HOST,
|
||||
} from '../constants';
|
||||
import { PLATFORM_CONFIG } from './platform-config';
|
||||
import { DionCookieFile } from './dion-cookie-file';
|
||||
import { BitrixCookieFile, BitrixCookie } from './bitrix-cookie-file';
|
||||
import { buildStoredZip } from './util/zip';
|
||||
|
||||
export interface BitrixSession {
|
||||
portal: string;
|
||||
cookies: BitrixCookie[];
|
||||
}
|
||||
|
||||
export class CookieStore {
|
||||
cookieFilePath(platform: Platform): string {
|
||||
return path.join(app.getPath('userData'), `cookies-${platform}.json`);
|
||||
}
|
||||
|
||||
async getCookiesForDomains(domains: string[]): Promise<{ name: string; value: string }[]> {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const all = await ses.cookies.get({});
|
||||
return all
|
||||
.filter((c) => c.domain != null && domains.some((d) => c.domain!.includes(d)))
|
||||
.map((c) => ({ name: c.name, value: c.value }));
|
||||
}
|
||||
|
||||
waitForLogin(cookieDomains: string[], authCookieName: string): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const finish = () => {
|
||||
ses.cookies.removeListener('changed', onChanged);
|
||||
resolve();
|
||||
};
|
||||
const onChanged = (
|
||||
_e: Electron.Event,
|
||||
cookie: Electron.Cookie,
|
||||
_cause: string,
|
||||
removed: boolean,
|
||||
) => {
|
||||
if (removed) return;
|
||||
if (cookie.name !== authCookieName) return;
|
||||
if (!cookie.domain || !cookieDomains.some((d) => cookie.domain!.includes(d))) return;
|
||||
finish();
|
||||
};
|
||||
ses.cookies.on('changed', onChanged);
|
||||
ses.cookies.get({ name: authCookieName }).then((found) => {
|
||||
if (found.some((c) => c.domain && cookieDomains.some((d) => c.domain!.includes(d)))) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
waitForCookies(names: string[]): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const remaining = new Set(names);
|
||||
const finish = () => {
|
||||
ses.cookies.removeListener('changed', onChanged);
|
||||
resolve();
|
||||
};
|
||||
const onChanged = (
|
||||
_e: Electron.Event,
|
||||
cookie: Electron.Cookie,
|
||||
_cause: string,
|
||||
removed: boolean,
|
||||
) => {
|
||||
if (removed) return;
|
||||
if (!remaining.has(cookie.name)) return;
|
||||
remaining.delete(cookie.name);
|
||||
if (remaining.size === 0) finish();
|
||||
};
|
||||
ses.cookies.on('changed', onChanged);
|
||||
Promise.all(names.map((name) => ses.cookies.get({ name }))).then((results) => {
|
||||
results.forEach((found, i) => {
|
||||
if (found.length > 0) remaining.delete(names[i]);
|
||||
});
|
||||
if (remaining.size === 0) finish();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
waitForBitrixSession(): Promise<BitrixSession | null> {
|
||||
return new Promise((resolve) => {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
let settled = false;
|
||||
const finish = (value: BitrixSession | null): void => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
ses.cookies.removeListener('changed', onChanged);
|
||||
resolve(value);
|
||||
};
|
||||
const check = (): void => {
|
||||
this.captureBitrixSession().then((data) => {
|
||||
if (data) finish(data);
|
||||
});
|
||||
};
|
||||
const onChanged = (
|
||||
_e: Electron.Event,
|
||||
cookie: Electron.Cookie,
|
||||
_cause: string,
|
||||
removed: boolean,
|
||||
): void => {
|
||||
if (removed) return;
|
||||
if (cookie.name !== BITRIX_SESSION_COOKIE) return;
|
||||
check();
|
||||
};
|
||||
ses.cookies.on('changed', onChanged);
|
||||
check();
|
||||
});
|
||||
}
|
||||
|
||||
async captureBitrixSession(preferredPortal?: string): Promise<BitrixSession | null> {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const all = await ses.cookies.get({});
|
||||
const relevant = all.filter((c) => c.domain != null && BITRIX_COOKIE_DOMAINS.some((d) => c.domain!.includes(d)));
|
||||
if (relevant.length === 0) return null;
|
||||
const bareHost = (domain: string): string => (domain.startsWith('.') ? domain.slice(1) : domain);
|
||||
const isPortalHost = (host: string): boolean =>
|
||||
/\.bitrix24\.(ru|com)$/.test(host) && host !== 'www.bitrix24.ru' && host !== 'www.bitrix24.com';
|
||||
let preferredHost = '';
|
||||
if (preferredPortal) {
|
||||
try {
|
||||
preferredHost = new URL(preferredPortal).hostname;
|
||||
} catch {
|
||||
preferredHost = '';
|
||||
}
|
||||
}
|
||||
const sessionHosts = relevant
|
||||
.filter((c) => c.name === BITRIX_SESSION_COOKIE)
|
||||
.map((c) => bareHost(c.domain!))
|
||||
.filter(isPortalHost);
|
||||
let portalHost = '';
|
||||
if (preferredHost && sessionHosts.includes(preferredHost)) portalHost = preferredHost;
|
||||
else if (sessionHosts.length > 0) portalHost = sessionHosts[0];
|
||||
if (!portalHost) return null;
|
||||
const portal = 'https://' + portalHost;
|
||||
const cookies: BitrixCookie[] = relevant.map((c) => {
|
||||
const host = bareHost(c.domain!);
|
||||
const hostUrl = host.includes('bitrix24.net') ? BITRIX_AUTH_NET_HOST : portal;
|
||||
return { name: c.name, value: c.value, host: hostUrl };
|
||||
});
|
||||
return { portal, cookies };
|
||||
}
|
||||
|
||||
async clearAuthCookies(cookieDomains: string[], authCookieName: string): Promise<void> {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const matches = await ses.cookies.get({ name: authCookieName });
|
||||
for (const cookie of matches) {
|
||||
if (!cookie.domain || !cookieDomains.some((d) => cookie.domain!.includes(d))) continue;
|
||||
const host = cookie.domain.startsWith('.') ? cookie.domain.slice(1) : cookie.domain;
|
||||
const url = `https://${host}${cookie.path || '/'}`;
|
||||
try {
|
||||
await ses.cookies.remove(url, cookie.name);
|
||||
} catch (err) {
|
||||
console.log(`[COOKIES] failed to remove ${cookie.name} on ${url}:`, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async clearPlatformCookies(platform: Platform): Promise<number> {
|
||||
if (platform === Platform.Bitrix) {
|
||||
const removed = await this.removeCookiesForDomains(BITRIX_COOKIE_DOMAINS);
|
||||
const account = new BitrixCookieFile(this.cookieFilePath(Platform.Bitrix));
|
||||
const creds = await account.readCredentials();
|
||||
if (creds.email && creds.password) {
|
||||
await account.writeCredentials(creds.portal, creds.email, creds.password);
|
||||
} else {
|
||||
await fs.unlink(this.cookieFilePath(Platform.Bitrix)).catch(() => {});
|
||||
}
|
||||
console.log(`[COOKIES] cleared ${removed} bitrix cookies`);
|
||||
return removed;
|
||||
}
|
||||
const config = PLATFORM_CONFIG[platform];
|
||||
if (!config) return 0;
|
||||
const removed = await this.removeCookiesForDomains(config.cookieDomains);
|
||||
await fs.unlink(this.cookieFilePath(platform)).catch(() => {});
|
||||
console.log(`[COOKIES] cleared ${removed} cookies for ${platform}`);
|
||||
return removed;
|
||||
}
|
||||
|
||||
private async removeCookiesForDomains(domains: string[]): Promise<number> {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const all = await ses.cookies.get({});
|
||||
let removed = 0;
|
||||
for (const cookie of all) {
|
||||
if (!cookie.domain || !domains.some((d) => cookie.domain!.includes(d))) continue;
|
||||
const host = cookie.domain.startsWith('.') ? cookie.domain.slice(1) : cookie.domain;
|
||||
const url = `https://${host}${cookie.path || '/'}`;
|
||||
try {
|
||||
await ses.cookies.remove(url, cookie.name);
|
||||
removed++;
|
||||
} catch (err) {
|
||||
console.log(`[COOKIES] failed to remove ${cookie.name} on ${url}:`, err);
|
||||
}
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
async getDionCredentials(): Promise<DionCredentials> {
|
||||
return new DionCookieFile(this.cookieFilePath(Platform.Dion)).readCredentials();
|
||||
}
|
||||
|
||||
async setDionCredentials(email: string, password: string): Promise<void> {
|
||||
await new DionCookieFile(this.cookieFilePath(Platform.Dion)).writeCredentials(email, password);
|
||||
}
|
||||
|
||||
async getBitrixCredentials(): Promise<BitrixCredentials> {
|
||||
return new BitrixCookieFile(this.cookieFilePath(Platform.Bitrix)).readCredentials();
|
||||
}
|
||||
|
||||
async setBitrixCredentials(portal: string, email: string, password: string): Promise<void> {
|
||||
await new BitrixCookieFile(this.cookieFilePath(Platform.Bitrix)).writeCredentials(portal, email, password);
|
||||
}
|
||||
|
||||
async buildCookiesZip(): Promise<Buffer> {
|
||||
const platforms: { filename: string; domains: string[]; platform: Platform }[] = [
|
||||
{ filename: 'cookies-vk.json', domains: VK_COOKIE_DOMAINS, platform: Platform.VK },
|
||||
{ filename: 'cookies-yandex.json', domains: YANDEX_COOKIE_DOMAINS, platform: Platform.Telemost },
|
||||
{ filename: 'cookies-dion.json', domains: DION_COOKIE_DOMAINS, platform: Platform.Dion },
|
||||
{ filename: 'cookies-wbstream.json', domains: WBSTREAM_COOKIE_DOMAINS, platform: Platform.WBStream },
|
||||
];
|
||||
const cookies = await Promise.all(platforms.map((p) => this.getCookiesForDomains(p.domains)));
|
||||
const dionContent = await new DionCookieFile(this.cookieFilePath(Platform.Dion)).readContent();
|
||||
const entries = platforms.map((p, i) => {
|
||||
const content = p.platform === Platform.Dion && dionContent ? dionContent : cookies[i];
|
||||
return { name: p.filename, data: Buffer.from(JSON.stringify(content, null, 2), 'utf8') };
|
||||
});
|
||||
return buildStoredZip(entries);
|
||||
}
|
||||
|
||||
async setWBStreamDeviceId(id: string): Promise<void> {
|
||||
if (!id) return;
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const existing = await ses.cookies.get({ url: 'https://stream.wb.ru/', name: '__wb_device_id' });
|
||||
if (existing.length > 0 && existing[0].value === id) return;
|
||||
try {
|
||||
await ses.cookies.set({
|
||||
url: 'https://stream.wb.ru/',
|
||||
name: '__wb_device_id',
|
||||
value: id,
|
||||
domain: 'stream.wb.ru',
|
||||
path: '/',
|
||||
secure: true,
|
||||
httpOnly: false,
|
||||
expirationDate: Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 365 * 5,
|
||||
});
|
||||
console.log(`[wb-device-id] persisted ${id}`);
|
||||
} catch (err) {
|
||||
console.log(`[wb-device-id] failed to persist:`, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
import { BrowserWindow } from 'electron';
|
||||
import { spawn, ChildProcess } from 'child_process';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs/promises';
|
||||
import {
|
||||
TabState,
|
||||
Platform,
|
||||
TunnelMode,
|
||||
RelayMode,
|
||||
HeadlessStartArgs,
|
||||
HeadlessMode,
|
||||
UpstreamProxy,
|
||||
} from '../types';
|
||||
import { IPC, BITRIX_LOGIN_URL } from '../constants';
|
||||
import { BotManager } from '../bot/bot-manager';
|
||||
import { DionCookieFile } from './dion-cookie-file';
|
||||
import { BitrixCookieFile } from './bitrix-cookie-file';
|
||||
import { resolveResourcePath, binaryName } from './util/paths';
|
||||
import { PLATFORM_CONFIG } from './platform-config';
|
||||
import { CookieStore } from './cookie-store';
|
||||
|
||||
export interface LauncherHost {
|
||||
getOrCreateTab(tabId: string): Promise<TabState>;
|
||||
getTab(tabId: string): TabState | undefined;
|
||||
readonly mainWindow: BrowserWindow | null;
|
||||
readonly botManager: BotManager | null;
|
||||
}
|
||||
|
||||
type AuthErrorKind = 'invalid' | 'expired';
|
||||
|
||||
function parseAuthError(msg: string): AuthErrorKind | null {
|
||||
if (msg.includes('STATUS:AUTH_ERROR:INVALID_CREDENTIALS')) return 'invalid';
|
||||
if (msg.includes('STATUS:AUTH_ERROR:SESSION_EXPIRED')) return 'expired';
|
||||
return null;
|
||||
}
|
||||
|
||||
export class HeadlessLauncher {
|
||||
private relayPath: string;
|
||||
private bitrixPath: string;
|
||||
private binaryPaths = new Map<Platform, string>();
|
||||
private upstreamProxy: UpstreamProxy = { socks: '', user: '', pass: '' };
|
||||
private debugLogging = false;
|
||||
|
||||
constructor(
|
||||
private host: LauncherHost,
|
||||
private cookies: CookieStore,
|
||||
) {
|
||||
this.relayPath = resolveResourcePath(
|
||||
path.join('relay', binaryName('relay')),
|
||||
binaryName('relay'),
|
||||
);
|
||||
this.bitrixPath = resolveResourcePath(
|
||||
path.join('headless', 'bitrix', binaryName('headless-bitrix-creator')),
|
||||
binaryName('headless-bitrix-creator'),
|
||||
);
|
||||
for (const [platform, config] of Object.entries(PLATFORM_CONFIG)) {
|
||||
this.binaryPaths.set(
|
||||
platform as Platform,
|
||||
resolveResourcePath(
|
||||
path.join('headless', config!.binarySubdir, binaryName(config!.binaryBase)),
|
||||
binaryName(config!.binaryBase),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
setUpstreamProxy(proxy: UpstreamProxy): void {
|
||||
this.upstreamProxy = {
|
||||
socks: (proxy?.socks || '').trim(),
|
||||
user: (proxy?.user || '').trim(),
|
||||
pass: (proxy?.pass || '').trim(),
|
||||
};
|
||||
}
|
||||
|
||||
setDebugLogging(enabled: boolean): void {
|
||||
this.debugLogging = enabled;
|
||||
}
|
||||
|
||||
sendLog(tabId: string, msg: string): void {
|
||||
const win = this.host.mainWindow;
|
||||
if (win && !win.isDestroyed()) {
|
||||
win.webContents.send(IPC.RELAY_LOG, { tabId, msg });
|
||||
}
|
||||
}
|
||||
|
||||
killRelay(tabId: string, tab: TabState): void {
|
||||
if (tab.relay) {
|
||||
console.log(`[${tabId}] killing process pid=${tab.relay.pid}`);
|
||||
tab.relay.kill();
|
||||
tab.relay = null;
|
||||
}
|
||||
}
|
||||
|
||||
startRelay(tabId: string, tab: TabState): void {
|
||||
this.killRelay(tabId, tab);
|
||||
const port = tab.tunnelMode === TunnelMode.PionVideo ? tab.pionPort : tab.dcPort;
|
||||
let relayMode: RelayMode = RelayMode.DCCreator;
|
||||
if (tab.tunnelMode === TunnelMode.PionVideo) {
|
||||
relayMode = tab.platform === Platform.Telemost
|
||||
? RelayMode.TelemostVideoCreator
|
||||
: RelayMode.VKVideoCreator;
|
||||
}
|
||||
const relayArgs = ['--mode', relayMode, '--ws-port', String(port)];
|
||||
this.appendUpstreamArgs(relayArgs);
|
||||
if (this.debugLogging) relayArgs.push('--debug');
|
||||
const proc = spawn(this.relayPath, relayArgs, {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
tab.relay = proc;
|
||||
this.attachProcessOutput(proc, tabId);
|
||||
proc.on('close', (code) => {
|
||||
this.sendLog(tabId, `Relay exited with code ${code}`);
|
||||
});
|
||||
}
|
||||
|
||||
async startHeadless(tabId: string, platform: Platform, args: HeadlessStartArgs): Promise<void> {
|
||||
if (platform === Platform.Bitrix) {
|
||||
await this.startBitrixHeadless(tabId, args);
|
||||
return;
|
||||
}
|
||||
const tab = await this.host.getOrCreateTab(tabId);
|
||||
tab.platform = platform;
|
||||
const joinTarget = args.mode === HeadlessMode.Join ? (args.target || '').trim() : '';
|
||||
if (args.mode === HeadlessMode.Join && !joinTarget) {
|
||||
this.sendLog(tabId, 'Join requested but no target link/room provided.');
|
||||
return;
|
||||
}
|
||||
|
||||
const config = PLATFORM_CONFIG[platform];
|
||||
if (!config) {
|
||||
this.sendLog(tabId, `Unsupported headless platform: ${platform}`);
|
||||
return;
|
||||
}
|
||||
tab.tunnelMode = config.tunnelMode;
|
||||
const cookiesPath = this.cookies.cookieFilePath(platform);
|
||||
const dionCookieFile = platform === Platform.Dion ? new DionCookieFile(cookiesPath) : null;
|
||||
const fileHasSession = dionCookieFile != null && await dionCookieFile.hasSession();
|
||||
let cookies = await this.cookies.getCookiesForDomains(config.cookieDomains);
|
||||
const needsLogin = !fileHasSession && !cookies.some((c) => c.name === config.refreshCookie);
|
||||
if (needsLogin) {
|
||||
if (tab.isBot) {
|
||||
const reply = `Please log into ${config.platformName} in the creator app first, then try again.`;
|
||||
this.sendLog(tabId, reply);
|
||||
if (this.host.botManager && tab.peerId != null) {
|
||||
await this.host.botManager.sendMessage(tab.peerId, reply);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.sendLog(tabId, `No ${config.platformName} session found, opening login.`);
|
||||
const win = this.host.mainWindow;
|
||||
if (win && !win.isDestroyed()) {
|
||||
win.webContents.send(IPC.LOGIN_REQUIRED, { tabId, url: config.loginUrl });
|
||||
}
|
||||
if (config.loginWaitCookies) {
|
||||
this.sendLog(tabId, `Waiting for ${config.loginWaitCookies.join(', ')}...`);
|
||||
await this.cookies.waitForCookies(config.loginWaitCookies);
|
||||
} else {
|
||||
await this.cookies.waitForLogin(config.cookieDomains, config.authCookie);
|
||||
}
|
||||
if (win && !win.isDestroyed()) {
|
||||
win.webContents.send(IPC.LOGIN_DONE, { tabId });
|
||||
}
|
||||
this.sendLog(tabId, `${config.platformName} login captured.`);
|
||||
cookies = await this.cookies.getCookiesForDomains(config.cookieDomains);
|
||||
}
|
||||
if (fileHasSession) {
|
||||
this.sendLog(tabId, `${config.platformName} session file is still active, keeping it as is.`);
|
||||
} else {
|
||||
this.sendLog(tabId, `${config.platformName} cookies (${cookies.length}): ${cookies.map((c) => c.name).join(', ')}`);
|
||||
await fs.writeFile(cookiesPath, JSON.stringify(cookies));
|
||||
}
|
||||
const spawnArgs = ['--resources', 'default', '--cookies', cookiesPath];
|
||||
this.killRelay(tabId, tab);
|
||||
if (joinTarget && config.joinFlag) {
|
||||
spawnArgs.push(config.joinFlag, joinTarget);
|
||||
}
|
||||
this.appendUpstreamArgs(spawnArgs);
|
||||
if (this.debugLogging) spawnArgs.push('--debug');
|
||||
const proc = spawn(this.binaryPaths.get(platform)!, spawnArgs, {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
tab.relay = proc;
|
||||
let authError: AuthErrorKind | null = null;
|
||||
this.attachProcessOutput(proc, tabId, (msg) => {
|
||||
const kind = parseAuthError(msg);
|
||||
if (kind) authError = kind;
|
||||
});
|
||||
proc.on('close', async (code) => {
|
||||
this.sendLog(tabId, `Headless exited with code ${code}`);
|
||||
if (authError === 'invalid') {
|
||||
this.sendLog(tabId, `${config.platformName} rejected the email and password stored in ${cookiesPath}, fix them or clear cookies to log in through the browser.`);
|
||||
return;
|
||||
}
|
||||
if (authError === 'expired') {
|
||||
if (dionCookieFile) await dionCookieFile.clearTokens();
|
||||
await this.cookies.clearAuthCookies(config.cookieDomains, config.authCookie);
|
||||
if (this.host.getTab(tabId) === tab) this.startHeadless(tabId, platform, args);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async startBitrixHeadless(tabId: string, args: HeadlessStartArgs): Promise<void> {
|
||||
const tab = await this.host.getOrCreateTab(tabId);
|
||||
tab.platform = Platform.Bitrix;
|
||||
tab.tunnelMode = TunnelMode.HeadlessBitrix;
|
||||
const joinTarget = args.mode === HeadlessMode.Join ? (args.target || '').trim() : '';
|
||||
if (args.mode === HeadlessMode.Join && !joinTarget) {
|
||||
this.sendLog(tabId, 'Join requested but no target link/room provided.');
|
||||
return;
|
||||
}
|
||||
const cookiesPath = this.cookies.cookieFilePath(Platform.Bitrix);
|
||||
const account = new BitrixCookieFile(cookiesPath);
|
||||
const creds = await account.readCredentials();
|
||||
const hasPassword = !!(creds.portal && creds.email && creds.password);
|
||||
|
||||
let sessionData = await this.cookies.captureBitrixSession();
|
||||
if (!hasPassword && !sessionData) {
|
||||
if (tab.isBot) {
|
||||
const reply = 'Please log into Bitrix in the creator app first, then try again.';
|
||||
this.sendLog(tabId, reply);
|
||||
if (this.host.botManager && tab.peerId != null) {
|
||||
await this.host.botManager.sendMessage(tab.peerId, reply);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.sendLog(tabId, 'No Bitrix session found, opening login. Pick your portal in the Bitrix login screen.');
|
||||
const win = this.host.mainWindow;
|
||||
if (win && !win.isDestroyed()) {
|
||||
win.webContents.send(IPC.LOGIN_REQUIRED, { tabId, url: BITRIX_LOGIN_URL });
|
||||
}
|
||||
this.sendLog(tabId, 'Waiting for the portal session...');
|
||||
sessionData = await this.cookies.waitForBitrixSession();
|
||||
if (win && !win.isDestroyed()) {
|
||||
win.webContents.send(IPC.LOGIN_DONE, { tabId });
|
||||
}
|
||||
this.sendLog(tabId, `Bitrix login captured on ${sessionData?.portal}.`);
|
||||
}
|
||||
|
||||
if (!hasPassword) {
|
||||
if (!sessionData) {
|
||||
this.sendLog(tabId, 'Could not capture Bitrix cookies, log in and try again.');
|
||||
return;
|
||||
}
|
||||
await account.writeSession(sessionData.portal, sessionData.cookies);
|
||||
this.sendLog(tabId, `Bitrix session captured, portal ${sessionData.portal}`);
|
||||
} else {
|
||||
this.sendLog(tabId, 'Bitrix account credentials present, logging in with portal and password.');
|
||||
}
|
||||
|
||||
const spawnArgs = ['--resources', 'default', '--cookies', cookiesPath];
|
||||
this.killRelay(tabId, tab);
|
||||
if (joinTarget) {
|
||||
spawnArgs.push('--room', joinTarget);
|
||||
}
|
||||
this.appendUpstreamArgs(spawnArgs);
|
||||
if (this.debugLogging) spawnArgs.push('--debug');
|
||||
const proc = spawn(this.bitrixPath, spawnArgs, {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
tab.relay = proc;
|
||||
let authError: AuthErrorKind | null = null;
|
||||
this.attachProcessOutput(proc, tabId, (msg) => {
|
||||
const kind = parseAuthError(msg);
|
||||
if (kind) authError = kind;
|
||||
});
|
||||
proc.on('close', async (code) => {
|
||||
this.sendLog(tabId, `Headless exited with code ${code}`);
|
||||
if (authError === 'invalid') {
|
||||
this.sendLog(tabId, `Bitrix rejected the portal, email or password stored in ${cookiesPath}, fix them in the Bitrix account card or log in again.`);
|
||||
return;
|
||||
}
|
||||
if (authError === 'expired' && !hasPassword) {
|
||||
await this.cookies.clearPlatformCookies(Platform.Bitrix);
|
||||
if (this.host.getTab(tabId) === tab) this.startBitrixHeadless(tabId, args);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private attachProcessOutput(
|
||||
proc: ChildProcess,
|
||||
tabId: string,
|
||||
inspect?: (msg: string) => void,
|
||||
): void {
|
||||
const onData = (data: Buffer) => {
|
||||
data
|
||||
.toString()
|
||||
.trim()
|
||||
.split('\n')
|
||||
.forEach((msg) => {
|
||||
if (!msg) return;
|
||||
console.log(`[relay:${tabId}]`, msg);
|
||||
this.sendLog(tabId, msg);
|
||||
if (inspect) inspect(msg);
|
||||
});
|
||||
};
|
||||
proc.stdout?.on('data', onData);
|
||||
proc.stderr?.on('data', onData);
|
||||
}
|
||||
}
|
||||
@@ -120,6 +120,14 @@ export function registerIpcHandlers(tabManager: TabManager): void {
|
||||
return tabManager.setDionCredentials(email, password);
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC.GET_BITRIX_CREDENTIALS, () => {
|
||||
return tabManager.getBitrixCredentials();
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC.SET_BITRIX_CREDENTIALS, (_e, portal: string, email: string, password: string) => {
|
||||
return tabManager.setBitrixCredentials(portal, email, password);
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC.SEND_BOT_CALL_LINK, (_e, tabId: string, link: string) => {
|
||||
tabManager.sendBotCallLink(tabId, link);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import { Platform, TunnelMode } from '../types';
|
||||
import {
|
||||
VK_COOKIE_DOMAINS,
|
||||
YANDEX_COOKIE_DOMAINS,
|
||||
DION_COOKIE_DOMAINS,
|
||||
WBSTREAM_COOKIE_DOMAINS,
|
||||
VK_LOGIN_URL,
|
||||
YANDEX_LOGIN_URL,
|
||||
DION_LOGIN_URL,
|
||||
WBSTREAM_LOGIN_URL,
|
||||
VK_AUTH_COOKIE,
|
||||
YANDEX_AUTH_COOKIE,
|
||||
DION_AUTH_COOKIE,
|
||||
WBSTREAM_AUTH_COOKIE,
|
||||
} from '../constants';
|
||||
|
||||
export interface PlatformConfig {
|
||||
tunnelMode: TunnelMode;
|
||||
authCookie: string;
|
||||
refreshCookie: string;
|
||||
loginUrl: string;
|
||||
cookieDomains: string[];
|
||||
platformName: string;
|
||||
binarySubdir: string;
|
||||
binaryBase: string;
|
||||
joinFlag: string | null;
|
||||
loginWaitCookies: string[] | null;
|
||||
}
|
||||
|
||||
export const PLATFORM_CONFIG: Partial<Record<Platform, PlatformConfig>> = {
|
||||
[Platform.VK]: {
|
||||
tunnelMode: TunnelMode.HeadlessVK,
|
||||
authCookie: VK_AUTH_COOKIE,
|
||||
refreshCookie: VK_AUTH_COOKIE,
|
||||
loginUrl: VK_LOGIN_URL,
|
||||
cookieDomains: VK_COOKIE_DOMAINS,
|
||||
platformName: 'VK',
|
||||
binarySubdir: 'vk',
|
||||
binaryBase: 'headless-vk-creator',
|
||||
joinFlag: '--vk-link',
|
||||
loginWaitCookies: null,
|
||||
},
|
||||
[Platform.Telemost]: {
|
||||
tunnelMode: TunnelMode.HeadlessTelemost,
|
||||
authCookie: YANDEX_AUTH_COOKIE,
|
||||
refreshCookie: YANDEX_AUTH_COOKIE,
|
||||
loginUrl: YANDEX_LOGIN_URL,
|
||||
cookieDomains: YANDEX_COOKIE_DOMAINS,
|
||||
platformName: 'Yandex',
|
||||
binarySubdir: 'telemost',
|
||||
binaryBase: 'headless-telemost-creator',
|
||||
joinFlag: '--tm-link',
|
||||
loginWaitCookies: null,
|
||||
},
|
||||
[Platform.Dion]: {
|
||||
tunnelMode: TunnelMode.HeadlessDion,
|
||||
authCookie: DION_AUTH_COOKIE,
|
||||
refreshCookie: DION_AUTH_COOKIE,
|
||||
loginUrl: DION_LOGIN_URL,
|
||||
cookieDomains: DION_COOKIE_DOMAINS,
|
||||
platformName: 'DION',
|
||||
binarySubdir: 'dion',
|
||||
binaryBase: 'headless-dion-creator',
|
||||
joinFlag: '--room',
|
||||
loginWaitCookies: ['vc-refresh-token', 'vc-access-token'],
|
||||
},
|
||||
[Platform.WBStream]: {
|
||||
tunnelMode: TunnelMode.HeadlessWBStream,
|
||||
authCookie: WBSTREAM_AUTH_COOKIE,
|
||||
refreshCookie: 'wbx-refresh',
|
||||
loginUrl: WBSTREAM_LOGIN_URL,
|
||||
cookieDomains: WBSTREAM_COOKIE_DOMAINS,
|
||||
platformName: 'WB Stream',
|
||||
binarySubdir: 'wbstream',
|
||||
binaryBase: 'headless-wbstream-creator',
|
||||
joinFlag: '--room',
|
||||
loginWaitCookies: ['x_wbaas_token', 'wbx-refresh', 'wbx-validation-key'],
|
||||
},
|
||||
};
|
||||
@@ -1,6 +1,4 @@
|
||||
import { app } from 'electron';
|
||||
import { spawn, ChildProcess } from 'child_process';
|
||||
import { BrowserWindow, session } from 'electron';
|
||||
import { app, BrowserWindow } from 'electron';
|
||||
import * as net from 'net';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs/promises';
|
||||
@@ -10,36 +8,20 @@ import {
|
||||
TabListEntry,
|
||||
Platform,
|
||||
TunnelMode,
|
||||
RelayMode,
|
||||
CallStatus,
|
||||
HeadlessStartArgs,
|
||||
HeadlessMode,
|
||||
UpstreamProxy,
|
||||
DionCredentials,
|
||||
BitrixCredentials,
|
||||
} from '../types';
|
||||
import {
|
||||
INITIAL_PORT_BASE,
|
||||
IPC,
|
||||
RELAY_RESTART_DELAY_MS,
|
||||
SESSION_PARTITION,
|
||||
VK_COOKIE_DOMAINS,
|
||||
YANDEX_COOKIE_DOMAINS,
|
||||
DION_COOKIE_DOMAINS,
|
||||
WBSTREAM_COOKIE_DOMAINS,
|
||||
VK_LOGIN_URL,
|
||||
YANDEX_LOGIN_URL,
|
||||
DION_LOGIN_URL,
|
||||
WBSTREAM_LOGIN_URL,
|
||||
VK_AUTH_COOKIE,
|
||||
YANDEX_AUTH_COOKIE,
|
||||
DION_AUTH_COOKIE,
|
||||
WBSTREAM_AUTH_COOKIE,
|
||||
LOG_CAPTURE_SNIPPET,
|
||||
} from '../constants';
|
||||
import { BotManager } from '../bot/bot-manager';
|
||||
import { DionCookieFile } from './dion-cookie-file';
|
||||
import { buildStoredZip } from './util/zip';
|
||||
import { resolveResourcePath, binaryName } from './util/paths';
|
||||
import { CookieStore } from './cookie-store';
|
||||
import { HeadlessLauncher } from './headless-launcher';
|
||||
|
||||
export class TabManager {
|
||||
private tabs = new Map<string, TabState>();
|
||||
@@ -48,39 +30,15 @@ export class TabManager {
|
||||
private nextPortBase = INITIAL_PORT_BASE;
|
||||
private _mainWindow: BrowserWindow | null = null;
|
||||
private _botManager: BotManager | null = null;
|
||||
private relayPath: string;
|
||||
private headlessVKPath: string;
|
||||
private headlessTelemostPath: string;
|
||||
private headlessWBStreamPath: string;
|
||||
private headlessDionPath: string;
|
||||
private hooksDir: string;
|
||||
private upstreamProxy: UpstreamProxy = { socks: '', user: '', pass: '' };
|
||||
private debugLogging = false;
|
||||
private cookies = new CookieStore();
|
||||
private launcher: HeadlessLauncher;
|
||||
|
||||
constructor() {
|
||||
this.relayPath = resolveResourcePath(
|
||||
path.join('relay', binaryName('relay')),
|
||||
binaryName('relay'),
|
||||
);
|
||||
this.headlessVKPath = resolveResourcePath(
|
||||
path.join('headless', 'vk', binaryName('headless-vk-creator')),
|
||||
binaryName('headless-vk-creator'),
|
||||
);
|
||||
this.headlessTelemostPath = resolveResourcePath(
|
||||
path.join('headless', 'telemost', binaryName('headless-telemost-creator')),
|
||||
binaryName('headless-telemost-creator'),
|
||||
);
|
||||
this.headlessWBStreamPath = resolveResourcePath(
|
||||
path.join('headless', 'wbstream', binaryName('headless-wbstream-creator')),
|
||||
binaryName('headless-wbstream-creator'),
|
||||
);
|
||||
this.headlessDionPath = resolveResourcePath(
|
||||
path.join('headless', 'dion', binaryName('headless-dion-creator')),
|
||||
binaryName('headless-dion-creator'),
|
||||
);
|
||||
this.hooksDir = app.isPackaged
|
||||
? path.join(process.resourcesPath!, 'hooks')
|
||||
: path.join(__dirname, '..', '..', '..', 'hooks');
|
||||
this.launcher = new HeadlessLauncher(this, this.cookies);
|
||||
}
|
||||
|
||||
get mainWindow(): BrowserWindow | null {
|
||||
@@ -142,7 +100,7 @@ export class TabManager {
|
||||
deleteTab(tabId: string): void {
|
||||
const tab = this.tabs.get(tabId);
|
||||
if (tab) {
|
||||
this.killRelay(tabId, tab);
|
||||
this.launcher.killRelay(tabId, tab);
|
||||
this.tabs.delete(tabId);
|
||||
}
|
||||
this.botTabIds.delete(tabId);
|
||||
@@ -183,33 +141,6 @@ export class TabManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
private sendLog(tabId: string, msg: string): void {
|
||||
if (this._mainWindow && !this._mainWindow.isDestroyed()) {
|
||||
this._mainWindow.webContents.send(IPC.RELAY_LOG, { tabId, msg });
|
||||
}
|
||||
}
|
||||
|
||||
private attachProcessOutput(
|
||||
proc: ChildProcess,
|
||||
tabId: string,
|
||||
inspect?: (msg: string) => void,
|
||||
): void {
|
||||
const onData = (data: Buffer) => {
|
||||
data
|
||||
.toString()
|
||||
.trim()
|
||||
.split('\n')
|
||||
.forEach((msg) => {
|
||||
if (!msg) return;
|
||||
console.log(`[relay:${tabId}]`, msg);
|
||||
this.sendLog(tabId, msg);
|
||||
if (inspect) inspect(msg);
|
||||
});
|
||||
};
|
||||
proc.stdout?.on('data', onData);
|
||||
proc.stderr?.on('data', onData);
|
||||
}
|
||||
|
||||
sendBotCallLink(tabId: string, link: string): void {
|
||||
if (!this.botTabIds.has(tabId) || !this._botManager) return;
|
||||
const tab = this.tabs.get(tabId);
|
||||
@@ -219,292 +150,42 @@ export class TabManager {
|
||||
}
|
||||
|
||||
setUpstreamProxy(proxy: UpstreamProxy): void {
|
||||
this.upstreamProxy = {
|
||||
socks: (proxy?.socks || '').trim(),
|
||||
user: (proxy?.user || '').trim(),
|
||||
pass: (proxy?.pass || '').trim(),
|
||||
};
|
||||
this.launcher.setUpstreamProxy(proxy);
|
||||
}
|
||||
|
||||
setDebugLogging(enabled: boolean): void {
|
||||
this.debugLogging = enabled;
|
||||
}
|
||||
|
||||
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);
|
||||
this.launcher.setDebugLogging(enabled);
|
||||
}
|
||||
|
||||
startRelay(tabId: string, tab: TabState): void {
|
||||
this.killRelay(tabId, tab);
|
||||
const port = tab.tunnelMode === TunnelMode.PionVideo ? tab.pionPort : tab.dcPort;
|
||||
let relayMode: RelayMode = RelayMode.DCCreator;
|
||||
if (tab.tunnelMode === TunnelMode.PionVideo) {
|
||||
relayMode = tab.platform === Platform.Telemost
|
||||
? RelayMode.TelemostVideoCreator
|
||||
: RelayMode.VKVideoCreator;
|
||||
}
|
||||
const relayArgs = ['--mode', relayMode, '--ws-port', String(port)];
|
||||
this.appendUpstreamArgs(relayArgs);
|
||||
if (this.debugLogging) relayArgs.push('--debug');
|
||||
const proc = spawn(this.relayPath, relayArgs, {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
tab.relay = proc;
|
||||
this.attachProcessOutput(proc, tabId);
|
||||
proc.on('close', (code) => {
|
||||
this.sendLog(tabId, `Relay exited with code ${code}`);
|
||||
});
|
||||
this.launcher.startRelay(tabId, tab);
|
||||
}
|
||||
|
||||
private headlessConfig(platform: Platform): {
|
||||
tunnelMode: TunnelMode;
|
||||
authCookie: string;
|
||||
loginUrl: string;
|
||||
cookieDomains: string[];
|
||||
platformName: string;
|
||||
binaryPath: string;
|
||||
} | null {
|
||||
switch (platform) {
|
||||
case Platform.Telemost:
|
||||
return {
|
||||
tunnelMode: TunnelMode.HeadlessTelemost,
|
||||
authCookie: YANDEX_AUTH_COOKIE,
|
||||
loginUrl: YANDEX_LOGIN_URL,
|
||||
cookieDomains: YANDEX_COOKIE_DOMAINS,
|
||||
platformName: 'Yandex',
|
||||
binaryPath: this.headlessTelemostPath,
|
||||
};
|
||||
case Platform.Dion:
|
||||
return {
|
||||
tunnelMode: TunnelMode.HeadlessDion,
|
||||
authCookie: DION_AUTH_COOKIE,
|
||||
loginUrl: DION_LOGIN_URL,
|
||||
cookieDomains: DION_COOKIE_DOMAINS,
|
||||
platformName: 'DION',
|
||||
binaryPath: this.headlessDionPath,
|
||||
};
|
||||
case Platform.VK:
|
||||
return {
|
||||
tunnelMode: TunnelMode.HeadlessVK,
|
||||
authCookie: VK_AUTH_COOKIE,
|
||||
loginUrl: VK_LOGIN_URL,
|
||||
cookieDomains: VK_COOKIE_DOMAINS,
|
||||
platformName: 'VK',
|
||||
binaryPath: this.headlessVKPath,
|
||||
};
|
||||
case Platform.WBStream:
|
||||
return {
|
||||
tunnelMode: TunnelMode.HeadlessWBStream,
|
||||
authCookie: WBSTREAM_AUTH_COOKIE,
|
||||
loginUrl: WBSTREAM_LOGIN_URL,
|
||||
cookieDomains: WBSTREAM_COOKIE_DOMAINS,
|
||||
platformName: 'WB Stream',
|
||||
binaryPath: this.headlessWBStreamPath,
|
||||
};
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private joinFlagFor(platform: Platform): string | null {
|
||||
switch (platform) {
|
||||
case Platform.VK:
|
||||
return '--vk-link';
|
||||
case Platform.Telemost:
|
||||
return '--tm-link';
|
||||
case Platform.WBStream:
|
||||
case Platform.Dion:
|
||||
return '--room';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async startHeadless(tabId: string, platform: Platform, args: HeadlessStartArgs): Promise<void> {
|
||||
const tab = await this.getOrCreateTab(tabId);
|
||||
tab.platform = platform;
|
||||
const joinTarget = args.mode === HeadlessMode.Join ? (args.target || '').trim() : '';
|
||||
if (args.mode === HeadlessMode.Join && !joinTarget) {
|
||||
this.sendLog(tabId, 'Join requested but no target link/room provided.');
|
||||
return;
|
||||
}
|
||||
|
||||
const config = this.headlessConfig(platform);
|
||||
if (!config) {
|
||||
this.sendLog(tabId, `Unsupported headless platform: ${platform}`);
|
||||
return;
|
||||
}
|
||||
tab.tunnelMode = config.tunnelMode;
|
||||
const cookiesPath = this.cookieFilePath(platform);
|
||||
const refreshCookie = platform === Platform.WBStream ? 'wbx-refresh' : config.authCookie;
|
||||
const dionCookieFile = platform === Platform.Dion ? new DionCookieFile(cookiesPath) : null;
|
||||
const fileHasSession = dionCookieFile != null && await dionCookieFile.hasSession();
|
||||
let cookies = await this.getCookiesForDomains(config.cookieDomains);
|
||||
const needsLogin = !fileHasSession && !cookies.some((c) => c.name === refreshCookie);
|
||||
if (needsLogin) {
|
||||
if (tab.isBot) {
|
||||
const reply = `Please log into ${config.platformName} in the creator app first, then try again.`;
|
||||
this.sendLog(tabId, reply);
|
||||
if (this._botManager && tab.peerId != null) {
|
||||
await this._botManager.sendMessage(tab.peerId, reply);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.sendLog(tabId, `No ${config.platformName} session found, opening login.`);
|
||||
if (this._mainWindow && !this._mainWindow.isDestroyed()) {
|
||||
this._mainWindow.webContents.send(IPC.LOGIN_REQUIRED, { tabId, url: config.loginUrl });
|
||||
}
|
||||
if (platform === Platform.WBStream) {
|
||||
this.sendLog(tabId, 'Waiting for x_wbaas_token, wbx-refresh, wbx-validation-key...');
|
||||
await this.waitForCookies(['x_wbaas_token', 'wbx-refresh', 'wbx-validation-key']);
|
||||
} else if (platform === Platform.Dion) {
|
||||
this.sendLog(tabId, 'Waiting for vc-refresh-token, vc-access-token...');
|
||||
await this.waitForCookies(['vc-refresh-token', 'vc-access-token']);
|
||||
} else {
|
||||
await this.waitForLogin(config.cookieDomains, config.authCookie);
|
||||
}
|
||||
if (this._mainWindow && !this._mainWindow.isDestroyed()) {
|
||||
this._mainWindow.webContents.send(IPC.LOGIN_DONE, { tabId });
|
||||
}
|
||||
this.sendLog(tabId, `${config.platformName} login captured.`);
|
||||
cookies = await this.getCookiesForDomains(config.cookieDomains);
|
||||
}
|
||||
if (fileHasSession) {
|
||||
this.sendLog(tabId, `${config.platformName} session file is still active, keeping it as is.`);
|
||||
} else {
|
||||
this.sendLog(tabId, `${config.platformName} cookies (${cookies.length}): ${cookies.map((c) => c.name).join(', ')}`);
|
||||
await fs.writeFile(cookiesPath, JSON.stringify(cookies));
|
||||
}
|
||||
const spawnArgs = ['--resources', 'default', '--cookies', cookiesPath];
|
||||
this.killRelay(tabId, tab);
|
||||
if (joinTarget) {
|
||||
const flag = this.joinFlagFor(platform);
|
||||
if (flag) spawnArgs.push(flag, joinTarget);
|
||||
}
|
||||
this.appendUpstreamArgs(spawnArgs);
|
||||
if (this.debugLogging) spawnArgs.push('--debug');
|
||||
const proc = spawn(config.binaryPath, spawnArgs, {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
tab.relay = proc;
|
||||
let sawAuthFailure = false;
|
||||
let sawInvalidCredentials = false;
|
||||
this.attachProcessOutput(proc, tabId, (msg) => {
|
||||
if (dionCookieFile && (msg.includes('"code":1086') || msg.includes('Invalid credentials'))) {
|
||||
sawInvalidCredentials = true;
|
||||
}
|
||||
if (
|
||||
msg.includes('status 401') ||
|
||||
msg.includes('"UnauthorizedError"') ||
|
||||
msg.includes('"error":"unauthorized') ||
|
||||
msg.includes('empty access_token')
|
||||
) {
|
||||
sawAuthFailure = true;
|
||||
}
|
||||
});
|
||||
proc.on('close', async (code) => {
|
||||
this.sendLog(tabId, `Headless exited with code ${code}`);
|
||||
if (sawInvalidCredentials) {
|
||||
this.sendLog(tabId, `${config.platformName} rejected the email and password stored in ${cookiesPath}, fix them or clear cookies to log in through the browser.`);
|
||||
return;
|
||||
}
|
||||
if (sawAuthFailure) {
|
||||
if (dionCookieFile) await dionCookieFile.clearTokens();
|
||||
await this.clearAuthCookies(config.cookieDomains, config.authCookie);
|
||||
if (this.tabs.get(tabId) === tab) this.startHeadless(tabId, platform, args);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async clearAuthCookies(cookieDomains: string[], authCookieName: string): Promise<void> {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const matches = await ses.cookies.get({ name: authCookieName });
|
||||
for (const cookie of matches) {
|
||||
if (!cookie.domain || !cookieDomains.some((d) => cookie.domain!.includes(d))) continue;
|
||||
const host = cookie.domain.startsWith('.') ? cookie.domain.slice(1) : cookie.domain;
|
||||
const url = `https://${host}${cookie.path || '/'}`;
|
||||
try {
|
||||
await ses.cookies.remove(url, cookie.name);
|
||||
} catch (err) {
|
||||
console.log(`[COOKIES] failed to remove ${cookie.name} on ${url}:`, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private cookieFilePath(platform: Platform): string {
|
||||
return path.join(app.getPath('userData'), `cookies-${platform}.json`);
|
||||
}
|
||||
|
||||
async getDionCredentials(): Promise<DionCredentials> {
|
||||
return new DionCookieFile(this.cookieFilePath(Platform.Dion)).readCredentials();
|
||||
}
|
||||
|
||||
async setDionCredentials(email: string, password: string): Promise<void> {
|
||||
await new DionCookieFile(this.cookieFilePath(Platform.Dion)).writeCredentials(email, password);
|
||||
}
|
||||
|
||||
async clearPlatformCookies(platform: Platform): Promise<number> {
|
||||
const config = this.headlessConfig(platform);
|
||||
if (!config) return 0;
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const all = await ses.cookies.get({});
|
||||
let removed = 0;
|
||||
for (const cookie of all) {
|
||||
if (!cookie.domain || !config.cookieDomains.some((d) => cookie.domain!.includes(d))) continue;
|
||||
const host = cookie.domain.startsWith('.') ? cookie.domain.slice(1) : cookie.domain;
|
||||
const url = `https://${host}${cookie.path || '/'}`;
|
||||
try {
|
||||
await ses.cookies.remove(url, cookie.name);
|
||||
removed++;
|
||||
} catch (err) {
|
||||
console.log(`[COOKIES] failed to remove ${cookie.name} on ${url}:`, err);
|
||||
}
|
||||
}
|
||||
await fs.unlink(this.cookieFilePath(platform)).catch(() => {});
|
||||
console.log(`[COOKIES] cleared ${removed} cookies for ${platform}`);
|
||||
return removed;
|
||||
}
|
||||
|
||||
private waitForLogin(cookieDomains: string[], authCookieName: string): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const finish = () => {
|
||||
ses.cookies.removeListener('changed', onChanged);
|
||||
resolve();
|
||||
};
|
||||
const onChanged = (
|
||||
_e: Electron.Event,
|
||||
cookie: Electron.Cookie,
|
||||
_cause: string,
|
||||
removed: boolean,
|
||||
) => {
|
||||
if (removed) return;
|
||||
if (cookie.name !== authCookieName) return;
|
||||
if (!cookie.domain || !cookieDomains.some((d) => cookie.domain!.includes(d))) return;
|
||||
finish();
|
||||
};
|
||||
ses.cookies.on('changed', onChanged);
|
||||
ses.cookies.get({ name: authCookieName }).then((found) => {
|
||||
if (found.some((c) => c.domain && cookieDomains.some((d) => c.domain!.includes(d)))) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
});
|
||||
startHeadless(tabId: string, platform: Platform, args: HeadlessStartArgs): Promise<void> {
|
||||
return this.launcher.startHeadless(tabId, platform, args);
|
||||
}
|
||||
|
||||
killRelay(tabId: string, tab: TabState): void {
|
||||
if (tab.relay) {
|
||||
console.log(`[${tabId}] killing process pid=${tab.relay.pid}`);
|
||||
tab.relay.kill();
|
||||
tab.relay = null;
|
||||
}
|
||||
this.launcher.killRelay(tabId, tab);
|
||||
}
|
||||
|
||||
killAllRelays(): void {
|
||||
this.tabs.forEach((tab, tabId) => this.killRelay(tabId, tab));
|
||||
this.tabs.forEach((tab, tabId) => this.launcher.killRelay(tabId, tab));
|
||||
}
|
||||
|
||||
async setTunnelMode(tabId: string, mode: TunnelMode, platform?: Platform): Promise<void> {
|
||||
const tab = await this.getOrCreateTab(tabId);
|
||||
tab.tunnelMode = mode;
|
||||
if (platform) tab.platform = platform;
|
||||
if (
|
||||
mode === TunnelMode.HeadlessVK ||
|
||||
mode === TunnelMode.HeadlessTelemost ||
|
||||
mode === TunnelMode.HeadlessWBStream ||
|
||||
mode === TunnelMode.HeadlessDion ||
|
||||
mode === TunnelMode.HeadlessBitrix
|
||||
) return;
|
||||
this.launcher.killRelay(tabId, tab);
|
||||
setTimeout(() => this.launcher.startRelay(tabId, tab), RELAY_RESTART_DELAY_MS);
|
||||
}
|
||||
|
||||
async loadHook(tabId: string, url: string, tab: TabState): Promise<string> {
|
||||
@@ -526,93 +207,31 @@ export class TabManager {
|
||||
return LOG_CAPTURE_SNIPPET + `window.WS_PORT=${tab.dcPort};` + hook;
|
||||
}
|
||||
|
||||
async setTunnelMode(tabId: string, mode: TunnelMode, platform?: Platform): Promise<void> {
|
||||
const tab = await this.getOrCreateTab(tabId);
|
||||
tab.tunnelMode = mode;
|
||||
if (platform) tab.platform = platform;
|
||||
if (
|
||||
mode === TunnelMode.HeadlessVK ||
|
||||
mode === TunnelMode.HeadlessTelemost ||
|
||||
mode === TunnelMode.HeadlessWBStream ||
|
||||
mode === TunnelMode.HeadlessDion
|
||||
) return;
|
||||
this.killRelay(tabId, tab);
|
||||
setTimeout(() => this.startRelay(tabId, tab), RELAY_RESTART_DELAY_MS);
|
||||
getDionCredentials(): Promise<DionCredentials> {
|
||||
return this.cookies.getDionCredentials();
|
||||
}
|
||||
|
||||
private async getCookiesForDomains(domains: string[]): Promise<{ name: string; value: string }[]> {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const all = await ses.cookies.get({});
|
||||
return all
|
||||
.filter((c) => c.domain != null && domains.some((d) => c.domain!.includes(d)))
|
||||
.map((c) => ({ name: c.name, value: c.value }));
|
||||
setDionCredentials(email: string, password: string): Promise<void> {
|
||||
return this.cookies.setDionCredentials(email, password);
|
||||
}
|
||||
|
||||
private waitForCookies(names: string[]): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const remaining = new Set(names);
|
||||
const finish = () => {
|
||||
ses.cookies.removeListener('changed', onChanged);
|
||||
resolve();
|
||||
};
|
||||
const onChanged = (
|
||||
_e: Electron.Event,
|
||||
cookie: Electron.Cookie,
|
||||
_cause: string,
|
||||
removed: boolean,
|
||||
) => {
|
||||
if (removed) return;
|
||||
if (!remaining.has(cookie.name)) return;
|
||||
remaining.delete(cookie.name);
|
||||
if (remaining.size === 0) finish();
|
||||
};
|
||||
ses.cookies.on('changed', onChanged);
|
||||
Promise.all(names.map((name) => ses.cookies.get({ name }))).then((results) => {
|
||||
results.forEach((found, i) => {
|
||||
if (found.length > 0) remaining.delete(names[i]);
|
||||
});
|
||||
if (remaining.size === 0) finish();
|
||||
});
|
||||
});
|
||||
getBitrixCredentials(): Promise<BitrixCredentials> {
|
||||
return this.cookies.getBitrixCredentials();
|
||||
}
|
||||
|
||||
async buildCookiesZip(): Promise<Buffer> {
|
||||
const platforms: { filename: string; domains: string[]; platform: Platform }[] = [
|
||||
{ filename: 'cookies-vk.json', domains: VK_COOKIE_DOMAINS, platform: Platform.VK },
|
||||
{ filename: 'cookies-yandex.json', domains: YANDEX_COOKIE_DOMAINS, platform: Platform.Telemost },
|
||||
{ filename: 'cookies-dion.json', domains: DION_COOKIE_DOMAINS, platform: Platform.Dion },
|
||||
{ filename: 'cookies-wbstream.json', domains: WBSTREAM_COOKIE_DOMAINS, platform: Platform.WBStream },
|
||||
];
|
||||
const cookies = await Promise.all(platforms.map((p) => this.getCookiesForDomains(p.domains)));
|
||||
const dionContent = await new DionCookieFile(this.cookieFilePath(Platform.Dion)).readContent();
|
||||
const entries = platforms.map((p, i) => {
|
||||
const content = p.platform === Platform.Dion && dionContent ? dionContent : cookies[i];
|
||||
return { name: p.filename, data: Buffer.from(JSON.stringify(content, null, 2), 'utf8') };
|
||||
});
|
||||
return buildStoredZip(entries);
|
||||
setBitrixCredentials(portal: string, email: string, password: string): Promise<void> {
|
||||
return this.cookies.setBitrixCredentials(portal, email, password);
|
||||
}
|
||||
|
||||
async setWBStreamDeviceId(id: string): Promise<void> {
|
||||
if (!id) return;
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const existing = await ses.cookies.get({ url: 'https://stream.wb.ru/', name: '__wb_device_id' });
|
||||
if (existing.length > 0 && existing[0].value === id) return;
|
||||
try {
|
||||
await ses.cookies.set({
|
||||
url: 'https://stream.wb.ru/',
|
||||
name: '__wb_device_id',
|
||||
value: id,
|
||||
domain: 'stream.wb.ru',
|
||||
path: '/',
|
||||
secure: true,
|
||||
httpOnly: false,
|
||||
expirationDate: Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 365 * 5,
|
||||
});
|
||||
console.log(`[wb-device-id] persisted ${id}`);
|
||||
} catch (err) {
|
||||
console.log(`[wb-device-id] failed to persist:`, err);
|
||||
}
|
||||
clearPlatformCookies(platform: Platform): Promise<number> {
|
||||
return this.cookies.clearPlatformCookies(platform);
|
||||
}
|
||||
|
||||
buildCookiesZip(): Promise<Buffer> {
|
||||
return this.cookies.buildCookiesZip();
|
||||
}
|
||||
|
||||
setWBStreamDeviceId(id: string): Promise<void> {
|
||||
return this.cookies.setWBStreamDeviceId(id);
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,12 @@ import { IPC } from '../constants';
|
||||
setDionCredentials(email: string, password: string) {
|
||||
return ipcRenderer.invoke(IPC.SET_DION_CREDENTIALS, email, password);
|
||||
},
|
||||
getBitrixCredentials() {
|
||||
return ipcRenderer.invoke(IPC.GET_BITRIX_CREDENTIALS);
|
||||
},
|
||||
setBitrixCredentials(portal: string, email: string, password: string) {
|
||||
return ipcRenderer.invoke(IPC.SET_BITRIX_CREDENTIALS, portal, email, password);
|
||||
},
|
||||
onCreateBotTab(cb: (data: any) => void) {
|
||||
ipcRenderer.on(IPC.CREATE_BOT_TAB, (_e, data) => cb(data));
|
||||
},
|
||||
|
||||
@@ -56,6 +56,7 @@ export function renderContent(tm: RendererTabManager): void {
|
||||
if (activeTab.platform === Platform.Telemost) title = 'Telemost';
|
||||
else if (activeTab.platform === Platform.WBStream) title = 'WBStream';
|
||||
else if (activeTab.platform === Platform.Dion) title = 'DION';
|
||||
else if (activeTab.platform === Platform.Bitrix) title = 'Bitrix';
|
||||
document.getElementById('headlessTitle')!.textContent = title;
|
||||
const startEl = document.getElementById('headlessStart')!;
|
||||
const statusEl = document.getElementById('headlessStatus')!;
|
||||
@@ -70,12 +71,17 @@ export function renderContent(tm: RendererTabManager): void {
|
||||
errorEl.textContent = '';
|
||||
const dionAccountCard = document.getElementById('headlessDionAccountCard')!;
|
||||
dionAccountCard.style.display = activeTab.platform === Platform.Dion ? '' : 'none';
|
||||
const bitrixAccountCard = document.getElementById('headlessBitrixAccountCard')!;
|
||||
bitrixAccountCard.style.display = activeTab.platform === Platform.Bitrix ? '' : 'none';
|
||||
if (activeTab.platform === Platform.WBStream) {
|
||||
targetLabel.textContent = 'Paste a room id or stream.wb.ru/room/<id> link.';
|
||||
targetInput.placeholder = 'https://stream.wb.ru/room/<id>';
|
||||
} else if (activeTab.platform === Platform.Dion) {
|
||||
targetLabel.textContent = 'Paste a room id or dion.vc event link.';
|
||||
targetInput.placeholder = 'abc-def-ghi';
|
||||
} else if (activeTab.platform === Platform.Bitrix) {
|
||||
targetLabel.textContent = 'Paste a portal /video/ link, or leave empty to create a new room.';
|
||||
targetInput.placeholder = 'https://your-portal.bitrix24.ru/video/CODE';
|
||||
} else if (activeTab.platform === Platform.Telemost) {
|
||||
targetLabel.textContent = 'Paste a Telemost conference link.';
|
||||
targetInput.placeholder = 'https://telemost.yandex.ru/j/...';
|
||||
@@ -93,10 +99,12 @@ export function renderContent(tm: RendererTabManager): void {
|
||||
const callInfoTM = document.getElementById('headlessCallInfoTM')!;
|
||||
const callInfoWB = document.getElementById('headlessCallInfoWB')!;
|
||||
const callInfoDion = document.getElementById('headlessCallInfoDion')!;
|
||||
const callInfoBitrix = document.getElementById('headlessCallInfoBitrix')!;
|
||||
callInfoVK.style.display = 'none';
|
||||
callInfoTM.style.display = 'none';
|
||||
callInfoWB.style.display = 'none';
|
||||
callInfoDion.style.display = 'none';
|
||||
callInfoBitrix.style.display = 'none';
|
||||
if (callInfo) {
|
||||
if (activeTab.platform === Platform.WBStream) {
|
||||
callInfoWB.style.display = 'block';
|
||||
@@ -108,6 +116,9 @@ export function renderContent(tm: RendererTabManager): void {
|
||||
} else if (activeTab.platform === Platform.Dion) {
|
||||
callInfoDion.style.display = 'block';
|
||||
document.getElementById('headlessDionJoinLink')!.textContent = callInfo.joinLink || '';
|
||||
} else if (activeTab.platform === Platform.Bitrix) {
|
||||
callInfoBitrix.style.display = 'block';
|
||||
document.getElementById('headlessBitrixJoinLink')!.textContent = callInfo.joinLink || '';
|
||||
} else {
|
||||
callInfoVK.style.display = 'block';
|
||||
document.getElementById('headlessJoinLink')!.textContent = callInfo.joinLink || '';
|
||||
|
||||
@@ -60,6 +60,7 @@ function bindToolbarEvents(): void {
|
||||
document.getElementById('btnHeadlessTM')!.addEventListener('click', () => tm.switchToHeadless(Platform.Telemost));
|
||||
document.getElementById('btnHeadlessWB')!.addEventListener('click', () => tm.switchToHeadless(Platform.WBStream));
|
||||
document.getElementById('btnHeadlessDion')!.addEventListener('click', () => tm.switchToHeadless(Platform.Dion));
|
||||
document.getElementById('btnHeadlessBitrix')!.addEventListener('click', () => tm.switchToHeadless(Platform.Bitrix));
|
||||
document.getElementById('modeSelect')!.addEventListener('change', (event) => {
|
||||
tm.setTunnelMode((event.target as HTMLSelectElement).value);
|
||||
});
|
||||
@@ -108,41 +109,52 @@ function bindSettingsEvents(): void {
|
||||
});
|
||||
}
|
||||
|
||||
function bindDionAccountEvents(): void {
|
||||
document.getElementById('btnDionAccount')!.addEventListener('click', openDionAccount);
|
||||
document.getElementById('dionAccountPopup')!.addEventListener('click', closeDionAccount);
|
||||
document.querySelector('#dionAccountPopup .popup')!.addEventListener('click', (event) => event.stopPropagation());
|
||||
document.getElementById('btnDionAccountCancel')!.addEventListener('click', closeDionAccount);
|
||||
document.getElementById('btnDionAccountSave')!.addEventListener('click', async () => {
|
||||
const email = (document.getElementById('dionEmail') as HTMLInputElement).value.trim();
|
||||
const password = (document.getElementById('dionPassword') as HTMLInputElement).value;
|
||||
const status = document.getElementById('dionAccountStatus')!;
|
||||
interface AccountPopupConfig {
|
||||
name: string;
|
||||
fields: string[];
|
||||
load: () => Promise<Record<string, string>>;
|
||||
save: (values: Record<string, string>) => Promise<void>;
|
||||
readError: string;
|
||||
}
|
||||
|
||||
function bindAccountPopup(cfg: AccountPopupConfig): void {
|
||||
const lc = cfg.name.toLowerCase();
|
||||
const popup = document.getElementById(`${lc}AccountPopup`)!;
|
||||
const status = document.getElementById(`${lc}AccountStatus`)!;
|
||||
const field = (key: string) =>
|
||||
document.getElementById(`${lc}${key[0].toUpperCase()}${key.slice(1)}`) as HTMLInputElement;
|
||||
|
||||
const close = (): void => popup.classList.remove('visible');
|
||||
const open = async (): Promise<void> => {
|
||||
status.textContent = '';
|
||||
popup.classList.add('visible');
|
||||
try {
|
||||
await window.bridge.setDionCredentials(email, password);
|
||||
closeDionAccount();
|
||||
const values = await cfg.load();
|
||||
for (const key of cfg.fields) field(key).value = values[key] ?? '';
|
||||
} catch {
|
||||
status.textContent = cfg.readError;
|
||||
}
|
||||
};
|
||||
|
||||
document.getElementById(`btn${cfg.name}Account`)!.addEventListener('click', open);
|
||||
popup.addEventListener('click', close);
|
||||
popup.querySelector('.popup')!.addEventListener('click', (event) => event.stopPropagation());
|
||||
document.getElementById(`btn${cfg.name}AccountCancel`)!.addEventListener('click', close);
|
||||
document.getElementById(`btn${cfg.name}AccountSave`)!.addEventListener('click', async () => {
|
||||
const values: Record<string, string> = {};
|
||||
for (const key of cfg.fields) {
|
||||
const raw = field(key).value;
|
||||
values[key] = key === 'password' ? raw : raw.trim();
|
||||
}
|
||||
try {
|
||||
await cfg.save(values);
|
||||
close();
|
||||
} catch {
|
||||
status.textContent = 'Failed to save the credentials.';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function openDionAccount(): Promise<void> {
|
||||
const status = document.getElementById('dionAccountStatus')!;
|
||||
status.textContent = '';
|
||||
document.getElementById('dionAccountPopup')!.classList.add('visible');
|
||||
try {
|
||||
const credentials = await window.bridge.getDionCredentials();
|
||||
(document.getElementById('dionEmail') as HTMLInputElement).value = credentials.email;
|
||||
(document.getElementById('dionPassword') as HTMLInputElement).value = credentials.password;
|
||||
} catch {
|
||||
status.textContent = 'Failed to read the session file.';
|
||||
}
|
||||
}
|
||||
|
||||
function closeDionAccount(): void {
|
||||
document.getElementById('dionAccountPopup')!.classList.remove('visible');
|
||||
}
|
||||
|
||||
function bindErrorPopup(): void {
|
||||
document.getElementById('errorPopup')!.addEventListener('click', closeError);
|
||||
document.querySelector('#errorPopup .popup')!.addEventListener('click', (event) => event.stopPropagation());
|
||||
@@ -224,7 +236,20 @@ function init(): void {
|
||||
bindToolbarEvents();
|
||||
bindActionBarEvents();
|
||||
bindSettingsEvents();
|
||||
bindDionAccountEvents();
|
||||
bindAccountPopup({
|
||||
name: 'Dion',
|
||||
fields: ['email', 'password'],
|
||||
load: async () => ({ ...(await window.bridge.getDionCredentials()) }),
|
||||
save: (v) => window.bridge.setDionCredentials(v.email, v.password),
|
||||
readError: 'Failed to read the session file.',
|
||||
});
|
||||
bindAccountPopup({
|
||||
name: 'Bitrix',
|
||||
fields: ['portal', 'email', 'password'],
|
||||
load: async () => ({ ...(await window.bridge.getBitrixCredentials()) }),
|
||||
save: (v) => window.bridge.setBitrixCredentials(v.portal, v.email, v.password),
|
||||
readError: 'Failed to read the account file.',
|
||||
});
|
||||
bindErrorPopup();
|
||||
bindLogEvents();
|
||||
bindHeadlessEvents();
|
||||
@@ -253,6 +278,8 @@ function init(): void {
|
||||
tm.switchToHeadless(Platform.WBStream, data.joinTarget);
|
||||
} else if (data.mode === TunnelMode.HeadlessDion) {
|
||||
tm.switchToHeadless(Platform.Dion, data.joinTarget);
|
||||
} else if (data.mode === TunnelMode.HeadlessBitrix) {
|
||||
tm.switchToHeadless(Platform.Bitrix, data.joinTarget);
|
||||
} else {
|
||||
const url = data.platform === Platform.Telemost ? TELEMOST_URL : VK_IM_URL;
|
||||
loadURL(tm, url);
|
||||
|
||||
@@ -70,6 +70,10 @@ export class RendererTabManager {
|
||||
tab.mode = TunnelMode.HeadlessDion;
|
||||
if (!tab.isBot) tab.name = 'DION';
|
||||
break;
|
||||
case Platform.Bitrix:
|
||||
tab.mode = TunnelMode.HeadlessBitrix;
|
||||
if (!tab.isBot) tab.name = 'Bitrix';
|
||||
break;
|
||||
default:
|
||||
tab.mode = TunnelMode.HeadlessVK;
|
||||
if (!tab.isBot) tab.name = 'VK';
|
||||
@@ -109,11 +113,13 @@ export class RendererTabManager {
|
||||
data.mode === TunnelMode.HeadlessVK ||
|
||||
data.mode === TunnelMode.HeadlessTelemost ||
|
||||
data.mode === TunnelMode.HeadlessWBStream ||
|
||||
data.mode === TunnelMode.HeadlessDion;
|
||||
data.mode === TunnelMode.HeadlessDion ||
|
||||
data.mode === TunnelMode.HeadlessBitrix;
|
||||
let platformName = 'VK';
|
||||
if (data.platform === Platform.Telemost) platformName = 'Telemost';
|
||||
else if (data.platform === Platform.WBStream) platformName = 'WBStream';
|
||||
else if (data.platform === Platform.Dion) platformName = 'DION';
|
||||
else if (data.platform === Platform.Bitrix) platformName = 'Bitrix';
|
||||
const botName = isHeadless ? `Bot-${platformName}` : `Bot-${platformName} (legacy)`;
|
||||
this.tabs[data.tabId] = {
|
||||
wv: null,
|
||||
|
||||
@@ -7,6 +7,7 @@ export enum TunnelMode {
|
||||
HeadlessTelemost = 'headless-telemost',
|
||||
HeadlessWBStream = 'headless-wbstream',
|
||||
HeadlessDion = 'headless-dion',
|
||||
HeadlessBitrix = 'headless-bitrix',
|
||||
}
|
||||
|
||||
export enum Platform {
|
||||
@@ -14,6 +15,7 @@ export enum Platform {
|
||||
Telemost = 'telemost',
|
||||
WBStream = 'wbstream',
|
||||
Dion = 'dion',
|
||||
Bitrix = 'bitrix',
|
||||
}
|
||||
|
||||
export enum RelayMode {
|
||||
@@ -87,6 +89,12 @@ export interface DionCredentials {
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface BitrixCredentials {
|
||||
portal: string;
|
||||
email: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface TabConfig {
|
||||
mode: TunnelMode;
|
||||
peerId: number;
|
||||
@@ -171,6 +179,8 @@ export interface Bridge {
|
||||
clearCookies(platform: string): Promise<number>;
|
||||
getDionCredentials(): Promise<DionCredentials>;
|
||||
setDionCredentials(email: string, password: string): Promise<void>;
|
||||
getBitrixCredentials(): Promise<BitrixCredentials>;
|
||||
setBitrixCredentials(portal: string, email: string, password: string): Promise<void>;
|
||||
onCreateBotTab(cb: (data: BotTabData) => void): void;
|
||||
getCallCreatorCode(scriptFile: string): Promise<string>;
|
||||
onBotError(cb: (msg: string) => void): void;
|
||||
|
||||
@@ -188,6 +188,12 @@ body {
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.btn-headless-bitrix {
|
||||
background: #2fc7f7;
|
||||
color: white;
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.toolbar-spacer {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user