@gjsify/webrtc 0.4.0 → 0.4.3

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.
Files changed (44) hide show
  1. package/package.json +73 -70
  2. package/src/get-user-media.ts +0 -131
  3. package/src/gst-enum-maps.ts +0 -125
  4. package/src/gst-init.ts +0 -49
  5. package/src/gst-stats-parser.ts +0 -137
  6. package/src/gst-utils.ts +0 -41
  7. package/src/index.ts +0 -104
  8. package/src/internal/gst-types.ts +0 -122
  9. package/src/media-device-info.ts +0 -33
  10. package/src/media-devices.ts +0 -191
  11. package/src/media-stream-track.ts +0 -159
  12. package/src/media-stream.ts +0 -96
  13. package/src/register/data-channel.ts +0 -11
  14. package/src/register/error.ts +0 -11
  15. package/src/register/media-devices.ts +0 -10
  16. package/src/register/media.ts +0 -15
  17. package/src/register/peer-connection.ts +0 -20
  18. package/src/register.spec.ts +0 -55
  19. package/src/register.ts +0 -10
  20. package/src/rtc-certificate.ts +0 -110
  21. package/src/rtc-data-channel.ts +0 -283
  22. package/src/rtc-dtls-transport.ts +0 -48
  23. package/src/rtc-dtmf-sender.ts +0 -146
  24. package/src/rtc-error.ts +0 -49
  25. package/src/rtc-events.ts +0 -64
  26. package/src/rtc-ice-candidate.ts +0 -115
  27. package/src/rtc-ice-transport.ts +0 -104
  28. package/src/rtc-peer-connection.ts +0 -1039
  29. package/src/rtc-rtp-receiver.ts +0 -122
  30. package/src/rtc-rtp-sender.ts +0 -471
  31. package/src/rtc-rtp-transceiver.ts +0 -131
  32. package/src/rtc-sctp-transport.ts +0 -48
  33. package/src/rtc-session-description.ts +0 -64
  34. package/src/rtc-stats-report.ts +0 -39
  35. package/src/rtc-track-event.ts +0 -45
  36. package/src/rtp-capabilities.ts +0 -48
  37. package/src/tee-multiplexer.ts +0 -75
  38. package/src/test.mts +0 -11
  39. package/src/webrtc.spec.ts +0 -1186
  40. package/src/wpt-helpers.ts +0 -156
  41. package/src/wpt-media.spec.ts +0 -1154
  42. package/src/wpt.spec.ts +0 -1136
  43. package/tsconfig.json +0 -36
  44. package/tsconfig.tsbuildinfo +0 -1
