basic dion implementation
This commit is contained in:
1 parent
42aa45465a
commit
0643d24aa2
42 files changed
+3449
-63
No files matched your search
@@ -12,11 +12,14 @@ export const VK_API_VERSION = '5.131';
|
||||
export const VK_API_BASE_URL = 'https://api.vk.com/method';
|
||||
export const VK_IM_URL = 'https://vk.com/im';
|
||||
export const TELEMOST_URL = 'https://telemost.yandex.ru/';
|
||||
export const DION_URL = 'https://dion.vc/';
|
||||
|
||||
export const VK_LOGIN_URL = 'https://vk.com/';
|
||||
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 VK_AUTH_COOKIE = 'remixsid';
|
||||
export const YANDEX_AUTH_COOKIE = 'Session_id';
|
||||
export const DION_AUTH_COOKIE = 'vc-refresh-token';
|
||||
|
||||
export const SESSION_PARTITION = 'persist:creator';
|
||||
export const WINDOW_WIDTH = 1200;
|
||||
@@ -28,6 +31,7 @@ export const USER_AGENT =
|
||||
|
||||
export const VK_COOKIE_DOMAINS = ['vk.com', 'vk.ru'];
|
||||
export const YANDEX_COOKIE_DOMAINS = ['yandex.ru', 'yandex.net', 'ya.ru'];
|
||||
export const DION_COOKIE_DOMAINS = ['dion.vc'];
|
||||
|
||||
export enum Selector {
|
||||
VK_ADMIT = '[data-testid="calls_waiting_hall_promote"]',
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
SESSION_PARTITION,
|
||||
VK_COOKIE_DOMAINS,
|
||||
YANDEX_COOKIE_DOMAINS,
|
||||
DION_COOKIE_DOMAINS,
|
||||
} from '../constants';
|
||||
import { TunnelMode, Platform, BotSettings } from '../types';
|
||||
|
||||
@@ -97,7 +98,10 @@ export function registerIpcHandlers(tabManager: TabManager): void {
|
||||
ipcMain.handle(IPC.GET_COOKIES, async (_e, domain: string) => {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const all = await ses.cookies.get({});
|
||||
const domains = domain === 'yandex' ? YANDEX_COOKIE_DOMAINS : VK_COOKIE_DOMAINS;
|
||||
let domains: string[];
|
||||
if (domain === 'yandex') domains = YANDEX_COOKIE_DOMAINS;
|
||||
else if (domain === 'dion') domains = DION_COOKIE_DOMAINS;
|
||||
else domains = VK_COOKIE_DOMAINS;
|
||||
const filtered = all.filter((cookie) => {
|
||||
return cookie.domain != null && domains.some((d) => cookie.domain!.includes(d));
|
||||
});
|
||||
|
||||
@@ -12,10 +12,13 @@ import {
|
||||
SESSION_PARTITION,
|
||||
VK_COOKIE_DOMAINS,
|
||||
YANDEX_COOKIE_DOMAINS,
|
||||
DION_COOKIE_DOMAINS,
|
||||
VK_LOGIN_URL,
|
||||
YANDEX_LOGIN_URL,
|
||||
DION_LOGIN_URL,
|
||||
VK_AUTH_COOKIE,
|
||||
YANDEX_AUTH_COOKIE,
|
||||
DION_AUTH_COOKIE,
|
||||
LOG_CAPTURE_SNIPPET,
|
||||
} from '../constants';
|
||||
import { BotManager } from '../bot/bot-manager';
|
||||
@@ -42,6 +45,7 @@ export class TabManager {
|
||||
private headlessVKPath: string;
|
||||
private headlessTelemostPath: string;
|
||||
private headlessWBStreamPath: string;
|
||||
private headlessDionPath: string;
|
||||
private hooksDir: string;
|
||||
|
||||
constructor() {
|
||||
@@ -61,6 +65,10 @@ export class TabManager {
|
||||
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');
|
||||
@@ -220,6 +228,51 @@ export class TabManager {
|
||||
});
|
||||
}
|
||||
|
||||
private headlessConfig(platform: Platform): {
|
||||
tunnelMode: TunnelMode;
|
||||
authCookie: string;
|
||||
loginUrl: string;
|
||||
cookieDomains: string[];
|
||||
platformName: string;
|
||||
binaryPath: string;
|
||||
getCookies: () => Promise<{ name: string; value: 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,
|
||||
getCookies: () => this.getYandexCookies(),
|
||||
};
|
||||
case Platform.Dion:
|
||||
return {
|
||||
tunnelMode: TunnelMode.HeadlessDion,
|
||||
authCookie: DION_AUTH_COOKIE,
|
||||
loginUrl: DION_LOGIN_URL,
|
||||
cookieDomains: DION_COOKIE_DOMAINS,
|
||||
platformName: 'DION',
|
||||
binaryPath: this.headlessDionPath,
|
||||
getCookies: () => this.getDionCookies(),
|
||||
};
|
||||
case Platform.VK:
|
||||
return {
|
||||
tunnelMode: TunnelMode.HeadlessVK,
|
||||
authCookie: VK_AUTH_COOKIE,
|
||||
loginUrl: VK_LOGIN_URL,
|
||||
cookieDomains: VK_COOKIE_DOMAINS,
|
||||
platformName: 'VK',
|
||||
binaryPath: this.headlessVKPath,
|
||||
getCookies: () => this.getVKCookies(),
|
||||
};
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async startHeadless(tabId: string, platform: Platform): Promise<void> {
|
||||
const tab = await this.getOrCreateTab(tabId);
|
||||
tab.platform = platform;
|
||||
@@ -238,31 +291,30 @@ export class TabManager {
|
||||
return;
|
||||
}
|
||||
|
||||
const isTelemost = platform === Platform.Telemost;
|
||||
tab.tunnelMode = isTelemost ? TunnelMode.HeadlessTelemost : TunnelMode.HeadlessVK;
|
||||
const authCookie = isTelemost ? YANDEX_AUTH_COOKIE : VK_AUTH_COOKIE;
|
||||
const loginUrl = isTelemost ? YANDEX_LOGIN_URL : VK_LOGIN_URL;
|
||||
const cookieDomains = isTelemost ? YANDEX_COOKIE_DOMAINS : VK_COOKIE_DOMAINS;
|
||||
const platformName = isTelemost ? 'Yandex' : 'VK';
|
||||
let cookies = isTelemost ? await this.getYandexCookies() : await this.getVKCookies();
|
||||
if (!cookies.some((c) => c.name === authCookie)) {
|
||||
this.sendLog(tabId, `No ${platformName} session found, opening login.`);
|
||||
const config = this.headlessConfig(platform);
|
||||
if (!config) {
|
||||
this.sendLog(tabId, `Unsupported headless platform: ${platform}`);
|
||||
return;
|
||||
}
|
||||
tab.tunnelMode = config.tunnelMode;
|
||||
let cookies = await config.getCookies();
|
||||
if (!cookies.some((c) => c.name === config.authCookie)) {
|
||||
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: loginUrl });
|
||||
this._mainWindow.webContents.send(IPC.LOGIN_REQUIRED, { tabId, url: config.loginUrl });
|
||||
}
|
||||
await this.waitForLogin(cookieDomains, authCookie);
|
||||
await this.waitForLogin(config.cookieDomains, config.authCookie);
|
||||
if (this._mainWindow && !this._mainWindow.isDestroyed()) {
|
||||
this._mainWindow.webContents.send(IPC.LOGIN_DONE, { tabId });
|
||||
}
|
||||
this.sendLog(tabId, `${platformName} login captured.`);
|
||||
cookies = isTelemost ? await this.getYandexCookies() : await this.getVKCookies();
|
||||
this.sendLog(tabId, `${config.platformName} login captured.`);
|
||||
cookies = await config.getCookies();
|
||||
}
|
||||
this.sendLog(tabId, `${platformName} cookies (${cookies.length}): ${cookies.map((c) => c.name).join(', ')}`);
|
||||
this.sendLog(tabId, `${config.platformName} cookies (${cookies.length}): ${cookies.map((c) => c.name).join(', ')}`);
|
||||
this.killRelay(tabId, tab);
|
||||
const cookiesPath = path.join(app.getPath('userData'), `cookies-${platform}.json`);
|
||||
await fs.writeFile(cookiesPath, JSON.stringify(cookies));
|
||||
const binaryPath = isTelemost ? this.headlessTelemostPath : this.headlessVKPath;
|
||||
const proc = spawn(binaryPath, ['--resources', 'default', '--cookies', cookiesPath], {
|
||||
const proc = spawn(config.binaryPath, ['--resources', 'default', '--cookies', cookiesPath], {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
tab.relay = proc;
|
||||
@@ -275,8 +327,8 @@ export class TabManager {
|
||||
proc.on('close', async (code) => {
|
||||
this.sendLog(tabId, `Headless exited with code ${code}`);
|
||||
if (sawAuthFailure) {
|
||||
this.sendLog(tabId, `${platformName} session rejected (401), clearing and re-prompting login.`);
|
||||
await this.clearAuthCookies(cookieDomains, authCookie);
|
||||
this.sendLog(tabId, `${config.platformName} session rejected (401), clearing and re-prompting login.`);
|
||||
await this.clearAuthCookies(config.cookieDomains, config.authCookie);
|
||||
if (this.tabs.get(tabId) === tab) {
|
||||
this.startHeadless(tabId, platform);
|
||||
}
|
||||
@@ -339,7 +391,12 @@ export class TabManager {
|
||||
}
|
||||
|
||||
async loadHook(tabId: string, url: string, tab: TabState): Promise<string> {
|
||||
const isDion = url.includes('dion.vc');
|
||||
const isTelemost = url.includes('telemost.yandex');
|
||||
if (isDion) {
|
||||
tab.platform = Platform.Dion;
|
||||
return LOG_CAPTURE_SNIPPET;
|
||||
}
|
||||
tab.platform = isTelemost ? Platform.Telemost : Platform.VK;
|
||||
|
||||
if (isTelemost || tab.tunnelMode === TunnelMode.PionVideo) {
|
||||
@@ -356,7 +413,12 @@ export class TabManager {
|
||||
const tab = await this.getOrCreateTab(tabId);
|
||||
tab.tunnelMode = mode;
|
||||
if (platform) tab.platform = platform;
|
||||
if (mode === TunnelMode.HeadlessVK || mode === TunnelMode.HeadlessTelemost) return;
|
||||
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);
|
||||
}
|
||||
@@ -377,4 +439,12 @@ export class TabManager {
|
||||
.map((c) => ({ name: c.name, value: c.value }));
|
||||
}
|
||||
|
||||
async getDionCookies(): Promise<{ name: string; value: string }[]> {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const all = await ses.cookies.get({});
|
||||
return all
|
||||
.filter((c) => c.domain != null && DION_COOKIE_DOMAINS.some((d) => c.domain!.includes(d)))
|
||||
.map((c) => ({ name: c.name, value: c.value }));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,15 +55,18 @@ export function renderContent(tm: RendererTabManager): void {
|
||||
let title = 'VK';
|
||||
if (activeTab.platform === Platform.Telemost) title = 'Telemost';
|
||||
else if (activeTab.platform === Platform.WBStream) title = 'WBStream';
|
||||
else if (activeTab.platform === Platform.Dion) title = 'DION';
|
||||
document.getElementById('headlessTitle')!.textContent = title;
|
||||
document.getElementById('headlessStatus')!.textContent = activeTab.headlessStatus || 'Starting...';
|
||||
const callInfo = activeTab.callInfo;
|
||||
const callInfoVK = document.getElementById('headlessCallInfo')!;
|
||||
const callInfoTM = document.getElementById('headlessCallInfoTM')!;
|
||||
const callInfoWB = document.getElementById('headlessCallInfoWB')!;
|
||||
const callInfoDion = document.getElementById('headlessCallInfoDion')!;
|
||||
callInfoVK.style.display = 'none';
|
||||
callInfoTM.style.display = 'none';
|
||||
callInfoWB.style.display = 'none';
|
||||
callInfoDion.style.display = 'none';
|
||||
if (callInfo) {
|
||||
if (activeTab.platform === Platform.WBStream) {
|
||||
callInfoWB.style.display = 'block';
|
||||
@@ -72,6 +75,9 @@ export function renderContent(tm: RendererTabManager): void {
|
||||
callInfoTM.style.display = 'block';
|
||||
document.getElementById('headlessTMJoinLink')!.textContent = callInfo.joinLink || '';
|
||||
document.getElementById('headlessTMProtocol')!.textContent = callInfo.protocol || '';
|
||||
} else if (activeTab.platform === Platform.Dion) {
|
||||
callInfoDion.style.display = 'block';
|
||||
document.getElementById('headlessDionJoinLink')!.textContent = callInfo.joinLink || '';
|
||||
} else {
|
||||
callInfoVK.style.display = 'block';
|
||||
document.getElementById('headlessJoinLink')!.textContent = callInfo.joinLink || '';
|
||||
|
||||
@@ -58,6 +58,7 @@ function bindToolbarEvents(): void {
|
||||
document.getElementById('btnHeadlessVK')!.addEventListener('click', () => tm.switchToHeadless(Platform.VK));
|
||||
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('modeSelect')!.addEventListener('change', (event) => {
|
||||
tm.setTunnelMode((event.target as HTMLSelectElement).value);
|
||||
});
|
||||
@@ -75,6 +76,13 @@ function bindActionBarEvents(): void {
|
||||
'No Yandex cookies found.\nPlease log into Yandex (telemost.yandex.ru) first.',
|
||||
);
|
||||
});
|
||||
document.getElementById('btnDionCookies')!.addEventListener('click', () => {
|
||||
exportCookies(
|
||||
'dion',
|
||||
'cookies-dion.json',
|
||||
'No DION cookies found.\nPlease log into DION (dion.vc) first.',
|
||||
);
|
||||
});
|
||||
document.getElementById('btnSettings')!.addEventListener('click', openSettings);
|
||||
document.getElementById('tabBot')!.addEventListener('click', () => {
|
||||
if (!tm.botSettings.token || !tm.botSettings.groupId) {
|
||||
@@ -162,6 +170,8 @@ function init(): void {
|
||||
tm.switchToHeadless(Platform.Telemost);
|
||||
} else if (data.mode === TunnelMode.HeadlessWBStream) {
|
||||
tm.switchToHeadless(Platform.WBStream);
|
||||
} else if (data.mode === TunnelMode.HeadlessDion) {
|
||||
tm.switchToHeadless(Platform.Dion);
|
||||
} else {
|
||||
const url = data.platform === Platform.Telemost ? TELEMOST_URL : VK_IM_URL;
|
||||
loadURL(tm, url);
|
||||
|
||||
@@ -49,6 +49,10 @@ export class RendererTabManager {
|
||||
tab.mode = TunnelMode.HeadlessWBStream;
|
||||
if (!tab.isBot) tab.name = 'WBStream';
|
||||
break;
|
||||
case Platform.Dion:
|
||||
tab.mode = TunnelMode.HeadlessDion;
|
||||
if (!tab.isBot) tab.name = 'DION';
|
||||
break;
|
||||
default:
|
||||
tab.mode = TunnelMode.HeadlessVK;
|
||||
if (!tab.isBot) tab.name = 'VK';
|
||||
@@ -69,10 +73,12 @@ export class RendererTabManager {
|
||||
const isHeadless =
|
||||
data.mode === TunnelMode.HeadlessVK ||
|
||||
data.mode === TunnelMode.HeadlessTelemost ||
|
||||
data.mode === TunnelMode.HeadlessWBStream;
|
||||
data.mode === TunnelMode.HeadlessWBStream ||
|
||||
data.mode === TunnelMode.HeadlessDion;
|
||||
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';
|
||||
const botName = isHeadless ? `Bot-${platformName}` : `Bot-${platformName} (legacy)`;
|
||||
this.tabs[data.tabId] = {
|
||||
wv: null,
|
||||
@@ -127,6 +133,7 @@ export class RendererTabManager {
|
||||
if (tab.url) {
|
||||
if (tab.url.includes('vk.com')) return 'VK (legacy)';
|
||||
if (tab.url.includes('telemost')) return 'Telemost (legacy)';
|
||||
if (tab.url.includes('dion.vc')) return 'DION';
|
||||
}
|
||||
return 'New';
|
||||
}
|
||||
|
||||
@@ -6,12 +6,14 @@ export enum TunnelMode {
|
||||
HeadlessVK = 'headless-vk',
|
||||
HeadlessTelemost = 'headless-telemost',
|
||||
HeadlessWBStream = 'headless-wbstream',
|
||||
HeadlessDion = 'headless-dion',
|
||||
}
|
||||
|
||||
export enum Platform {
|
||||
VK = 'vk',
|
||||
Telemost = 'telemost',
|
||||
WBStream = 'wbstream',
|
||||
Dion = 'dion',
|
||||
}
|
||||
|
||||
export enum RelayMode {
|
||||
|
||||
Reference in new issue
Block a user