electron-direct-ipc - v2.2.3
    Preparing search index...

    Class DirectIpcRenderer<TMessageMap, TInvokeMap, TIdentifierStrings>

    Renderer process DirectIpc client Provides type-safe direct communication between renderer processes

    Type Parameters

    • TMessageMap extends EventMap = EventMap

      Map of message channels to their handler function signatures (WITHOUT sender)

    • TInvokeMap extends InvokeMap = InvokeMap

      Map of invoke channels to their handler function signatures (WITHOUT sender)

    • TIdentifierStrings extends string = string

      Union of allowed identifier strings for type-safe identifier usage

      Note: When listening to events from TMessageMap or TInvokeMap, the listener signature will automatically include 'sender: DirectIpcTarget' as the first parameter.

    Hierarchy (View Summary)

    Index

    Properties

    Local event emitter for lifecycle events

    Throttled message sending/receiving for high-frequency updates. Use this for lossy communication where only the latest value matters.

    // High-frequency position updates (throttled)
    directIpc.throttled.sendToIdentifier('output', 'position-update', x, y)

    // Important events (not throttled)
    directIpc.sendToIdentifier('output', 'button-clicked')

    Methods

    • Get the current default timeout

      Returns number

    • Invoke a handler on a remote renderer using a TargetSelector Note: Only single-target selectors are supported (not allIdentifiers/allUrls)

      Type Parameters

      • T extends string | number | symbol

      Parameters

      Returns Promise<TInvokeMap[T] extends (...args: any[]) => R ? Awaited<R> : unknown>

      // Invoke on specific webContentsId
      const result = await directIpc.invoke({ webContentsId: 123 }, 'get-data', arg1, arg2)

      // Invoke on identifier (throws if multiple matches)
      const result = await directIpc.invoke({ identifier: 'output' }, 'get-data', arg1, arg2)

      // Invoke on URL pattern (throws if multiple matches)
      const result = await directIpc.invoke({ url: /^https://example/ }, 'get-data', arg1, arg2)

      // With timeout option
      const result = await directIpc.invoke({ identifier: 'output' }, 'get-data', arg1, { timeout: 5000 })
    • Remove a handler for a specific channel

      Type Parameters

      • T extends string | number | symbol

      Parameters

      • channel: T

      Returns void

    • Resolve a target to its webContentsId using the local map

      Parameters

      • target: {
            identifier?: RegExp | TIdentifierStrings;
            url?: string | RegExp;
            webContentsId?: number;
        }

      Returns number | undefined

      Use resolveTargetToProcessId instead

    • Send a message to target renderer(s) using a TargetSelector

      Type Parameters

      • T extends string | number | symbol

      Parameters

      Returns Promise<void>

      // Send to specific webContentsId
      await directIpc.send({ webContentsId: 123 }, 'my-message', arg1, arg2)

      // Send to single identifier (throws if multiple matches)
      await directIpc.send({ identifier: 'output' }, 'my-message', arg1, arg2)

      // Send to single URL pattern (throws if multiple matches)
      await directIpc.send({ url: /^https://example/ }, 'my-message', arg1, arg2)

      // Send to all matching identifiers
      await directIpc.send({ allIdentifiers: /^output/ }, 'my-message', arg1, arg2)

      // Send to all matching URLs
      await directIpc.send({ allUrls: 'https://example.com' }, 'my-message', arg1, arg2)
    • Set the default timeout for invoke calls

      Parameters

      • ms: number

      Returns void