https://github.com/longern/flarepeer
https://github.com/longern/flarepeer
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/longern/flarepeer
- Owner: longern
- Created: 2024-07-22T05:26:04.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-22T12:48:46.000Z (almost 2 years ago)
- Last Synced: 2025-01-28T00:28:25.779Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://longern.github.io/FlarePeer/
- Size: 39.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FlarePeer
Free serverless signalling for WebRTC using Cloudflare Workers and D1.
## Usage & Example
### Protocol
Use [JSON-RPC 2.0](https://www.jsonrpc.org/specification) over WebSocket.
Example request:
```json
{
"jsonrpc": "2.0",
"method": "open",
"params": { "key": "PEER_API_KEY" },
"id": 1
}
```
Example response:
```json
{
"jsonrpc": "2.0",
"result": { "id": "xxxx-xxxx", "token": "TOKEN" },
"id": 1
}
```
### Methods
```typescript
interface FlarePeerClient {
open(params?: { key?: string }): Promise<{ id: string; token: string }>;
reconnect(params: { id: string; token: string }): Promise;
destroy(): Promise;
send(params: {
type: "offer" | "answer" | "ice-candidate";
id: string;
content: string;
}): Promise;
poll(): Promise<
Array<{
type: "offer" | "answer" | "ice-candidate";
source: string;
content: string;
}>
>;
}
```
See `example/main.js` for a complete example.
### Demo server
A demo server is available at `wss://peer.longern.com`.
However, it is recommended to host your own server to ensure privacy and reliability.
### Host your own server
Create a new D1 database and run SQL queries in `src/db.sql`.
Create a new Workers project and copy `src/worker.js` to the editor.
Set the following environment variables and deploy.
- `DB`: (Required) D1 database binding.
- `SECRET_KEY`: (Required) A random secret key.
- `PEER_API_KEY`: If set, clients must provide this key to connect.
- `PEER_POLL_INTERVAL`: The minimum interval (ms) between polling. Default is 0.
- `PEER_MAX_DURATION`: The maximum duration (s) of a connection. If not set, connections will not expire.