@xtr-dev/rondevu-client 0.3.4 → 0.4.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/client.js CHANGED
@@ -150,4 +150,22 @@ export class RondevuAPI {
150
150
  method: 'GET',
151
151
  });
152
152
  }
153
+ /**
154
+ * Ends a session by deleting the offer from the server
155
+ *
156
+ * @param code - The offer code
157
+ * @returns Success confirmation
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * const api = new RondevuAPI({ baseUrl: 'https://example.com' });
162
+ * await api.leave('my-offer-code');
163
+ * ```
164
+ */
165
+ async leave(code) {
166
+ return this.request('/leave', {
167
+ method: 'POST',
168
+ body: JSON.stringify({ code }),
169
+ });
170
+ }
153
171
  }
@@ -1,76 +1,127 @@
1
- import { EventEmitter } from './event-emitter.js';
2
- import { RondevuAPI } from './client.js';
3
- import { RondevuConnectionParams } from './types.js';
1
+ import { RondevuOffers } from './offers.js';
4
2
  /**
5
- * Represents a WebRTC connection with automatic signaling and ICE exchange
3
+ * Events emitted by RondevuConnection
6
4
  */
7
- export declare class RondevuConnection extends EventEmitter {
8
- readonly id: string;
9
- readonly role: 'offerer' | 'answerer';
10
- readonly remotePeerId: string;
5
+ export interface RondevuConnectionEvents {
6
+ 'connecting': () => void;
7
+ 'connected': () => void;
8
+ 'disconnected': () => void;
9
+ 'error': (error: Error) => void;
10
+ 'datachannel': (channel: RTCDataChannel) => void;
11
+ 'track': (event: RTCTrackEvent) => void;
12
+ }
13
+ /**
14
+ * Options for creating a WebRTC connection
15
+ */
16
+ export interface ConnectionOptions {
17
+ /**
18
+ * RTCConfiguration for the peer connection
19
+ * @default { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] }
20
+ */
21
+ rtcConfig?: RTCConfiguration;
22
+ /**
23
+ * Topics to advertise this connection under
24
+ */
25
+ topics: string[];
26
+ /**
27
+ * How long the offer should live (milliseconds)
28
+ * @default 300000 (5 minutes)
29
+ */
30
+ ttl?: number;
31
+ /**
32
+ * Whether to create a data channel automatically (for offerer)
33
+ * @default true
34
+ */
35
+ createDataChannel?: boolean;
36
+ /**
37
+ * Label for the automatically created data channel
38
+ * @default 'data'
39
+ */
40
+ dataChannelLabel?: string;
41
+ }
42
+ /**
43
+ * High-level WebRTC connection manager for Rondevu
44
+ * Handles offer/answer exchange, ICE candidates, and connection lifecycle
45
+ */
46
+ export declare class RondevuConnection {
47
+ private rtcConfig;
11
48
  private pc;
12
- private client;
13
- private localPeerId;
14
- private dataChannels;
15
- private pollingInterval?;
16
- private pollingIntervalMs;
17
- private connectionTimeoutMs;
18
- private connectionTimer?;
19
- private isPolling;
20
- private isClosed;
21
- private wrtc?;
22
- private RTCIceCandidate;
23
- constructor(params: RondevuConnectionParams, client: RondevuAPI);
49
+ private offersApi;
50
+ private offerId?;
51
+ private role?;
52
+ private icePollingInterval?;
53
+ private answerPollingInterval?;
54
+ private lastIceTimestamp;
55
+ private eventListeners;
56
+ private dataChannel?;
57
+ private pendingIceCandidates;
24
58
  /**
25
- * Setup RTCPeerConnection event handlers
59
+ * Current connection state
26
60
  */
27
- private setupEventHandlers;
61
+ get connectionState(): RTCPeerConnectionState;
28
62
  /**
29
- * Handle RTCPeerConnection state changes
63
+ * The offer ID for this connection
30
64
  */
31
- private handleConnectionStateChange;
65
+ get id(): string | undefined;
32
66
  /**
33
- * Send an ICE candidate to the remote peer via signaling server
67
+ * Get the primary data channel (if created)
34
68
  */
35
- private sendIceCandidate;
69
+ get channel(): RTCDataChannel | undefined;
70
+ constructor(offersApi: RondevuOffers, rtcConfig?: RTCConfiguration);
36
71
  /**
37
- * Start polling for remote session data (answer/candidates)
72
+ * Set up peer connection event handlers
38
73
  */
39
- startPolling(): void;
74
+ private setupPeerConnection;
40
75
  /**
41
- * Stop polling
76
+ * Flush buffered ICE candidates (trickle ICE support)
42
77
  */
43
- private stopPolling;
78
+ private flushPendingIceCandidates;
44
79
  /**
45
- * Poll the signaling server for remote data
80
+ * Create an offer and advertise on topics
46
81
  */
47
- private poll;
82
+ createOffer(options: ConnectionOptions): Promise<string>;
48
83
  /**
49
- * Handle remotely created data channel
84
+ * Answer an existing offer
50
85
  */
51
- private handleRemoteDataChannel;
86
+ answer(offerId: string, offerSdp: string): Promise<void>;
52
87
  /**
53
- * Get or create a data channel
88
+ * Start polling for answers (offerer only)
54
89
  */
55
- dataChannel(label: string, options?: RTCDataChannelInit): RTCDataChannel;
90
+ private startAnswerPolling;
91
+ /**
92
+ * Start polling for ICE candidates
93
+ */
94
+ private startIcePolling;
95
+ /**
96
+ * Stop answer polling
97
+ */
98
+ private stopAnswerPolling;
99
+ /**
100
+ * Stop ICE polling
101
+ */
102
+ private stopIcePolling;
103
+ /**
104
+ * Stop all polling
105
+ */
106
+ private stopPolling;
56
107
  /**
57
- * Add a local media stream to the connection
108
+ * Add event listener
58
109
  */
59
- addStream(stream: MediaStream): void;
110
+ on<K extends keyof RondevuConnectionEvents>(event: K, listener: RondevuConnectionEvents[K]): void;
60
111
  /**
61
- * Get the underlying RTCPeerConnection for advanced usage
112
+ * Remove event listener
62
113
  */
63
- getPeerConnection(): RTCPeerConnection;
114
+ off<K extends keyof RondevuConnectionEvents>(event: K, listener: RondevuConnectionEvents[K]): void;
64
115
  /**
65
- * Start connection timeout
116
+ * Emit event
66
117
  */
67
- private startConnectionTimeout;
118
+ private emit;
68
119
  /**
69
- * Clear connection timeout
120
+ * Add a media track to the connection
70
121
  */
71
- private clearConnectionTimeout;
122
+ addTrack(track: MediaStreamTrack, ...streams: MediaStream[]): RTCRtpSender;
72
123
  /**
73
- * Close the connection and cleanup resources
124
+ * Close the connection and clean up
74
125
  */
75
126
  close(): void;
76
127
  }