diff --git a/package.json b/package.json index e7e9763..8035930 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtr-dev/rondevu-client", - "version": "0.1.2", + "version": "0.2.1", "description": "TypeScript client for Rondevu peer signaling and discovery server", "type": "module", "main": "dist/index.js", @@ -8,8 +8,7 @@ "scripts": { "build": "tsc", "typecheck": "tsc --noEmit", - "prepublishOnly": "npm run build", - "publish": "npm publish" + "prepublishOnly": "npm run build" }, "keywords": [ "webrtc", diff --git a/src/client.ts b/src/client.ts index 5aefb88..426c001 100644 --- a/src/client.ts +++ b/src/client.ts @@ -16,14 +16,14 @@ import { } from './types'; /** - * HTTP client for Rondevu peer signaling and discovery server + * HTTP API client for Rondevu peer signaling and discovery server */ -export class RondevuClient { +export class RondevuAPI { private readonly baseUrl: string; private readonly fetchImpl: typeof fetch; /** - * Creates a new Rondevu client instance + * Creates a new Rondevu API client instance * @param options - Client configuration options */ constructor(options: RondevuClientOptions) { @@ -70,8 +70,8 @@ export class RondevuClient { * * @example * ```typescript - * const client = new RondevuClient({ baseUrl: 'https://example.com' }); - * const { version } = await client.getVersion(); + * const api = new RondevuAPI({ baseUrl: 'https://example.com' }); + * const { version } = await api.getVersion(); * console.log('Server version:', version); * ``` */ @@ -90,8 +90,8 @@ export class RondevuClient { * * @example * ```typescript - * const client = new RondevuClient({ baseUrl: 'https://example.com' }); - * const { topics, pagination } = await client.listTopics(); + * const api = new RondevuAPI({ baseUrl: 'https://example.com' }); + * const { topics, pagination } = await api.listTopics(); * console.log(`Found ${topics.length} topics`); * ``` */ @@ -113,8 +113,8 @@ export class RondevuClient { * * @example * ```typescript - * const client = new RondevuClient({ baseUrl: 'https://example.com' }); - * const { sessions } = await client.listSessions('my-room'); + * const api = new RondevuAPI({ baseUrl: 'https://example.com' }); + * const { sessions } = await api.listSessions('my-room'); * const otherPeers = sessions.filter(s => s.peerId !== myPeerId); * ``` */ @@ -133,8 +133,8 @@ export class RondevuClient { * * @example * ```typescript - * const client = new RondevuClient({ baseUrl: 'https://example.com' }); - * const { code } = await client.createOffer('my-room', { + * const api = new RondevuAPI({ baseUrl: 'https://example.com' }); + * const { code } = await api.createOffer('my-room', { * peerId: 'peer-123', * offer: signalingData * }); @@ -162,17 +162,17 @@ export class RondevuClient { * * @example * ```typescript - * const client = new RondevuClient({ baseUrl: 'https://example.com' }); + * const api = new RondevuAPI({ baseUrl: 'https://example.com' }); * * // Send answer - * await client.sendAnswer({ + * await api.sendAnswer({ * code: sessionCode, * answer: answerData, * side: 'answerer' * }); * * // Send candidate - * await client.sendAnswer({ + * await api.sendAnswer({ * code: sessionCode, * candidate: candidateData, * side: 'offerer' @@ -195,16 +195,16 @@ export class RondevuClient { * * @example * ```typescript - * const client = new RondevuClient({ baseUrl: 'https://example.com' }); + * const api = new RondevuAPI({ baseUrl: 'https://example.com' }); * * // Offerer polls for answer - * const offererData = await client.poll(sessionCode, 'offerer'); + * const offererData = await api.poll(sessionCode, 'offerer'); * if (offererData.answer) { * console.log('Received answer:', offererData.answer); * } * * // Answerer polls for offer - * const answererData = await client.poll(sessionCode, 'answerer'); + * const answererData = await api.poll(sessionCode, 'answerer'); * console.log('Received offer:', answererData.offer); * ``` */ @@ -226,8 +226,8 @@ export class RondevuClient { * * @example * ```typescript - * const client = new RondevuClient({ baseUrl: 'https://example.com' }); - * const health = await client.health(); + * const api = new RondevuAPI({ baseUrl: 'https://example.com' }); + * const health = await api.health(); * console.log('Server status:', health.status); * ``` */ diff --git a/src/connection.ts b/src/connection.ts index 6c1175e..88f60a3 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -1,5 +1,5 @@ import { EventEmitter } from './event-emitter'; -import { RondevuClient } from './client'; +import { RondevuAPI } from './client'; import { RondevuConnectionParams } from './types'; /** @@ -12,7 +12,7 @@ export class RondevuConnection extends EventEmitter { readonly remotePeerId: string; private pc: RTCPeerConnection; - private client: RondevuClient; + private client: RondevuAPI; private localPeerId: string; private dataChannels: Map; private pollingInterval?: ReturnType; @@ -22,7 +22,7 @@ export class RondevuConnection extends EventEmitter { private isPolling: boolean = false; private isClosed: boolean = false; - constructor(params: RondevuConnectionParams, client: RondevuClient) { + constructor(params: RondevuConnectionParams, client: RondevuAPI) { super(); this.id = params.id; this.topic = params.topic; diff --git a/src/index.ts b/src/index.ts index 22e963b..d36205c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,8 +9,8 @@ export { Rondevu } from './rondevu'; // Export connection class export { RondevuConnection } from './connection'; -// Export low-level signaling client (for advanced usage) -export { RondevuClient } from './client'; +// Export low-level signaling API (for advanced usage) +export { RondevuAPI } from './client'; // Export all types export type { diff --git a/src/rondevu.ts b/src/rondevu.ts index ee87c24..568a47b 100644 --- a/src/rondevu.ts +++ b/src/rondevu.ts @@ -1,4 +1,4 @@ -import { RondevuClient } from './client'; +import { RondevuAPI } from './client'; import { RondevuConnection } from './connection'; import { RondevuOptions, JoinOptions, RondevuConnectionParams } from './types'; @@ -7,8 +7,8 @@ import { RondevuOptions, JoinOptions, RondevuConnectionParams } from './types'; */ export class Rondevu { readonly peerId: string; + readonly api: RondevuAPI; - private client: RondevuClient; private baseUrl: string; private fetchImpl?: typeof fetch; private rtcConfig?: RTCConfiguration; @@ -23,7 +23,7 @@ export class Rondevu { this.baseUrl = options.baseUrl || 'https://rondevu.xtrdev.workers.dev'; this.fetchImpl = options.fetch; - this.client = new RondevuClient({ + this.api = new RondevuAPI({ baseUrl: this.baseUrl, fetch: options.fetch, }); @@ -70,7 +70,7 @@ export class Rondevu { await this.waitForIceGathering(pc); // Create session on server with custom code - await this.client.createOffer(topic, { + await this.api.createOffer(topic, { peerId: this.peerId, offer: pc.localDescription!.sdp, code: id, @@ -88,7 +88,7 @@ export class Rondevu { connectionTimeout: this.connectionTimeout, }; - const connection = new RondevuConnection(connectionParams, this.client); + const connection = new RondevuConnection(connectionParams, this.api); // Start polling for answer connection.startPolling(); @@ -103,7 +103,7 @@ export class Rondevu { */ async connect(id: string): Promise { // Poll server to get session by ID - const sessionData = await this.findSessionByIdWithClient(id, this.client); + const sessionData = await this.findSessionByIdWithClient(id, this.api); if (!sessionData) { throw new Error(`Connection ${id} not found or expired`); @@ -126,7 +126,7 @@ export class Rondevu { await this.waitForIceGathering(pc); // Send answer to server - await this.client.sendAnswer({ + await this.api.sendAnswer({ code: id, answer: pc.localDescription!.sdp, side: 'answerer', @@ -144,7 +144,7 @@ export class Rondevu { connectionTimeout: this.connectionTimeout, }; - const connection = new RondevuConnection(connectionParams, this.client); + const connection = new RondevuConnection(connectionParams, this.api); // Start polling for ICE candidates connection.startPolling(); @@ -160,7 +160,7 @@ export class Rondevu { */ async join(topic: string, options?: JoinOptions): Promise { // List sessions in topic - const { sessions } = await this.client.listSessions(topic); + const { sessions } = await this.api.listSessions(topic); // Filter out self (sessions with our peer ID) let availableSessions = sessions.filter( @@ -243,7 +243,7 @@ export class Rondevu { */ private async findSessionByIdWithClient( id: string, - client: RondevuClient + client: RondevuAPI ): Promise<{ code: string; peerId: string;