diff --git a/src/api.ts b/src/api.ts index 8c2640a..5a2e55b 100644 --- a/src/api.ts +++ b/src/api.ts @@ -70,6 +70,7 @@ interface RpcRequest { method: string message: string signature: string + publicKey?: string params?: any } @@ -232,6 +233,7 @@ export class RondevuAPI { method: 'claimUsername', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { username, publicKey }, }) } @@ -263,6 +265,7 @@ export class RondevuAPI { method: 'publishService', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { serviceFqn: service.serviceFqn, offers: service.offers, @@ -283,6 +286,7 @@ export class RondevuAPI { method: 'getService', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { serviceFqn, ...options, @@ -299,6 +303,7 @@ export class RondevuAPI { method: 'deleteService', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { serviceFqn }, }) } @@ -316,6 +321,7 @@ export class RondevuAPI { method: 'answerOffer', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { serviceFqn, offerId, sdp }, }) } @@ -333,6 +339,7 @@ export class RondevuAPI { method: 'getOfferAnswer', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { serviceFqn, offerId }, }) } catch (err) { @@ -369,6 +376,7 @@ export class RondevuAPI { method: 'poll', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { since }, }) } @@ -386,6 +394,7 @@ export class RondevuAPI { method: 'addIceCandidates', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { serviceFqn, offerId, candidates }, }) } @@ -403,6 +412,7 @@ export class RondevuAPI { method: 'getIceCandidates', message: auth.message, signature: auth.signature, + publicKey: this.keypair.publicKey, params: { serviceFqn, offerId, since }, }) diff --git a/src/rondevu.ts b/src/rondevu.ts index 4a34d1a..601ce54 100644 --- a/src/rondevu.ts +++ b/src/rondevu.ts @@ -167,18 +167,13 @@ export class Rondevu { /** * Publish a service with automatic signature generation + * Username will be automatically claimed on first publish if not already claimed */ async publishService(options: PublishServiceOptions): Promise { if (!this.keypair) { throw new Error('Not initialized. Call initialize() first.') } - if (!this.usernameClaimed) { - throw new Error( - 'Username not claimed. Call claimUsername() first or the server will reject the service.' - ) - } - const { serviceFqn, offers, ttl } = options // Generate signature for service publication @@ -194,8 +189,13 @@ export class Rondevu { ttl, } - // Publish to server - return await this.getAPI().publishService(serviceRequest) + // Publish to server (server will auto-claim username if needed) + const result = await this.getAPI().publishService(serviceRequest) + + // Mark username as claimed after successful publish + this.usernameClaimed = true + + return result } // ============================================