join to existing call via bot in creator

This commit is contained in:
kulikov0 committed 2026-05-16 13:15:22 +02:00
1 parent cdfed572f0
commit e94d0b2fb7
12 files changed
+134 -16

No files matched your search

+80
View File
@@ -4,6 +4,7 @@ import { VK_API_VERSION, VK_API_BASE_URL, BOT_POLL_RETRY_DELAY_MS, BOT_POLL_WAIT
import {
createMainKeyboard,
createListKeyboard,
createWaitingKeyboard,
findTabByShortId,
generateShortId,
padShortId,
@@ -52,6 +53,7 @@ export class BotManager {
private key: string | null = null;
private server: string | null = null;
private running = false;
private awaitingJoinLink = new Set<number>();
onError: ((msg: string) => void) | null = null;
constructor(
@@ -171,15 +173,86 @@ export class BotManager {
if (payload.cmd === BotCommand.VK) cmdPrefix = '/vk';
else if (payload.cmd === BotCommand.TM) cmdPrefix = '/tm';
else if (payload.cmd === BotCommand.WB) cmdPrefix = '/wb';
else if (payload.cmd === BotCommand.Dion) cmdPrefix = '/dion';
if (cmdPrefix && payload.mode) {
text = `${cmdPrefix} ${payload.mode}`;
}
}
const wasAwaiting = this.awaitingJoinLink.has(peerId);
const joinLink = this.detectJoinLink(text);
if (joinLink) {
this.awaitingJoinLink.delete(peerId);
console.log('[BOT] Detected join link for', joinLink.platform, ':', joinLink.target);
this.onCreateTab({
mode: this.headlessModeFor(joinLink.platform),
peerId,
platform: joinLink.platform,
joinTarget: joinLink.target,
});
await this.sendMessage(peerId, `Joining ${this.platformLabel(joinLink.platform)} call`, createMainKeyboard());
return;
}
if (wasAwaiting) {
await this.sendMessage(
peerId,
"Couldn't detect a VK / Telemost / WBStream / DION link in that message. Paste a join link or press Back.",
createWaitingKeyboard(),
);
return;
}
await this.handleTextCommand(text, peerId);
}
private detectJoinLink(text: string): { platform: Platform; target: string } | null {
const trimmed = text.trim();
if (!trimmed) return null;
const lower = trimmed.toLowerCase();
if (lower.startsWith('wbstream://') || lower.includes('stream.wb.ru')) {
return { platform: Platform.WBStream, target: trimmed };
}
if (lower.includes('telemost.yandex')) {
return { platform: Platform.Telemost, target: trimmed };
}
if (lower.startsWith('dion://') || lower.includes('dion.vc')) {
return { platform: Platform.Dion, target: trimmed };
}
if (lower.includes('vk.com/call/join')) {
return { platform: Platform.VK, target: trimmed };
}
return null;
}
private headlessModeFor(platform: Platform): TunnelMode {
switch (platform) {
case Platform.Telemost: return TunnelMode.HeadlessTelemost;
case Platform.WBStream: return TunnelMode.HeadlessWBStream;
case Platform.Dion: return TunnelMode.HeadlessDion;
default: return TunnelMode.HeadlessVK;
}
}
private platformLabel(platform: Platform): string {
switch (platform) {
case Platform.Telemost: return 'Telemost';
case Platform.WBStream: return 'WB Stream';
case Platform.Dion: return 'DION';
default: return 'VK';
}
}
private async handlePayloadCommand(payload: ButtonPayload, peerId: number): Promise<boolean> {
if (payload.cmd === BotCommand.Noop) {
return true;
}
if (payload.cmd === BotCommand.JoinPrompt) {
this.awaitingJoinLink.add(peerId);
await this.sendMessage(peerId, 'Paste a join link', createWaitingKeyboard());
return true;
}
this.awaitingJoinLink.delete(peerId);
if (payload.cmd === BotCommand.List) {
await this.showList(peerId);
return true;
@@ -203,6 +276,7 @@ export class BotManager {
private parseTunnelMode(text: string, platform: Platform): TunnelMode {
if (platform === Platform.WBStream) return TunnelMode.HeadlessWBStream;
if (platform === Platform.Dion) return TunnelMode.HeadlessDion;
if (text.includes('headless')) {
return platform === Platform.VK ? TunnelMode.HeadlessVK : TunnelMode.HeadlessTelemost;
}
@@ -215,6 +289,7 @@ export class BotManager {
case TunnelMode.HeadlessVK:
case TunnelMode.HeadlessTelemost:
case TunnelMode.HeadlessWBStream:
case TunnelMode.HeadlessDion:
return 'Headless';
case TunnelMode.PionVideo:
return 'Video';
@@ -239,6 +314,11 @@ export class BotManager {
console.log('[BOT] Creating WB Stream tab with mode:', mode);
this.onCreateTab({ mode, peerId, platform: Platform.WBStream });
await this.sendMessage(peerId, `Creating WB Stream room (${this.tunnelModeLabel(mode)})`, createMainKeyboard());
} else if (text.startsWith('/dion')) {
const mode = this.parseTunnelMode(text, Platform.Dion);
console.log('[BOT] Creating DION tab with mode:', mode);
this.onCreateTab({ mode, peerId, platform: Platform.Dion });
await this.sendMessage(peerId, `Creating DION room (${this.tunnelModeLabel(mode)})`, createMainKeyboard());
} else if (text === '/list') {
await this.showList(peerId);
} else if (text.startsWith('/close ')) {
+23 -5
View File
@@ -27,19 +27,37 @@ export function createMainKeyboard() {
buttons: [
[
{ action: { type: 'text', label: '🟦 VK', payload: JSON.stringify({ cmd: BotCommand.VK, mode: 'headless' }) } },
{ action: { type: 'text', label: 'DC (legacy)', payload: JSON.stringify({ cmd: BotCommand.VK, mode: 'dc' }) } },
{ action: { type: 'text', label: 'Video (legacy)', payload: JSON.stringify({ cmd: BotCommand.VK, mode: 'video' }) } },
],
[
{ action: { type: 'text', label: '🟥 Telemost', payload: JSON.stringify({ cmd: BotCommand.TM, mode: 'headless' }) } },
{ action: { type: 'text', label: 'Video (legacy)', payload: JSON.stringify({ cmd: BotCommand.TM, mode: 'video' }) } },
],
[
{ action: { type: 'text', label: '🟪 WBStream', payload: JSON.stringify({ cmd: BotCommand.WB, mode: 'headless' }) } },
{ action: { type: 'text', label: '🟩 DION', payload: JSON.stringify({ cmd: BotCommand.Dion, mode: 'headless' }) } },
],
[
{ action: { type: 'text', label: '🔗 Join by link', payload: JSON.stringify({ cmd: BotCommand.JoinPrompt }) } },
],
[
{ action: { type: 'text', label: '📋 Active Tabs', payload: JSON.stringify({ cmd: BotCommand.List }) } },
],
[
{ action: { type: 'text', label: 'ℹ️ Buttons below: old webview mode', payload: JSON.stringify({ cmd: BotCommand.Noop }) } },
],
[
{ action: { type: 'text', label: '🟦 DC (legacy)', payload: JSON.stringify({ cmd: BotCommand.VK, mode: 'dc' }) } },
{ action: { type: 'text', label: '🟦 Video (legacy)', payload: JSON.stringify({ cmd: BotCommand.VK, mode: 'video' }) } },
{ action: { type: 'text', label: '🟥 Video (legacy)', payload: JSON.stringify({ cmd: BotCommand.TM, mode: 'video' }) } },
],
],
};
}
export function createWaitingKeyboard() {
return {
one_time: false,
buttons: [
[
{ action: { type: 'text', label: '◀️ Back', payload: JSON.stringify({ cmd: BotCommand.Menu }) } },
],
],
};
}
+1
View File
@@ -55,6 +55,7 @@ export function registerIpcHandlers(tabManager: TabManager): void {
mode: tabConfig.mode,
peerId: tabConfig.peerId,
platform: tabConfig.platform || Platform.VK,
joinTarget: tabConfig.joinTarget,
});
console.log('[BOT] Created tab:', tabId, 'mode:', tabConfig.mode, 'platform:', tabConfig.platform);
},
+9 -1
View File
@@ -315,6 +315,14 @@ export class TabManager {
const refreshCookie = platform === Platform.WBStream ? 'wbx-refresh' : config.authCookie;
const needsLogin = !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 });
@@ -332,10 +340,10 @@ export class TabManager {
cookies = await this.getCookiesForDomains(config.cookieDomains);
}
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 spawnArgs = ['--resources', 'default', '--cookies', cookiesPath];
this.killRelay(tabId, tab);
if (joinTarget) {
const flag = this.joinFlagFor(platform);
if (flag) spawnArgs.push(flag, joinTarget);
-2
View File
@@ -128,8 +128,6 @@ export function renderContent(tm: RendererTabManager): void {
document.getElementById('relayLog')!.textContent = activeTab.relayLogs || '';
document.getElementById('hookLog')!.textContent = activeTab.hookLogs || '';
scrollLogs();
renderBotButton(tm);
}
export function renderBotButton(tm: RendererTabManager): void {
+5 -4
View File
@@ -23,6 +23,7 @@ declare const window: Window & { bridge: Bridge };
const tm = new RendererTabManager(() => {
renderTabs(tm);
renderContent(tm);
renderBotButton(tm);
});
function bindTabBarEvents(): void {
@@ -183,13 +184,13 @@ function init(): void {
tm.createBotTab(data);
(document.getElementById('modeSelect') as HTMLSelectElement).value = data.mode;
if (data.mode === TunnelMode.HeadlessVK) {
tm.switchToHeadless(Platform.VK);
tm.switchToHeadless(Platform.VK, data.joinTarget);
} else if (data.mode === TunnelMode.HeadlessTelemost) {
tm.switchToHeadless(Platform.Telemost);
tm.switchToHeadless(Platform.Telemost, data.joinTarget);
} else if (data.mode === TunnelMode.HeadlessWBStream) {
tm.switchToHeadless(Platform.WBStream);
tm.switchToHeadless(Platform.WBStream, data.joinTarget);
} else if (data.mode === TunnelMode.HeadlessDion) {
tm.switchToHeadless(Platform.Dion);
tm.switchToHeadless(Platform.Dion, data.joinTarget);
} else {
const url = data.platform === Platform.Telemost ? TELEMOST_URL : VK_IM_URL;
loadURL(tm, url);
+9 -3
View File
@@ -43,7 +43,7 @@ export class RendererTabManager {
return tabId;
}
switchToHeadless(platform: Platform): void {
switchToHeadless(platform: Platform, joinTarget?: string): void {
if (!this.activeTabId) return;
const tab = this.tabs[this.activeTabId];
if (tab.wv) tab.wv.remove();
@@ -75,7 +75,11 @@ export class RendererTabManager {
tab.relayLogs = '';
tab.hookLogs = '';
if (tab.isBot) {
this.startHeadlessCall({ mode: HeadlessMode.Create });
if (joinTarget) {
this.startHeadlessCall({ mode: HeadlessMode.Join, target: joinTarget });
} else {
this.startHeadlessCall({ mode: HeadlessMode.Create });
}
}
this.onRender();
}
@@ -113,6 +117,7 @@ export class RendererTabManager {
isBot: true,
peerId: data.peerId,
platform: data.platform,
joinedByLink: !!data.joinTarget,
};
}
this.selectTab(data.tabId);
@@ -191,7 +196,8 @@ export class RendererTabManager {
if (trimmed.includes(HeadlessLogMarker.JOIN_LINK) && tab.callInfo) {
tab.callInfo.joinLink = trimmed.split(HeadlessLogMarker.JOIN_LINK)[1].trim();
if (tab.isBot) {
window.bridge.sendBotCallLink(tabId, tab.callInfo.joinLink);
const reply = tab.joinedByLink ? 'Joined successfully' : tab.callInfo.joinLink;
window.bridge.sendBotCallLink(tabId, reply);
}
changed = true;
}
+6
View File
@@ -31,9 +31,12 @@ export enum BotCommand {
VK = 'vk',
TM = 'tm',
WB = 'wb',
Dion = 'dion',
JoinPrompt = 'join-prompt',
List = 'list',
Menu = 'menu',
Close = 'close',
Noop = 'noop',
}
export enum LogPanel {
@@ -66,6 +69,7 @@ export interface TabConfig {
mode: TunnelMode;
peerId: number;
platform: Platform;
joinTarget?: string;
}
export interface TabListEntry {
@@ -116,6 +120,7 @@ export interface RendererTab {
callInfo?: CallInfo;
tunnelConnected?: boolean;
loginWebview?: Webview;
joinedByLink?: boolean;
}
export interface BotTabData {
@@ -123,6 +128,7 @@ export interface BotTabData {
mode: TunnelMode;
peerId: number;
platform: Platform;
joinTarget?: string;
}
export interface RelayLogData {