add blink to creator app
This commit is contained in:
1 parent
38fff05bb3
commit
e0e82f5212
25 files changed
+317
-111
No files matched your search
+27
-1
@@ -10,6 +10,7 @@ HEADLESS_TM_DIR="$HEADLESS_DIR/telemost"
|
||||
HEADLESS_WB_DIR="$HEADLESS_DIR/wbstream"
|
||||
HEADLESS_DION_DIR="$HEADLESS_DIR/dion"
|
||||
HEADLESS_BITRIX_DIR="$HEADLESS_DIR/bitrix"
|
||||
HEADLESS_BLINK_DIR="$HEADLESS_DIR/blink"
|
||||
PREBUILTS="$ROOT/prebuilts"
|
||||
|
||||
verify_artifact() {
|
||||
@@ -29,6 +30,7 @@ stage_darwin_binaries() {
|
||||
cp "$HEADLESS_DIR/headless-wbstream-darwin-$darwin_arch" "$HEADLESS_DIR/headless-wbstream-darwin"
|
||||
cp "$HEADLESS_DIR/headless-dion-darwin-$darwin_arch" "$HEADLESS_DIR/headless-dion-darwin"
|
||||
cp "$HEADLESS_DIR/headless-bitrix-darwin-$darwin_arch" "$HEADLESS_DIR/headless-bitrix-darwin"
|
||||
cp "$HEADLESS_DIR/headless-blink-darwin-$darwin_arch" "$HEADLESS_DIR/headless-blink-darwin"
|
||||
}
|
||||
|
||||
echo "=== Building relay binaries ==="
|
||||
@@ -146,7 +148,26 @@ GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" -o "$HEADLESS_DIR/he
|
||||
echo "Linux x86..."
|
||||
GOOS=linux GOARCH=386 go build -trimpath -ldflags="-s -w" -o "$HEADLESS_DIR/headless-bitrix-linux-ia32" .
|
||||
|
||||
ls -lh "$HEADLESS_DIR"/headless-vk-darwin-* "$HEADLESS_DIR"/headless-telemost-darwin-* "$HEADLESS_DIR"/headless-wbstream-darwin-* "$HEADLESS_DIR"/headless-dion-darwin-* "$HEADLESS_DIR"/headless-bitrix-darwin-*
|
||||
echo ""
|
||||
echo "=== Building headless-blink-creator ==="
|
||||
cd "$HEADLESS_BLINK_DIR"
|
||||
|
||||
echo "macOS x64..."
|
||||
GOOS=darwin GOARCH=amd64 go build -trimpath -ldflags="-s -w" -o "$HEADLESS_DIR/headless-blink-darwin-amd64" .
|
||||
echo "macOS arm64..."
|
||||
GOOS=darwin GOARCH=arm64 go build -trimpath -ldflags="-s -w" -o "$HEADLESS_DIR/headless-blink-darwin-arm64" .
|
||||
|
||||
echo "Windows x64..."
|
||||
GOOS=windows GOARCH=amd64 go build -trimpath -ldflags="-s -w" -o "$HEADLESS_DIR/headless-blink-windows-x64.exe" .
|
||||
echo "Windows x86..."
|
||||
GOOS=windows GOARCH=386 go build -trimpath -ldflags="-s -w" -o "$HEADLESS_DIR/headless-blink-windows-ia32.exe" .
|
||||
|
||||
echo "Linux x64..."
|
||||
GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w" -o "$HEADLESS_DIR/headless-blink-linux-x64" .
|
||||
echo "Linux x86..."
|
||||
GOOS=linux GOARCH=386 go build -trimpath -ldflags="-s -w" -o "$HEADLESS_DIR/headless-blink-linux-ia32" .
|
||||
|
||||
ls -lh "$HEADLESS_DIR"/headless-vk-darwin-* "$HEADLESS_DIR"/headless-telemost-darwin-* "$HEADLESS_DIR"/headless-wbstream-darwin-* "$HEADLESS_DIR"/headless-dion-darwin-* "$HEADLESS_DIR"/headless-bitrix-darwin-* "$HEADLESS_DIR"/headless-blink-darwin-*
|
||||
|
||||
echo ""
|
||||
echo "=== Building Electron apps ==="
|
||||
@@ -182,6 +203,7 @@ cp "$HEADLESS_DIR/headless-telemost-windows-x64.exe" "$HEADLESS_DIR/headless-tel
|
||||
cp "$HEADLESS_DIR/headless-wbstream-windows-x64.exe" "$HEADLESS_DIR/headless-wbstream-bundle.exe"
|
||||
cp "$HEADLESS_DIR/headless-dion-windows-x64.exe" "$HEADLESS_DIR/headless-dion-bundle.exe"
|
||||
cp "$HEADLESS_DIR/headless-bitrix-windows-x64.exe" "$HEADLESS_DIR/headless-bitrix-bundle.exe"
|
||||
cp "$HEADLESS_DIR/headless-blink-windows-x64.exe" "$HEADLESS_DIR/headless-blink-bundle.exe"
|
||||
rm -f "$PREBUILTS/$PRODUCT_NAME-$APP_VERSION-x64.exe"
|
||||
npx electron-builder --win --x64
|
||||
verify_artifact "$PRODUCT_NAME-$APP_VERSION-x64.exe"
|
||||
@@ -195,6 +217,7 @@ cp "$HEADLESS_DIR/headless-telemost-windows-ia32.exe" "$HEADLESS_DIR/headless-te
|
||||
cp "$HEADLESS_DIR/headless-wbstream-windows-ia32.exe" "$HEADLESS_DIR/headless-wbstream-bundle.exe"
|
||||
cp "$HEADLESS_DIR/headless-dion-windows-ia32.exe" "$HEADLESS_DIR/headless-dion-bundle.exe"
|
||||
cp "$HEADLESS_DIR/headless-bitrix-windows-ia32.exe" "$HEADLESS_DIR/headless-bitrix-bundle.exe"
|
||||
cp "$HEADLESS_DIR/headless-blink-windows-ia32.exe" "$HEADLESS_DIR/headless-blink-bundle.exe"
|
||||
rm -f "$PREBUILTS/$PRODUCT_NAME-$APP_VERSION-ia32.exe"
|
||||
npx electron-builder --win --ia32
|
||||
verify_artifact "$PRODUCT_NAME-$APP_VERSION-ia32.exe"
|
||||
@@ -208,6 +231,7 @@ cp "$HEADLESS_DIR/headless-telemost-linux-x64" "$HEADLESS_DIR/headless-telemost-
|
||||
cp "$HEADLESS_DIR/headless-wbstream-linux-x64" "$HEADLESS_DIR/headless-wbstream-bundle"
|
||||
cp "$HEADLESS_DIR/headless-dion-linux-x64" "$HEADLESS_DIR/headless-dion-bundle"
|
||||
cp "$HEADLESS_DIR/headless-bitrix-linux-x64" "$HEADLESS_DIR/headless-bitrix-bundle"
|
||||
cp "$HEADLESS_DIR/headless-blink-linux-x64" "$HEADLESS_DIR/headless-blink-bundle"
|
||||
rm -f "$PREBUILTS/$PRODUCT_NAME-$APP_VERSION-x86_64.AppImage"
|
||||
npx electron-builder --linux --x64
|
||||
verify_artifact "$PRODUCT_NAME-$APP_VERSION-x86_64.AppImage"
|
||||
@@ -225,6 +249,8 @@ rm -f "$HEADLESS_DIR"/headless-dion-darwin* "$HEADLESS_DIR"/headless-dion-window
|
||||
rm -f "$HEADLESS_DIR"/headless-dion-bundle "$HEADLESS_DIR"/headless-dion-bundle.exe
|
||||
rm -f "$HEADLESS_DIR"/headless-bitrix-darwin* "$HEADLESS_DIR"/headless-bitrix-windows-*.exe "$HEADLESS_DIR"/headless-bitrix-linux-*
|
||||
rm -f "$HEADLESS_DIR"/headless-bitrix-bundle "$HEADLESS_DIR"/headless-bitrix-bundle.exe
|
||||
rm -f "$HEADLESS_DIR"/headless-blink-darwin* "$HEADLESS_DIR"/headless-blink-windows-*.exe "$HEADLESS_DIR"/headless-blink-linux-*
|
||||
rm -f "$HEADLESS_DIR"/headless-blink-bundle "$HEADLESS_DIR"/headless-blink-bundle.exe
|
||||
|
||||
"$ROOT/clean-prebuilts.sh"
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<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-headless-blink" id="btnHeadlessBlink">Blink</button>
|
||||
<button class="btn-vk" id="btnVk">VK (legacy)</button>
|
||||
<button class="btn-telemost" id="btnTelemost">Telemost (legacy)</button>
|
||||
<span class="toolbar-spacer"></span>
|
||||
@@ -86,9 +87,15 @@
|
||||
<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"><span class="headless-save" data-action="save-call" title="Save this call"></span></div>
|
||||
</div>
|
||||
<div class="headless-call-info" id="headlessCallInfoBlink">
|
||||
<div class="headless-row"><span class="headless-label">Join link:</span> <a id="headlessBlinkJoinLink" href="#" class="headless-link"></a><img class="headless-copy" src="resources/icons8-copy-50.png" data-copy="headlessBlinkJoinLink" title="Copy"><span class="headless-save" data-action="save-call" title="Save this call"></span></div>
|
||||
</div>
|
||||
<div class="headless-call-info" id="headlessLoginInfo">
|
||||
<div class="headless-row"><span class="headless-label">Login link:</span> <a id="headlessLoginLink" href="#" class="headless-link"></a><img class="headless-copy" src="resources/icons8-copy-50.png" data-copy="headlessLoginLink" 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>
|
||||
<div class="headless-qr-hint" id="headlessQrHint">Scan in the Android app</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -130,6 +137,7 @@
|
||||
<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>
|
||||
<button type="button" class="btn-clear-cookies" data-platform="blink">Blink</button>
|
||||
</div>
|
||||
<div class="clear-cookies-status" id="clearCookiesStatus"></div>
|
||||
<div class="popup-buttons">
|
||||
|
||||
@@ -74,6 +74,10 @@
|
||||
{
|
||||
"from": "../headless/headless-bitrix-darwin",
|
||||
"to": "headless-bitrix-creator"
|
||||
},
|
||||
{
|
||||
"from": "../headless/headless-blink-darwin",
|
||||
"to": "headless-blink-creator"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -105,6 +109,10 @@
|
||||
{
|
||||
"from": "../headless/headless-bitrix-bundle.exe",
|
||||
"to": "headless-bitrix-creator.exe"
|
||||
},
|
||||
{
|
||||
"from": "../headless/headless-blink-bundle.exe",
|
||||
"to": "headless-blink-creator.exe"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -136,6 +144,10 @@
|
||||
{
|
||||
"from": "../headless/headless-bitrix-bundle",
|
||||
"to": "headless-bitrix-creator"
|
||||
},
|
||||
{
|
||||
"from": "../headless/headless-blink-bundle",
|
||||
"to": "headless-blink-creator"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -175,6 +175,7 @@ export class BotManager {
|
||||
else if (payload.cmd === BotCommand.WB) cmdPrefix = '/wb';
|
||||
else if (payload.cmd === BotCommand.Dion) cmdPrefix = '/dion';
|
||||
else if (payload.cmd === BotCommand.Bitrix) cmdPrefix = '/bitrix';
|
||||
else if (payload.cmd === BotCommand.Blink) cmdPrefix = '/blink';
|
||||
if (cmdPrefix && payload.mode) {
|
||||
text = `${cmdPrefix} ${payload.mode}`;
|
||||
}
|
||||
@@ -198,7 +199,7 @@ export class BotManager {
|
||||
if (wasAwaiting) {
|
||||
await this.sendMessage(
|
||||
peerId,
|
||||
"Couldn't detect a VK / Telemost / WBStream / DION / Bitrix link in that message. Paste a join link or press Back.",
|
||||
"Couldn't detect a VK / Telemost / WBStream / DION / Bitrix / Blink link in that message. Paste a join link or press Back.",
|
||||
createWaitingKeyboard(),
|
||||
);
|
||||
return;
|
||||
@@ -223,6 +224,9 @@ export class BotManager {
|
||||
if (lower.includes('bitrix24') && lower.includes('/video/')) {
|
||||
return { platform: Platform.Bitrix, target: trimmed };
|
||||
}
|
||||
if (lower.startsWith('blink://') || (lower.includes('blinkmap.com') && lower.includes('/join/'))) {
|
||||
return { platform: Platform.Blink, target: trimmed };
|
||||
}
|
||||
if (lower.includes('vk.ru/call/join')) {
|
||||
return { platform: Platform.VK, target: trimmed };
|
||||
}
|
||||
@@ -235,6 +239,7 @@ export class BotManager {
|
||||
case Platform.WBStream: return TunnelMode.HeadlessWBStream;
|
||||
case Platform.Dion: return TunnelMode.HeadlessDion;
|
||||
case Platform.Bitrix: return TunnelMode.HeadlessBitrix;
|
||||
case Platform.Blink: return TunnelMode.HeadlessBlink;
|
||||
default: return TunnelMode.HeadlessVK;
|
||||
}
|
||||
}
|
||||
@@ -245,6 +250,7 @@ export class BotManager {
|
||||
case Platform.WBStream: return 'WB Stream';
|
||||
case Platform.Dion: return 'DION';
|
||||
case Platform.Bitrix: return 'Bitrix';
|
||||
case Platform.Blink: return 'Blink';
|
||||
default: return 'VK';
|
||||
}
|
||||
}
|
||||
@@ -284,6 +290,7 @@ export class BotManager {
|
||||
if (platform === Platform.WBStream) return TunnelMode.HeadlessWBStream;
|
||||
if (platform === Platform.Dion) return TunnelMode.HeadlessDion;
|
||||
if (platform === Platform.Bitrix) return TunnelMode.HeadlessBitrix;
|
||||
if (platform === Platform.Blink) return TunnelMode.HeadlessBlink;
|
||||
if (text.includes('headless')) {
|
||||
return platform === Platform.VK ? TunnelMode.HeadlessVK : TunnelMode.HeadlessTelemost;
|
||||
}
|
||||
@@ -298,6 +305,7 @@ export class BotManager {
|
||||
case TunnelMode.HeadlessWBStream:
|
||||
case TunnelMode.HeadlessDion:
|
||||
case TunnelMode.HeadlessBitrix:
|
||||
case TunnelMode.HeadlessBlink:
|
||||
return 'Headless';
|
||||
case TunnelMode.PionVideo:
|
||||
return 'Video';
|
||||
@@ -332,6 +340,11 @@ export class BotManager {
|
||||
console.log('[BOT] Creating Bitrix tab with mode:', mode);
|
||||
this.onCreateTab({ mode, peerId, platform: Platform.Bitrix });
|
||||
await this.sendMessage(peerId, `Creating Bitrix room (${this.tunnelModeLabel(mode)})`, createMainKeyboard());
|
||||
} else if (text.startsWith('/blink')) {
|
||||
const mode = this.parseTunnelMode(text, Platform.Blink);
|
||||
console.log('[BOT] Creating Blink tab with mode:', mode);
|
||||
this.onCreateTab({ mode, peerId, platform: Platform.Blink });
|
||||
await this.sendMessage(peerId, `Creating Blink room (${this.tunnelModeLabel(mode)})`, createMainKeyboard());
|
||||
} else if (text === '/list') {
|
||||
await this.showList(peerId);
|
||||
} else if (text.startsWith('/close ')) {
|
||||
|
||||
@@ -35,6 +35,7 @@ export function createMainKeyboard() {
|
||||
],
|
||||
[
|
||||
{ action: { type: 'text', label: '🟧 Bitrix', payload: JSON.stringify({ cmd: BotCommand.Bitrix, mode: 'headless' }) } },
|
||||
{ action: { type: 'text', label: '🟨 Blink', payload: JSON.stringify({ cmd: BotCommand.Blink, mode: 'headless' }) } },
|
||||
],
|
||||
[
|
||||
{ action: { type: 'text', label: '🔗 Join by link', payload: JSON.stringify({ cmd: BotCommand.JoinPrompt }) } },
|
||||
|
||||
@@ -32,6 +32,7 @@ export const DION_AUTH_COOKIE = 'vc-refresh-token';
|
||||
export const WBSTREAM_ACCESS_TOKEN_COOKIE = 'wb_access_token';
|
||||
export const BITRIX_SESSION_COOKIE = 'BITRIX_SM_UIDH';
|
||||
export const BITRIX_AUTH_NET_HOST = 'https://auth2.bitrix24.net';
|
||||
export const BLINK_AUTH_COOKIE = 'blink_refresh_token';
|
||||
|
||||
export const SESSION_PARTITION = 'persist:creator';
|
||||
export const WINDOW_WIDTH = 1200;
|
||||
@@ -114,4 +115,5 @@ export enum HeadlessLogMarker {
|
||||
TURN = 'TURN:',
|
||||
PROTOCOL = 'protocol:',
|
||||
TUNNEL_CONNECTED = 'TUNNEL CONNECTED',
|
||||
LOGIN_LINK = 'STATUS:LOGIN_LINK:',
|
||||
}
|
||||
@@ -184,6 +184,12 @@ export class CookieStore {
|
||||
console.log(`[COOKIES] cleared ${removed} bitrix cookies`);
|
||||
return removed;
|
||||
}
|
||||
if (platform === Platform.Blink) {
|
||||
const entries = await this.readBlinkCookies();
|
||||
await fs.unlink(this.cookieFilePath(Platform.Blink)).catch(() => {});
|
||||
console.log(`[COOKIES] cleared ${entries.length} blink cookies`);
|
||||
return entries.length;
|
||||
}
|
||||
const config = PLATFORM_CONFIG[platform];
|
||||
if (!config) return 0;
|
||||
const removed = await this.removeCookiesForDomains(config.cookieDomains);
|
||||
@@ -210,6 +216,10 @@ export class CookieStore {
|
||||
return removed;
|
||||
}
|
||||
|
||||
private async readBlinkCookies(): Promise<unknown[]> {
|
||||
return fs.readFile(this.cookieFilePath(Platform.Blink), 'utf8').then(JSON.parse).catch(() => []);
|
||||
}
|
||||
|
||||
async getDionCredentials(): Promise<DionCredentials> {
|
||||
return new DionCookieFile(this.cookieFilePath(Platform.Dion)).readCredentials();
|
||||
}
|
||||
@@ -241,6 +251,8 @@ export class CookieStore {
|
||||
});
|
||||
const bitrixContent = await new BitrixCookieFile(this.cookieFilePath(Platform.Bitrix)).readRaw();
|
||||
entries.push({ name: 'cookies-bitrix.json', data: Buffer.from(JSON.stringify(bitrixContent ?? {}, null, 2), 'utf8') });
|
||||
const blinkContent = await this.readBlinkCookies();
|
||||
entries.push({ name: 'cookies-blink.json', data: Buffer.from(JSON.stringify(blinkContent, null, 2), 'utf8') });
|
||||
return buildStoredZip(entries);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
HeadlessMode,
|
||||
UpstreamProxy,
|
||||
} from '../types';
|
||||
import { IPC, BITRIX_LOGIN_URL } from '../constants';
|
||||
import { IPC, BITRIX_LOGIN_URL, BLINK_AUTH_COOKIE } from '../constants';
|
||||
import { BotManager } from '../bot/bot-manager';
|
||||
import { DionCookieFile } from './dion-cookie-file';
|
||||
import { BitrixCookieFile } from './bitrix-cookie-file';
|
||||
@@ -48,6 +48,7 @@ async function cookieFileHasCookie(filePath: string, name: string | undefined):
|
||||
export class HeadlessLauncher {
|
||||
private relayPath: string;
|
||||
private bitrixPath: string;
|
||||
private blinkPath: string;
|
||||
private binaryPaths = new Map<Platform, string>();
|
||||
private upstreamProxy: UpstreamProxy = { socks: '', user: '', pass: '' };
|
||||
private debugLogging = false;
|
||||
@@ -66,6 +67,10 @@ export class HeadlessLauncher {
|
||||
path.join('headless', 'bitrix', binaryName('headless-bitrix-creator')),
|
||||
binaryName('headless-bitrix-creator'),
|
||||
);
|
||||
this.blinkPath = resolveResourcePath(
|
||||
path.join('headless', 'blink', binaryName('headless-blink-creator')),
|
||||
binaryName('headless-blink-creator'),
|
||||
);
|
||||
for (const [platform, config] of Object.entries(PLATFORM_CONFIG)) {
|
||||
this.binaryPaths.set(
|
||||
platform as Platform,
|
||||
@@ -139,6 +144,10 @@ export class HeadlessLauncher {
|
||||
await this.startBitrixHeadless(tabId, args);
|
||||
return;
|
||||
}
|
||||
if (platform === Platform.Blink) {
|
||||
await this.startBlinkHeadless(tabId, args);
|
||||
return;
|
||||
}
|
||||
const tab = await this.host.getOrCreateTab(tabId);
|
||||
tab.platform = platform;
|
||||
const joinTarget = args.mode === HeadlessMode.Join ? (args.target || '').trim() : '';
|
||||
@@ -301,6 +310,71 @@ export class HeadlessLauncher {
|
||||
});
|
||||
}
|
||||
|
||||
private async startBlinkHeadless(tabId: string, args: HeadlessStartArgs): Promise<void> {
|
||||
const tab = await this.host.getOrCreateTab(tabId);
|
||||
tab.platform = Platform.Blink;
|
||||
tab.tunnelMode = TunnelMode.HeadlessBlink;
|
||||
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.Blink);
|
||||
if (!(await cookieFileHasCookie(cookiesPath, BLINK_AUTH_COOKIE))) {
|
||||
if (tab.isBot) {
|
||||
const reply = 'Please log into Blink 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 Blink session found, opening login. Scan the QR with the Blink app or open the link on the phone.');
|
||||
this.killRelay(tabId, tab);
|
||||
const loginProc = spawn(this.blinkPath, ['--login', '--cookies', cookiesPath], {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
tab.relay = loginProc;
|
||||
this.attachProcessOutput(loginProc, tabId);
|
||||
const code = await new Promise<number | null>((resolve) => loginProc.on('close', resolve));
|
||||
if (tab.relay !== loginProc) return;
|
||||
tab.relay = null;
|
||||
const win = this.host.mainWindow;
|
||||
if (win && !win.isDestroyed()) {
|
||||
win.webContents.send(IPC.LOGIN_DONE, { tabId });
|
||||
}
|
||||
if (code !== 0) {
|
||||
this.sendLog(tabId, 'Could not capture the Blink login, try again.');
|
||||
return;
|
||||
}
|
||||
this.sendLog(tabId, 'Blink login captured.');
|
||||
}
|
||||
|
||||
const spawnArgs = ['--resources', 'default', '--cookies', cookiesPath];
|
||||
this.killRelay(tabId, tab);
|
||||
if (joinTarget) {
|
||||
spawnArgs.push('--room', joinTarget);
|
||||
}
|
||||
this.appendEgressArgs(spawnArgs);
|
||||
if (this.debugLogging) spawnArgs.push('--debug');
|
||||
const proc = spawn(this.blinkPath, 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 === 'expired') {
|
||||
await this.cookies.clearPlatformCookies(Platform.Blink);
|
||||
if (this.host.getTab(tabId) === tab) this.startBlinkHeadless(tabId, args);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private appendEgressArgs(args: string[]): void {
|
||||
if (this.allowPrivateDst) args.push('--allow-private-dst');
|
||||
if (this.allowLoopbackDst) args.push('--allow-loopback');
|
||||
|
||||
@@ -190,7 +190,8 @@ export class TabManager {
|
||||
mode === TunnelMode.HeadlessTelemost ||
|
||||
mode === TunnelMode.HeadlessWBStream ||
|
||||
mode === TunnelMode.HeadlessDion ||
|
||||
mode === TunnelMode.HeadlessBitrix
|
||||
mode === TunnelMode.HeadlessBitrix ||
|
||||
mode === TunnelMode.HeadlessBlink
|
||||
) return;
|
||||
this.launcher.killRelay(tabId, tab);
|
||||
setTimeout(() => this.launcher.startRelay(tabId, tab), RELAY_RESTART_DELAY_MS);
|
||||
|
||||
@@ -58,6 +58,7 @@ export function renderContent(tm: RendererTabManager): void {
|
||||
else if (activeTab.platform === Platform.WBStream) title = 'WBStream';
|
||||
else if (activeTab.platform === Platform.Dion) title = 'DION';
|
||||
else if (activeTab.platform === Platform.Bitrix) title = 'Bitrix';
|
||||
else if (activeTab.platform === Platform.Blink) title = 'Blink';
|
||||
document.getElementById('headlessTitle')!.textContent = title;
|
||||
const startEl = document.getElementById('headlessStart')!;
|
||||
const statusEl = document.getElementById('headlessStatus')!;
|
||||
@@ -83,6 +84,9 @@ export function renderContent(tm: RendererTabManager): void {
|
||||
} 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.Blink) {
|
||||
targetLabel.textContent = 'Paste a chat id, blink:// link or group invite link.';
|
||||
targetInput.placeholder = 'https://blinkmap.com/join/<key>';
|
||||
} else if (activeTab.platform === Platform.Telemost) {
|
||||
targetLabel.textContent = 'Paste a Telemost conference link.';
|
||||
targetInput.placeholder = 'https://telemost.yandex.ru/j/...';
|
||||
@@ -101,12 +105,20 @@ export function renderContent(tm: RendererTabManager): void {
|
||||
const callInfoWB = document.getElementById('headlessCallInfoWB')!;
|
||||
const callInfoDion = document.getElementById('headlessCallInfoDion')!;
|
||||
const callInfoBitrix = document.getElementById('headlessCallInfoBitrix')!;
|
||||
const callInfoBlink = document.getElementById('headlessCallInfoBlink')!;
|
||||
const loginInfo = document.getElementById('headlessLoginInfo')!;
|
||||
callInfoVK.style.display = 'none';
|
||||
callInfoTM.style.display = 'none';
|
||||
callInfoWB.style.display = 'none';
|
||||
callInfoDion.style.display = 'none';
|
||||
callInfoBitrix.style.display = 'none';
|
||||
if (callInfo) {
|
||||
callInfoBlink.style.display = 'none';
|
||||
loginInfo.style.display = 'none';
|
||||
if (activeTab.loginLink) {
|
||||
loginInfo.style.display = 'block';
|
||||
document.getElementById('headlessLoginLink')!.textContent = activeTab.loginLink;
|
||||
renderHeadlessQr(activeTab.loginLink, `Scan with the ${title} app`);
|
||||
} else if (callInfo) {
|
||||
if (activeTab.platform === Platform.WBStream) {
|
||||
callInfoWB.style.display = 'block';
|
||||
document.getElementById('headlessWBJoinLink')!.textContent = callInfo.joinLink || '';
|
||||
@@ -120,20 +132,23 @@ export function renderContent(tm: RendererTabManager): void {
|
||||
} else if (activeTab.platform === Platform.Bitrix) {
|
||||
callInfoBitrix.style.display = 'block';
|
||||
document.getElementById('headlessBitrixJoinLink')!.textContent = callInfo.joinLink || '';
|
||||
} else if (activeTab.platform === Platform.Blink) {
|
||||
callInfoBlink.style.display = 'block';
|
||||
document.getElementById('headlessBlinkJoinLink')!.textContent = callInfo.joinLink || '';
|
||||
} else {
|
||||
callInfoVK.style.display = 'block';
|
||||
document.getElementById('headlessJoinLink')!.textContent = callInfo.joinLink || '';
|
||||
document.getElementById('headlessTurn')!.textContent = callInfo.turn || '';
|
||||
document.getElementById('headlessProtocol')!.textContent = callInfo.protocol || '';
|
||||
}
|
||||
renderJoinQr(callInfo.joinLink || '');
|
||||
renderHeadlessQr(callInfo.joinLink || '', 'Scan in the Android app');
|
||||
} else {
|
||||
renderJoinQr('');
|
||||
renderHeadlessQr('', '');
|
||||
}
|
||||
} else {
|
||||
toolbar.style.display = 'flex';
|
||||
headlessInfo.style.display = 'none';
|
||||
renderJoinQr('');
|
||||
renderHeadlessQr('', '');
|
||||
const isVK = activeTab.platform === Platform.VK && activeTab.url.includes('vk.ru');
|
||||
const modeSelect = document.getElementById('modeSelect') as HTMLSelectElement;
|
||||
const tunnelLabel = document.getElementById('tunnelLabel') as HTMLElement;
|
||||
@@ -310,7 +325,7 @@ export function exportCookiesZip(): void {
|
||||
|
||||
let renderedQrText = '';
|
||||
|
||||
function renderJoinQr(link: string): void {
|
||||
function renderHeadlessQr(link: string, hint: string): void {
|
||||
const wrap = document.getElementById('headlessQrWrap') as HTMLElement | null;
|
||||
const image = document.getElementById('headlessQr') as HTMLImageElement | null;
|
||||
if (!wrap || !image) return;
|
||||
@@ -320,6 +335,7 @@ function renderJoinQr(link: string): void {
|
||||
image.removeAttribute('src');
|
||||
return;
|
||||
}
|
||||
document.getElementById('headlessQrHint')!.textContent = hint;
|
||||
if (link === renderedQrText) {
|
||||
wrap.style.display = 'block';
|
||||
return;
|
||||
|
||||
@@ -67,6 +67,7 @@ function bindToolbarEvents(): void {
|
||||
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('btnHeadlessBlink')!.addEventListener('click', () => tm.switchToHeadless(Platform.Blink));
|
||||
document.getElementById('modeSelect')!.addEventListener('change', (event) => {
|
||||
tm.setTunnelMode((event.target as HTMLSelectElement).value);
|
||||
});
|
||||
@@ -318,6 +319,8 @@ function init(): void {
|
||||
tm.switchToHeadless(Platform.Dion, data.joinTarget);
|
||||
} else if (data.mode === TunnelMode.HeadlessBitrix) {
|
||||
tm.switchToHeadless(Platform.Bitrix, data.joinTarget);
|
||||
} else if (data.mode === TunnelMode.HeadlessBlink) {
|
||||
tm.switchToHeadless(Platform.Blink, data.joinTarget);
|
||||
} else {
|
||||
const url = data.platform === Platform.Telemost ? TELEMOST_URL : VK_IM_URL;
|
||||
loadURL(tm, url);
|
||||
@@ -343,6 +346,7 @@ function init(): void {
|
||||
const tab = tm.tabs[tabId];
|
||||
if (!tab) return;
|
||||
detachLoginWebview(tm, tabId);
|
||||
tab.loginLink = undefined;
|
||||
tab.headlessStatus = 'Starting...';
|
||||
if (tabId === tm.activeTabId) renderContent(tm);
|
||||
});
|
||||
|
||||
@@ -10,6 +10,7 @@ const PLATFORM_TITLES: Record<Platform, string> = {
|
||||
[Platform.WBStream]: 'WBStream',
|
||||
[Platform.Dion]: 'DION',
|
||||
[Platform.Bitrix]: 'Bitrix',
|
||||
[Platform.Blink]: 'Blink',
|
||||
};
|
||||
|
||||
export class SavedCallsView {
|
||||
|
||||
@@ -80,6 +80,10 @@ export class RendererTabManager {
|
||||
tab.mode = TunnelMode.HeadlessBitrix;
|
||||
if (!tab.isBot) tab.name = 'Bitrix';
|
||||
break;
|
||||
case Platform.Blink:
|
||||
tab.mode = TunnelMode.HeadlessBlink;
|
||||
if (!tab.isBot) tab.name = 'Blink';
|
||||
break;
|
||||
default:
|
||||
tab.mode = TunnelMode.HeadlessVK;
|
||||
if (!tab.isBot) tab.name = 'VK';
|
||||
@@ -88,6 +92,7 @@ export class RendererTabManager {
|
||||
tab.headlessStarted = false;
|
||||
tab.platform = platform;
|
||||
tab.callInfo = undefined;
|
||||
tab.loginLink = undefined;
|
||||
tab.headlessStatus = undefined;
|
||||
tab.tunnelConnected = false;
|
||||
tab.relayLogs = '';
|
||||
@@ -109,6 +114,7 @@ export class RendererTabManager {
|
||||
tab.headlessStarted = true;
|
||||
tab.headlessStatus = 'Starting...';
|
||||
tab.callInfo = undefined;
|
||||
tab.loginLink = undefined;
|
||||
window.bridge.startHeadless(this.activeTabId, tab.platform, args);
|
||||
this.onRender();
|
||||
}
|
||||
@@ -120,12 +126,14 @@ export class RendererTabManager {
|
||||
data.mode === TunnelMode.HeadlessTelemost ||
|
||||
data.mode === TunnelMode.HeadlessWBStream ||
|
||||
data.mode === TunnelMode.HeadlessDion ||
|
||||
data.mode === TunnelMode.HeadlessBitrix;
|
||||
data.mode === TunnelMode.HeadlessBitrix ||
|
||||
data.mode === TunnelMode.HeadlessBlink;
|
||||
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';
|
||||
else if (data.platform === Platform.Blink) platformName = 'Blink';
|
||||
const botName = isHeadless ? `Bot-${platformName}` : `Bot-${platformName} (legacy)`;
|
||||
this.tabs[data.tabId] = {
|
||||
wv: null,
|
||||
@@ -225,6 +233,11 @@ export class RendererTabManager {
|
||||
tab.callInfo.protocol = trimmed.split(HeadlessLogMarker.PROTOCOL)[1].trim();
|
||||
changed = true;
|
||||
}
|
||||
if (trimmed.includes(HeadlessLogMarker.LOGIN_LINK)) {
|
||||
tab.loginLink = trimmed.split(HeadlessLogMarker.LOGIN_LINK)[1].trim();
|
||||
tab.headlessStatus = 'Waiting for login...';
|
||||
changed = true;
|
||||
}
|
||||
if (trimmed.includes('[FATAL]')) {
|
||||
const fatalMessage = trimmed.split('[FATAL]')[1]?.trim() || 'fatal error';
|
||||
tab.headlessStatus = 'Disconnected: ' + fatalMessage;
|
||||
|
||||
@@ -8,6 +8,7 @@ export enum TunnelMode {
|
||||
HeadlessWBStream = 'headless-wbstream',
|
||||
HeadlessDion = 'headless-dion',
|
||||
HeadlessBitrix = 'headless-bitrix',
|
||||
HeadlessBlink = 'headless-blink',
|
||||
}
|
||||
|
||||
export enum Platform {
|
||||
@@ -16,6 +17,7 @@ export enum Platform {
|
||||
WBStream = 'wbstream',
|
||||
Dion = 'dion',
|
||||
Bitrix = 'bitrix',
|
||||
Blink = 'blink',
|
||||
}
|
||||
|
||||
export enum RelayMode {
|
||||
@@ -35,6 +37,7 @@ export enum BotCommand {
|
||||
WB = 'wb',
|
||||
Dion = 'dion',
|
||||
Bitrix = 'bitrix',
|
||||
Blink = 'blink',
|
||||
JoinPrompt = 'join-prompt',
|
||||
List = 'list',
|
||||
Menu = 'menu',
|
||||
@@ -158,6 +161,7 @@ export interface RendererTab {
|
||||
callInfo?: CallInfo;
|
||||
tunnelConnected?: boolean;
|
||||
loginWebview?: Webview;
|
||||
loginLink?: string;
|
||||
joinedByLink?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -190,6 +190,12 @@ body {
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.btn-headless-blink {
|
||||
background: #f5c400;
|
||||
color: #1e1e1e;
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.toolbar-spacer {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ require (
|
||||
golang.org/x/crypto v0.51.0
|
||||
golang.org/x/mobile v0.0.0-20260508232728-bebd421c7fa8
|
||||
golang.org/x/sys v0.45.0
|
||||
rsc.io/qr v0.2.0
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@@ -188,5 +188,3 @@ gvisor.dev/gvisor v0.0.0-20250523182742-eede7a881b20 h1:0DxLu8hxI1OGp1qVRPqNd+2k
|
||||
gvisor.dev/gvisor v0.0.0-20250523182742-eede7a881b20/go.mod h1:3r5CMtNQMKIvBlrmM9xWUNamjKBYPOWyXOjmg5Kts3g=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY=
|
||||
rsc.io/qr v0.2.0/go.mod h1:IF+uZjkb9fqyeF/4tlBoynqmQxUoPfWEKh921coOuXs=
|
||||
@@ -18,9 +18,9 @@ import (
|
||||
|
||||
func main() {
|
||||
common.MaybePrintVersion()
|
||||
roomFlag := flag.String("room", "", "Blink chat id or blink://<chat id> printed by the creator (required)")
|
||||
roomFlag := flag.String("room", "", "Blink chat id, blink://<chat id> printed by the creator or group invite link (required)")
|
||||
cookiesPath := flag.String("cookies", "", "path to the joiner's own Blink login file, e.g. cookies-blink-joiner.json")
|
||||
loginFlag := flag.Bool("login", false, "log in with a QR code, save the tokens to --cookies and exit")
|
||||
loginFlag := flag.Bool("login", false, "log in through the Blink app, save the tokens to --cookies and exit")
|
||||
socksHost := flag.String("socks-host", common.SocksLocalhostIP, "SOCKS5 listen address (use 0.0.0.0 to expose on LAN)")
|
||||
socksPort := flag.Int("socks-port", 1080, "SOCKS5 listen port")
|
||||
socksUser := flag.String("socks-user", "", "SOCKS5 username (optional)")
|
||||
@@ -39,7 +39,7 @@ func main() {
|
||||
log.Fatal("--cookies is required")
|
||||
}
|
||||
if *loginFlag {
|
||||
if err := blink.LoginToFile(*cookiesPath, nil, os.Stdout, log.Printf); err != nil {
|
||||
if err := blink.LoginToFile(*cookiesPath, nil, common.EmitStatus, log.Printf); err != nil {
|
||||
log.Fatalf("[login] %v", err)
|
||||
}
|
||||
return
|
||||
@@ -63,14 +63,14 @@ func main() {
|
||||
debug.SetMemoryLimit(memLimit)
|
||||
}
|
||||
|
||||
chatID, err := blink.ParseChatID(*roomFlag)
|
||||
if err != nil {
|
||||
log.Fatalf("[config] --room: %v", err)
|
||||
}
|
||||
credentials, err := blink.LoadCredentials(*cookiesPath, nil, log.Printf)
|
||||
if err != nil {
|
||||
log.Fatalf("[auth] %v", err)
|
||||
}
|
||||
chatID, err := credentials.ResolveChatID(*roomFlag)
|
||||
if err != nil {
|
||||
log.Fatalf("[config] --room: %v", err)
|
||||
}
|
||||
connection, err := credentials.ConnectCall(chatID)
|
||||
if err != nil {
|
||||
log.Fatalf("[call] %v", err)
|
||||
|
||||
@@ -18,8 +18,8 @@ import (
|
||||
func main() {
|
||||
common.MaybePrintVersion()
|
||||
cookiesPath := flag.String("cookies", "", "path to cookies-blink.json with the Blink login tokens")
|
||||
loginFlag := flag.Bool("login", false, "log in with a QR code, save the tokens to --cookies and exit")
|
||||
roomFlag := flag.String("room", "", "Blink chat id or blink://<chat id> to rejoin (empty = create new room)")
|
||||
loginFlag := flag.Bool("login", false, "log in through the Blink app, save the tokens to --cookies and exit")
|
||||
roomFlag := flag.String("room", "", "Blink chat id, blink://<chat id> or group invite link to rejoin (empty = create new room)")
|
||||
resources := flag.String("resources", "default", "resource mode: default, moderate, unlimited, custom")
|
||||
customReadBuf := flag.Int("read-buf", 0, "DC read buffer size in bytes, used with -resources custom")
|
||||
customMemLimit := flag.Int64("mem-limit", 0, "memory limit in bytes, used with -resources custom")
|
||||
@@ -68,7 +68,7 @@ func main() {
|
||||
log.Fatalf("[auth] --cookies is required")
|
||||
}
|
||||
if *loginFlag {
|
||||
if err := blink.LoginToFile(*cookiesPath, nil, os.Stdout, log.Printf); err != nil {
|
||||
if err := blink.LoginToFile(*cookiesPath, nil, common.EmitStatus, log.Printf); err != nil {
|
||||
log.Fatalf("[login] %v", err)
|
||||
}
|
||||
return
|
||||
@@ -81,8 +81,9 @@ func main() {
|
||||
}
|
||||
var chatID int64
|
||||
if *roomFlag != "" {
|
||||
chatID, err = blink.ParseChatID(*roomFlag)
|
||||
chatID, err = credentials.ResolveChatID(*roomFlag)
|
||||
if err != nil {
|
||||
common.EmitAuthErrorFor(err)
|
||||
log.Fatalf("[config] --room: %v", err)
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -44,8 +44,9 @@ that platform.
|
||||
## Blink
|
||||
|
||||
Blink has no guest access, so the creator and the joiner each need their own login.
|
||||
Both can be the same account, but every login must be a separate QR scan. Create the
|
||||
two files from the repository root, scanning each QR with the Blink app:
|
||||
Both can be the same account, but every login must be approved separately. Create the
|
||||
two files from the repository root. Each command prints a login link, open it on the
|
||||
phone with the Blink app:
|
||||
|
||||
./headless/blink/headless-blink-creator --login --cookies cookies-blink.json
|
||||
./headless/blink/headless-blink-creator --login --cookies cookies-blink-joiner.json
|
||||
|
||||
@@ -286,7 +286,7 @@ func detectJoinLink(text string) (platform, target string, ok bool) {
|
||||
return "dion", trimmed, true
|
||||
case strings.Contains(lower, "bitrix24") && strings.Contains(lower, "/video/"):
|
||||
return "bitrix", trimmed, true
|
||||
case strings.HasPrefix(lower, "blink://"):
|
||||
case strings.HasPrefix(lower, "blink://"), strings.Contains(lower, "blinkmap.com") && strings.Contains(lower, "/join/"):
|
||||
return "blink", trimmed, true
|
||||
case strings.Contains(lower, "vk.ru/call/join"):
|
||||
return "vk", trimmed, true
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -22,6 +23,7 @@ const (
|
||||
ClientUserAgent = "web_client (client 0.1.85)"
|
||||
LoginLinkBase = "https://blinkmap.com/deeplink/webapp/login"
|
||||
JoinLinkScheme = "blink://"
|
||||
InviteLinkHost = "blinkmap.com"
|
||||
)
|
||||
|
||||
var ErrLoginPending = errors.New("blink login is not approved yet")
|
||||
@@ -65,6 +67,23 @@ func ParseChatID(input string) (int64, error) {
|
||||
return chatID, nil
|
||||
}
|
||||
|
||||
func ParseInviteKey(input string) (string, bool) {
|
||||
trimmed := strings.TrimSpace(input)
|
||||
if !strings.Contains(trimmed, "://") {
|
||||
trimmed = "https://" + trimmed
|
||||
}
|
||||
parsed, err := url.Parse(trimmed)
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
host := parsed.Hostname()
|
||||
invitePath := strings.TrimRight(parsed.Path, "/")
|
||||
if (host != InviteLinkHost && host != "web."+InviteLinkHost) || !strings.Contains(invitePath, "/join/") {
|
||||
return "", false
|
||||
}
|
||||
return path.Base(invitePath), true
|
||||
}
|
||||
|
||||
func JoinLink(chatID int64) string {
|
||||
return JoinLinkScheme + strconv.FormatInt(chatID, 10)
|
||||
}
|
||||
@@ -205,6 +224,30 @@ func CreateGroupChat(client *http.Client, accessToken string, accountID int64, n
|
||||
return result.Data.ChatID, nil
|
||||
}
|
||||
|
||||
func FetchInviteChatID(client *http.Client, accessToken, inviteKey string) (int64, error) {
|
||||
var result struct {
|
||||
ChatID int64 `json:"chat_id"`
|
||||
AlreadyMember bool `json:"already_member"`
|
||||
}
|
||||
raw, status, err := apiDo(client, http.MethodGet, "/messenger/v2/chats/invite/"+url.PathEscape(inviteKey)+"/preview", accessToken, nil)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("invite preview: %w", err)
|
||||
}
|
||||
if status != http.StatusOK {
|
||||
return 0, &StatusError{Operation: "invite preview", Status: status, Body: common.BodySnippet(raw)}
|
||||
}
|
||||
if err := json.Unmarshal(raw, &result); err != nil {
|
||||
return 0, fmt.Errorf("invite preview decode: %w", err)
|
||||
}
|
||||
if result.ChatID <= 0 {
|
||||
return 0, fmt.Errorf("invite preview: no chat_id in %s", common.BodySnippet(raw))
|
||||
}
|
||||
if !result.AlreadyMember {
|
||||
return 0, fmt.Errorf("invite preview: the account is not a member of chat %d, join it in the Blink app first", result.ChatID)
|
||||
}
|
||||
return result.ChatID, nil
|
||||
}
|
||||
|
||||
func apiDo(client *http.Client, method, path, bearer string, body any) ([]byte, int, error) {
|
||||
var reader io.Reader
|
||||
if body != nil {
|
||||
|
||||
@@ -18,6 +18,9 @@ const (
|
||||
RefreshTokenEntry = "blink_refresh_token"
|
||||
|
||||
accessTokenRefreshMargin = time.Hour
|
||||
loginPollInterval = 5 * time.Second
|
||||
loginDefaultTTL = 600
|
||||
loginRenewFraction = 0.8
|
||||
)
|
||||
|
||||
type Credentials struct {
|
||||
@@ -51,6 +54,18 @@ func SaveTokens(path string, tokens TokenPair) error {
|
||||
})
|
||||
}
|
||||
|
||||
func LoginToFile(path string, client *http.Client, statusFn func(string), logFn func(string, ...any)) error {
|
||||
tokens, err := waitForLogin(client, statusFn, logFn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := SaveTokens(path, tokens); err != nil {
|
||||
return fmt.Errorf("save tokens to %s: %w", path, err)
|
||||
}
|
||||
logFn("[login] approved, tokens saved to %s", path)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Credentials) AccessToken() (string, error) {
|
||||
if accessTokenFresh(c.tokens) {
|
||||
return c.tokens.Token, nil
|
||||
@@ -67,6 +82,16 @@ func (c *Credentials) ConnectCall(chatID int64) (CallConnection, error) {
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Credentials) ResolveChatID(room string) (int64, error) {
|
||||
inviteKey, isInvite := ParseInviteKey(room)
|
||||
if !isInvite {
|
||||
return ParseChatID(room)
|
||||
}
|
||||
return withAccessToken(c, "invite preview", func(accessToken string) (int64, error) {
|
||||
return FetchInviteChatID(c.client, accessToken, inviteKey)
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Credentials) CreateChat(name string) (int64, error) {
|
||||
return withAccessToken(c, "group chat create", func(accessToken string) (int64, error) {
|
||||
accountID, err := FetchAccountID(c.client, accessToken)
|
||||
@@ -149,3 +174,31 @@ func accessTokenFresh(tokens TokenPair) bool {
|
||||
expiresIn := time.Until(time.Unix(tokens.TokenExpiresAt, 0))
|
||||
return tokens.Token != "" && expiresIn > accessTokenRefreshMargin
|
||||
}
|
||||
|
||||
func waitForLogin(client *http.Client, statusFn func(string), logFn func(string, ...any)) (TokenPair, error) {
|
||||
for {
|
||||
request, err := RequestLogin(client)
|
||||
if err != nil {
|
||||
return TokenPair{}, err
|
||||
}
|
||||
link := LoginLink(request.WAT)
|
||||
logFn("[login] open this link on the phone with the Blink app: %s", link)
|
||||
statusFn(common.StatusLoginLink + ":" + link)
|
||||
ttl := request.TTL
|
||||
if ttl <= 0 {
|
||||
ttl = loginDefaultTTL
|
||||
}
|
||||
renewAt := time.Now().Add(time.Duration(float64(ttl)*loginRenewFraction) * time.Second)
|
||||
for time.Now().Before(renewAt) {
|
||||
time.Sleep(loginPollInterval)
|
||||
tokens, err := PollLogin(client, request.WAT)
|
||||
if err == nil {
|
||||
return tokens, nil
|
||||
}
|
||||
if !errors.Is(err, ErrLoginPending) {
|
||||
logFn("[login] poll: %v", err)
|
||||
}
|
||||
}
|
||||
logFn("[login] login link expired, requesting a new one")
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package blink
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"rsc.io/qr"
|
||||
)
|
||||
|
||||
const (
|
||||
loginPollInterval = 5 * time.Second
|
||||
loginDefaultTTL = 600
|
||||
loginRenewFraction = 0.8
|
||||
qrQuietZone = 2
|
||||
qrDarkCell = "\x1b[40m \x1b[0m"
|
||||
qrLightCell = "\x1b[47m \x1b[0m"
|
||||
)
|
||||
|
||||
func LoginToFile(path string, client *http.Client, out io.Writer, logFn func(string, ...any)) error {
|
||||
tokens, err := LoginWithQR(client, out, logFn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := SaveTokens(path, tokens); err != nil {
|
||||
return fmt.Errorf("save tokens to %s: %w", path, err)
|
||||
}
|
||||
logFn("[login] approved, tokens saved to %s", path)
|
||||
return nil
|
||||
}
|
||||
|
||||
func LoginWithQR(client *http.Client, out io.Writer, logFn func(string, ...any)) (TokenPair, error) {
|
||||
for {
|
||||
request, err := RequestLogin(client)
|
||||
if err != nil {
|
||||
return TokenPair{}, err
|
||||
}
|
||||
link := LoginLink(request.WAT)
|
||||
if err := WriteQR(out, link); err != nil {
|
||||
return TokenPair{}, err
|
||||
}
|
||||
fmt.Fprintf(out, "\n Scan the QR with the Blink app, or open this link on the phone:\n %s\n\n", link)
|
||||
ttl := request.TTL
|
||||
if ttl <= 0 {
|
||||
ttl = loginDefaultTTL
|
||||
}
|
||||
renewAt := time.Now().Add(time.Duration(float64(ttl)*loginRenewFraction) * time.Second)
|
||||
for time.Now().Before(renewAt) {
|
||||
time.Sleep(loginPollInterval)
|
||||
tokens, err := PollLogin(client, request.WAT)
|
||||
if err == nil {
|
||||
return tokens, nil
|
||||
}
|
||||
if !errors.Is(err, ErrLoginPending) {
|
||||
logFn("[login] poll: %v", err)
|
||||
}
|
||||
}
|
||||
logFn("[login] QR expired, requesting a new one")
|
||||
}
|
||||
}
|
||||
|
||||
func WriteQR(out io.Writer, text string) error {
|
||||
code, err := qr.Encode(text, qr.M)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var builder strings.Builder
|
||||
for y := -qrQuietZone; y < code.Size+qrQuietZone; y++ {
|
||||
for x := -qrQuietZone; x < code.Size+qrQuietZone; x++ {
|
||||
if code.Black(x, y) {
|
||||
builder.WriteString(qrDarkCell)
|
||||
} else {
|
||||
builder.WriteString(qrLightCell)
|
||||
}
|
||||
}
|
||||
builder.WriteString("\n")
|
||||
}
|
||||
_, err = io.WriteString(out, builder.String())
|
||||
return err
|
||||
}
|
||||
@@ -12,6 +12,7 @@ const (
|
||||
StatusTunnelConnected = "TUNNEL_CONNECTED"
|
||||
StatusTunnelLost = "TUNNEL_LOST"
|
||||
StatusError = "ERROR"
|
||||
StatusLoginLink = "LOGIN_LINK"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
Reference in new issue
Block a user