@gjsify/webrtc 0.4.0 → 0.4.4
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/package.json +73 -70
- package/src/get-user-media.ts +0 -131
- package/src/gst-enum-maps.ts +0 -125
- package/src/gst-init.ts +0 -49
- package/src/gst-stats-parser.ts +0 -137
- package/src/gst-utils.ts +0 -41
- package/src/index.ts +0 -104
- package/src/internal/gst-types.ts +0 -122
- package/src/media-device-info.ts +0 -33
- package/src/media-devices.ts +0 -191
- package/src/media-stream-track.ts +0 -159
- package/src/media-stream.ts +0 -96
- package/src/register/data-channel.ts +0 -11
- package/src/register/error.ts +0 -11
- package/src/register/media-devices.ts +0 -10
- package/src/register/media.ts +0 -15
- package/src/register/peer-connection.ts +0 -20
- package/src/register.spec.ts +0 -55
- package/src/register.ts +0 -10
- package/src/rtc-certificate.ts +0 -110
- package/src/rtc-data-channel.ts +0 -283
- package/src/rtc-dtls-transport.ts +0 -48
- package/src/rtc-dtmf-sender.ts +0 -146
- package/src/rtc-error.ts +0 -49
- package/src/rtc-events.ts +0 -64
- package/src/rtc-ice-candidate.ts +0 -115
- package/src/rtc-ice-transport.ts +0 -104
- package/src/rtc-peer-connection.ts +0 -1039
- package/src/rtc-rtp-receiver.ts +0 -122
- package/src/rtc-rtp-sender.ts +0 -471
- package/src/rtc-rtp-transceiver.ts +0 -131
- package/src/rtc-sctp-transport.ts +0 -48
- package/src/rtc-session-description.ts +0 -64
- package/src/rtc-stats-report.ts +0 -39
- package/src/rtc-track-event.ts +0 -45
- package/src/rtp-capabilities.ts +0 -48
- package/src/tee-multiplexer.ts +0 -75
- package/src/test.mts +0 -11
- package/src/webrtc.spec.ts +0 -1186
- package/src/wpt-helpers.ts +0 -156
- package/src/wpt-media.spec.ts +0 -1154
- package/src/wpt.spec.ts +0 -1136
- package/tsconfig.json +0 -36
- package/tsconfig.tsbuildinfo +0 -1
package/src/wpt-helpers.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
// Helpers for WPT-ported tests.
|
|
2
|
-
//
|
|
3
|
-
// Ported from: refs/wpt/webrtc/RTCPeerConnection-helper.js (W3C, BSD-3-Clause)
|
|
4
|
-
// The originals use browser globals and the testharness.js framework; here
|
|
5
|
-
// we bind them to @gjsify/webrtc's named exports so the test can run under
|
|
6
|
-
// @gjsify/unit on GJS.
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
RTCPeerConnection,
|
|
10
|
-
type RTCDataChannel,
|
|
11
|
-
type RTCDataChannelInit,
|
|
12
|
-
type RTCSessionDescriptionInit,
|
|
13
|
-
} from './index.js';
|
|
14
|
-
|
|
15
|
-
/** Mirror WPT's `createPeerConnectionWithCleanup` — returns a fresh pc. */
|
|
16
|
-
export function createPeerConnection(): RTCPeerConnection {
|
|
17
|
-
return new RTCPeerConnection();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Mirror WPT's `exchangeOfferAnswer(pc1, pc2)` + `exchangeIceCandidates`.
|
|
22
|
-
* Runs the full handshake to completion.
|
|
23
|
-
*/
|
|
24
|
-
export async function exchangeOfferAnswer(
|
|
25
|
-
pc1: RTCPeerConnection,
|
|
26
|
-
pc2: RTCPeerConnection,
|
|
27
|
-
): Promise<void> {
|
|
28
|
-
// Late-arriving ICE candidates may fire after the other peer has already
|
|
29
|
-
// been closed; swallow the InvalidStateError so it doesn't become an
|
|
30
|
-
// unhandled rejection during test teardown.
|
|
31
|
-
pc1.onicecandidate = (ev) => {
|
|
32
|
-
if (ev.candidate) pc2.addIceCandidate(ev.candidate.toJSON()).catch(() => {});
|
|
33
|
-
};
|
|
34
|
-
pc2.onicecandidate = (ev) => {
|
|
35
|
-
if (ev.candidate) pc1.addIceCandidate(ev.candidate.toJSON()).catch(() => {});
|
|
36
|
-
};
|
|
37
|
-
const offer = (await pc1.createOffer()) as RTCSessionDescriptionInit;
|
|
38
|
-
await pc1.setLocalDescription(offer);
|
|
39
|
-
await pc2.setRemoteDescription(offer);
|
|
40
|
-
const answer = (await pc2.createAnswer()) as RTCSessionDescriptionInit;
|
|
41
|
-
await pc2.setLocalDescription(answer);
|
|
42
|
-
await pc1.setRemoteDescription(answer);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Port of WPT `createDataChannelPair(t, options, pc1, pc2)` — returns
|
|
47
|
-
* `[dc1, dc2]` both in `'open'` state, handshake complete. If `options.negotiated`
|
|
48
|
-
* both sides pre-create the channel with matching id; otherwise pc1 creates
|
|
49
|
-
* and pc2 receives via `ondatachannel`.
|
|
50
|
-
*/
|
|
51
|
-
export async function createDataChannelPair(
|
|
52
|
-
options: RTCDataChannelInit = {},
|
|
53
|
-
pc1: RTCPeerConnection = createPeerConnection(),
|
|
54
|
-
pc2: RTCPeerConnection = createPeerConnection(),
|
|
55
|
-
label = 'wpt',
|
|
56
|
-
): Promise<[RTCDataChannel, RTCDataChannel, RTCPeerConnection, RTCPeerConnection]> {
|
|
57
|
-
let pair: [RTCDataChannel, RTCDataChannel];
|
|
58
|
-
let bothOpen: Promise<unknown>;
|
|
59
|
-
|
|
60
|
-
if (options.negotiated) {
|
|
61
|
-
const dc1 = pc1.createDataChannel(label, options);
|
|
62
|
-
const dc2 = pc2.createDataChannel(label, options);
|
|
63
|
-
pair = [dc1, dc2];
|
|
64
|
-
bothOpen = Promise.all(pair.map((dc) => new Promise<void>((res, rej) => {
|
|
65
|
-
if (dc.readyState === 'open') return res();
|
|
66
|
-
dc.onopen = () => res();
|
|
67
|
-
dc.onerror = (ev: any) => rej(ev?.error ?? new Error('onerror'));
|
|
68
|
-
})));
|
|
69
|
-
} else {
|
|
70
|
-
const dc1 = pc1.createDataChannel(label, options);
|
|
71
|
-
bothOpen = Promise.all([
|
|
72
|
-
new Promise<void>((res, rej) => {
|
|
73
|
-
if (dc1.readyState === 'open') return res();
|
|
74
|
-
dc1.onopen = () => res();
|
|
75
|
-
dc1.onerror = (ev: any) => rej(ev?.error ?? new Error('onerror'));
|
|
76
|
-
}),
|
|
77
|
-
new Promise<RTCDataChannel>((res, rej) => {
|
|
78
|
-
pc2.ondatachannel = (ev) => {
|
|
79
|
-
const dc2 = ev.channel;
|
|
80
|
-
if (dc2.readyState === 'open') return res(dc2);
|
|
81
|
-
dc2.onopen = () => res(dc2);
|
|
82
|
-
dc2.onerror = (e: any) => rej(e?.error ?? new Error('onerror'));
|
|
83
|
-
};
|
|
84
|
-
}).then((dc2) => { pair[1] = dc2; }),
|
|
85
|
-
]);
|
|
86
|
-
pair = [dc1, undefined as unknown as RTCDataChannel];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
await exchangeOfferAnswer(pc1, pc2);
|
|
90
|
-
await bothOpen;
|
|
91
|
-
return [pair[0], pair[1], pc1, pc2];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** Port of WPT `awaitMessage(channel)` — resolves with the next incoming data. */
|
|
95
|
-
export function awaitMessage<T = unknown>(channel: RTCDataChannel): Promise<T> {
|
|
96
|
-
return new Promise<T>((resolve, reject) => {
|
|
97
|
-
const messageHandler = (ev: MessageEvent) => {
|
|
98
|
-
channel.removeEventListener('message', messageHandler);
|
|
99
|
-
channel.removeEventListener('error', errorHandler);
|
|
100
|
-
resolve(ev.data as T);
|
|
101
|
-
};
|
|
102
|
-
const errorHandler = (ev: any) => {
|
|
103
|
-
channel.removeEventListener('message', messageHandler);
|
|
104
|
-
channel.removeEventListener('error', errorHandler);
|
|
105
|
-
reject(ev?.error ?? new Error('channel error'));
|
|
106
|
-
};
|
|
107
|
-
channel.addEventListener('message', messageHandler);
|
|
108
|
-
channel.addEventListener('error', errorHandler);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Mirror WPT's `EventWatcher(t, target, events)` — accumulates events in
|
|
114
|
-
* order and returns `wait_for(types)` that matches the expected sequence.
|
|
115
|
-
*/
|
|
116
|
-
export class EventWatcher {
|
|
117
|
-
private _events: string[] = [];
|
|
118
|
-
private _waiters: Array<{ types: string[]; resolve: () => void; reject: (e: Error) => void }> = [];
|
|
119
|
-
|
|
120
|
-
constructor(target: EventTarget, eventTypes: string[]) {
|
|
121
|
-
for (const type of eventTypes) {
|
|
122
|
-
target.addEventListener(type, () => {
|
|
123
|
-
this._events.push(type);
|
|
124
|
-
this._tryResolve();
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
wait_for(expected: string | string[]): Promise<void> {
|
|
130
|
-
const types = Array.isArray(expected) ? expected : [expected];
|
|
131
|
-
return new Promise((resolve, reject) => {
|
|
132
|
-
this._waiters.push({ types, resolve, reject });
|
|
133
|
-
this._tryResolve();
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
private _tryResolve(): void {
|
|
138
|
-
while (this._waiters.length > 0 && this._events.length >= this._waiters[0].types.length) {
|
|
139
|
-
const waiter = this._waiters.shift()!;
|
|
140
|
-
const got = this._events.splice(0, waiter.types.length);
|
|
141
|
-
const matches = waiter.types.every((t, i) => got[i] === t);
|
|
142
|
-
if (matches) {
|
|
143
|
-
waiter.resolve();
|
|
144
|
-
} else {
|
|
145
|
-
waiter.reject(new Error(`EventWatcher: expected ${JSON.stringify(waiter.types)}, got ${JSON.stringify(got)}`));
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/** Close an array of RTCPeerConnection instances, ignoring errors. */
|
|
152
|
-
export function closePeerConnections(...pcs: (RTCPeerConnection | undefined)[]): void {
|
|
153
|
-
for (const pc of pcs) {
|
|
154
|
-
try { pc?.close(); } catch { /* ignore */ }
|
|
155
|
-
}
|
|
156
|
-
}
|