@pulsebeam/peer 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +78 -0
- package/package.json +70 -0
package/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# @pulsebeam/peer: WebRTC Peer-to-Peer Communication SDK
|
2
|
+
|
3
|
+
Simplifies real-time application development. Defines signaling protocol for connection establishment, handling media and data transmission, and provides infrastructure.
|
4
|
+
|
5
|
+
### Features
|
6
|
+
|
7
|
+
- Media & Data Support: Transmit audio, video, and/or data channels within your applications.
|
8
|
+
- Abstracted Signaling: Handles the exchange of information required to set up WebRTC connections, relieving you of low-level details.
|
9
|
+
- Automatic Reconnection: Maintains connection stability by automatically re-establishing connections when disruptions occur.
|
10
|
+
- Opt out of Peer-to-Peer: Can configure to force server-relayed communication.
|
11
|
+
|
12
|
+
# Installation
|
13
|
+
|
14
|
+
Install and import the package using npm, deno, or yarn:
|
15
|
+
|
16
|
+
### Use with npm
|
17
|
+
|
18
|
+
Add Package
|
19
|
+
|
20
|
+
`npx jsr add @pulsebeam/peer`
|
21
|
+
|
22
|
+
Import symbol
|
23
|
+
|
24
|
+
`import * as peer from "@pulsebeam/peer";`
|
25
|
+
|
26
|
+
### Use with Yarn
|
27
|
+
|
28
|
+
Add Package
|
29
|
+
|
30
|
+
`yarn dlx jsr add @pulsebeam/peer`
|
31
|
+
|
32
|
+
Import symbol
|
33
|
+
|
34
|
+
`import * as peer from "@pulsebeam/peer";`
|
35
|
+
|
36
|
+
|
37
|
+
# Usage
|
38
|
+
|
39
|
+
Here's an example demonstrating how to use @pulsebeam/peer to establish a peer-to-peer connection:
|
40
|
+
|
41
|
+
```ts
|
42
|
+
import { Peer, createPeer } from "@pulsebeam/peer";
|
43
|
+
|
44
|
+
// Obtain an authentication token (implementation specific)
|
45
|
+
const authResponse = await fetch("/auth");
|
46
|
+
const { groupId, peerId, token } = await authResponse.json();
|
47
|
+
|
48
|
+
// Create a Peer instance
|
49
|
+
const peer = await createPeer({ groupId, peerId, token });
|
50
|
+
|
51
|
+
// Define handlers for incoming events (optional)
|
52
|
+
peer.onsession = (session) => {
|
53
|
+
session.ontrack = ({ streams }) => console.log("New media stream:", streams);
|
54
|
+
session.ondatachannel = (event) => console.log("Data channel:", event.channel);
|
55
|
+
session.onconnectionstatechange = () => console.log("Connection state changed");
|
56
|
+
};
|
57
|
+
|
58
|
+
// Start Alice's availability. Connect to our signaling servers
|
59
|
+
peer.start();
|
60
|
+
|
61
|
+
// Connect to bob
|
62
|
+
const abortController = new AbortController();
|
63
|
+
await peer.connect(groupId, "bob", abortController.signal);
|
64
|
+
```
|
65
|
+
|
66
|
+
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.
|
67
|
+
|
68
|
+
# Documentation
|
69
|
+
|
70
|
+
For documentation, API keys, and usage scenarios, please refer to the official PulseBeam documentation:
|
71
|
+
|
72
|
+
* https://pulsebeam.dev/docs/getting-started/
|
73
|
+
|
74
|
+
# WebRTC Resources
|
75
|
+
|
76
|
+
For a deeper understanding of WebRTC concepts, consult the official WebRTC documentation:
|
77
|
+
|
78
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API
|
package/package.json
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
{
|
2
|
+
"name": "@pulsebeam/peer",
|
3
|
+
"version": "0.0.11",
|
4
|
+
"type": "module",
|
5
|
+
"main": "./dist/index.cjs",
|
6
|
+
"module": "dist/index.mjs",
|
7
|
+
"types": "dist/index.d.mts",
|
8
|
+
"exports": {
|
9
|
+
"import": {
|
10
|
+
"types": "./dist/index.d.ts",
|
11
|
+
"import": "./dist/index.js"
|
12
|
+
},
|
13
|
+
"require": {
|
14
|
+
"types": "./dist/index.d.cts",
|
15
|
+
"require": "./dist/index.cjs"
|
16
|
+
}
|
17
|
+
},
|
18
|
+
"scripts": {
|
19
|
+
"gen": "protoc --ts_out=. --experimental_allow_proto3_optional --ts_opt=client_generic --proto_path proto/v1 ./proto/v1/tunnel.proto && node ./scripts/patch.cjs",
|
20
|
+
"build": "tsup",
|
21
|
+
"build:watch": "tsup --watch",
|
22
|
+
"clean": "rm -rf dist",
|
23
|
+
"test": "vitest",
|
24
|
+
"publish": "jsr publish --allow-slow-types"
|
25
|
+
},
|
26
|
+
"files": [
|
27
|
+
"dist"
|
28
|
+
],
|
29
|
+
"keywords": [
|
30
|
+
"typescript",
|
31
|
+
"library",
|
32
|
+
"browser"
|
33
|
+
],
|
34
|
+
"author": "Lukas Herman support@pulsebeam.dev",
|
35
|
+
"repository": {
|
36
|
+
"type": "git",
|
37
|
+
"url": "https://github.com/PulseBeamDev/pulsebeam-js.git"
|
38
|
+
},
|
39
|
+
"homepage": "https://pulsebeam.dev",
|
40
|
+
"license": "Apache-2.0",
|
41
|
+
"dependencies": {
|
42
|
+
"@protobuf-ts/runtime": "^2.9.4",
|
43
|
+
"@protobuf-ts/runtime-rpc": "^2.9.4",
|
44
|
+
"@protobuf-ts/twirp-transport": "^2.9.4",
|
45
|
+
"jwt-decode": "^4.0.0"
|
46
|
+
},
|
47
|
+
"devDependencies": {
|
48
|
+
"@protobuf-ts/plugin": "^2.9.4",
|
49
|
+
"jsr": "^0.13.2",
|
50
|
+
"protoc-gen-ts": "^0.8.7",
|
51
|
+
"tsup": "^8.3.5",
|
52
|
+
"typescript": "^5.6.3",
|
53
|
+
"vitest": "^2.1.5",
|
54
|
+
"webrtc-adapter": "^9.0.1"
|
55
|
+
},
|
56
|
+
"tsup": {
|
57
|
+
"entry": [
|
58
|
+
"index.ts"
|
59
|
+
],
|
60
|
+
"format": [
|
61
|
+
"esm",
|
62
|
+
"cjs"
|
63
|
+
],
|
64
|
+
"dts": true,
|
65
|
+
"minify": true,
|
66
|
+
"sourcemap": true,
|
67
|
+
"target": "esnext",
|
68
|
+
"outDir": "dist"
|
69
|
+
}
|
70
|
+
}
|