mirror of
https://github.com/xtr-dev/rondevu-client.git
synced 2025-12-10 10:53:24 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6057c3c582 | |||
| 255fe42a43 | |||
| 83fd0f84a4 | |||
| aa53d5bc3d | |||
| f5aa6e2189 | |||
| afdca83640 |
22
README.md
22
README.md
@@ -411,7 +411,8 @@ const offers = await client.offers.create([{
|
||||
sdp: 'v=0...', // Your WebRTC offer SDP
|
||||
topics: ['movie-xyz', 'hd-content'],
|
||||
ttl: 300000, // 5 minutes
|
||||
secret: 'my-secret-password' // Optional: protect offer (max 128 chars)
|
||||
secret: 'my-secret-password', // Optional: protect offer (max 128 chars)
|
||||
info: 'Looking for peers in EU region' // Optional: public info (max 128 chars)
|
||||
}]);
|
||||
|
||||
// Discover peers by topic
|
||||
@@ -436,14 +437,26 @@ const newPeers = await client.offers.findByTopic('movie-xyz', {
|
||||
|
||||
### Authentication
|
||||
|
||||
#### `client.register()`
|
||||
#### `client.register(customPeerId?)`
|
||||
Register a new peer and receive credentials.
|
||||
|
||||
```typescript
|
||||
// Auto-generate peer ID
|
||||
const creds = await client.register();
|
||||
// { peerId: '...', secret: '...' }
|
||||
// { peerId: 'f17c195f067255e357232e34cf0735d9', secret: '...' }
|
||||
|
||||
// Or use a custom peer ID (1-128 characters)
|
||||
const customCreds = await client.register('my-custom-peer-id');
|
||||
// { peerId: 'my-custom-peer-id', secret: '...' }
|
||||
```
|
||||
|
||||
**Parameters:**
|
||||
- `customPeerId` (optional): Custom peer ID (1-128 characters). If not provided, a random ID will be generated.
|
||||
|
||||
**Notes:**
|
||||
- Returns 409 Conflict if the custom peer ID is already in use
|
||||
- Custom peer IDs must be non-empty and between 1-128 characters
|
||||
|
||||
### Topics
|
||||
|
||||
#### `client.offers.getTopics(options?)`
|
||||
@@ -477,7 +490,8 @@ const offers = await client.offers.create([
|
||||
sdp: 'v=0...',
|
||||
topics: ['topic-1', 'topic-2'],
|
||||
ttl: 300000, // optional, default 5 minutes
|
||||
secret: 'my-secret-password' // optional, max 128 chars
|
||||
secret: 'my-secret-password', // optional, max 128 chars
|
||||
info: 'Looking for peers in EU region' // optional, public info, max 128 chars
|
||||
}
|
||||
]);
|
||||
```
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@xtr-dev/rondevu-client",
|
||||
"version": "0.7.8",
|
||||
"version": "0.7.11",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@xtr-dev/rondevu-client",
|
||||
"version": "0.7.8",
|
||||
"version": "0.7.11",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@xtr-dev/rondevu-client": "^0.5.1"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@xtr-dev/rondevu-client",
|
||||
"version": "0.7.8",
|
||||
"version": "0.7.11",
|
||||
"description": "TypeScript client for Rondevu topic-based peer discovery and signaling server",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
|
||||
11
src/auth.ts
11
src/auth.ts
@@ -29,14 +29,21 @@ export class RondevuAuth {
|
||||
|
||||
/**
|
||||
* Register a new peer and receive credentials
|
||||
* @param customPeerId - Optional custom peer ID (1-128 characters). If not provided, a random ID will be generated.
|
||||
* @throws Error if registration fails (e.g., peer ID already in use)
|
||||
*/
|
||||
async register(): Promise<Credentials> {
|
||||
async register(customPeerId?: string): Promise<Credentials> {
|
||||
const body: { peerId?: string } = {};
|
||||
if (customPeerId !== undefined) {
|
||||
body.peerId = customPeerId;
|
||||
}
|
||||
|
||||
const response = await this.fetchFn(`${this.baseUrl}/register`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({}),
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
@@ -9,6 +9,7 @@ export interface CreateOfferRequest {
|
||||
topics: string[];
|
||||
ttl?: number;
|
||||
secret?: string;
|
||||
info?: string;
|
||||
}
|
||||
|
||||
export interface Offer {
|
||||
@@ -21,6 +22,7 @@ export interface Offer {
|
||||
lastSeen: number;
|
||||
secret?: string;
|
||||
hasSecret?: boolean;
|
||||
info?: string;
|
||||
answererPeerId?: string;
|
||||
answerSdp?: string;
|
||||
answeredAt?: number;
|
||||
|
||||
@@ -179,6 +179,15 @@ export default class RondevuPeer extends EventEmitter<PeerEvents> {
|
||||
return this.pc.addTrack(track, ...streams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a data channel for sending and receiving arbitrary data
|
||||
* This should typically be called by the offerer before creating the offer
|
||||
* The answerer will receive the channel via the 'datachannel' event
|
||||
*/
|
||||
createDataChannel(label: string, options?: RTCDataChannelInit): RTCDataChannel {
|
||||
return this.pc.createDataChannel(label, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the connection and clean up
|
||||
*/
|
||||
|
||||
@@ -100,9 +100,10 @@ export class Rondevu {
|
||||
|
||||
/**
|
||||
* Register and initialize authenticated client
|
||||
* @param customPeerId - Optional custom peer ID (1-128 characters). If not provided, a random ID will be generated.
|
||||
*/
|
||||
async register(): Promise<Credentials> {
|
||||
this.credentials = await this.auth.register();
|
||||
async register(customPeerId?: string): Promise<Credentials> {
|
||||
this.credentials = await this.auth.register(customPeerId);
|
||||
|
||||
// Create offers API instance
|
||||
this._offers = new RondevuOffers(
|
||||
|
||||
Reference in New Issue
Block a user