Browser Client

Overview

This guide will show you how to initialize the @interopio/browser library in a simple JavaScript app.

Referencing

The @interopio/browser library is available as a package from NPM and UNPKG.

  • From NPM:

Install the @interopio/browser package in the root directory of your project:

npm install @interopio/browser

Reference the library as a script in your web app:

<script src="./node_modules/@interopio/browser/dist/browser.umd.js">

You can also import it as a module:

import IOBrowser from "@interopio/browser";
  • From UNPKG:

Reference the library as a script in your web app:

<script src="https://unpkg.com/@interopio/browser@latest/dist/browser.umd.js"></script>

The @interopio/browser library will attach an IOBrowser() factory function to the window object.

Initialization

Initialize the @interopio/browser library by invoking the exposed IOBrowser() factory function. It accepts an optional Config object in which you can specify settings regarding the io.Connect APIs.

The following example demonstrates initializing the @interopio/browser library with the default settings:

import IOBrowser from "@interopio/browser";

// Use the object returned from the factory function
// to access the io.Connect APIs.
const io = await IOBrowser();

Initializing the @interopio/browser library with custom settings:

import IOBrowser from "@interopio/browser";
import IOWorkspaces from "@interopio/workspaces-api";

const initializeIOConnect = async () => {

    // Initializing the Workspaces library.
    const initOptions = {
        libraries: [IOWorkspaces]
    };

    // Use the object returned from the factory function
    // to access the io.Connect APIs.
    const io = await IOBrowser(initOptions);

    // Here the io.Connect library is initialized and you can access all io.Connect APIs.
};

initializeIOConnect().catch(console.error);