> For the complete documentation index, see [llms.txt](https://neurosell.gitbook.io/parallelix/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://neurosell.gitbook.io/parallelix/api-reference/general-client.md).

# General Client

### About General Client Classes (parallelix.js)

The main script <mark style="background-color:yellow;">parallelix.js</mark> contains two classes, the main one - **Parallelix** and an additional virtual class **ParallelixWrapper**. Let's analyze why they are needed in general.

* **Parallelix** (class) - It contains basic methods and events for initialization of required platforms. Further work after platform definition is done with its instance through the unified API described in **ParallelixWrapper**, as all modules are inherited from it.
* **ParallelixWrapper** (class) - Contains virtual properties and methods that describe a single and unified API for each module and platform.

**Now that we are clear, we can start describing the methods and their parameters.**

***

### General Client API Reference (Parallelix)

To work with **Parallelix** you need to create an instance of the class of the same name. Below we will consider description of all fields and types.

#### Parallelix Class

| Field                                       | Type                                                                             | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ------------------------------------------- | -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| constructor(options)                        | Function \[[ParallelixConfig](#parallelixconfig)]                                | Basic Parallelix Constructor. Setup general configuration and handlers                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| OnError(error)                              | Callback Handler \[Error]                                                        | Fired on any initialization errors from General Class or Platfrom-specific initialization                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| OnInitialized()                             | Callback Handler                                                                 | Fired when General Class and Platform-specific class are completely initialized                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| Initialize()                                | Function                                                                         | Starts initialization of the class and all necessary classes for the required platforms, determines the current application platform and calls <mark style="background-color:yellow;">OnInitialized</mark> in case of success or <mark style="background-color:red;">OnError</mark> in case of an error                                                                                                                                                                                                                                                                                                                                                  |
| LoadLibraries(libraries, onSucces, onError) | Function \[Array, Callback, Callback]                                            | Loads the necessary libraries and plugs them into the body tag of your page, then calls <mark style="background-color:yellow;">onSuccess</mark>. Or <mark style="background-color:red;">onError</mark> is called in case of an error                                                                                                                                                                                                                                                                                                                                                                                                                     |
| LoadLibrary(library, onSuccess, onError)    | Function \[string, Callback, Callback]                                           | Load the necessary library by url and plugs them into the body tag of your page, then calls <mark style="background-color:yellow;">onSuccess</mark>. Or <mark style="background-color:red;">onError</mark> is called in case of an error                                                                                                                                                                                                                                                                                                                                                                                                                 |
| GetPlatformName()                           | Function                                                                         | Returns current loaded and detected platform name (string)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| Platform                                    | [ParallelixWrapper](#basic-virtual-class-for-platform-modules-parallelixwrapper) | Returns an instance of the currently loaded module class defined for the current platform, inherited from the virtual [ParallelixWrapper](#basic-virtual-class-for-platform-modules-parallelixwrapper)                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| Invoker                                     | object                                                                           | <p>Returns an object that contains a reference to an instance of an SDK or API class used for the internal workings of the current platform.</p><p></p><p>For <strong>example</strong>, for the <mark style="background-color:orange;">“vk”</mark> platform, an instance of the <mark style="background-color:orange;">vkBridge</mark> class will be returned (see the <a href="https://www.npmjs.com/package/@vkontakte/vk-bridge">VK Bridge documentation</a> for its API Reference).</p><p></p><p>Can be used in case of unrealized functionality in <a href="#basic-virtual-class-for-platform-modules-parallelixwrapper">ParallelixWrapper</a>.</p> |
| ConnectWrappers(onConnected)                | Internal Function \[Callback]                                                    | This function is executed inside Parallelix initialization to connect the necessary platforms from the class configuration                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| DetectPlatform()                            | Internal Function                                                                | Sorts the classes of different connected platforms by priority, after which each of them calls a method to check the current platform and sets the current platform to the Parallelix class                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

#### ParallelixConfig

| Field              | Type            | Description                                                                                                                                                                                                                                                                                   |
| ------------------ | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| baseModulesPath    | string          | Sets the base storage path of libraries to be loaded by name from the <mark style="background-color:yellow;">supportedPlatforms</mark> array                                                                                                                                                  |
| supportedPlatforms | Array \[string] | <p><strong>Example:</strong></p><p>\["vk","telegram","web"]</p><p></p><p>An array of supported platforms. It will always include the "<strong>web</strong>" platform as the default platform, so scripts must be present in <mark style="background-color:yellow;">baseModulesPath</mark></p> |
| specificLibraries  | Array \[object] | <p>Example:</p><p>\[{</p><p>    platform: "vk",</p><p>    script: "script\_url.js"</p><p> }]</p><p></p><p>Stores an array of objects indicating the need to connect certain scripts for specific platform</p>                                                                                 |
| \[dynamic objects] | object(s)       | <p><strong>For Example:</strong></p><p>vk: {</p><p>    // VK Specific Options</p><p>}</p><p></p><p>Dynamic configuration objects can also be added to the constructor object for each module. <strong>The name of the object is the same as the name of the module.</strong></p>              |

***

### Basic Virtual Class for Platform Modules (ParallelixWrapper)

Now let's consider the description of types and methods used in the **ParallelixWrapper** virtual class. **All modules you use in your project are inherited from it.**

#### **ParallelixWrapper class**

| Field                                                        | Type                                                                                              | Description                                                                                                                                                                                                        |
| ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| constructor(instance, options)                               | Function \[[Parallelix](#parallelix-class), object]                                               | A common constructor for all inherited modules. Can contain an object for customizing a specific module. **It is loaded into the** [**Parallelix**](#parallelix-class) **constructor under the module name.**      |
| Priority                                                     | Number \[int]                                                                                     | Returns Platform Detection Priority **from 0 to 1000** (do not use 1000 - it is for default "web" module)                                                                                                          |
| Invoker                                                      | object                                                                                            | Returns a platform-specific SDK or API instance                                                                                                                                                                    |
| GetLaunchParams(onSuccess, onError)                          | Function \[Callback, Callback]                                                                    | Request a launch parameters for current platform. Returns an <mark style="background-color:yellow;">object</mark> in <mark style="background-color:yellow;">onSuccess</mark> callback.                             |
| launchParams                                                 | object                                                                                            | Platform-specific launch parameters object.                                                                                                                                                                        |
| ToggleFullscreen(isEnabled)                                  | Function \[boolean]                                                                               | Toggle fullscreen for this platform                                                                                                                                                                                |
| AddToHomeScreen(onSuccess, onError)                          | Function \[Callback, Callback]                                                                    | Add your web application to device home screen on specific platform                                                                                                                                                |
| OpenPaymentForm(parameters, onSucces, onError)               | Function \[[PlatformSpecificParameters](#platformspecificparameters), Callback, Callback]         | Open platform specific native payment form with parameters <mark style="background-color:yellow;">object</mark> and fire Callbacks.                                                                                |
| AddToFavorites(parameters, onSucces, onError)                | Function \[[PlatformSpecificParameters](#platformspecificparameters), Callback, Callback]         | Add applicaiton to platform-specific favourites section                                                                                                                                                            |
| ShareApplication(parameters, onSuccess, onError)             | Function \[[PlatformSpecificParameters](#platformspecificparameters), Callback, Callback]         | Platform-specific application sharing with callbacks. <mark style="background-color:yellow;">onSuccess</mark> callback returns platform specific result data <mark style="background-color:yellow;">object</mark>. |
| PublishStory(mediaURL, parameters, onSuccess, onError)       | Function \[string, [PlatformSpecificParameters](#platformspecificparameters), Callback, Callback] | Platform-specific stories publication. <mark style="background-color:yellow;">onSuccess</mark> callback returns platform specific result data <mark style="background-color:yellow;">object</mark>.                |
| AllowNotifications(onSuccess, onError)                       | Function \[Callback, Callback]                                                                    | Platform-specific push-notification request. <mark style="background-color:yellow;">onSuccess</mark> callback returns platform specific result data <mark style="background-color:yellow;">object</mark>.          |
| ShowQRReader(parameters, onSuccess, onError)                 | Function \[[PlatformSpecificParameters](#platformspecificparameters), Callback, Callback]         | Platform-specific QR code reader request. <mark style="background-color:yellow;">onSuccess</mark> callback returns platform specific result data <mark style="background-color:yellow;">object</mark>.             |
| RequestUserEmail(onSuccess, onError)                         | Function \[Callback, Callback]                                                                    | Platform-specific user email request. <mark style="background-color:yellow;">onSuccess</mark> callback returns platform specific result data <mark style="background-color:yellow;">object</mark>.                 |
| RequestLocation(onSuccess, onError)                          | Function \[Callback, Callback]                                                                    | Platform-specific geolocation request. <mark style="background-color:yellow;">onSuccess</mark> callback returns platform specific result data <mark style="background-color:yellow;">object</mark>.                |
| RequestUserPhone(onSuccess, onError)                         | Function \[Callback, Callback]                                                                    | Platform-specific user phone number request. <mark style="background-color:yellow;">onSuccess</mark> callback returns platform specific result data <mark style="background-color:yellow;">object</mark>.          |
| GetUserInfo(parameters, onSuccess, onError)                  | Function \[[PlatformSpecificParameters](#platformspecificparameters), Callback, Callback]         | Platform-specific user information request. <mark style="background-color:yellow;">onSuccess</mark> callback returns platform specific result data <mark style="background-color:yellow;">object</mark>.           |
| RequestAuthToken(parameters, onSuccess, onError)             | Function \[[PlatformSpecificParameters](#platformspecificparameters), Callback, Callback]         | Platfrom-specific authentication token request. <mark style="background-color:yellow;">onSuccess</mark> callback returns platform specific result data <mark style="background-color:yellow;">object</mark>.       |
| GetStorage(parameters, onSuccess, onError)                   | Function \[[PlatformSpecificParameters](#platformspecificparameters), Callback, Callback]         | Platform-specific user storage key request. <mark style="background-color:yellow;">onSuccess</mark> callback returns platform specific result data <mark style="background-color:yellow;">object</mark>.           |
| SetStorage(parameters, onSuccess, onError)                   | Function \[[PlatformSpecificParameters](#platformspecificparameters), Callback, Callback]         | Platform-specific user storage set key values. <mark style="background-color:yellow;">onSuccess</mark> callback returns platform specific result data <mark style="background-color:yellow;">object</mark>.        |
| CallCustomMethod(methodName, parameters, onSuccess, onError) | Function \[string, [PlatformSpecificParameters](#platformspecificparameters), Callback, Callback] | Platform-specific request to internal method. <mark style="background-color:yellow;">onSuccess</mark> callback returns platform specific result data <mark style="background-color:yellow;">object</mark>.         |
| CallCustomMethod(methodName, onSuccess, onError)             | Function \[string, Callback, Callback]                                                            | CallCustomMethod override without parameters object.                                                                                                                                                               |
| CallAPI(methodName, parameters, onSuccess, onError)          | Function \[string, [PlatformSpecificParameters](#platformspecificparameters), Callback, Callback] | Platfrom-specific raw API request. <mark style="background-color:yellow;">onSuccess</mark> callback returns platform specific result data <mark style="background-color:yellow;">object</mark>.                    |
| OpenLink(url)                                                | Function \[string]                                                                                | Platform-specific open external link. <mark style="background-color:yellow;">onSuccess</mark> callback returns platform specific result data <mark style="background-color:yellow;">object</mark>.                 |
| CloseApplication(onSuccess, onError)                         | Function \[Callback, Callback]                                                                    | Platform-specific application close.                                                                                                                                                                               |
| GoBack()                                                     | Function                                                                                          | Plafrom-specific emulation of GoBack button.                                                                                                                                                                       |
| AddEventListener(eventName, eventHandler)                    | Function \[string, Callback]                                                                      | Add platform-specific listener for events fired by platform                                                                                                                                                        |
| RemoveEventListener(eventName, eventHandler)                 | Function \[string, Callback]                                                                      | Remove platform specific event listener                                                                                                                                                                            |
| GetEventListener(eventName)                                  | Function \[Callback]                                                                              | Returns Callback for event listener by name                                                                                                                                                                        |
| Initialize()                                                 | Internal Function                                                                                 | Initialize Current Platfrom. Called from [Parallelix ](#parallelix-class)class.                                                                                                                                    |
| IsCurrentPlatform()                                          | Internal Function                                                                                 | Check the current platfrom. Returns boolean. Called from [Parallelix](#parallelix-class) class.                                                                                                                    |

#### PlatformSpecificParameters

When forming a parameter object to call certain methods in inherited classes from ParallelixWrapper, you must pass parameters for each platform you need with a key name corresponding to your platform.&#x20;

**For example:**

```javascript
client.Platform.PublishStory("mediaURL", { 
    vk: {
        // Options from VK Bridge Documentation
    }, telegram: {
        // Options from Telegram SDK for Mini Apps Documentation
    }
}, (data)=> {
    console.log(data);
}, (error)=> {
    console.error(error.message);
})
```

**So, now having learned the common API for all platforms, you can learn the specific method overrides for each platform**

***

### Platform-Specific References

Now that you have learned the basics, you can see the specific **API description** for each currently available Parallelix platform:

* [VK Bridge / Mini-Apps](/parallelix/api-reference/vk-bridge-mini-apps.md);
* [Telegram Mini Apps](/parallelix/api-reference/telegram-mini-apps.md);
* [Basic Web Applications / PWA](/parallelix/api-reference/pwa-and-web-applications.md) (Default Provider);
* [WeChat Mini Apps](/parallelix/api-reference/wechat.md) (Coming Soon);
* [Android, iOS powered by Cordova](/parallelix/android-and-ios-apache-cordova.md) (Coming Soon);
* [Windows, Linux, Mac powered by Electron](/parallelix/windows-mac-linux-electron.md) (Coming Soon);
* [VK Direct Games](/parallelix/api-reference/direct-games.md) (Coming Soon);
* [Yandex Games](/parallelix/api-reference/yandex-games.md) (Coming Soon);

Or [create your own platform module](/parallelix/get-started/develop-your-modules.md).
