@xtr-dev/rondevu-client 0.13.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.d.ts CHANGED
@@ -1,30 +1,10 @@
1
1
  /**
2
- * Rondevu API Client - Single class for all API endpoints
2
+ * Rondevu API Client - RPC interface
3
3
  */
4
- export interface Credentials {
5
- peerId: string;
6
- secret: string;
7
- }
8
- export interface Keypair {
9
- publicKey: string;
10
- privateKey: string;
11
- }
12
- export interface OfferRequest {
13
- sdp: string;
14
- topics?: string[];
15
- ttl?: number;
16
- secret?: string;
17
- }
18
- export interface Offer {
19
- id: string;
20
- peerId: string;
21
- sdp: string;
22
- topics: string[];
23
- ttl: number;
24
- createdAt: number;
25
- expiresAt: number;
26
- answererPeerId?: string;
27
- }
4
+ import { CryptoAdapter, Keypair } from './crypto-adapter.js';
5
+ import { BatcherOptions } from './rpc-batcher.js';
6
+ export type { Keypair } from './crypto-adapter.js';
7
+ export type { BatcherOptions } from './rpc-batcher.js';
28
8
  export interface OfferRequest {
29
9
  sdp: string;
30
10
  }
@@ -50,55 +30,77 @@ export interface Service {
50
30
  expiresAt: number;
51
31
  }
52
32
  export interface IceCandidate {
53
- candidate: RTCIceCandidateInit;
33
+ candidate: RTCIceCandidateInit | null;
54
34
  createdAt: number;
55
35
  }
56
36
  /**
57
- * RondevuAPI - Complete API client for Rondevu signaling server
37
+ * RondevuAPI - RPC-based API client for Rondevu signaling server
58
38
  */
