mirror of
https://github.com/xtr-dev/rondevu-client.git
synced 2025-12-10 10:53:24 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 83fd0f84a4 | |||
| aa53d5bc3d |
16
README.md
16
README.md
@@ -436,14 +436,26 @@ const newPeers = await client.offers.findByTopic('movie-xyz', {
|
|||||||
|
|
||||||
### Authentication
|
### Authentication
|
||||||
|
|
||||||
#### `client.register()`
|
#### `client.register(customPeerId?)`
|
||||||
Register a new peer and receive credentials.
|
Register a new peer and receive credentials.
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
|
// Auto-generate peer ID
|
||||||
const creds = await client.register();
|
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
|
### Topics
|
||||||
|
|
||||||
#### `client.offers.getTopics(options?)`
|
#### `client.offers.getTopics(options?)`
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@xtr-dev/rondevu-client",
|
"name": "@xtr-dev/rondevu-client",
|
||||||
"version": "0.7.9",
|
"version": "0.7.10",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@xtr-dev/rondevu-client",
|
"name": "@xtr-dev/rondevu-client",
|
||||||
"version": "0.7.9",
|
"version": "0.7.10",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@xtr-dev/rondevu-client": "^0.5.1"
|
"@xtr-dev/rondevu-client": "^0.5.1"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@xtr-dev/rondevu-client",
|
"name": "@xtr-dev/rondevu-client",
|
||||||
"version": "0.7.9",
|
"version": "0.7.10",
|
||||||
"description": "TypeScript client for Rondevu topic-based peer discovery and signaling server",
|
"description": "TypeScript client for Rondevu topic-based peer discovery and signaling server",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"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
|
* 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`, {
|
const response = await this.fetchFn(`${this.baseUrl}/register`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({}),
|
body: JSON.stringify(body),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
@@ -100,9 +100,10 @@ export class Rondevu {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Register and initialize authenticated client
|
* 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> {
|
async register(customPeerId?: string): Promise<Credentials> {
|
||||||
this.credentials = await this.auth.register();
|
this.credentials = await this.auth.register(customPeerId);
|
||||||
|
|
||||||
// Create offers API instance
|
// Create offers API instance
|
||||||
this._offers = new RondevuOffers(
|
this._offers = new RondevuOffers(
|
||||||
|
|||||||
Reference in New Issue
Block a user