@gjsify/webrtc 0.3.12 → 0.3.14

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 (36) hide show
  1. package/lib/esm/get-user-media.js +95 -80
  2. package/lib/esm/gst-enum-maps.js +55 -59
  3. package/lib/esm/gst-init.js +19 -22
  4. package/lib/esm/gst-stats-parser.js +94 -67
  5. package/lib/esm/gst-utils.js +24 -13
  6. package/lib/esm/index.js +13 -43
  7. package/lib/esm/media-device-info.js +23 -22
  8. package/lib/esm/media-devices.js +150 -139
  9. package/lib/esm/media-stream-track.js +136 -139
  10. package/lib/esm/media-stream.js +76 -75
  11. package/lib/esm/register/data-channel.js +7 -3
  12. package/lib/esm/register/error.js +6 -2
  13. package/lib/esm/register/media-devices.js +6 -2
  14. package/lib/esm/register/media.js +8 -4
  15. package/lib/esm/register/peer-connection.js +9 -5
  16. package/lib/esm/rtc-certificate.js +62 -66
  17. package/lib/esm/rtc-data-channel.js +240 -251
  18. package/lib/esm/rtc-dtls-transport.js +40 -39
  19. package/lib/esm/rtc-dtmf-sender.js +92 -100
  20. package/lib/esm/rtc-error.js +24 -22
  21. package/lib/esm/rtc-events.js +33 -33
  22. package/lib/esm/rtc-ice-candidate.js +71 -72
  23. package/lib/esm/rtc-ice-transport.js +95 -94
  24. package/lib/esm/rtc-peer-connection.js +796 -845
  25. package/lib/esm/rtc-rtp-receiver.js +89 -87
  26. package/lib/esm/rtc-rtp-sender.js +282 -290
  27. package/lib/esm/rtc-rtp-transceiver.js +92 -93
  28. package/lib/esm/rtc-sctp-transport.js +38 -38
  29. package/lib/esm/rtc-session-description.js +47 -51
  30. package/lib/esm/rtc-stats-report.js +39 -34
  31. package/lib/esm/rtc-track-event.js +29 -27
  32. package/lib/esm/rtp-capabilities.js +81 -35
  33. package/lib/esm/tee-multiplexer.js +58 -60
  34. package/lib/esm/wpt-helpers.js +128 -112
  35. package/package.json +13 -13
  36. package/tsconfig.tsbuildinfo +1 -1
@@ -1,41 +1,42 @@
1
1
  import "@gjsify/dom-events/register/event-target";