@@ -1,1039 +0,0 @@
1
- // RTCPeerConnection — W3C WebRTC peer connection backed by GStreamer webrtcbin.
2
- //
3
- // Reference: refs/node-gst-webrtc/src/webrtc/RTCPeerConnection.ts (ISC)
4
- // Adapted from node-gtk to GJS. Phase 1: Data Channel. Phase 2: Media API
5
- // surface (addTransceiver, getSenders/getReceivers/getTransceivers, RTCTrackEvent).
6
-
7
- import GLib from 'gi://GLib?version=2.0';
8
- import GObject from 'gi://GObject?version=2.0';
9
- import GstWebRTC from 'gi://GstWebRTC?version=1.0';
10
-
11
- import {
12
- WebrtcbinBridge,
13
- type WebrtcbinBridge as WebrtcbinBridgeType,
14
- type DataChannelBridge as DataChannelBridgeType,
15
- } from '@gjsify/webrtc-native';
16
- import { ensureWebrtcbinAvailable, Gst } from './gst-init.js';
17
- import { withGstPromise } from './gst-utils.js';
18
- import {
19
- gstToSignalingState,
20
- gstToConnectionState,
21
- gstToIceConnectionState,
22
- gstToIceGatheringState,
23
- w3cDirectionToGst,
24
- } from './gst-enum-maps.js';
25
- import { asWebRtcBin, asWebRtcSrcPad } from './internal/gst-types.js';
26
- import { DOMException } from '@gjsify/dom-exception';
27
- import { RTCSessionDescription, type RTCSessionDescriptionInit } from './rtc-session-description.js';
28
- import { RTCIceCandidate, type RTCIceCandidateInit } from './rtc-ice-candidate.js';
29
- import { RTCDataChannel } from './rtc-data-channel.js';
30
- import { RTCPeerConnectionIceEvent, RTCDataChannelEvent } from './rtc-events.js';
31
- import { RTCRtpSender, type RTCRtpTransceiverDirection } from './rtc-rtp-sender.js';
32
- import { RTCRtpReceiver } from './rtc-rtp-receiver.js';
33
- import { RTCRtpTransceiver } from './rtc-rtp-transceiver.js';
34
- import { MediaStream } from './media-stream.js';
35
- import { MediaStreamTrack } from './media-stream-track.js';
36
- import { RTCTrackEvent } from './rtc-track-event.js';
37
- import { parseGstStats, filterStatsByTrackId } from './gst-stats-parser.js';
38
- import type { RTCStatsReport } from './rtc-stats-report.js';
39
- import { RTCIceTransport } from './rtc-ice-transport.js';
40
- import { RTCDtlsTransport } from './rtc-dtls-transport.js';
41
- import { RTCSctpTransport } from './rtc-sctp-transport.js';
42
- import { RTCCertificate, generateCertificate, type AlgorithmIdentifier } from './rtc-certificate.js';
43
-
44
- export type RTCSignalingState =
45
- | 'stable' | 'closed'
46
- | 'have-local-offer' | 'have-remote-offer'
47
- | 'have-local-pranswer' | 'have-remote-pranswer';
48
- export type RTCPeerConnectionState =
49
- | 'new' | 'connecting' | 'connected' | 'disconnected' | 'failed' | 'closed';
50
- export type RTCIceConnectionState =
51
- | 'new' | 'checking' | 'connected' | 'completed' | 'failed' | 'disconnected' | 'closed';
52
- export type RTCIceGatheringState = 'new' | 'gathering' | 'complete';
53
- export type RTCIceTransportPolicy = 'all' | 'relay';
54
- export type RTCBundlePolicy = 'balanced' | 'max-compat' | 'max-bundle';
55
- export type RTCRtcpMuxPolicy = 'require';
56
-
57
- export interface RTCIceServer {
58
- urls: string | string[];
59
- username?: string;
60
- credential?: string;
61
- credentialType?: 'password';
62
- }
63
-
64
- export interface RTCConfiguration {
65
- iceServers?: RTCIceServer[];
66
- iceTransportPolicy?: RTCIceTransportPolicy;
67
- bundlePolicy?: RTCBundlePolicy;
68
- rtcpMuxPolicy?: RTCRtcpMuxPolicy;
69
- peerIdentity?: string;
70
- certificates?: unknown[];
71
- iceCandidatePoolSize?: number;
72
- }
73
-
74
- export interface RTCOfferOptions {
75
- offerToReceiveAudio?: boolean;
76
- offerToReceiveVideo?: boolean;
77
- iceRestart?: boolean;
78
- }
79
- export interface RTCAnswerOptions {}
80
-
81
- export interface RTCDataChannelInit {
82
- ordered?: boolean;
83
- maxPacketLifeTime?: number;
84
- maxRetransmits?: number;
85
- protocol?: string;
86
- negotiated?: boolean;
87
- id?: number;
88
- priority?: 'very-low' | 'low' | 'medium' | 'high';
89
- }
90
-
91
- type EventHandler<E extends Event = Event> =
92
- ((this: RTCPeerConnection, ev: E) => any) | null;
93
-
94
- /**
95
- * Web-IDL `[EnforceRange] unsigned short` coercion. Coerces via ToNumber,
96
- * rejects values that can't be represented as an unsigned short (0..65535).
97
- * Matches Web-IDL §3.2.4.10: reject NaN, ±Infinity, and integers outside
98
- * the range; "100" → 100; fractional values are truncated.
99
- *
100
- * Reference: refs/wpt/webrtc/RTCDataChannelInit-{maxPacketLifeTime,maxRetransmits}-enforce-range.html
101
- */
102
- function coerceUnsignedShort(name: string, raw: unknown): number {
103
- const n = Number(raw);
104
- if (!Number.isFinite(n)) {
105
- throw new TypeError(`createDataChannel: ${name} must be a finite number, got ${String(raw)}`);
106
- }
107
- const truncated = Math.trunc(n);
108
- if (truncated < 0 || truncated > 65535) {
109
- throw new TypeError(`createDataChannel: ${name}=${truncated} is outside the [0, 65535] range`);
110
- }
111
- return truncated;
112
- }
113
-
114
-
115
- export interface RTCRtpTransceiverInit {
116
- direction?: RTCRtpTransceiverDirection;
117
- streams?: MediaStream[];
118
- sendEncodings?: Array<{ rid?: string; active?: boolean; maxBitrate?: number; scaleResolutionDownBy?: number }>;
119
- }
120
-
121
-
122
- let globalCounter = 0;
123
-
124
- export class RTCPeerConnection extends EventTarget {
125
- private _pipeline: Gst.Pipeline;
126
- private _webrtcbin: Gst.Element;
127
- private _bridge: WebrtcbinBridgeType;
128
- private _conf: RTCConfiguration;
129
- private _closed = false;
130
- private _iceRestartNeeded = false;
131
- private _hasNegotiated = false;
132
- private _dataChannels = new Map<unknown, RTCDataChannel>();
133
- private _transceivers = new Map<unknown, RTCRtpTransceiver>();
134
- private _senders: RTCRtpSender[] = [];
135
- private _receivers: RTCRtpReceiver[] = [];
136
- private _iceTransport: RTCIceTransport | null = null;
137
- private _dtlsTransport: RTCDtlsTransport | null = null;
138
- private _sctpTransport: RTCSctpTransport | null = null;
139
- readonly canTrickleIceCandidates: boolean = true;
140
-
141
- constructor(configuration?: RTCConfiguration) {
142
- super();
143
- ensureWebrtcbinAvailable();
144
-
145
- const [major, minor] = Gst.version();
146
- if (major < 1 || (major === 1 && minor < 20)) {
147
- throw new DOMException(
148
- `@gjsify/webrtc requires GStreamer >= 1.20 (you have ${major}.${minor}). webrtcbin is only stable from 1.20 onward.`,
149
- 'NotSupportedError',
150
- );
151
- }
152
-
153
- const id = ++globalCounter;
154
- this._pipeline = new Gst.Pipeline({ name: `gjsify-webrtc-pipeline-${id}` });
155
- const bin = Gst.ElementFactory.make('webrtcbin', `gjsify-webrtcbin-${id}`);
156
- if (!bin) {
157
- throw new Error('Failed to create webrtcbin element');
158
- }
159
- this._webrtcbin = bin;
160
- this._conf = { ...configuration };
161
-
162
- // Validate certificates — expired certs must be rejected
163
- if (configuration?.certificates) {
164
- for (const cert of configuration.certificates) {
165
- if (cert instanceof RTCCertificate && cert.expires <= Date.now()) {
166
- throw new DOMException(
167
- 'RTCPeerConnection: one of the provided certificates has expired',
168
- 'InvalidAccessError',
169
- );
170
- }
171
- }
172
- }
173
-
174
- this._applyIceServers(configuration?.iceServers ?? []);
175
- this._applyIceTransportPolicy(configuration?.iceTransportPolicy);
176
- this._applyBundlePolicy(configuration?.bundlePolicy);
177
-
178
- this._pipeline.add(this._webrtcbin);
179
-
180
- // Connect via @gjsify/webrtc-native's WebrtcbinBridge — webrtcbin fires
181
- // its signals from the streaming thread, GJS would block direct JS
182
- // callbacks. The bridge hops to the main context on the C side.
183
- this._bridge = new WebrtcbinBridge({ bin: this._webrtcbin });
184
- this._bridge.connect('negotiation-needed', () => this._handleNegotiationNeeded());
185
- this._bridge.connect('icecandidate', (_b, mlineIndex, candidate) =>
186
- this._handleIceCandidate(mlineIndex, candidate));
187
- this._bridge.connect('datachannel', (_b, channelBridge) =>
188
- this._handleDataChannel(channelBridge));
189
- this._bridge.connect('new-transceiver', (_b, gstTrans) =>
190
- this._handleNewTransceiver(gstTrans));
191
- this._bridge.connect('pad-added', (_b, pad) =>
192
- this._handlePadAdded(pad));
193
- this._bridge.connect('connection-state-changed', () =>
194
- this._dispatchStateChange('connectionstatechange'));
195
- this._bridge.connect('ice-connection-state-changed', () =>
196
- this._dispatchStateChange('iceconnectionstatechange'));
197
- this._bridge.connect('ice-gathering-state-changed', () =>
198
- this._dispatchStateChange('icegatheringstatechange'));
199
- this._bridge.connect('signaling-state-changed', () =>
200
- this._dispatchStateChange('signalingstatechange'));
201
-
202
- // webrtcbin needs PLAYING to exit its `is_closed` state before it accepts
203
- // createDataChannel/create-offer etc. (see GStreamer webrtcbin source).
204
- this._pipeline.set_state(Gst.State.PLAYING);
205
- }
206
-
207
- // ---- ICE server / policy config ---------------------------------------
208
-
209
- private _applyIceServers(iceServers: RTCIceServer[]): void {
210
- let stunSet = false;
211
- for (const server of iceServers) {
212
- const urls = Array.isArray(server.urls) ? server.urls : [server.urls];
213
- if (urls.length === 0) {
214
- throw new SyntaxError('RTCIceServer.urls must not be empty');
215
- }
216
- for (const url of urls) {
217
- if (typeof url !== 'string' || url.length === 0) {
218
- throw new TypeError('RTCIceServer.urls entries must be non-empty strings');
219
- }
220
- const colonIdx = url.indexOf(':');
221
- if (colonIdx < 0) {
222
- throw new TypeError(`Invalid ICE server URL "${url}"`);
223
- }
224
- const proto = url.slice(0, colonIdx + 1);
225
- const hostPort = url.slice(colonIdx + 1);
226
-
227
- if (proto === 'stun:' || proto === 'stuns:') {
228
- if (stunSet) continue; // webrtcbin supports only one STUN server
229
- asWebRtcBin(this._webrtcbin).stun_server = `${proto}//${hostPort}`;
230
- stunSet = true;
231
- } else if (proto === 'turn:' || proto === 'turns:') {
232
- if (typeof server.username !== 'string' || typeof server.credential !== 'string') {
233
- throw new TypeError(`TURN server credential for ${url} missing`);
234
- }
235
- const encUser = encodeURIComponent(server.username);
236
- const encCred = encodeURIComponent(server.credential);
237
- const turnUrl = `${proto}//${encUser}:${encCred}@${hostPort}`;
238
- try {
239
- this._webrtcbin.emit('add-turn-server', turnUrl);
240
- } catch {
241
- asWebRtcBin(this._webrtcbin).turn_server = turnUrl;
242
- }
243
- } else {
244
- throw new TypeError(`Unsupported ICE server protocol "${proto}"`);
245
- }
246
- }
247
- }
248
- }
249
-
250
- private _applyIceTransportPolicy(policy?: RTCIceTransportPolicy): void {
251
- if (!policy) return;
252
- const gstPolicy = policy === 'relay'
253
- ? GstWebRTC.WebRTCICETransportPolicy.RELAY
254
- : GstWebRTC.WebRTCICETransportPolicy.ALL;
255
- try { asWebRtcBin(this._webrtcbin).ice_transport_policy = gstPolicy; } catch { /* ignore */ }
256
- }
257
-
258
- private _applyBundlePolicy(policy?: RTCBundlePolicy): void {
259
- if (!policy) return;
260
- let gstPolicy: GstWebRTC.WebRTCBundlePolicy;
261
- switch (policy) {
262
- case 'balanced': gstPolicy = GstWebRTC.WebRTCBundlePolicy.BALANCED; break;
263
- case 'max-compat': gstPolicy = GstWebRTC.WebRTCBundlePolicy.MAX_COMPAT; break;
264
- case 'max-bundle': gstPolicy = GstWebRTC.WebRTCBundlePolicy.MAX_BUNDLE; break;
265
- default: return;
266
- }
267
- try { asWebRtcBin(this._webrtcbin).bundle_policy = gstPolicy; } catch { /* ignore */ }
268
- }
269
-
270
- // ---- Properties --------------------------------------------------------
271
-
272
- get signalingState(): RTCSignalingState {
273
- if (this._closed) return 'closed';
274
- try { return gstToSignalingState(asWebRtcBin(this._webrtcbin).signaling_state); }
275
- catch { return 'stable'; }
276
- }
277
-
278
- get connectionState(): RTCPeerConnectionState {
279
- if (this._closed) return 'closed';
280
- try { return gstToConnectionState(asWebRtcBin(this._webrtcbin).connection_state); }
281
- catch { return 'new'; }
282
- }
283
-
284
- get iceConnectionState(): RTCIceConnectionState {
285
- if (this._closed) return 'closed';
286
- try { return gstToIceConnectionState(asWebRtcBin(this._webrtcbin).ice_connection_state); }
287
- catch { return 'new'; }
288
- }
289
-
290
- get iceGatheringState(): RTCIceGatheringState {
291
- try { return gstToIceGatheringState(asWebRtcBin(this._webrtcbin).ice_gathering_state); }
292
- catch { return 'new'; }
293
- }
294
-
295
- private _descProp(
296
- prop: 'local_description' | 'remote_description'
297
- | 'current_local_description' | 'current_remote_description'
298
- | 'pending_local_description' | 'pending_remote_description',
299
- ): RTCSessionDescription | null {
300
- try {
301
- const desc = asWebRtcBin(this._webrtcbin)[prop];
302
- if (!desc) return null;
303
- return RTCSessionDescription.fromGstDesc(desc);
304
- } catch { return null; }
305
- }
306
-
307
- get localDescription(): RTCSessionDescription | null { return this._descProp('local_description'); }
308
- get remoteDescription(): RTCSessionDescription | null { return this._descProp('remote_description'); }
309
- get currentLocalDescription(): RTCSessionDescription | null { return this._descProp('current_local_description'); }
310
- get currentRemoteDescription(): RTCSessionDescription | null { return this._descProp('current_remote_description'); }
311
- get pendingLocalDescription(): RTCSessionDescription | null { return this._descProp('pending_local_description'); }
312
- get pendingRemoteDescription(): RTCSessionDescription | null { return this._descProp('pending_remote_description'); }
313
-
314
- get sctp(): RTCSctpTransport | null { return this._sctpTransport; }
315
- get peerIdentity(): Promise<never> {
316
- return Promise.reject(new TypeError('peerIdentity assertions are not implemented'));
317
- }
318
- get idpErrorInfo(): null { return null; }
319
- get idpLoginUrl(): null { return null; }
320
-
321
- // ---- Core methods ------------------------------------------------------
322
-
323
- private _rejectIfClosed(method: string): void {
324
- if (!this._closed) return;
325
- throw new DOMException(
326
- `RTCPeerConnection.${method}: connection is closed`,
327
- 'InvalidStateError',
328
- );
329
- }
330
-
331
- async createOffer(_options?: RTCOfferOptions): Promise<RTCSessionDescriptionInit> {
332
- this._rejectIfClosed('createOffer');
333
- const opts = Gst.Structure.new_empty('offer-options');
334
- // If restartIce() was called, request fresh ICE credentials
335
- if (this._iceRestartNeeded) {
336
- this._setStructureField(opts, 'ice-restart', 'boolean', true);
337
- this._iceRestartNeeded = false;
338
- }
339
- const reply = await withGstPromise((p) => {
340
- this._webrtcbin.emit('create-offer', opts, p);
341
- });
342
- // GJS unboxes `get_value` for boxed types directly to the underlying
343
- // struct; no GObject.Value wrapper involvement.
344
- const desc = reply!.get_value('offer') as unknown as GstWebRTC.WebRTCSessionDescription;
345
- return RTCSessionDescription.fromGstDesc(desc).toJSON();
346
- }
347
-
348
- async createAnswer(_options?: RTCAnswerOptions): Promise<RTCSessionDescriptionInit> {
349
- this._rejectIfClosed('createAnswer');
350
- const opts = Gst.Structure.new_empty('answer-options');
351
- const reply = await withGstPromise((p) => {
352
- this._webrtcbin.emit('create-answer', opts, p);
353
- });
354
- const desc = reply!.get_value('answer') as unknown as GstWebRTC.WebRTCSessionDescription;
355
- return RTCSessionDescription.fromGstDesc(desc).toJSON();
356
- }
357
-
358
- async setLocalDescription(description?: RTCSessionDescriptionInit): Promise<void> {
359
- this._rejectIfClosed('setLocalDescription');
360
-
361
- // W3C § 4.4.1.6 — implicit setLocalDescription (perfect negotiation):
362
- // When called without arguments (or with empty type/sdp), auto-create
363
- // the appropriate SDP based on the current signaling state.
364
- if (!description || !description.type || !description.sdp) {
365
- const state = this.signalingState;
366
- if (state === 'stable' || state === 'have-local-offer') {
367
- // Stable → create offer; have-local-offer → rollback + re-offer
368
- description = await this.createOffer();
369
- } else if (state === 'have-remote-offer' || state === 'have-remote-pranswer') {
370
- description = await this.createAnswer();
371
- } else {
372
- throw new DOMException(
373
- `setLocalDescription: cannot auto-create SDP in signalingState '${state}'`,
374
- 'InvalidStateError',
375
- );
376
- }
377
- }
378
-
379
- // On first-time setLocalDescription, the pipeline needs to start running.
380
- this._pipeline.set_state(Gst.State.PLAYING);
381
- const gstDesc = new RTCSessionDescription(description).toGstDesc();
382
- await withGstPromise((p) => {
383
- this._webrtcbin.emit('set-local-description', gstDesc, p);
384
- });
385
- }
386
-
387
- async setRemoteDescription(description: RTCSessionDescriptionInit): Promise<void> {
388
- this._rejectIfClosed('setRemoteDescription');
389
- if (!description || !description.sdp || !description.type) {
390
- throw new TypeError('setRemoteDescription requires an RTCSessionDescriptionInit with sdp and type');
391
- }
392
- this._pipeline.set_state(Gst.State.PLAYING);
393
- const gstDesc = new RTCSessionDescription(description).toGstDesc();
394
- await withGstPromise((p) => {
395
- this._webrtcbin.emit('set-remote-description', gstDesc, p);
396
- });
397
- // Track that at least one negotiation has completed (for restartIce)
398
- if (this.signalingState === 'stable') {
399
- this._hasNegotiated = true;
400
- }
401
- }
402
-
403
- async addIceCandidate(candidate: RTCIceCandidateInit | RTCIceCandidate | null): Promise<void> {
404
- this._rejectIfClosed('addIceCandidate');
405
- if (!candidate) return; // end-of-candidates marker — webrtcbin handles implicitly
406
- const { candidate: cand, sdpMLineIndex } = candidate;
407
- if (typeof cand !== 'string' || typeof sdpMLineIndex !== 'number') return;
408
- this._webrtcbin.emit('add-ice-candidate', sdpMLineIndex, cand);
409
- }
410
-
411
- createDataChannel(label: string, options: RTCDataChannelInit = {}): RTCDataChannel {
412
- if (this._closed) {
413
- throw new DOMException(
414
- 'Cannot create a data channel on a closed RTCPeerConnection',
415
- 'InvalidStateError',
416
- );
417
- }
418
- if (typeof label !== 'string') {
419
- throw new TypeError('createDataChannel: label must be a string');
420
- }
421
- if (new TextEncoder().encode(label).byteLength > 65535) {
422
- throw new TypeError('createDataChannel: label too long (> 65535 bytes)');
423
- }
424
-
425
- // Web-IDL `[EnforceRange] unsigned short` coercion for the three
426
- // numeric options. Input is coerced via ToNumber (so "100" → 100)
427
- // then range-checked against [0, 65535]; any value that can't be
428
- // represented exactly as an unsigned short throws TypeError. Also
429
- // handles WPT's `0` edge case (number) vs `undefined` (no value).
430
- const maxPacketLifeTime = options.maxPacketLifeTime == null
431
- ? undefined
432
- : coerceUnsignedShort('maxPacketLifeTime', options.maxPacketLifeTime);
433
- const maxRetransmits = options.maxRetransmits == null
434
- ? undefined
435
- : coerceUnsignedShort('maxRetransmits', options.maxRetransmits);
436
- const id = options.id == null
437
- ? undefined
438
- : coerceUnsignedShort('id', options.id);
439
-
440
- if (maxPacketLifeTime !== undefined && maxRetransmits !== undefined) {
441
- throw new TypeError('createDataChannel: maxPacketLifeTime and maxRetransmits are mutually exclusive');
442
- }
443
- if (options.negotiated === true && id === undefined) {
444
- throw new TypeError('createDataChannel: negotiated=true requires an id');
445
- }
446
- if (id === 65535) {
447
- // Per RFC 8832 §5.1, id must be < 65535 (65535 is reserved).
448
- throw new TypeError('createDataChannel: id 65535 is reserved');
449
- }
450
-
451
- const gstOpts = Gst.Structure.new_empty('data-channel-opts');
452
- this._setStructureField(gstOpts, 'ordered', 'boolean', options.ordered);
453
- this._setStructureField(gstOpts, 'max-packet-lifetime', 'int', maxPacketLifeTime);
454
- this._setStructureField(gstOpts, 'max-retransmits', 'int', maxRetransmits);
455
- this._setStructureField(gstOpts, 'protocol', 'string', options.protocol);
456
- this._setStructureField(gstOpts, 'negotiated', 'boolean', options.negotiated);
457
- this._setStructureField(gstOpts, 'id', 'int', id);
458
-
459
- let native: GstWebRTC.WebRTCDataChannel | null = null;
460
- try {
461
- // webrtcbin's `create-data-channel` is an action signal that returns
462
- // a `GstWebRTCDataChannel`. The GIR-generated `emit()` overloads
463
- // declare a `void` return for action signals, but at runtime the
464
- // value flows back. Cast through `unknown` to acknowledge the gap.
465
- native = this._webrtcbin.emit('create-data-channel', label, gstOpts) as unknown as GstWebRTC.WebRTCDataChannel | null;
466
- } catch (err: any) {
467
- throw new Error(`create-data-channel failed: ${err?.message ?? err}`);
468
- }
469
- if (!native) {
470
- throw new Error('webrtcbin returned null data channel (check id/label/options)');
471
- }
472
-
473
- // Data channel created → ensure SCTP transport exists
474
- this._ensureSctpTransport();
475
-
476
- const js = new RTCDataChannel(native);
477
- this._dataChannels.set(native, js);
478
- js.addEventListener('close', () => {
479
- this._dataChannels.delete(native);
480
- });
481
- return js;
482
- }
483
-
484
- private _setStructureField(
485
- structure: Gst.Structure,
486
- name: string,
487
- type: 'boolean' | 'int' | 'string',
488
- value: unknown,
489
- ): void {
490
- if (value == null) return;
491
- const gvalue = new GObject.Value();
492
- if (type === 'boolean') {
493
- gvalue.init(GObject.TYPE_BOOLEAN);
494
- gvalue.set_boolean(Boolean(value));
495
- } else if (type === 'int') {
496
- gvalue.init(GObject.TYPE_INT);
497
- gvalue.set_int(Number(value));
498
- } else if (type === 'string') {
499
- gvalue.init(GObject.TYPE_STRING);
500
- gvalue.set_string(String(value));
501
- }
502
- structure.set_value(name, gvalue);
503
- gvalue.unset();
504
- }
505
-
506
- getConfiguration(): RTCConfiguration { return { ...this._conf }; }
507
-
508
- close(): void {
509
- if (this._closed) return;
510
- this._closed = true;
511
- GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
512
- try { this._pipeline.set_state(Gst.State.NULL); } catch { /* ignore */ }
513
- for (const ch of this._dataChannels.values()) {
514
- try { ch._disconnectSignals(); } catch { /* ignore */ }
515
- }
516
- this._dataChannels.clear();
517
- for (const s of this._senders) {
518
- try { s._teardownPipeline(); } catch { /* ignore */ }
519
- }
520
- for (const r of this._receivers) {
521
- try { r._dispose(); } catch { /* ignore */ }
522
- }
523
- this._transceivers.clear();
524
- this._senders.length = 0;
525
- this._receivers.length = 0;
526
- // Close transport objects
527
- if (this._dtlsTransport) this._dtlsTransport._setState('closed');
528
- if (this._iceTransport) this._iceTransport._setState('closed');
529
- if (this._sctpTransport) this._sctpTransport._setState('closed');
530
- try { this._bridge.dispose_bridge(); } catch { /* ignore */ }
531
- return GLib.SOURCE_REMOVE;
532
- });
533
- }
534
-
535
- // ---- Media / Transceiver API (Phase 2) ----------------------------------
536
-
537
- addTransceiver(
538
- trackOrKind: MediaStreamTrack | string,
539
- init?: RTCRtpTransceiverInit,
540
- ): RTCRtpTransceiver {
541
- this._rejectIfClosed('addTransceiver');
542
-
543
- let kind: 'audio' | 'video';
544
- if (typeof trackOrKind === 'string') {
545
- if (trackOrKind !== 'audio' && trackOrKind !== 'video') {
546
- throw new TypeError(
547
- `Failed to execute 'addTransceiver' on 'RTCPeerConnection': The provided value '${trackOrKind}' is not a valid enum value of type MediaStreamTrackKind.`,
548
- );
549
- }
550
- kind = trackOrKind;
551
- } else if (trackOrKind instanceof MediaStreamTrack) {
552
- kind = trackOrKind.kind;
553
- } else {
554
- throw new TypeError(
555
- "Failed to execute 'addTransceiver' on 'RTCPeerConnection': parameter 1 is not of type 'MediaStreamTrack' or a valid MediaStreamTrackKind.",
556
- );
557
- }
558
-
559
- if (init?.sendEncodings) {
560
- const rids = new Set<string>();
561
- for (const enc of init.sendEncodings) {
562
- if (enc.rid !== undefined) {
563
- if (typeof enc.rid !== 'string' || enc.rid.length === 0 || enc.rid.length > 16 || !/^[a-zA-Z0-9]+$/.test(enc.rid)) {
564
- throw new TypeError(`Invalid RID value: ${enc.rid}`);
565
- }
566
- if (rids.has(enc.rid)) {
567
- throw new TypeError(`Duplicate RID: ${enc.rid}`);
568
- }
569
- rids.add(enc.rid);
570
- }
571
- if (enc.scaleResolutionDownBy !== undefined && enc.scaleResolutionDownBy < 1.0) {
572
- throw new RangeError('scaleResolutionDownBy must be >= 1.0');
573
- }
574
- }
575
- }
576
-
577
- const direction = init?.direction ?? 'sendrecv';
578
- const validDirections = ['sendrecv', 'sendonly', 'recvonly', 'inactive'];
579
- if (!validDirections.includes(direction)) {
580
- throw new TypeError(
581
- `Failed to execute 'addTransceiver' on 'RTCPeerConnection': The provided value '${direction}' is not a valid enum value of type RTCRtpTransceiverDirection.`,
582
- );
583
- }
584
- const hasGstSource = trackOrKind instanceof MediaStreamTrack && trackOrKind._gstSource;
585
- const wantsSend = direction === 'sendrecv' || direction === 'sendonly';
586
-
587
- let gstTrans: GstWebRTC.WebRTCRTPTransceiver;
588
- let jsTrans: RTCRtpTransceiver;
589
-
590
- if (hasGstSource && wantsSend) {
591
- // Path A: Track has a GStreamer source and needs to send.
592
- // Requesting a sink pad from webrtcbin implicitly creates both
593
- // the pad AND the transceiver. Using emit('add-transceiver')
594
- // would create a duplicate with mline=-1.
595
- const track = trackOrKind as MediaStreamTrack;
596
-
597
- // Build encoder chain, link to webrtcbin via request_pad_simple
598
- const sender = new RTCRtpSender(null, this._pipeline, this._webrtcbin);
599
- sender._kind = kind;
600
- // Allow sender to update our pipeline if it migrates to a VideoBridge pipeline
601
- sender._onPipelineChanged = (newPipeline) => { this._pipeline = newPipeline; };
602
- sender._setTrack(track);
603
- sender._wirePipeline(track);
604
-
605
- // Find the GstTransceiver that request_pad_simple created
606
- const found = this._findNewGstTransceiver();
607
- if (!found) {
608
- throw new Error('webrtcbin did not create a transceiver for the send pad');
609
- }
610
- gstTrans = found;
611
-
612
- // Create wrapper with the pre-wired sender
613
- const gstReceiver = gstTrans.receiver ?? null;
614
- const receiver = new RTCRtpReceiver(kind, gstReceiver, this._pipeline);
615
-
616
- // Wire stats delegation + transport
617
- const statsDelegate = (t: MediaStreamTrack) => this.getStats(t);
618
- sender._getStatsForTrack = statsDelegate;
619
- receiver._getStatsForTrack = statsDelegate;
620
- const dtls = this._ensureTransports();
621
- sender._transport = dtls;
622
- receiver._transport = dtls;
623
-
624
- jsTrans = new RTCRtpTransceiver(gstTrans, sender, receiver);
625
- sender._transceiver = jsTrans;
626
- this._transceivers.set(gstTrans, jsTrans);
627
- this._senders.push(sender);
628
- this._receivers.push(receiver);
629
-
630
- // Apply direction
631
- gstTrans.direction = w3cDirectionToGst(direction);
632
- } else {
633
- // Path B: No GStreamer source, or receive-only/inactive.
634
- // Use emit('add-transceiver') which creates a transceiver without pads.
635
- const caps = Gst.Caps.from_string(`application/x-rtp,media=${kind}`);
636
- // webrtcbin doesn't accept NONE for add-transceiver; use SENDRECV
637
- // and override to inactive after creation.
638
- const createDirection = direction === 'inactive'
639
- ? w3cDirectionToGst('sendrecv')
640
- : w3cDirectionToGst(direction);
641
-
642
- // `add-transceiver` is an action signal returning the new
643
- // GstWebRTCRTPTransceiver — see comment on `create-data-channel` above.
644
- const result = this._webrtcbin.emit('add-transceiver', createDirection, caps) as unknown as GstWebRTC.WebRTCRTPTransceiver | null;
645
- if (!result) {
646
- throw new Error('webrtcbin did not create a transceiver');
647
- }
648
- gstTrans = result;
649
-
650
- jsTrans = this._transceivers.get(gstTrans)!;
651
- if (!jsTrans) {
652
- jsTrans = this._createTransceiverWrapper(gstTrans);
653
- }
654
-
655
- gstTrans.direction = w3cDirectionToGst(direction);
656
-
657
- if (trackOrKind instanceof MediaStreamTrack) {
658
- jsTrans.sender._setTrack(trackOrKind);
659
- }
660
- }
661
-
662
- return jsTrans;
663
- }
664
-
665
- addTrack(track: MediaStreamTrack, ..._streams: MediaStream[]): RTCRtpSender {
666
- this._rejectIfClosed('addTrack');
667
-
668
- if (!(track instanceof MediaStreamTrack)) {
669
- throw new TypeError(
670
- "Failed to execute 'addTrack' on 'RTCPeerConnection': parameter 1 is not a MediaStreamTrack",
671
- );
672
- }
673
-
674
- // Check if this track is already assigned to a sender
675
- const existing = this._senders.find(s => s.track === track);
676
- if (existing) {
677
- throw new DOMException(
678
- 'Track already exists in a sender of this connection',
679
- 'InvalidAccessError',
680
- );
681
- }
682
-
683
- // Look for a reusable transceiver (matching kind, no track, recvonly/inactive)
684
- let reusable: RTCRtpTransceiver | undefined;
685
- for (const t of this._transceivers.values()) {
686
- if (
687
- t.sender.track === null &&
688
- !t.stopped &&
689
- t.direction !== 'stopped' &&
690
- t.receiver.track.kind === track.kind
691
- ) {
692
- const dir = t.direction;
693
- if (dir === 'recvonly' || dir === 'inactive') {
694
- reusable = t;
695
- break;
696
- }
697
- }
698
- }
699
-
700
- if (reusable) {
701
- // Expand direction to include send
702
- const dir = reusable.direction;
703
- reusable.direction = dir === 'recvonly' ? 'sendrecv' : 'sendonly';
704
- reusable.sender._setTrack(track);
705
- // Note: _wirePipeline is NOT called here for reusable transceivers.
706
- // Tracks with GStreamer sources will be handled by addTransceiver Path A
707
- // if no reusable transceiver exists, or the pipeline will be wired
708
- // when webrtcbin creates the sink pad during SDP negotiation.
709
- return reusable.sender;
710
- }
711
-
712
- // Create a new transceiver — addTransceiver handles both _setTrack
713
- // and _wirePipeline for tracks with GStreamer sources (Path A).
714
- const transceiver = this.addTransceiver(track, { direction: 'sendrecv' });
715
- return transceiver.sender;
716
- }
717
-
718
- removeTrack(sender: RTCRtpSender): void {
719
- this._rejectIfClosed('removeTrack');
720
- if (!this._senders.includes(sender)) {
721
- throw new DOMException(
722
- 'sender was not created by this connection',
723
- 'InvalidAccessError',
724
- );
725
- }
726
- sender._setTrack(null);
727
- }
728
-
729
- getSenders(): RTCRtpSender[] { return [...this._senders]; }
730
- getReceivers(): RTCRtpReceiver[] { return [...this._receivers]; }
731
- getTransceivers(): RTCRtpTransceiver[] { return [...this._transceivers.values()]; }
732
-
733
- async getStats(selector?: MediaStreamTrack | null): Promise<RTCStatsReport> {
734
- this._rejectIfClosed('getStats');
735
-
736
- // Validate selector — if a track is given, it must belong to a sender or receiver
737
- if (selector != null && selector instanceof MediaStreamTrack) {
738
- const hasSender = this._senders.some(s => s.track === selector);
739
- const hasReceiver = this._receivers.some(r => r.track === selector);
740
- if (!hasSender && !hasReceiver) {
741
- throw new DOMException(
742
- 'The selector track is not associated with a sender or receiver of this connection',
743
- 'InvalidAccessError',
744
- );
745
- }
746
- }
747
-
748
- const reply = await withGstPromise((p) => {
749
- this._webrtcbin.emit('get-stats', null, p);
750
- });
751
-
752
- const report = parseGstStats(reply);
753
-
754
- // If a track selector was provided, filter to relevant stats
755
- if (selector != null && selector instanceof MediaStreamTrack) {
756
- return filterStatsByTrackId(report, selector.id);
757
- }
758
-
759
- return report;
760
- }
761
-
762
- // ---- ICE restart / reconfiguration (Phase 4.4) ---------------------------
763
-
764
- restartIce(): void {
765
- if (this._closed) return; // no-op on closed connections per spec
766
- this._iceRestartNeeded = true;
767
- // Only fire negotiationneeded if we've completed at least one negotiation.
768
- // Before initial negotiation, restartIce has no observable effect.
769
- if (this._hasNegotiated) {
770
- // Fire asynchronously per spec (queued as a microtask)
771
- Promise.resolve().then(() => {
772
- if (this._closed) return;
773
- this._handleNegotiationNeeded();
774
- });
775
- }
776
- }
777
-
778
- setConfiguration(configuration: RTCConfiguration): void {
779
- this._rejectIfClosed('setConfiguration');
780
-
781
- // Per spec: bundlePolicy and rtcpMuxPolicy cannot change after construction
782
- if (configuration.bundlePolicy && configuration.bundlePolicy !== (this._conf.bundlePolicy ?? 'balanced')) {
783
- throw new DOMException(
784
- 'setConfiguration: bundlePolicy cannot be changed',
785
- 'InvalidModificationError',
786
- );
787
- }
788
- if (configuration.rtcpMuxPolicy && configuration.rtcpMuxPolicy !== (this._conf.rtcpMuxPolicy ?? 'require')) {
789
- throw new DOMException(
790
- 'setConfiguration: rtcpMuxPolicy cannot be changed',
791
- 'InvalidModificationError',
792
- );
793
- }
794
-
795
- // Apply new ICE servers
796
- if (configuration.iceServers) {
797
- this._applyIceServers(configuration.iceServers);
798
- }
799
- // Apply new ICE transport policy
800
- if (configuration.iceTransportPolicy) {
801
- this._applyIceTransportPolicy(configuration.iceTransportPolicy);
802
- }
803
-
804
- this._conf = { ...this._conf, ...configuration };
805
- }
806
- getIdentityAssertion(): Promise<never> {
807
- return Promise.reject(new Error('getIdentityAssertion is not implemented'));
808
- }
809
-
810
- // ---- Transceiver helper -------------------------------------------------
811
-
812
- /** Find a GstWebRTCRTPTransceiver not yet in our map (created by request_pad_simple). */
813
- private _findNewGstTransceiver(): GstWebRTC.WebRTCRTPTransceiver | null {
814
- for (let i = 0; ; i++) {
815
- // `get-transceiver` is an action signal — return value flows back at
816
- // runtime even though the GIR `emit()` overload is typed `void`.
817
- const gt = this._webrtcbin.emit('get-transceiver', i) as unknown as GstWebRTC.WebRTCRTPTransceiver | null;
818
- if (!gt) return null;
819
- if (!this._transceivers.has(gt)) return gt;
820
- }
821
- }
822
-
823
- /** Lazily create the shared DTLS and ICE transport instances (max-bundle → one pair). */
824
- private _ensureTransports(): RTCDtlsTransport {
825
- if (!this._dtlsTransport) {
826
- this._iceTransport = new RTCIceTransport();
827
- this._dtlsTransport = new RTCDtlsTransport(this._iceTransport);
828
- }
829
- return this._dtlsTransport;
830
- }
831
-
832
- /** Create the SCTP transport when a data channel is first negotiated. */
833
- private _ensureSctpTransport(): void {
834
- if (this._sctpTransport) return;
835
- const dtls = this._ensureTransports();
836
- this._sctpTransport = new RTCSctpTransport(dtls);
837
- }
838
-
839
- private _createTransceiverWrapper(gstTrans: GstWebRTC.WebRTCRTPTransceiver): RTCRtpTransceiver {
840
- let kind: 'audio' | 'video' = 'audio';
841
- try {
842
- const gstKind = gstTrans.kind;
843
- if (gstKind === GstWebRTC.WebRTCKind.VIDEO) kind = 'video';
844
- } catch { /* default audio */ }
845
-
846
- const gstReceiver = gstTrans.receiver ?? null;
847
- const gstSender = gstTrans.sender ?? null;
848
-
849
- const receiver = new RTCRtpReceiver(kind, gstReceiver, this._pipeline);
850
- const sender = new RTCRtpSender(gstSender, this._pipeline, this._webrtcbin);
851
- sender._kind = kind;
852
- sender._onPipelineChanged = (newPipeline) => { this._pipeline = newPipeline; };
853
-
854
- // Wire stats delegation so sender.getStats() / receiver.getStats() work
855
- const statsDelegate = (track: MediaStreamTrack) => this.getStats(track);
856
- sender._getStatsForTrack = statsDelegate;
857
- receiver._getStatsForTrack = statsDelegate;
858
-
859
- // Assign shared DTLS transport to sender/receiver
860
- const dtls = this._ensureTransports();
861
- sender._transport = dtls;
862
- receiver._transport = dtls;
863
-
864
- // Pass mline index to sender for sink pad naming
865
- try {
866
- const mline = gstTrans.mlineindex;
867
- if (typeof mline === 'number' && mline >= 0) {
868
- sender._setMlineIndex(mline);
869
- }
870
- } catch { /* ignore */ }
871
-
872
- const transceiver = new RTCRtpTransceiver(gstTrans, sender, receiver);
873
- sender._transceiver = transceiver;
874
-
875
- this._transceivers.set(gstTrans, transceiver);
876
- this._senders.push(sender);
877
- this._receivers.push(receiver);
878
- return transceiver;
879
- }
880
-
881
- // ---- Signal handlers ---------------------------------------------------
882
- // The WebrtcbinBridge (webrtc-native) has already marshalled these from
883
- // the GStreamer streaming thread onto the GLib main context, so we can
884
- // synchronously dispatch from here.
885
-
886
- private _handleNegotiationNeeded(): void {
887
- const ev = new Event('negotiationneeded');
888
- this._onnegotiationneeded?.call(this, ev);
889
- this.dispatchEvent(ev);
890
- }
891
-
892
- private _handleIceCandidate(sdpMLineIndex: number, candidate: string): void {
893
- const cand = new RTCIceCandidate({ candidate, sdpMLineIndex });
894
- const ev = new RTCPeerConnectionIceEvent('icecandidate', { candidate: cand });
895
- this._onicecandidate?.call(this, ev);
896
- this.dispatchEvent(ev);
897
- }
898
-
899
- private _handleNewTransceiver(gstTrans: GstWebRTC.WebRTCRTPTransceiver): void {
900
- if (this._closed) return;
901
- if (this._transceivers.has(gstTrans)) return;
902
- this._createTransceiverWrapper(gstTrans);
903
- }
904
-
905
- private _handlePadAdded(pad: Gst.Pad): void {
906
- if (this._closed) return;
907
- // Only process SRC pads (incoming media from remote peer)
908
- if (pad.direction !== Gst.PadDirection.SRC) return;
909
-
910
- const gstTrans = asWebRtcSrcPad(pad).transceiver;
911
- if (!gstTrans) return;
912
-
913
- let jsTrans = this._transceivers.get(gstTrans);
914
- if (!jsTrans) {
915
- jsTrans = this._createTransceiverWrapper(gstTrans);
916
- }
917
-
918
- // Phase 2.5: wire incoming media through ReceiverBridge (decodebin → tee)
919
- jsTrans.receiver._connectToPad(pad);
920
-
921
- const stream = new MediaStream([jsTrans.receiver.track]);
922
- const ev = new RTCTrackEvent('track', {
923
- receiver: jsTrans.receiver,
924
- track: jsTrans.receiver.track,
925
- streams: [stream],
926
- transceiver: jsTrans,
927
- });
928
- this._ontrack?.call(this, ev);
929
- this.dispatchEvent(ev);
930
- }
931
-
932
- private _handleDataChannel(channelBridge: DataChannelBridgeType): void {
933
- this._ensureSctpTransport();
934
- const native = channelBridge.channel as unknown as GstWebRTC.WebRTCDataChannel;
935
- let js = this._dataChannels.get(native);
936
- if (!js) {
937
- js = new RTCDataChannel(channelBridge);
938
- this._dataChannels.set(native, js);
939
- js.addEventListener('close', () => {
940
- this._dataChannels.delete(native);
941
- });
942
- }
943
- const ev = new RTCDataChannelEvent('datachannel', { channel: js });
944
- this._ondatachannel?.call(this, ev);
945
- this.dispatchEvent(ev);
946
- }
947
-
948
- private _dispatchStateChange(type: string): void {
949
- // Sync transport object states from webrtcbin before dispatching
950
- if (type === 'connectionstatechange') {
951
- this._syncDtlsState();
952
- } else if (type === 'iceconnectionstatechange') {
953
- this._syncIceState();
954
- } else if (type === 'icegatheringstatechange') {
955
- this._syncIceGatheringState();
956
- }
957
-
958
- const ev = new Event(type);
959
- switch (type) {
960
- case 'connectionstatechange': this._onconnectionstatechange?.call(this, ev); break;
961
- case 'iceconnectionstatechange': this._oniceconnectionstatechange?.call(this, ev); break;
962
- case 'icegatheringstatechange': this._onicegatheringstatechange?.call(this, ev); break;
963
- case 'signalingstatechange': this._onsignalingstatechange?.call(this, ev); break;
964
- }
965
- this.dispatchEvent(ev);
966
- }
967
-
968
- /** Map PC connection state → DTLS transport state. */
969
- private _syncDtlsState(): void {
970
- if (!this._dtlsTransport) return;
971
- const pcState = this.connectionState;
972
- const dtlsMap: Record<string, 'new' | 'connecting' | 'connected' | 'closed' | 'failed'> = {
973
- 'new': 'new',
974
- 'connecting': 'connecting',
975
- 'connected': 'connected',
976
- 'disconnected': 'connected', // DTLS stays connected even if ICE disconnects
977
- 'failed': 'failed',
978
- 'closed': 'closed',
979
- };
980
- this._dtlsTransport._setState(dtlsMap[pcState] ?? 'new');
981
-
982
- // Connected DTLS → SCTP connected
983
- if (pcState === 'connected' && this._sctpTransport) {
984
- this._sctpTransport._setState('connected');
985
- }
986
- }
987
-
988
- /** Map PC ICE connection state → ICE transport state. */
989
- private _syncIceState(): void {
990
- if (!this._iceTransport) return;
991
- const iceState = this.iceConnectionState;
992
- // RTCIceConnectionState ≡ RTCIceTransportState (same string union).
993
- this._iceTransport._setState(iceState);
994
- }
995
-
996
- /** Map PC ICE gathering state → ICE transport gathering state. */
997
- private _syncIceGatheringState(): void {
998
- if (!this._iceTransport) return;
999
- const gatheringState = this.iceGatheringState;
1000
- this._iceTransport._setGatheringState(gatheringState);
1001
- }
1002
-
1003
- // ---- on<event> attribute handlers --------------------------------------
1004
-
1005
- private _onconnectionstatechange: EventHandler = null;
1006
- private _ondatachannel: EventHandler<RTCDataChannelEvent> = null;
1007
- private _onicecandidate: EventHandler<RTCPeerConnectionIceEvent> = null;
1008
- private _oniceconnectionstatechange: EventHandler = null;
1009
- private _onicegatheringstatechange: EventHandler = null;
1010
- private _onnegotiationneeded: EventHandler = null;
1011
- private _onsignalingstatechange: EventHandler = null;
1012
-
1013
- get onconnectionstatechange() { return this._onconnectionstatechange; }
1014
- set onconnectionstatechange(v: EventHandler) { this._onconnectionstatechange = v; }
1015
- get ondatachannel() { return this._ondatachannel; }
1016
- set ondatachannel(v: EventHandler<RTCDataChannelEvent>) { this._ondatachannel = v; }
1017
- get onicecandidate() { return this._onicecandidate; }
1018
- set onicecandidate(v: EventHandler<RTCPeerConnectionIceEvent>) { this._onicecandidate = v; }
1019
- get oniceconnectionstatechange() { return this._oniceconnectionstatechange; }
1020
- set oniceconnectionstatechange(v: EventHandler) { this._oniceconnectionstatechange = v; }
1021
- get onicegatheringstatechange() { return this._onicegatheringstatechange; }
1022
- set onicegatheringstatechange(v: EventHandler) { this._onicegatheringstatechange = v; }
1023
- get onnegotiationneeded() { return this._onnegotiationneeded; }
1024
- set onnegotiationneeded(v: EventHandler) { this._onnegotiationneeded = v; }
1025
- get onsignalingstatechange() { return this._onsignalingstatechange; }
1026
- set onsignalingstatechange(v: EventHandler) { this._onsignalingstatechange = v; }
1027
-
1028
- private _ontrack: EventHandler<RTCTrackEvent> = null;
1029
- get ontrack() { return this._ontrack; }
1030
- set ontrack(v: EventHandler<RTCTrackEvent>) { this._ontrack = v; }
1031
- get onicecandidateerror(): EventHandler { return null; }
1032
- set onicecandidateerror(_v: EventHandler) { /* no-op */ }
1033
-
1034
- // ---- Certificate management (Phase 4.7) --------------------------------
1035
-
1036
- static generateCertificate(keygenAlgorithm: AlgorithmIdentifier): Promise<RTCCertificate> {
1037
- return generateCertificate(keygenAlgorithm);
1038
- }
1039
- }