Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SafariClient

Handles communication with the Safari extension using JSON-RPC over custom events.

Hierarchy

  • SafariClient

Implements

Index

Constructors

constructor

Properties

Private isFirstPing

isFirstPing: boolean = true

Private keepAliveInterval

keepAliveInterval: number = 1000

Private lastPing

lastPing: number | null = null

Private lastPong

lastPong: number | null = null

Private promiseExecutors

promiseExecutors: Map<string, PromiseExecutor>

Private safariExtensionEnabled

safariExtensionEnabled: boolean = false

Private statusInterval

statusInterval: number = 100

Private subscribedTransferActivity

subscribedTransferActivity: boolean = false

Methods

Private buildRPCRequest

  • Builds a JSON-RPC request object with a unique identifier.

    Parameters

    • method: string

      The method name to invoke on the extension.

    • Optional payload: unknown

      Optional parameters for the method.

    Returns JSONRPCRequest

    The constructed JSON-RPC request object.

Private checkSafariExtensionStatus

  • checkSafariExtensionStatus(): void

Private dispatchEvent

Private dispatchPromiseEvent

  • Dispatches a custom event to the document to communicate with the Safari extension.

    Parameters

    • type: SafariExtensionEventType

      The type of Safari extension event to dispatch.

    • method: string

      The method name to invoke on the extension.

    • Optional payload: unknown

      Optional parameters for the method.

    Returns Promise<any>

Private handleResponse

  • Handles incoming JSON-RPC responses from the Safari extension. Resolves or rejects promises based on the response.

    Parameters

    • response: JSONRPCResponse

      The JSON-RPC response object received from the extension.

    Returns void

Private keepAlive

  • keepAlive(): void

Private listenPongEvents

  • listenPongEvents(): void

Private listenResponseEvents

  • listenResponseEvents(): void

Private listenStatusEvents

  • listenStatusEvents(): void

Private listenTransferActivityEvents

  • listenTransferActivityEvents(): void

monitorTransferActivity

  • monitorTransferActivity(): Promise<unknown>

request

  • request(method: string, payload?: any): Promise<any>
  • Sends a JSON-RPC request to the Safari extension.

    Parameters

    • method: string

      The method name to invoke on the extension.

    • Default value payload: any = {}

      Optional payload for the request.

    Returns Promise<any>

    A Promise that resolves with the response from the extension.

Private safariExtensionStatusChanged

  • safariExtensionStatusChanged(isEnabled: boolean): void
  • Listens for Safari extension status changes. If the extension was disabled and enabled again after initializing the SDK, it will call 'monitorTransferActivity' to resume transfer activities.

    Parameters

    • isEnabled: boolean

    Returns void