2
- class RTCDtlsTransport extends EventTarget {
3
- iceTransport;
4
- _state = "new";
5
- _onstatechange = null;
6
- _onerror = null;
7
- constructor(iceTransport) {
8
- super();
9
- this.iceTransport = iceTransport;
10
- }
11
- get state() {
12
- return this._state;
13
- }
14
- get onstatechange() {
15
- return this._onstatechange;
16
- }
17
- set onstatechange(v) {
18
- this._onstatechange = v;
19
- }
20
- get onerror() {
21
- return this._onerror;
22
- }
23
- set onerror(v) {
24
- this._onerror = v;
25
- }
26
- getRemoteCertificates() {
27
- return [];
28
- }
29
- // ---- Internal setters (called by RTCPeerConnection) ---------------------
30
- /** @internal */
31
- _setState(state) {
32
- if (this._state === state) return;
33
- this._state = state;
34
- const ev = new Event("statechange");
35
- this._onstatechange?.call(this, ev);
36
- this.dispatchEvent(ev);
37
- }
38
- }
39
- export {
40
- RTCDtlsTransport
2
+
3
+ //#region src/rtc-dtls-transport.ts
4
+ var RTCDtlsTransport = class extends EventTarget {
5
+ iceTransport;
6
+ _state = "new";
7
+ _onstatechange = null;
8
+ _onerror = null;
9
+ constructor(iceTransport) {
10
+ super();
11
+ this.iceTransport = iceTransport;
12
+ }
13
+ get state() {
14
+ return this._state;
15
+ }
16
+ get onstatechange() {
17
+ return this._onstatechange;
18
+ }
19
+ set onstatechange(v) {
20
+ this._onstatechange = v;
21
+ }
22
+ get onerror() {
23
+ return this._onerror;
24
+ }
25
+ set onerror(v) {
26
+ this._onerror = v;
27
+ }
28
+ getRemoteCertificates() {
29
+ return [];
30
+ }
31
+ /** @internal */
32
+ _setState(state) {
33
+ if (this._state === state) return;
34
+ this._state = state;
35
+ const ev = new Event("statechange");
36
+ this._onstatechange?.call(this, ev);
37
+ this.dispatchEvent(ev);
38
+ }
41
39
  };
40
+
41
+ //#endregion
42
+ export { RTCDtlsTransport };
@@ -1,4 +1,6 @@
1
1
  import "@gjsify/dom-events/register/event-target";
2
+
3
+ //#region src/rtc-dtmf-sender.ts
2
4
  const VALID_DTMF_CHARS = new Set("0123456789ABCDabcd#*,");
3
5
  const MIN_DURATION = 40;
4
6
  const MAX_DURATION = 6e3;
@@ -6,104 +8,94 @@ const DEFAULT_DURATION = 100;
6
8
  const MIN_INTER_TONE_GAP = 30;
7
9
  const DEFAULT_INTER_TONE_GAP = 70;
8
10
  const COMMA_DELAY = 2e3;
9
- class RTCDTMFToneChangeEvent extends Event {
10
- tone;
11
- constructor(type, init = {}) {
12
- super(type, init);
13
- this.tone = init.tone ?? "";
14
- }
15
- }
16
- class RTCDTMFSender extends EventTarget {
17
- _toneBuffer = "";
18
- _duration = DEFAULT_DURATION;
19
- _interToneGap = DEFAULT_INTER_TONE_GAP;
20
- _timerId = null;
21
- _canInsert = true;
22
- _ontonechange = null;
23
- /** @internal — back-references set by RTCRtpSender */
24
- _isStopped = () => false;
25
- _getCurrentDirection = () => null;
26
- get toneBuffer() {
27
- return this._toneBuffer;
28
- }
29
- get canInsertDTMF() {
30
- return this._canInsert;
31
- }
32
- get ontonechange() {
33
- return this._ontonechange;
34
- }
35
- set ontonechange(v) {
36
- this._ontonechange = v;
37
- }
38
- insertDTMF(tones, duration, interToneGap) {
39
- if (this._isStopped()) {
40
- throw new DOMException(
41
- "Failed to execute 'insertDTMF': The associated transceiver is stopped",
42
- "InvalidStateError"
43
- );
44
- }
45
- const dir = this._getCurrentDirection();
46
- if (dir === "recvonly" || dir === "inactive") {
47
- throw new DOMException(
48
- "Failed to execute 'insertDTMF': The associated transceiver direction does not allow sending",
49
- "InvalidStateError"
50
- );
51
- }
52
- for (const ch of tones) {
53
- if (!VALID_DTMF_CHARS.has(ch)) {
54
- throw new DOMException(
55
- `Failed to execute 'insertDTMF': Invalid DTMF character '${ch}'`,
56
- "InvalidCharacterError"
57
- );
58
- }
59
- }
60
- tones = tones.replace(/[a-d]/g, (c) => c.toUpperCase());
61
- const d = duration ?? DEFAULT_DURATION;
62
- this._duration = Math.max(MIN_DURATION, Math.min(MAX_DURATION, d));
63
- const g = interToneGap ?? DEFAULT_INTER_TONE_GAP;
64
- this._interToneGap = Math.max(MIN_INTER_TONE_GAP, g);
65
- this._toneBuffer = tones;
66
- if (this._timerId !== null) {
67
- clearTimeout(this._timerId);
68
- this._timerId = null;
69
- }
70
- if (tones.length > 0) {
71
- this._scheduleNextTone(0);
72
- }
73
- }
74
- _scheduleNextTone(delay) {
75
- this._timerId = setTimeout(() => {
76
- this._timerId = null;
77
- this._playNextTone();
78
- }, delay);
79
- }
80
- _playNextTone() {
81
- if (this._toneBuffer.length === 0) {
82
- this._fireToneChange("");
83
- return;
84
- }
85
- const tone = this._toneBuffer[0];
86
- this._toneBuffer = this._toneBuffer.slice(1);
87
- this._fireToneChange(tone);
88
- const delay = tone === "," ? COMMA_DELAY : this._duration + this._interToneGap;
89
- this._scheduleNextTone(delay);
90
- }
91
- _fireToneChange(tone) {
92
- const ev = new RTCDTMFToneChangeEvent("tonechange", { tone });
93
- this._ontonechange?.call(this, ev);
94
- this.dispatchEvent(ev);
95
- }
96
- /** @internal — called by RTCRtpSender on cleanup */
97
- _stop() {
98
- if (this._timerId !== null) {
99
- clearTimeout(this._timerId);
100
- this._timerId = null;
101
- }
102
- this._toneBuffer = "";
103
- this._canInsert = false;
104
- }
105
- }
106
- export {
107
- RTCDTMFSender,
108
- RTCDTMFToneChangeEvent
11
+ var RTCDTMFToneChangeEvent = class extends Event {
12
+ tone;
13
+ constructor(type, init = {}) {
14
+ super(type, init);
15
+ this.tone = init.tone ?? "";
16
+ }
109
17
  };
18
+ var RTCDTMFSender = class extends EventTarget {
19
+ _toneBuffer = "";
20
+ _duration = DEFAULT_DURATION;
21
+ _interToneGap = DEFAULT_INTER_TONE_GAP;
22
+ _timerId = null;
23
+ _canInsert = true;
24
+ _ontonechange = null;
25
+ /** @internal — back-references set by RTCRtpSender */
26
+ _isStopped = () => false;
27
+ _getCurrentDirection = () => null;
28
+ get toneBuffer() {
29
+ return this._toneBuffer;
30
+ }
31
+ get canInsertDTMF() {
32
+ return this._canInsert;
33
+ }
34
+ get ontonechange() {
35
+ return this._ontonechange;
36
+ }
37
+ set ontonechange(v) {
38
+ this._ontonechange = v;
39
+ }
40
+ insertDTMF(tones, duration, interToneGap) {
41
+ if (this._isStopped()) {
42
+ throw new DOMException("Failed to execute 'insertDTMF': The associated transceiver is stopped", "InvalidStateError");
43
+ }
44
+ const dir = this._getCurrentDirection();
45
+ if (dir === "recvonly" || dir === "inactive") {
46
+ throw new DOMException("Failed to execute 'insertDTMF': The associated transceiver direction does not allow sending", "InvalidStateError");
47
+ }
48
+ for (const ch of tones) {
49
+ if (!VALID_DTMF_CHARS.has(ch)) {
50
+ throw new DOMException(`Failed to execute 'insertDTMF': Invalid DTMF character '${ch}'`, "InvalidCharacterError");
51
+ }
52
+ }
53
+ tones = tones.replace(/[a-d]/g, (c) => c.toUpperCase());
54
+ const d = duration ?? DEFAULT_DURATION;
55
+ this._duration = Math.max(MIN_DURATION, Math.min(MAX_DURATION, d));
56
+ const g = interToneGap ?? DEFAULT_INTER_TONE_GAP;
57
+ this._interToneGap = Math.max(MIN_INTER_TONE_GAP, g);
58
+ this._toneBuffer = tones;
59
+ if (this._timerId !== null) {
60
+ clearTimeout(this._timerId);
61
+ this._timerId = null;
62
+ }
63
+ if (tones.length > 0) {
64
+ this._scheduleNextTone(0);
65
+ }
66
+ }
67
+ _scheduleNextTone(delay) {
68
+ this._timerId = setTimeout(() => {
69
+ this._timerId = null;
70
+ this._playNextTone();
71
+ }, delay);
72
+ }
73
+ _playNextTone() {
74
+ if (this._toneBuffer.length === 0) {
75
+ this._fireToneChange("");
76
+ return;
77
+ }
78
+ const tone = this._toneBuffer[0];
79
+ this._toneBuffer = this._toneBuffer.slice(1);
80
+ this._fireToneChange(tone);
81
+ const delay = tone === "," ? COMMA_DELAY : this._duration + this._interToneGap;
82
+ this._scheduleNextTone(delay);
83
+ }
84
+ _fireToneChange(tone) {
85
+ const ev = new RTCDTMFToneChangeEvent("tonechange", { tone });
86
+ this._ontonechange?.call(this, ev);
87
+ this.dispatchEvent(ev);
88
+ }
89
+ /** @internal — called by RTCRtpSender on cleanup */
90
+ _stop() {
91
+ if (this._timerId !== null) {
92
+ clearTimeout(this._timerId);
93
+ this._timerId = null;
94
+ }
95
+ this._toneBuffer = "";
96
+ this._canInsert = false;
97
+ }
98
+ };
99
+
100
+ //#endregion
101
+ export { RTCDTMFSender, RTCDTMFToneChangeEvent };
@@ -1,24 +1,26 @@
1
1
  import "@gjsify/dom-exception/register";
2
- class RTCError extends DOMException {
3
- errorDetail;
4
- sdpLineNumber;
5
- sctpCauseCode;
6
- receivedAlert;
7
- sentAlert;
8
- httpRequestStatusCode;
9
- constructor(init, message) {
10
- super(message ?? init.errorDetail, "OperationError");
11
- if (!init || !init.errorDetail) {
12
- throw new TypeError("RTCError: errorDetail is required");
13
- }
14
- this.errorDetail = init.errorDetail;
15
- this.sdpLineNumber = init.sdpLineNumber ?? null;
16
- this.sctpCauseCode = init.sctpCauseCode ?? null;
17
- this.receivedAlert = init.receivedAlert ?? null;
18
- this.sentAlert = init.sentAlert ?? null;
19
- this.httpRequestStatusCode = init.httpRequestStatusCode ?? null;
20
- }
21
- }
22
- export {
23
- RTCError
2
+
3
+ //#region src/rtc-error.ts
4
+ var RTCError = class extends DOMException {
5
+ errorDetail;
6
+ sdpLineNumber;
7
+ sctpCauseCode;
8
+ receivedAlert;
9
+ sentAlert;
10
+ httpRequestStatusCode;
11
+ constructor(init, message) {
12
+ super(message ?? init.errorDetail, "OperationError");
13
+ if (!init || !init.errorDetail) {
14
+ throw new TypeError("RTCError: errorDetail is required");
15
+ }
16
+ this.errorDetail = init.errorDetail;
17
+ this.sdpLineNumber = init.sdpLineNumber ?? null;
18
+ this.sctpCauseCode = init.sctpCauseCode ?? null;
19
+ this.receivedAlert = init.receivedAlert ?? null;
20
+ this.sentAlert = init.sentAlert ?? null;
21
+ this.httpRequestStatusCode = init.httpRequestStatusCode ?? null;
22
+ }
24
23
  };
24
+
25
+ //#endregion
26
+ export { RTCError };
@@ -1,35 +1,35 @@
1
1
  import "@gjsify/dom-events/register/event-target";
2
- class RTCPeerConnectionIceEvent extends Event {
3
- candidate;
4
- url;
5
- constructor(type, init = {}) {
6
- super(type, init);
7
- this.candidate = init.candidate ?? null;
8
- this.url = init.url ?? null;
9
- }
10
- }
11
- class RTCDataChannelEvent extends Event {
12
- channel;
13
- constructor(type, init) {
14
- super(type, init);
15
- if (!init || !init.channel) {
16
- throw new TypeError("RTCDataChannelEvent requires a `channel` member");
17
- }
18
- this.channel = init.channel;
19
- }
20
- }
21
- class RTCErrorEvent extends Event {
22
- error;
23
- constructor(type, init) {
24
- super(type, init);
25
- if (!init || !init.error) {
26
- throw new TypeError("RTCErrorEvent requires an `error` member");
27
- }
28
- this.error = init.error;
29
- }
30
- }
31
- export {
32
- RTCDataChannelEvent,
33
- RTCErrorEvent,
34
- RTCPeerConnectionIceEvent
2
+
3
+ //#region src/rtc-events.ts
4
+ var RTCPeerConnectionIceEvent = class extends Event {
5
+ candidate;
6
+ url;
7
+ constructor(type, init = {}) {
8
+ super(type, init);
9
+ this.candidate = init.candidate ?? null;
10
+ this.url = init.url ?? null;
11
+ }
35
12
  };
13
+ var RTCDataChannelEvent = class extends Event {
14
+ channel;
15
+ constructor(type, init) {
16
+ super(type, init);
17
+ if (!init || !init.channel) {
18
+ throw new TypeError("RTCDataChannelEvent requires a `channel` member");
19
+ }
20
+ this.channel = init.channel;
21
+ }
22
+ };
23
+ var RTCErrorEvent = class extends Event {
24
+ error;
25
+ constructor(type, init) {
26
+ super(type, init);
27
+ if (!init || !init.error) {
28
+ throw new TypeError("RTCErrorEvent requires an `error` member");
29
+ }
30
+ this.error = init.error;
31
+ }
32
+ };
33
+
34
+ //#endregion
35
+ export { RTCDataChannelEvent, RTCErrorEvent, RTCPeerConnectionIceEvent };
@@ -1,75 +1,74 @@
1
+ //#region src/rtc-ice-candidate.ts
1
2
  function parseCandidate(line) {
2
- let s = line.trim();
3
- if (s.startsWith("a=")) s = s.slice(2);
4
- if (s.startsWith("candidate:")) s = s.slice("candidate:".length);
5
- const parts = s.split(/\s+/);
6
- if (parts.length < 8) return {};
7
- const protocolRaw = parts[2]?.toLowerCase();
8
- const typeIdx = parts.indexOf("typ");
9
- const typeRaw = typeIdx >= 0 ? parts[typeIdx + 1] : void 0;
10
- const raddrIdx = parts.indexOf("raddr");
11
- const rportIdx = parts.indexOf("rport");
12
- const tcpTypeIdx = parts.indexOf("tcptype");
13
- const componentId = Number(parts[1]);
14
- return {
15
- foundation: parts[0],
16
- component: componentId === 1 ? "rtp" : componentId === 2 ? "rtcp" : null,
17
- priority: Number(parts[3]) || null,
18
- protocol: protocolRaw === "udp" || protocolRaw === "tcp" ? protocolRaw : null,
19
- address: parts[4] ?? null,
20
- port: Number(parts[5]) || null,
21
- type: typeRaw === "host" || typeRaw === "srflx" || typeRaw === "prflx" || typeRaw === "relay" ? typeRaw : null,
22
- relatedAddress: raddrIdx >= 0 ? parts[raddrIdx + 1] ?? null : null,
23
- relatedPort: rportIdx >= 0 ? Number(parts[rportIdx + 1]) || null : null,
24
- tcpType: tcpTypeIdx >= 0 ? parts[tcpTypeIdx + 1] : null
25
- };
3
+ let s = line.trim();
4
+ if (s.startsWith("a=")) s = s.slice(2);
5
+ if (s.startsWith("candidate:")) s = s.slice("candidate:".length);
6
+ const parts = s.split(/\s+/);
7
+ if (parts.length < 8) return {};
8
+ const protocolRaw = parts[2]?.toLowerCase();
9
+ const typeIdx = parts.indexOf("typ");
10
+ const typeRaw = typeIdx >= 0 ? parts[typeIdx + 1] : undefined;
11
+ const raddrIdx = parts.indexOf("raddr");
12
+ const rportIdx = parts.indexOf("rport");
13
+ const tcpTypeIdx = parts.indexOf("tcptype");
14
+ const componentId = Number(parts[1]);
15
+ return {
16
+ foundation: parts[0],
17
+ component: componentId === 1 ? "rtp" : componentId === 2 ? "rtcp" : null,
18
+ priority: Number(parts[3]) || null,
19
+ protocol: protocolRaw === "udp" || protocolRaw === "tcp" ? protocolRaw : null,
20
+ address: parts[4] ?? null,
21
+ port: Number(parts[5]) || null,
22
+ type: typeRaw === "host" || typeRaw === "srflx" || typeRaw === "prflx" || typeRaw === "relay" ? typeRaw : null,
23
+ relatedAddress: raddrIdx >= 0 ? parts[raddrIdx + 1] ?? null : null,
24
+ relatedPort: rportIdx >= 0 ? Number(parts[rportIdx + 1]) || null : null,
25
+ tcpType: tcpTypeIdx >= 0 ? parts[tcpTypeIdx + 1] : null
26
+ };
26
27
  }
27
- class RTCIceCandidate {
28
- candidate;
29
- sdpMid;
30
- sdpMLineIndex;
31
- usernameFragment;
32
- foundation;
33
- component;
34
- priority;
35
- protocol;
36
- address;
37
- port;
38
- type;
39
- tcpType;
40
- relatedAddress;
41
- relatedPort;
42
- constructor(init = {}) {
43
- if (init.sdpMid == null && init.sdpMLineIndex == null) {
44
- throw new TypeError(
45
- "RTCIceCandidate requires either sdpMid or sdpMLineIndex"
46
- );
47
- }
48
- this.candidate = init.candidate ?? "";
49
- this.sdpMid = init.sdpMid ?? null;
50
- this.sdpMLineIndex = init.sdpMLineIndex ?? null;
51
- this.usernameFragment = init.usernameFragment ?? null;
52
- const parsed = parseCandidate(this.candidate);
53
- this.foundation = parsed.foundation ?? null;
54
- this.component = parsed.component ?? null;
55
- this.priority = parsed.priority ?? null;
56
- this.protocol = parsed.protocol ?? null;
57
- this.address = parsed.address ?? null;
58
- this.port = parsed.port ?? null;
59
- this.type = parsed.type ?? null;
60
- this.tcpType = parsed.tcpType ?? null;
61
- this.relatedAddress = parsed.relatedAddress ?? null;
62
- this.relatedPort = parsed.relatedPort ?? null;
63
- }
64
- toJSON() {
65
- return {
66
- candidate: this.candidate,
67
- sdpMid: this.sdpMid,
68
- sdpMLineIndex: this.sdpMLineIndex,
69
- usernameFragment: this.usernameFragment
70
- };
71
- }
72
- }
73
- export {
74
- RTCIceCandidate
28
+ var RTCIceCandidate = class {
29
+ candidate;
30
+ sdpMid;
31
+ sdpMLineIndex;
32
+ usernameFragment;
33
+ foundation;
34
+ component;
35
+ priority;
36
+ protocol;
37
+ address;
38
+ port;
39
+ type;
40
+ tcpType;
41
+ relatedAddress;
42
+ relatedPort;
43
+ constructor(init = {}) {
44
+ if (init.sdpMid == null && init.sdpMLineIndex == null) {
45
+ throw new TypeError("RTCIceCandidate requires either sdpMid or sdpMLineIndex");
46
+ }
47
+ this.candidate = init.candidate ?? "";
48
+ this.sdpMid = init.sdpMid ?? null;
49
+ this.sdpMLineIndex = init.sdpMLineIndex ?? null;
50
+ this.usernameFragment = init.usernameFragment ?? null;
51
+ const parsed = parseCandidate(this.candidate);
52
+ this.foundation = parsed.foundation ?? null;
53
+ this.component = parsed.component ?? null;
54
+ this.priority = parsed.priority ?? null;
55
+ this.protocol = parsed.protocol ?? null;
56
+ this.address = parsed.address ?? null;
57
+ this.port = parsed.port ?? null;
58
+ this.type = parsed.type ?? null;
59
+ this.tcpType = parsed.tcpType ?? null;
60
+ this.relatedAddress = parsed.relatedAddress ?? null;
61
+ this.relatedPort = parsed.relatedPort ?? null;
62
+ }
63
+ toJSON() {
64
+ return {
65
+ candidate: this.candidate,
66
+ sdpMid: this.sdpMid,
67
+ sdpMLineIndex: this.sdpMLineIndex,
68
+ usernameFragment: this.usernameFragment
69
+ };
70
+ }
75
71
  };
72
+
73
+ //#endregion
74
+ export { RTCIceCandidate };