Acrobits IPC SDK
    Preparing search index...

    Class IPCManager

    A class that manages the IPC communication between the Client and the Host.

    Ideally, there should only be one instance of the IPCManager in the app. It is recommended to create the instance as a singleton and use it throughout the app.

    Index

    Constructors

    • A class that manages the IPC communication between the Client and the Host.

      Parameters

      • Optionallogger: ILogger

        An optional logger instance to use for logging. If not provided, a default logger will be used.

      Returns IPCManager

      Ideally, there should only be one instance of the IPCManager in the app. It is recommended to create the instance as a singleton and use it throughout the app.

    Properties

    cloudId?: string

    The cloud ID of the Host app the Client is embedded in.

    cloudUsername?: string

    The cloud username of the logged in user.

    displayName?: string

    The display name of the logged in user.

    host?: HostType

    The type of the Host app the Client is embedded in.

    networkId?: string

    The network ID of the logged in user, from the HELLO reply. Required from protocol 2.2; may be missing on older hosts.

    Accessors

    • get context(): undefined | "host" | "standalone"

      Returns whether the app is running inside a native WebView (host context) or as a standalone app.

      Returns undefined | "host" | "standalone"

    • get isConnected(): boolean

      Determines if the app is connected to a Host app.

      Returns boolean

    Methods

    • Sends the current badge count to the Host app.

      Parameters

      • count: number

        The count to update the badge to.

      • isActivity: boolean = false

        Optional. Whether the update is for an activity instead of a badge.

      Returns void

    • Determines if the app is embedded in a Host app or native CSP clients.

      Returns Promise<undefined | "host" | "standalone">

      A promise with IPCContext the app is running under.

    • Requests one page of contacts from a contact source.

      Parameters

      Returns Promise<ContactsPage>

      A promise with the ContactsPage.

      Page with offset and limit until totalCount is reached or a page comes back shorter than limit. resultTypes keeps contacts that have at least one of the given kinds; for example ['Uri', 'CloudUsername'] leaves out contacts with only an email address.

      Each entry carries the Host's matchesNumberPattern result unchanged. It reflects the app's number pattern, not whether a number may be dialed; apply your own Call and Message rules.

      This method requires protocol version 2.4 or higher.

      const page = await manager.getContacts(
      { sourceId: sources[0].sourceId, offset: 0, limit: 500, resultTypes: ['Uri', 'CloudUsername'] },
      { timeoutMs: 5000 }
      );

      UnsupportedVersionError if the negotiated version is below 2.4.

    • Requests the Host app's usable contact sources (address books and accounts).

      Parameters

      Returns Promise<ContactSourceInfo[]>

      A promise with the contact sources.

      The Host lists the sources in its own order with localized titles. When the set changes, it sends the contact-sources-changed LIFECYCLE event with the new list; contact changes in a source arrive as contacts-updated. Both reach IPCManager.onLifecycleEvent.

      This method requires protocol version 2.4 or higher.

      const controller = new AbortController();
      const sources = await manager.getContactSources({ signal: controller.signal, timeoutMs: 5000 });

      UnsupportedVersionError if the negotiated version is below 2.4.

    • Returns the Host app's preferred locales, most specific first, for example ['cs-CZ', 'cs'].

      Parameters

      Returns Promise<string[]>

      A promise with the locales in RFC 5646 format.

      The Host sends them in the CONFIG message once, right after the handshake; the manager keeps that message, so this can be called any time after IPCManager.initiateConnection. If CONFIG has not arrived yet, the promise waits for it; pass timeoutMs to bound the wait. Resolves with an empty array when the Host sends no locales.

      const locales = await manager.getLocales({ timeoutMs: 2000 });
      
    • Initiates the IPC handshake with the Host app.

      Returns Promise<void>

    • Registers a callback to be invoked when a IPCEvents.CallInfo event is received.

      Parameters

      Returns UnsubscribeCallback

      An unsubscribe callback to remove the listener.

      The Host app sends CALL INFO updates when call state changes occur. This includes new calls, call state transitions, and call terminations.

      Note: This event is only available on protocol version 2.2 or higher. On lower versions, the callback will never be invoked.

    • Registers a callback for the contacts-updated LIFECYCLE event: contacts in a source changed, so pages read from it are stale.

      Parameters

      Returns UnsubscribeCallback

      An unsubscribe callback to remove the listener.

      This method requires protocol version 2.4 or higher.

      UnsupportedVersionError if the negotiated version is below 2.4.

    • Registers a callback to be invoked when a IPCEvents.Lifecycle event is received.

      Parameters

      • callback: (event: string, payload: Record<string, unknown>) => void

        A callback function to be invoked when a IPCEvents.Lifecycle event is received.

      Returns UnsubscribeCallback

      An unsubscribe callback to remove the listener.

      The eventName and payload are defined by the Host app and can vary for each LIFECYCLE event. The payload can be an empty object for events without any additional data.

    • Registers a callback to be invoked when a IPCEvents.PushToken event is received.

      Parameters

      • callback: (token: string, appId: string, selector: string) => void

        A callback function to be invoked when a IPCEvents.PushToken event is received.

      Returns UnsubscribeCallback

      An unsubscribe callback to remove the listener.

      The token, appId, selector and expiry are defined by the Host app and can vary for each Push Token event.

    • Registers a callback to be invoked when a IPCEvents.PushToken event is received.

      Parameters

      • callback: (
            payload: {
                appId: string;
                installationId?: string;
                isRegistered?: boolean;
                pushToken: string;
                selector: string;
            },
        ) => void

        A callback function to be invoked when a IPCEvents.PushToken event is received. Receives a payload object with all push token fields.

      • options: { asPayload: true }

        Options for the callback registration. Set asPayload to true to receive a payload object instead of positional parameters.

      Returns UnsubscribeCallback

      An unsubscribe callback to remove the listener.

      When asPayload is true, the callback receives a single payload object with all fields including isRegistered and installationId.

    • Registers the provider used when the Host requests logs as an IPC file transfer.

      Parameters

      Returns UnsubscribeCallback

      An unsubscribe callback that removes the provider and staged file.

      New Hosts should use the semantic logs FILE REQUEST intent. For compatibility with deployed protocol-2.3 Hosts, the SDK also serves general requests whose file ID and hash match the staged logs file. Unmatched general requests remain available to other file responders.

    • Registers a callback to be invoked when a IPCEvents.RequestLogs event is received.

      Parameters

      • callback: (skipCompression?: boolean) => void

        A callback function to be invoked when a IPCEvents.RequestLogs event is received. The callback receives an optional skipCompression parameter.

      Returns () => undefined | boolean

      An unsubscribe callback to remove the listener.

      The Host app can request logs from the Client app by sending a RequestLogs event. The callback will receive a skipCompression parameter indicating whether the logs should be compressed or not.

      When skipCompression is true, the logs should be sent uncompressed. When false or undefined, the logs should be compressed before sending.

    • Registers a callback to be invoked when the Host app's translations change.

      Parameters

      • callback: () => void

        A callback function to be invoked when the translations change.

      Returns UnsubscribeCallback

      An unsubscribe callback to remove the listener.

      The Host sends the translations-changed LIFECYCLE event with an empty payload. Request the displayed strings again with IPCManager.translate and redraw them. Callbacks registered with IPCManager.onLifecycleEvent also receive this event.

      This method requires protocol version 2.5 or higher.

      UnsupportedVersionError if the negotiated version is below 2.5.

    • Requests the Host app to open the given URL in an external browser.

      Type Parameters

      • TData

      Parameters

      • url: string

        URL to open in the external browser

      • Optionaldata: TData

        Optional. Any additional data to be sent along with the URL

      Returns void

      Any additional data to be posted alongside the URL is included with the data parameter.

      // import the IPCManager
      import { IPCManager } from '@acrobits/ipc-sdk';

      // create an instance of IPCManager
      const manager = new IPCManager();

      // open the URL with additional data
      const url = 'https://example.com';
      const data = {
      name: 'John Doe',
      age: 30
      };

      manager.openUrl(url, data);
    • Requests the Host app to reset the app and log out the user.

      Returns void

      For added security, the Host can confirm the user's intention to reset the app by displaying a confirmation dialog. The user can decide to cancel the reset operation.

    • Requests the current call information from the Host app.

      Returns Promise<CallInfoItem[]>

      A promise with an array of CallInfoItem objects representing the current calls.

      This method requires protocol version 2.2 or higher. If the negotiated version is lower, an UnsupportedVersionError will be thrown.

      UnsupportedVersionError if the negotiated version is below 2.2.

    • Requests the Host app to provide the Push Token for the current device.

      Returns Promise<string>

      A promise with the Push Token as string.

    • Requests the Host app to provide the Push Token for the current device.

      Parameters

      • options: { extended: true }

        Options for the request. Set extended to true to return the full payload object instead of just the token.

      Returns Promise<
          {
              appId: string;
              installationId?: string;
              isRegistered?: boolean;
              pushToken: string;
              selector: string;
          },
      >

      A promise with the full Push Token payload object.

    • Requests the Host app to open the contact selection UI.

      Parameters

      • corelationId: number

        An identifier for the message stream

      • options: SelectContactsOptions

        Configuration options for contact selection:

        • mode: Whether to allow 'single' or 'multi' contact selection
        • currentContacts: For multi-select mode, the list of currently selected contacts
        • contactType: The type of contacts to select ('cloudUsername' or 'uri'). Defaults to 'cloudUsername'
        • includeOffNetworkContacts: Whether to include contacts not on the network. Defaults to false

      Returns Promise<ContactItem[]>

      A collection of ContactItem objects which the user selected

      This overload requires protocol version 2.1 or higher. If the negotiated version is 2.0, an UnsupportedVersionError will be thrown.

      UnsupportedVersionError if the negotiated version is 2.0.

    • Requests the Host app to open the contact selection UI.

      Parameters

      • corelationId: number

        An identifier for the message stream

      • Optionalmode: "single"

        Optional. Whether to allow single or multi contact selection.

      • OptionalcontactType: ContactType

        Optional. The type of contacts to be selected. This can be either cloudUsername or uri. Defaults to cloudUsername.

      Returns Promise<ContactItem[]>

      A collection of ContactItem objects which the user selected along with the corelationId.

      Use the selectContacts method with the options parameter instead.

      When requesting a single contact, the Host app will return immediately after contact selection.

    • Requests the Host app to open the contact selection UI.

      Parameters

      • corelationId: number

        An identifier for the message stream

      • mode: "multi"

        Whether to allow single or multi contact selection.

      • currentContacts: ContactItem[]

        A list of ContactItem objects that are currently selected. This is used to highlight the current contacts from the selection UI.

      • OptionalcontactType: ContactType

        Optional. The type of contacts to be selected. This can be either cloudUsername or uri. Defaults to cloudUsername.

      Returns Promise<ContactItem[]>

      A collection of ContactItem objects which the user selected along with the corelationId.

      Use the selectContacts method with the options parameter instead.

      When requesting a multi contact, the user will have to manually close the contact selection UI. The Host app will return the selected contacts when the user closes the UI.

      When requesting a multi contact, the currentContacts parameter is required. This will be used to highlight the contacts that are already selected.

    • Subscribes to provisioning request updates from the Host app.

      Parameters

      Returns UnsubscribeCallback

      An unsubscribe callback to remove the local listener.

      The Host app replies with the first valid provisioning request payload and sends later changes as updates. The IPC protocol does not provide an unsubscribe message, so the returned callback only removes the local listener.

      The receive-side listener is established before the subscribe request is sent, so the Host's first reply is delivered to the callback even if this is called before IPCManager.initiateConnection has wired up the listener. Note, however, that the subscribe request itself can only reach the Host once the IPC bridge is open.

      This method requires protocol version 2.3 or higher.

      The Host app only tracks a single active provisioning request subscription and replaces it when a new subscribe request is received. To mirror that on the Client and avoid accumulating stale listeners, each call replaces any previously registered callback. Apps should register one callback and fan out the payload locally if multiple consumers need it.

      UnsupportedVersionError if the negotiated version is below 2.3.

    • Asks the Host app to refresh a contact source from its server.

      Parameters

      • sourceId: string

        The source to refresh.

      Returns void

      The Host does not reply. It reports progress with IPCManager.onContactSourceSyncState and, when data changed, IPCManager.onContactsUpdated.

      This method requires protocol version 2.4 or higher.

      UnsupportedVersionError if the negotiated version is below 2.4.

    • Translates a string using the Host translation framework.

      Parameters

      Returns Promise<null | string>

      A promise with the translated string, or null when the Host cannot resolve the request.

      Concurrent requests are supported; each promise resolves with the reply to its own request.

      Translations can change while the app is running. Register IPCManager.onTranslationsChanged and translate the displayed strings again when it is invoked.

      This method requires protocol version 2.5 or higher.

      const label = await manager.translate({ key: 'call_count', count: 2, args: [2] });
      

      UnsupportedVersionError if the negotiated version is below 2.5.