59
39
  export declare class RondevuAPI {
60
40
  private baseUrl;
61
- private credentials?;
62
- constructor(baseUrl: string, credentials?: Credentials | undefined);
41
+ private username;
42
+ private keypair;
43
+ private crypto;
44
+ private batcher;
45
+ constructor(baseUrl: string, username: string, keypair: Keypair, cryptoAdapter?: CryptoAdapter, batcherOptions?: BatcherOptions | false);
46
+ /**
47
+ * Generate authentication parameters for RPC calls
48
+ */
49
+ private generateAuth;
50
+ /**
51
+ * Execute RPC call with optional batching
52
+ */
53
+ private rpc;
63
54
  /**
64
- * Set credentials for authentication
55
+ * Execute single RPC call directly (bypasses batcher)
65
56
  */
66
- setCredentials(credentials: Credentials): void;
57
+ private rpcDirect;
67
58
  /**
68
- * Authentication header
59
+ * Execute batch RPC calls directly (bypasses batcher)
69
60
  */
70
- private getAuthHeader;
61
+ private rpcBatchDirect;
71
62
  /**
72
63
  * Generate an Ed25519 keypair for username claiming and service publishing
64
+ * @param cryptoAdapter - Optional crypto adapter (defaults to WebCryptoAdapter)
73
65
  */
74
- static generateKeypair(): Promise<Keypair>;
66
+ static generateKeypair(cryptoAdapter?: CryptoAdapter): Promise<Keypair>;
75
67
  /**
76
68
  * Sign a message with an Ed25519 private key
69
+ * @param cryptoAdapter - Optional crypto adapter (defaults to WebCryptoAdapter)
77
70
  */
78
- static signMessage(message: string, privateKeyBase64: string): Promise<string>;
71
+ static signMessage(message: string, privateKeyBase64: string, cryptoAdapter?: CryptoAdapter): Promise<string>;
79
72
  /**
80
- * Verify a signature
73
+ * Verify an Ed25519 signature
74
+ * @param cryptoAdapter - Optional crypto adapter (defaults to WebCryptoAdapter)
81
75
  */
82
- static verifySignature(message: string, signatureBase64: string, publicKeyBase64: string): Promise<boolean>;
76
+ static verifySignature(message: string, signatureBase64: string, publicKeyBase64: string, cryptoAdapter?: CryptoAdapter): Promise<boolean>;
83
77
  /**
84
- * Register a new peer and get credentials
78
+ * Check if a username is available
85
79
  */
86
- register(): Promise<Credentials>;
80
+ isUsernameAvailable(username: string): Promise<boolean>;
87
81
  /**
88
- * Create one or more offers
82
+ * Check if current username is claimed
89
83
  */
90
- createOffers(offers: OfferRequest[]): Promise<Offer[]>;
84
+ isUsernameClaimed(): Promise<boolean>;
91
85
  /**
92
- * Get offer by ID
86
+ * Publish a service
93
87
  */
94
- getOffer(offerId: string): Promise<Offer>;
88
+ publishService(service: ServiceRequest): Promise<Service>;
95
89
  /**
96
- * Answer a specific offer from a service
90
+ * Get service by FQN (direct lookup, random, or paginated)
97
91
  */
98
- postOfferAnswer(serviceFqn: string, offerId: string, sdp: string): Promise<{
99
- success: boolean;
100
- offerId: string;
101
- }>;
92
+ getService(serviceFqn: string, options?: {
93
+ limit?: number;
94
+ offset?: number;
95
+ }): Promise<any>;
96
+ /**
97
+ * Delete a service
98
+ */
99
+ deleteService(serviceFqn: string): Promise<void>;
100
+ /**
101
+ * Answer an offer
102
+ */
103
+ answerOffer(serviceFqn: string, offerId: string, sdp: string): Promise<void>;
102
104
  /**
103
105
  * Get answer for a specific offer (offerer polls this)
104
106
  */
@@ -109,9 +111,23 @@ export declare class RondevuAPI {
109
111
  answeredAt: number;
110
112
  } | null>;
111
113
  /**
112
- * Search offers by topic
114
+ * Combined polling for answers and ICE candidates
113
115
  */
114
- searchOffers(topic: string): Promise<Offer[]>;
116
+ poll(since?: number): Promise<{
117
+ answers: Array<{
118
+ offerId: string;
119
+ serviceId?: string;
120
+ answererId: string;
121
+ sdp: string;
122
+ answeredAt: number;
123
+ }>;
124
+ iceCandidates: Record<string, Array<{
125
+ candidate: RTCIceCandidateInit | null;
126
+ role: 'offerer' | 'answerer';
127
+ peerId: string;
128
+ createdAt: number;
129
+ }>>;
130
+ }>;
115
131
  /**
116
132
  * Add ICE candidates to a specific offer
117
133
  */
@@ -120,75 +136,10 @@ export declare class RondevuAPI {
120
136
  offerId: string;
121
137
  }>;
122
138
  /**
123
- * Get ICE candidates for a specific offer (with polling support)
139
+ * Get ICE candidates for a specific offer
124
140
  */
125
141
  getOfferIceCandidates(serviceFqn: string, offerId: string, since?: number): Promise<{
126
142
  candidates: IceCandidate[];
127
143
  offerId: string;
128
144
  }>;
129
- /**
130
- * Publish a service
131
- * Service FQN must include username: service:version@username
132
- */
133
- publishService(service: ServiceRequest): Promise<Service>;
134
- /**
135
- * Get service by FQN (with username) - Direct lookup
136
- * Example: chat:1.0.0@alice
137
- */
138
- getService(serviceFqn: string): Promise<{
139
- serviceId: string;
140
- username: string;
141
- serviceFqn: string;
142
- offerId: string;
143
- sdp: string;
144
- createdAt: number;
145
- expiresAt: number;
146
- }>;
147
- /**
148
- * Discover a random available service without knowing the username
149
- * Example: chat:1.0.0 (without @username)
150
- */
151
- discoverService(serviceVersion: string): Promise<{
152
- serviceId: string;
153
- username: string;
154
- serviceFqn: string;
155
- offerId: string;
156
- sdp: string;
157
- createdAt: number;
158
- expiresAt: number;
159
- }>;
160
- /**
161
- * Discover multiple available services with pagination
162
- * Example: chat:1.0.0 (without @username)
163
- */
164
- discoverServices(serviceVersion: string, limit?: number, offset?: number): Promise<{
165
- services: Array<{
166
- serviceId: string;
167
- username: string;
168
- serviceFqn: string;
169
- offerId: string;
170
- sdp: string;
171
- createdAt: number;
172
- expiresAt: number;
173
- }>;
174
- count: number;
175
- limit: number;
176
- offset: number;
177
- }>;
178
- /**
179
- * Check if username is available
180
- */
181
- checkUsername(username: string): Promise<{
182
- available: boolean;
183
- publicKey?: string;
184
- claimedAt?: number;
185
- expiresAt?: number;
186
- }>;
187
- /**
188
- * Claim a username (requires Ed25519 signature)
189
- */
190
- claimUsername(username: string, publicKey: string, signature: string, message: string): Promise<{
191
- success: boolean;
192
- username: string;
193
- }>;
194
145
  }