Description
BIDC is a JavaScript library for bidirectional channels, which let code in one context talk to code in another, such as a page and an iframe, a web worker, or a service worker. Unlike a plain postMessage call, it provides asynchronous request and response communication, with Promises and async functions kept as first-class values during the transfer through a custom streaming protocol. It establishes the channel automatically whichever side starts first, handles collisions during the handshake, and re-establishes the connection if one side reloads, such as an iframe. Messages sent before the other side is ready are buffered and delivered once it is. Complex data types can be sent, including Dates, RegExp values, Maps, Sets, ArrayBuffers, typed arrays and nested Promises. Multiple messages can be in flight at the same time, and both sides can call each other through send and receive methods. The library supports TypeScript, with types inferred for RPC-style method calls. The README includes examples for basic transfer, two-way communication, complex data types, nested promises, remote callbacks, worker communication and namespaced channels. It is aimed at developers building apps that split work across frames, workers or extensions and need a typed way to call across the boundary.…
Highlights
- Asynchronous communication across iframes, workers and service workers
- Automatic handshake with collision handling
- Buffers messages until the other side is ready
- Sends Dates, Maps, Sets, ArrayBuffers and Promises
- TypeScript types for RPC-style calls
Ratings & Reviews
No ratings yet
Be the first to rate Bidc.
People also visit
Node Datachannel
WebRTC For Node.js and Electron (including WebSocket Client & Server)
Bidc FAQ
What is BIDC?
A bidirectional channel library for asynchronous communication between JavaScript contexts such as workers, iframes and service workers.
How is it different from postMessage?
It handles the connection, reconnects after a reload, buffers messages until the other side is ready, and supports Promises and complex data types.
What data types can it send?
Strings, numbers, booleans, bigints, null, undefined, Dates, RegExp, ArrayBuffers, typed arrays, Maps, Sets, objects and arrays, plus Promises and async functions.
Which side needs to start first?
Neither. The README says the channel is established no matter which side initiates.
Does it work with TypeScript?
Yes. Types are inferred for the RPC-style method calls.
Is it open source?
Yes. The source is on GitHub under the vercel organization.
What are the best Bidc alternatives?
Popular alternatives to Bidc include Broadcast Channel, Xmpp.js and Webapp. See all Bidc alternatives