BIDC is a JavaScript library designed for establishing robust, asynchronous, bidirectional communication channels between different JavaScript execution contexts, such as web workers, iframes, and service workers. Unlike traditional `postMessage` APIs, BIDC abstracts away the complexities of message passing, providing full support for promises, async functions, and a wide range of complex data types (e.g., Date, RegExp, Map, Set, ArrayBuffer). It features an automatic handshake mechanism to establish and re-establish connections seamlessly, even if one side reloads, and buffers messages until the recipient is ready. Currently at version 0.0.4, the library is in an early development stage, focusing on foundational features for secure and efficient cross-context communication. Its primary differentiators are automatic connection management, comprehensive data type serialization, and first-class async/await support, streamlining RPC-style interactions. It ships with TypeScript types, enhancing developer experience and type safety.
npm install bidcVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic one-way data transfer and response handling between a parent window and an iframe using `createChannel`, showing both sending and receiving sides.
Monitor releases and review changelogs for new minor versions before upgrading in production environments. Pin exact versions for critical applications.
Always explicitly provide a target (e.g., `iframe.contentWindow`, `worker`, `otherWindow`) to `createChannel(target)` unless you specifically intend to connect to `window.parent`.
For every message you intend to send, ensure there's a corresponding `receive` handler on the other side of the channel to process it and, if desired, return a response.
Use ESM import syntax: `import { createChannel } from 'bidc'`. Ensure your project's `package.json` specifies `"type": "module"` or your build system correctly handles ESM.Ensure that the data being sent directly as a payload consists of clonable JavaScript primitives or objects that BIDC explicitly supports for serialization. For DOM elements or functions, consider an RPC pattern where the function is executed remotely or only send serializable identifiers.
No dependency data recorded yet.