Initializing the core module

The Jabra library uses a modular architecture, consisting of a core module and two modules offering call control capabilities. The core module handles low-level communication with Jabra devices, while the Easy Call Control and Call Control modules provide call control for your application.

Due to a direct dependency between the modules and the core module, you must first initialize the core module before creating instances of any of the call control modules.

You can read Module Import Strategies in the appendix for all available approaches to initialize the core module.

Initializing the core module for web applications

The standard approach to initialize the core module is using a module bundler, such as webpack or rollup.

A module bundler resolves module paths automatically, enabling you to import the packages via the node_modules identifier, as follows:

import { init } from '@gnaudio/jabra-js';

const jabraCore = await init()

// Library initialized...

Initializing the core module for desktop applications

When using Node, the CommonJS (require) syntax is the standard approach to initialize the core module. For the ECMAScript import syntax, see Module Import Strategies in the appendix.

Using CommonJS, as shown in the following code snippet, pointing to the folder is sufficient:

const jabra = require('@gnaudio/jabra-js/node-cjs');

const jabraCore = await jabra.init();

// Library initialized...

Configuring the core module

This section elaborates on configuring the core module by passing an instance of the IConfig interface when initializing the Jabra library.

To help you with the configuration, each sub-section contains code snippets showing configuration options.

For example, you can provide an identifier and a name for your application, integrate with a Partner Key to register your application, and set a transport method.

Identifying and registering your application

To uniquely identify your application and display them properly to end users, you must configure the partnerKey, appId, and appName configuration fields.

The Partner Key, App ID and App Name fields let you register your application with Jabra Direct, empowering the end-user to choose your application as their preferred softphone. In turn, the Jabra library uses it to filter out messages not intended for your application.

Naming your application

The appName is an end-user friendly name for your application. Your app name consists of a string with a minimum of three characters. It may contain a combination of letters (A-Z, a-z), numbers (123), hyphens (-), whitespaces ( ), or ampersands (&). The name is restricted to 100 characters (100 bytes in UTF-8) and must begin with a letter or number.

On the other hand, an app identifier or appId consists of a string between three and 100 characters (maximum of 100 bytes in UTF-8). It may contain a combination of letters (A-Z, a-z), numbers (123), underscores (_), or hyphens (-).

See the following code snippet.

const config = {
  // Obtain your Partner Key from developer.jabra.com
  partnerKey: '0123-456789ab-cdef-0123-4567-89abcdef0123',
  appId: 'my-app',
  appName: 'My App',
};

Generating a Partner Key

As best practice, it is suggested that you initialize the core module with a Partner Key.

You can generate this key on the Partner Key page of developer.jabra.com.

Setting the transport method

When integrating the Jabra JavaScript library into a web application, it's important to set the correct transport method. The WebHID option is incompatible with Node applications and causes an exception to be thrown if used in a Node environment.

Therefore, for your web application you must choose one of the following three transport methods:

  • CHROME_EXTENSION_WITH_WEB_HID_FALLBACK
  • WEB_HID
  • CHROME_EXTENSION

Be aware that choosing the CHROME_EXTENSION_WITH_WEB_HID_FALLBACK method can increase the complexity of your integration, since the transport method will only be known at runtime. For example, you only have to show the consent button when the transport method is WebHID.

To set the transport method, see the following code sample.

const config = {
  transport: RequestedBrowserTransport.CHROME_EXTENSION
};

Setting the library logging

To receive a logging message from the library in your application, the logger field must be set during initialization of the Jabra core module, as illustrated in the following code sample.

const config = {
  logger: {
    write(logEvent) {
      if (logEvent.level === 'error') {
        console.log(logEvent.message, logEvent.layer);
      }
      // Ignore messages with other log levels
    }
  }
};

Configuring and initializing the core module

To configure and initialize the core module with all IConfig properties, see the following code sample.

import { init } from '@gnaudio/jabra-js';

const config = {
  // Obtain your Partner Key from developer.jabra.com
  partnerKey: '0123-456789ab-cdef-0123-4567-89abcdef0123',
  appId: 'my-app',
  appName: 'My App',
  transport: RequestedBrowserTransport.CHROME_EXTENSION,
  logger: {
    write(logEvent) {
      if (logEvent.level === 'error') {
        console.log(logEvent.message, logEvent.layer);
      }
      // Ignore messages with other log levels
    }
  }
};

const jabraCore = await init(config);

Error handling

To provide more details about the type of error that occurred, a custom JabraError class is used.

The following code sample shows how you can inform the end-user if they try to use a functionality not available on their device:

import { JabraError, ErrorType } from '@gnaudio/jabra-js';

// Assuming creation of call control instance

try {
  await callControl.takeCallLock(); // This will throw if another application has already locked the device
} catch (err) {
  let messageToUser = "An unknown error happened";

  if (err instanceof JabraError) {
    if (err.type === ErrorType.SDK_USAGE_ERROR) {
      messageToUser = "The device is used by another application";
    }
  }

  alert(messageToUser);
}