Hackers News

PulseBeamDev/pulsebeam-js: WebRTC Peer-to-Peer Communication JS Client SDK

Simplifies real-time application development. Defines signaling protocol for connection establishment, handling media and data transmission, and provides infrastructure.

  • Media & Data Support: Transmit audio, video, and/or data channels within your applications.
  • Abstracted Signaling: Handles the exchange of information required to set up WebRTC connections, relieving you of low-level details.
  • Automatic Reconnection: Maintains connection stability by automatically re-establishing connections when disruptions occur.
  • Opt out of Peer-to-Peer: Can configure to force server-relayed communication.

Warning

This SDK is currently in Developer Preview. During this phase:

  • APIs are subject to breaking changes
  • Stability issues may occur
  • Core functionality is still being validated

We value your input!
Report bugs, suggest improvements, or collaborate directly with our team:

Create GitHub Issues
Join PulseBeam Developer Discord

Install and import the package using npm, deno, or yarn:

Add Package

npm i @pulsebeam/peer

Import symbol

import * as peer from "@pulsebeam/peer";

Add Package

yarn add @pulsebeam/peer

Import symbol

import * as peer from "@pulsebeam/peer";

Here’s an example demonstrating how to use @pulsebeam/peer to establish a peer-to-peer connection:

import { Peer, createPeer } from "@pulsebeam/peer";

// Obtain an authentication token (implementation specific)
const authResponse = await fetch("/auth");
const { groupId, token } = await authResponse.json();

// Create a Peer instance
const peer = await createPeer({ token });

peer.onsession = (session) => {
  session.ontrack = ({ streams }) => console.log("New media stream:", streams);
  session.ondatachannel = (event) => console.log("Data channel:", event.channel);
  session.onconnectionstatechange = () => console.log("Connection state changed");
};

// Start Alice's availability. Connect to our signaling servers
peer.start();

// Connect to bob
const abortController = new AbortController();
await peer.connect(groupId, "bob", abortController.signal);

This example retrieves an authentication token (implementation details will vary depending on your setup), creates a Peer instance, and defines event handlers for receiving media streams, data channels, and connection state changes (optional). Finally, it starts connection attempts and connects to a specific peer identified by its ID within the group.

For documentation, API keys, and usage scenarios, please refer to the official PulseBeam documentation:

This project adheres to Semantic Versioning 2.0.0.

  • MAJOR version (X.y.z): Incompatible API changes.
  • MINOR version (x.Y.z): Functionality added in a backwards compatible manner.
  • PATCH version (x.y.Z): Backwards compatible bug fixes.

For a deeper understanding of WebRTC concepts, consult the official WebRTC documentation:

admin

The realistic wildlife fine art paintings and prints of Jacquie Vaux begin with a deep appreciation of wildlife and the environment. Jacquie Vaux grew up in the Pacific Northwest, soon developed an appreciation for nature by observing the native wildlife of the area. Encouraged by her grandmother, she began painting the creatures she loves and has continued for the past four decades. Now a resident of Ft. Collins, CO she is an avid hiker, but always carries her camera, and is ready to capture a nature or wildlife image, to use as a reference for her fine art paintings.

Related Articles

Leave a Reply