@xtr-dev/rondevu-client 0.3.5 → 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.
@@ -1,82 +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 hasConnected;
22
- private wrtc?;
23
- private RTCIceCandidate;
24
- 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;
25
58
  /**
26
- * Setup RTCPeerConnection event handlers
59
+ * Current connection state
27
60
  */
28
- private setupEventHandlers;
61
+ get connectionState(): RTCPeerConnectionState;
29
62
  /**
30
- * Handle RTCPeerConnection state changes
63
+ * The offer ID for this connection
31
64
  */
32
- private handleConnectionStateChange;
65
+ get id(): string | undefined;
33
66
  /**
34
- * Send an ICE candidate to the remote peer via signaling server
67
+ * Get the primary data channel (if created)
35
68
  */
36
- private sendIceCandidate;
69
+ get channel(): RTCDataChannel | undefined;
70
+ constructor(offersApi: RondevuOffers, rtcConfig?: RTCConfiguration);
37
71
  /**
38
- * Start polling for remote session data (answer/candidates)
72
+ * Set up peer connection event handlers
39
73
  */
40
- startPolling(): void;
74
+ private setupPeerConnection;
41
75
  /**
42
- * Stop polling
76
+ * Flush buffered ICE candidates (trickle ICE support)
43
77
  */
44
- private stopPolling;
78
+ private flushPendingIceCandidates;
79
+ /**
80
+ * Create an offer and advertise on topics
81
+ */
82
+ createOffer(options: ConnectionOptions): Promise<string>;
83
+ /**
84
+ * Answer an existing offer
85
+ */
86
+ answer(offerId: string, offerSdp: string): Promise<void>;
45
87
  /**
46
- * Poll the signaling server for remote data
88
+ * Start polling for answers (offerer only)
47
89
  */
48
- private poll;
90
+ private startAnswerPolling;
49
91
  /**
50
- * Handle remotely created data channel
92
+ * Start polling for ICE candidates
51
93
  */
52
- private handleRemoteDataChannel;
94
+ private startIcePolling;
53
95
  /**
54
- * Get or create a data channel
96
+ * Stop answer polling
55
97
  */
56
- dataChannel(label: string, options?: RTCDataChannelInit): RTCDataChannel;
98
+ private stopAnswerPolling;
57
99
  /**
58
- * Add a local media stream to the connection
100
+ * Stop ICE polling
59
101
  */
60
- addStream(stream: MediaStream): void;
102
+ private stopIcePolling;
103
+ /**
104
+ * Stop all polling
105
+ */
106
+ private stopPolling;
61
107
  /**
62
- * Get the underlying RTCPeerConnection for advanced usage
108
+ * Add event listener
63
109
  */
64
- getPeerConnection(): RTCPeerConnection;
110
+ on<K extends keyof RondevuConnectionEvents>(event: K, listener: RondevuConnectionEvents[K]): void;
65
111
  /**
66
- * Start connection timeout
112
+ * Remove event listener
67
113
  */
68
- private startConnectionTimeout;
114
+ off<K extends keyof RondevuConnectionEvents>(event: K, listener: RondevuConnectionEvents[K]): void;
69
115
  /**
70
- * Clear connection timeout
116
+ * Emit event
71
117
  */
72
- private clearConnectionTimeout;
118
+ private emit;
73
119
  /**
74
- * Leave the session by deleting the offer on the server and closing the connection
75
- * This ends the session for all connected peers
120
+ * Add a media track to the connection
76
121
  */
77
- leave(): Promise<void>;
122
+ addTrack(track: MediaStreamTrack, ...streams: MediaStream[]): RTCRtpSender;
78
123
  /**
79
- * Close the connection and cleanup resources
124
+ * Close the connection and clean up
80
125
  */
81
126
  close(): void;
82
127
  }