@gjsify/webrtc 0.3.13 → 0.3.15

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,142 +1,139 @@
1
+ import { Gst } from "./gst-init.js";
1
2
  import "@gjsify/dom-events/register/event-target";
2
3
  import GLib from "gi://GLib?version=2.0";
3
- import { Gst } from "./gst-init.js";
4
- class MediaStreamTrack extends EventTarget {
5
- id;
6
- kind;
7
- label;
8
- _enabled = true;
9
- _muted;
10
- _ended = false;
11
- _contentHint = "";
12
- _onended = null;
13
- _onmute = null;
14
- _onunmute = null;
15
- /** @internal GStreamer source element (e.g. pulsesrc, audiotestsrc) */
16
- _gstSource = null;
17
- /** @internal Pipeline the source currently lives in (updated by VideoBridge) */
18
- _gstPipeline = null;
19
- /** @internal Tee element inserted by VideoBridge for preview fan-out */
20
- _gstTee = null;
21
- /** @internal TeeMultiplexer for multi-PC fan-out (created on second addTrack) */
22
- _teeMultiplexer = null;
23
- /** @internal Callback set by RTCRtpSender to control valve drop property */
24
- _enableCallback = null;
25
- constructor(init) {
26
- super();
27
- this.id = init.id ?? GLib.uuid_string_random();
28
- this.kind = init.kind;
29
- this.label = init.label ?? "";
30
- this._muted = init.muted ?? false;
31
- if (init._gst) {
32
- this._gstSource = init._gst.source;
33
- this._gstPipeline = init._gst.pipeline;
34
- }
35
- }
36
- get enabled() {
37
- return this._enabled;
38
- }
39
- set enabled(v) {
40
- const val = !!v;
41
- if (this._enabled === val) return;
42
- this._enabled = val;
43
- this._enableCallback?.(val);
44
- }
45
- get muted() {
46
- return this._muted;
47
- }
48
- get readyState() {
49
- return this._ended ? "ended" : "live";
50
- }
51
- get contentHint() {
52
- return this._contentHint;
53
- }
54
- set contentHint(v) {
55
- if (this.kind === "audio") {
56
- if (v !== "" && v !== "speech" && v !== "speech-recognition" && v !== "music") return;
57
- } else {
58
- if (v !== "" && v !== "motion" && v !== "detail" && v !== "text") return;
59
- }
60
- this._contentHint = v;
61
- }
62
- get onended() {
63
- return this._onended;
64
- }
65
- set onended(v) {
66
- this._onended = v;
67
- }
68
- get onmute() {
69
- return this._onmute;
70
- }
71
- set onmute(v) {
72
- this._onmute = v;
73
- }
74
- get onunmute() {
75
- return this._onunmute;
76
- }
77
- set onunmute(v) {
78
- this._onunmute = v;
79
- }
80
- clone() {
81
- const cloned = new MediaStreamTrack({
82
- kind: this.kind,
83
- label: this.label,
84
- muted: this._muted
85
- });
86
- cloned._enabled = this._enabled;
87
- return cloned;
88
- }
89
- stop() {
90
- if (this._ended) return;
91
- this._ended = true;
92
- if (this._gstSource || this._gstPipeline) {
93
- try {
94
- this._gstPipeline?.set_state(Gst.State.NULL);
95
- } catch {
96
- }
97
- try {
98
- this._gstSource?.set_state(Gst.State.NULL);
99
- } catch {
100
- }
101
- this._gstSource = null;
102
- this._gstPipeline = null;
103
- }
104
- const ev = new Event("ended");
105
- this._onended?.call(this, ev);
106
- this.dispatchEvent(ev);
107
- }
108
- getCapabilities() {
109
- return {};
110
- }
111
- getConstraints() {
112
- return {};
113
- }
114
- getSettings() {
115
- return {};
116
- }
117
- applyConstraints(_constraints) {
118
- return Promise.reject(new DOMException(
119
- "applyConstraints is not supported",
120
- "NotSupportedError"
121
- ));
122
- }
123
- /** @internal used by RTCRtpReceiver to toggle mute state */
124
- _setMuted(muted) {
125
- if (this._muted === muted) return;
126
- this._muted = muted;
127
- const ev = new Event(muted ? "mute" : "unmute");
128
- if (muted) {
129
- this._onmute?.call(this, ev);
130
- } else {
131
- this._onunmute?.call(this, ev);
132
- }
133
- this.dispatchEvent(ev);
134
- }
135
- /** @internal — called by RTCRtpSender to wire valve control */
136
- _setEnableCallback(cb) {
137
- this._enableCallback = cb;
138
- }
139
- }
140
- export {
141
- MediaStreamTrack
4
+
5
+ //#region src/media-stream-track.ts
6
+ var MediaStreamTrack = class MediaStreamTrack extends EventTarget {
7
+ id;
8
+ kind;
9
+ label;
10
+ _enabled = true;
11
+ _muted;
12
+ _ended = false;
13
+ _contentHint = "";
14
+ _onended = null;
15
+ _onmute = null;
16
+ _onunmute = null;
17
+ /** @internal GStreamer source element (e.g. pulsesrc, audiotestsrc) */
18
+ _gstSource = null;
19
+ /** @internal Pipeline the source currently lives in (updated by VideoBridge) */
20
+ _gstPipeline = null;
21
+ /** @internal Tee element inserted by VideoBridge for preview fan-out */
22
+ _gstTee = null;
23
+ /** @internal TeeMultiplexer for multi-PC fan-out (created on second addTrack) */
24
+ _teeMultiplexer = null;
25
+ /** @internal Callback set by RTCRtpSender to control valve drop property */
26
+ _enableCallback = null;
27
+ constructor(init) {
28
+ super();
29
+ this.id = init.id ?? GLib.uuid_string_random();
30
+ this.kind = init.kind;
31
+ this.label = init.label ?? "";
32
+ this._muted = init.muted ?? false;
33
+ if (init._gst) {
34
+ this._gstSource = init._gst.source;
35
+ this._gstPipeline = init._gst.pipeline;
36
+ }
37
+ }
38
+ get enabled() {
39
+ return this._enabled;
40
+ }
41
+ set enabled(v) {
42
+ const val = !!v;
43
+ if (this._enabled === val) return;
44
+ this._enabled = val;
45
+ this._enableCallback?.(val);
46
+ }
47
+ get muted() {
48
+ return this._muted;
49
+ }
50
+ get readyState() {
51
+ return this._ended ? "ended" : "live";
52
+ }
53
+ get contentHint() {
54
+ return this._contentHint;
55
+ }
56
+ set contentHint(v) {
57
+ if (this.kind === "audio") {
58
+ if (v !== "" && v !== "speech" && v !== "speech-recognition" && v !== "music") return;
59
+ } else {
60
+ if (v !== "" && v !== "motion" && v !== "detail" && v !== "text") return;
61
+ }
62
+ this._contentHint = v;
63
+ }
64
+ get onended() {
65
+ return this._onended;
66
+ }
67
+ set onended(v) {
68
+ this._onended = v;
69
+ }
70
+ get onmute() {
71
+ return this._onmute;
72
+ }
73
+ set onmute(v) {
74
+ this._onmute = v;
75
+ }
76
+ get onunmute() {
77
+ return this._onunmute;
78
+ }
79
+ set onunmute(v) {
80
+ this._onunmute = v;
81
+ }
82
+ clone() {
83
+ const cloned = new MediaStreamTrack({
84
+ kind: this.kind,
85
+ label: this.label,
86
+ muted: this._muted
87
+ });
88
+ cloned._enabled = this._enabled;
89
+ return cloned;
90
+ }
91
+ stop() {
92
+ if (this._ended) return;
93
+ this._ended = true;
94
+ if (this._gstSource || this._gstPipeline) {
95
+ try {
96
+ this._gstPipeline?.set_state(Gst.State.NULL);
97
+ } catch {}
98
+ try {
99
+ this._gstSource?.set_state(Gst.State.NULL);
100
+ } catch {}
101
+ this._gstSource = null;
102
+ this._gstPipeline = null;
103
+ }
104
+ const ev = new Event("ended");
105
+ this._onended?.call(this, ev);
106
+ this.dispatchEvent(ev);
107
+ }
108
+ getCapabilities() {
109
+ return {};
110
+ }
111
+ getConstraints() {
112
+ return {};
113
+ }
114
+ getSettings() {
115
+ return {};
116
+ }
117
+ applyConstraints(_constraints) {
118
+ return Promise.reject(new DOMException("applyConstraints is not supported", "NotSupportedError"));
119
+ }
120
+ /** @internal used by RTCRtpReceiver to toggle mute state */
121
+ _setMuted(muted) {
122
+ if (this._muted === muted) return;
123
+ this._muted = muted;
124
+ const ev = new Event(muted ? "mute" : "unmute");
125
+ if (muted) {
126
+ this._onmute?.call(this, ev);
127
+ } else {
128
+ this._onunmute?.call(this, ev);
129
+ }
130
+ this.dispatchEvent(ev);
131
+ }
132
+ /** @internal — called by RTCRtpSender to wire valve control */
133
+ _setEnableCallback(cb) {
134
+ this._enableCallback = cb;
135
+ }
142
136
  };
137
+
138
+ //#endregion
139
+ export { MediaStreamTrack };
@@ -1,78 +1,79 @@
1
1
  import "@gjsify/dom-events/register/event-target";
2
2
  import GLib from "gi://GLib?version=2.0";
3
- class MediaStream extends EventTarget {
4
- id;
5
- _tracks = /* @__PURE__ */ new Map();
6
- _onaddtrack = null;
7
- _onremovetrack = null;
8
- constructor(streamOrTracks) {
9
- super();
10
- this.id = GLib.uuid_string_random();
11
- if (streamOrTracks instanceof MediaStream) {
12
- for (const track of streamOrTracks.getTracks()) {
13
- this._tracks.set(track.id, track.clone());
14
- }
15
- } else if (Array.isArray(streamOrTracks)) {
16
- for (const track of streamOrTracks) {
17
- this._tracks.set(track.id, track);
18
- }
19
- }
20
- }
21
- get active() {
22
- for (const track of this._tracks.values()) {
23
- if (track.readyState === "live") return true;
24
- }
25
- return false;
26
- }
27
- get onaddtrack() {
28
- return this._onaddtrack;
29
- }
30
- set onaddtrack(v) {
31
- this._onaddtrack = v;
32
- }
33
- get onremovetrack() {
34
- return this._onremovetrack;
35
- }
36
- set onremovetrack(v) {
37
- this._onremovetrack = v;
38
- }
39
- getTracks() {
40
- return [...this._tracks.values()];
41
- }
42
- getAudioTracks() {
43
- return this.getTracks().filter((t) => t.kind === "audio");
44
- }
45
- getVideoTracks() {
46
- return this.getTracks().filter((t) => t.kind === "video");
47
- }
48
- getTrackById(id) {
49
- return this._tracks.get(id) ?? null;
50
- }
51
- addTrack(track) {
52
- if (this._tracks.has(track.id)) return;
53
- this._tracks.set(track.id, track);
54
- const ev = new MediaStreamTrackEvent("addtrack", { track });
55
- this._onaddtrack?.call(this, ev);
56
- this.dispatchEvent(ev);
57
- }
58
- removeTrack(track) {
59
- if (!this._tracks.delete(track.id)) return;
60
- const ev = new MediaStreamTrackEvent("removetrack", { track });
61
- this._onremovetrack?.call(this, ev);
62
- this.dispatchEvent(ev);
63
- }
64
- clone() {
65
- return new MediaStream(this);
66
- }
67
- }
68
- class MediaStreamTrackEvent extends Event {
69
- track;
70
- constructor(type, init) {
71
- super(type, init);
72
- this.track = init.track;
73
- }
74
- }
75
- export {
76
- MediaStream,
77
- MediaStreamTrackEvent
3
+
4
+ //#region src/media-stream.ts
5
+ var MediaStream = class MediaStream extends EventTarget {
6
+ id;
7
+ _tracks = new Map();
8
+ _onaddtrack = null;
9
+ _onremovetrack = null;
10
+ constructor(streamOrTracks) {
11
+ super();
12
+ this.id = GLib.uuid_string_random();
13
+ if (streamOrTracks instanceof MediaStream) {
14
+ for (const track of streamOrTracks.getTracks()) {
15
+ this._tracks.set(track.id, track.clone());
16
+ }
17
+ } else if (Array.isArray(streamOrTracks)) {
18
+ for (const track of streamOrTracks) {
19
+ this._tracks.set(track.id, track);
20
+ }
21
+ }
22
+ }
23
+ get active() {
24
+ for (const track of this._tracks.values()) {
25
+ if (track.readyState === "live") return true;
26
+ }
27
+ return false;
28
+ }
29
+ get onaddtrack() {
30
+ return this._onaddtrack;
31
+ }
32
+ set onaddtrack(v) {
33
+ this._onaddtrack = v;
34
+ }
35
+ get onremovetrack() {
36
+ return this._onremovetrack;
37
+ }
38
+ set onremovetrack(v) {
39
+ this._onremovetrack = v;
40
+ }
41
+ getTracks() {
42
+ return [...this._tracks.values()];
43
+ }
44
+ getAudioTracks() {
45
+ return this.getTracks().filter((t) => t.kind === "audio");
46
+ }
47
+ getVideoTracks() {
48
+ return this.getTracks().filter((t) => t.kind === "video");
49
+ }
50
+ getTrackById(id) {
51
+ return this._tracks.get(id) ?? null;
52
+ }
53
+ addTrack(track) {
54
+ if (this._tracks.has(track.id)) return;
55
+ this._tracks.set(track.id, track);
56
+ const ev = new MediaStreamTrackEvent("addtrack", { track });
57
+ this._onaddtrack?.call(this, ev);
58
+ this.dispatchEvent(ev);
59
+ }
60
+ removeTrack(track) {
61
+ if (!this._tracks.delete(track.id)) return;
62
+ const ev = new MediaStreamTrackEvent("removetrack", { track });
63
+ this._onremovetrack?.call(this, ev);
64
+ this.dispatchEvent(ev);
65
+ }
66
+ clone() {
67
+ return new MediaStream(this);
68
+ }
78
69
  };
70
+ var MediaStreamTrackEvent = class extends Event {
71
+ track;
72
+ constructor(type, init) {
73
+ super(type, init);
74
+ this.track = init.track;
75
+ }
76
+ };
77
+
78
+ //#endregion
79
+ export { MediaStream, MediaStreamTrackEvent };
@@ -1,8 +1,12 @@
1
- import { RTCDataChannel } from "../rtc-data-channel.js";
2
1
  import { RTCDataChannelEvent } from "../rtc-events.js";
2
+ import { RTCDataChannel } from "../rtc-data-channel.js";
3
+
4
+ //#region src/register/data-channel.ts
3
5
  if (typeof globalThis.RTCDataChannel === "undefined") {
4
- globalThis.RTCDataChannel = RTCDataChannel;
6
+ globalThis.RTCDataChannel = RTCDataChannel;
5
7
  }
6
8
  if (typeof globalThis.RTCDataChannelEvent === "undefined") {
7
- globalThis.RTCDataChannelEvent = RTCDataChannelEvent;
9
+ globalThis.RTCDataChannelEvent = RTCDataChannelEvent;
8
10
  }
11
+
12
+ //#endregion
@@ -1,8 +1,12 @@
1
1
  import { RTCError } from "../rtc-error.js";
2
2
  import { RTCErrorEvent } from "../rtc-events.js";
3
+
4
+ //#region src/register/error.ts
3
5
  if (typeof globalThis.RTCError === "undefined") {
4
- globalThis.RTCError = RTCError;
6
+ globalThis.RTCError = RTCError;
5
7
  }
6
8
  if (typeof globalThis.RTCErrorEvent === "undefined") {
7
- globalThis.RTCErrorEvent = RTCErrorEvent;
9
+ globalThis.RTCErrorEvent = RTCErrorEvent;
8
10
  }
11
+
12
+ //#endregion
@@ -1,7 +1,11 @@
1
1
  import { MediaDevices } from "../media-devices.js";
2
+
3
+ //#region src/register/media-devices.ts
2
4
  if (typeof globalThis.navigator === "undefined") {
3
- globalThis.navigator = {};
5
+ globalThis.navigator = {};
4
6
  }
5
7
  if (typeof globalThis.navigator.mediaDevices === "undefined") {
6
- globalThis.navigator.mediaDevices = new MediaDevices();
8
+ globalThis.navigator.mediaDevices = new MediaDevices();
7
9
  }
10
+
11
+ //#endregion
@@ -1,12 +1,16 @@
1
- import { MediaStream } from "../media-stream.js";
2
1
  import { MediaStreamTrack } from "../media-stream-track.js";
2
+ import { MediaStream } from "../media-stream.js";
3
3
  import { RTCTrackEvent } from "../rtc-track-event.js";
4
+
5
+ //#region src/register/media.ts
4
6
  if (typeof globalThis.MediaStream === "undefined") {
5
- globalThis.MediaStream = MediaStream;
7
+ globalThis.MediaStream = MediaStream;
6
8
  }
7
9
  if (typeof globalThis.MediaStreamTrack === "undefined") {
8
- globalThis.MediaStreamTrack = MediaStreamTrack;
10
+ globalThis.MediaStreamTrack = MediaStreamTrack;
9
11
  }
10
12
  if (typeof globalThis.RTCTrackEvent === "undefined") {
11
- globalThis.RTCTrackEvent = RTCTrackEvent;
13
+ globalThis.RTCTrackEvent = RTCTrackEvent;
12
14
  }
15
+
16
+ //#endregion
@@ -1,16 +1,20 @@
1
- import { RTCPeerConnection } from "../rtc-peer-connection.js";
2
1
  import { RTCSessionDescription } from "../rtc-session-description.js";
3
2
  import { RTCIceCandidate } from "../rtc-ice-candidate.js";
4
3
  import { RTCPeerConnectionIceEvent } from "../rtc-events.js";
4
+ import { RTCPeerConnection } from "../rtc-peer-connection.js";
5
+
6
+ //#region src/register/peer-connection.ts
5
7
  if (typeof globalThis.RTCPeerConnection === "undefined") {
6
- globalThis.RTCPeerConnection = RTCPeerConnection;
8
+ globalThis.RTCPeerConnection = RTCPeerConnection;
7
9
  }
8
10
  if (typeof globalThis.RTCSessionDescription === "undefined") {
9
- globalThis.RTCSessionDescription = RTCSessionDescription;
11
+ globalThis.RTCSessionDescription = RTCSessionDescription;
10
12
  }
11
13
  if (typeof globalThis.RTCIceCandidate === "undefined") {
12
- globalThis.RTCIceCandidate = RTCIceCandidate;
14
+ globalThis.RTCIceCandidate = RTCIceCandidate;
13
15
  }
14
16
  if (typeof globalThis.RTCPeerConnectionIceEvent === "undefined") {
15
- globalThis.RTCPeerConnectionIceEvent = RTCPeerConnectionIceEvent;
17
+ globalThis.RTCPeerConnectionIceEvent = RTCPeerConnectionIceEvent;
16
18
  }
19
+
20
+ //#endregion