### start() Source: https://github.com/tellarion/webmaxsocket/blob/main/README.md Starts the client and establishes a connection. ```APIDOC ## start() Starts the client and establishes a connection. ### Method ```javascript await client.start(); ``` ``` -------------------------------- ### Start WebMaxClient Connection Source: https://github.com/tellarion/webmaxsocket/blob/main/README.md Initiates the client connection process. This method must be called after the client is instantiated. ```javascript await client.start(); ``` -------------------------------- ### WebMaxClient Constructor Options Source: https://github.com/tellarion/webmaxsocket/blob/main/README.md Detailed example of WebMaxClient constructor options, including session management, debugging, logging, transport URLs, reconnection settings, and user-agent details. ```javascript const client = new WebMaxClient({ name: 'session', // Имя сессии (для сохранения авторизации) token: 'An_Sx6H...', // Токен авторизации (опционально) configPath: 'myconfig', // Путь к config файлу (опционально) deviceType: 'WEB', // Тип устройства: 'WEB' или 'ANDROID' (опционально) saveToken: true, // Сохранять токен в сессию (по умолчанию true) debug: false, // TCP/WebSocket: краткий лог opcode; также учитывается WEBMAX_DEBUG=1, DEBUG=1 // Лог входящих (JSON в консоль), см. ниже: logIncoming: undefined, // false | 'messages' | 'verbose' — по умолчанию см. таблицу logIncomingVerbose: false, // явно включить verbose (как logIncoming: 'verbose') apiUrl: 'wss://...', // URL WebSocket API (опционально) maxReconnectAttempts: 5,// Максимальное количество попыток переподключения reconnectDelay: 3000, // Задержка между попытками переподключения (мс) // Сессия и токен (см. раздел «Сессии»): sessionRefreshIntervalMs: 0, // Периодический sync (мс), минимум 10_000; 0 — выключено. Алиас: autoSyncIntervalMs clearSessionOnFailedSync: false, // connectWithSession: при ошибке sync вызвать session.clear() перед authorize() (по умолчанию false) // User-Agent / клиент (важно для GET_QR, см. showLinkDeviceQR): appVersion: '26.14.1', // Актуальная версия Android-клиента из APK ua: 'Mozilla/5.0 ...', // или headerUserAgent osVersion: '14', screen: '360x780 3.0x', timezone: 'Europe/Moscow', locale: 'ru', buildNumber: 6686, // опционально clientSessionId: 1 // опционально }); ``` -------------------------------- ### WebMaxClient Configuration File Format Source: https://github.com/tellarion/webmaxsocket/blob/main/README.md Example structure for the configuration file used by WebMaxClient. This file can contain authentication tokens and device-specific settings. ```json { "token": "An_Sx6HQ9HDiftNk...", "ua": "Mozilla/5.0 (Linux; Android 14) ...", "device_type": 3, "deviceType": "ANDROID", "appVersion": "26.14.1", "buildNumber": 6686 } ``` -------------------------------- ### Token Authorization with WebMaxClient Source: https://github.com/tellarion/webmaxsocket/blob/main/README.md Instantiate and start the WebMaxClient using an existing token. The token can be provided directly or loaded from a configuration file. Token saving is enabled by default. ```javascript const client = new WebMaxClient({ name: 'my_session', token: 'An_Sx6HQ9HDiftNkVBNf6Q5PG5D8Oyj...', // Ваш токен configPath: 'config/myconfig.json', // Или из файла saveToken: true }); await client.start(); ``` -------------------------------- ### WebMaxClient Constructor Source: https://github.com/tellarion/webmaxsocket/blob/main/README.md Initializes a new WebMaxClient instance with various configuration options for session management, authentication, and logging. ```APIDOC ## WebMaxClient Constructor Initializes a new WebMaxClient instance. ### Parameters - **name** (string) - Required - The name of the session (for saving authorization). - **token** (string) - Optional - Authorization token. - **configPath** (string) - Optional - Path to the config file. - **deviceType** (string) - Optional - Device type: 'WEB' or 'ANDROID'. - **saveToken** (boolean) - Optional - Whether to save the token to the session (defaults to true). - **debug** (boolean) - Optional - TCP/WebSocket: brief opcode log; also considers WEBMAX_DEBUG=1, DEBUG=1. - **logIncoming** (boolean | 'messages' | 'verbose' | undefined) - Optional - Controls logging of incoming data. Defaults to 'messages' unless WEBMAX_DEBUG=1, then 'verbose'. Explicit 'messages' overrides WEBMAX_DEBUG. - **logIncomingVerbose** (boolean) - Optional - Explicitly enables verbose logging (same as `logIncoming: 'verbose'`). - **apiUrl** (string) - Optional - WebSocket API URL. - **maxReconnectAttempts** (number) - Optional - Maximum number of reconnection attempts. - **reconnectDelay** (number) - Optional - Delay between reconnection attempts in milliseconds. - **sessionRefreshIntervalMs** (number) - Optional - Periodic sync interval in milliseconds (minimum 10,000; 0 to disable). Alias: autoSyncIntervalMs. - **clearSessionOnFailedSync** (boolean) - Optional - If true, calls `session.clear()` before `authorize()` on sync error (defaults to false). - **appVersion** (string) - Optional - Current Android client version from APK. - **ua** (string) - Optional - User-Agent string or headerUserAgent. - **osVersion** (string) - Optional - Operating system version. - **screen** (string) - Optional - Screen resolution and density. - **timezone** (string) - Optional - Timezone of the device. - **locale** (string) - Optional - Locale setting. - **buildNumber** (number) - Optional - Build number of the application. - **clientSessionId** (number) - Optional - Client session identifier. ``` -------------------------------- ### SMS Authorization Flow Source: https://github.com/tellarion/webmaxsocket/blob/main/README.md Demonstrates the process of authorizing a user via SMS for Android devices. It involves sending a code and potentially a 2FA password. ```javascript await client.connect(); const authSession = await client.authorizeBySMS('+79001234567'); const out = await authSession.sendCode('123456'); if (out && out.needsPassword) await out.sendPassword('…'); ``` -------------------------------- ### authorizeBySMS(phone) Source: https://github.com/tellarion/webmaxsocket/blob/main/README.md Authorizes the user via SMS for ANDROID devices. It returns an object that allows sending the SMS code and potentially a 2FA password. ```APIDOC ## authorizeBySMS(phone) Authorizes by phone number via SMS (Android only). Returns an object with `tempToken`, `phone`, and `sendCode`. ### Parameters - **phone** (string) - Required - The phone number to authorize. ### Response Returns an object containing: - **tempToken** (string): A temporary token. - **phone** (string): The provided phone number. - **sendCode** (function): A function to send the SMS verification code. - **`sendCode(code)`**: - If 2FA password is not required, returns a **token string** (session saved, `sync()` performed). - If 2FA password is required, returns an object `{ needsPassword: true, passwordChallenge, trackId, sendPassword }`. Call `await sendPassword(password)`. ### Method ```javascript const authSession = await client.authorizeBySMS('+79001234567'); const out = await authSession.sendCode('123456'); if (out && out.needsPassword) await out.sendPassword('…'); ``` **Note:** The `saveTwofaPassword` constructor option (defaults to `true`) controls whether the 2FA password is saved to the session file. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.