@gjsify/webrtc 0.1.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 (117) hide show
  1. package/lib/esm/get-user-media.js +93 -0
  2. package/lib/esm/gst-enum-maps.js +88 -0
  3. package/lib/esm/gst-init.js +34 -0
  4. package/lib/esm/gst-stats-parser.js +79 -0
  5. package/lib/esm/gst-utils.js +16 -0
  6. package/lib/esm/index.js +53 -0
  7. package/lib/esm/media-device-info.js +23 -0
  8. package/lib/esm/media-devices.js +147 -0
  9. package/lib/esm/media-stream-track.js +142 -0
  10. package/lib/esm/media-stream.js +78 -0
  11. package/lib/esm/register/data-channel.js +8 -0
  12. package/lib/esm/register/error.js +8 -0
  13. package/lib/esm/register/media-devices.js +7 -0
  14. package/lib/esm/register/media.js +12 -0
  15. package/lib/esm/register/peer-connection.js +16 -0
  16. package/lib/esm/register.js +5 -0
  17. package/lib/esm/rtc-certificate.js +70 -0
  18. package/lib/esm/rtc-data-channel.js +266 -0
  19. package/lib/esm/rtc-dtls-transport.js +41 -0
  20. package/lib/esm/rtc-dtmf-sender.js +109 -0
  21. package/lib/esm/rtc-error.js +24 -0
  22. package/lib/esm/rtc-events.js +35 -0
  23. package/lib/esm/rtc-ice-candidate.js +75 -0
  24. package/lib/esm/rtc-ice-transport.js +96 -0
  25. package/lib/esm/rtc-peer-connection.js +855 -0
  26. package/lib/esm/rtc-rtp-receiver.js +91 -0
  27. package/lib/esm/rtc-rtp-sender.js +298 -0
  28. package/lib/esm/rtc-rtp-transceiver.js +97 -0
  29. package/lib/esm/rtc-sctp-transport.js +40 -0
  30. package/lib/esm/rtc-session-description.js +57 -0
  31. package/lib/esm/rtc-stats-report.js +35 -0
  32. package/lib/esm/rtc-track-event.js +29 -0
  33. package/lib/esm/rtp-capabilities.js +41 -0
  34. package/lib/esm/tee-multiplexer.js +62 -0
  35. package/lib/esm/wpt-helpers.js +122 -0
  36. package/lib/types/get-user-media.d.ts +14 -0
  37. package/lib/types/gst-enum-maps.d.ts +10 -0
  38. package/lib/types/gst-init.d.ts +5 -0
  39. package/lib/types/gst-stats-parser.d.ts +16 -0
  40. package/lib/types/gst-utils.d.ts +11 -0
  41. package/lib/types/index.d.ts +41 -0
  42. package/lib/types/media-device-info.d.ts +14 -0
  43. package/lib/types/media-devices.d.ts +12 -0
  44. package/lib/types/media-stream-track.d.ts +59 -0
  45. package/lib/types/media-stream.d.ts +28 -0
  46. package/lib/types/register/data-channel.d.ts +1 -0
  47. package/lib/types/register/error.d.ts +1 -0
  48. package/lib/types/register/media-devices.d.ts +1 -0
  49. package/lib/types/register/media.d.ts +1 -0
  50. package/lib/types/register/peer-connection.d.ts +1 -0
  51. package/lib/types/register.d.ts +5 -0
  52. package/lib/types/register.spec.d.ts +3 -0
  53. package/lib/types/rtc-certificate.d.ts +23 -0
  54. package/lib/types/rtc-data-channel.d.ts +64 -0
  55. package/lib/types/rtc-dtls-transport.d.ts +20 -0
  56. package/lib/types/rtc-dtmf-sender.d.ts +31 -0
  57. package/lib/types/rtc-error.d.ts +19 -0
  58. package/lib/types/rtc-events.d.ts +27 -0
  59. package/lib/types/rtc-ice-candidate.d.ts +28 -0
  60. package/lib/types/rtc-ice-transport.d.ts +56 -0
  61. package/lib/types/rtc-peer-connection.d.ts +165 -0
  62. package/lib/types/rtc-rtp-receiver.d.ts +45 -0
  63. package/lib/types/rtc-rtp-sender.d.ts +98 -0
  64. package/lib/types/rtc-rtp-transceiver.d.ts +20 -0
  65. package/lib/types/rtc-sctp-transport.d.ts +20 -0
  66. package/lib/types/rtc-session-description.d.ts +18 -0
  67. package/lib/types/rtc-stats-report.d.ts +22 -0
  68. package/lib/types/rtc-track-event.d.ts +18 -0
  69. package/lib/types/rtp-capabilities.d.ts +3 -0
  70. package/lib/types/tee-multiplexer.d.ts +25 -0
  71. package/lib/types/webrtc.spec.d.ts +2 -0
  72. package/lib/types/wpt-helpers.d.ts +30 -0
  73. package/lib/types/wpt-media.spec.d.ts +2 -0
  74. package/lib/types/wpt.spec.d.ts +2 -0
  75. package/package.json +74 -0
  76. package/src/get-user-media.ts +131 -0
  77. package/src/gst-enum-maps.ts +125 -0
  78. package/src/gst-init.ts +52 -0
  79. package/src/gst-stats-parser.ts +137 -0
  80. package/src/gst-utils.ts +41 -0
  81. package/src/index.ts +104 -0
  82. package/src/media-device-info.ts +33 -0
  83. package/src/media-devices.ts +191 -0
  84. package/src/media-stream-track.ts +159 -0
  85. package/src/media-stream.ts +96 -0
  86. package/src/register/data-channel.ts +11 -0
  87. package/src/register/error.ts +11 -0
  88. package/src/register/media-devices.ts +10 -0
  89. package/src/register/media.ts +15 -0
  90. package/src/register/peer-connection.ts +20 -0
  91. package/src/register.spec.ts +55 -0
  92. package/src/register.ts +10 -0
  93. package/src/rtc-certificate.ts +110 -0
  94. package/src/rtc-data-channel.ts +284 -0
  95. package/src/rtc-dtls-transport.ts +48 -0
  96. package/src/rtc-dtmf-sender.ts +146 -0
  97. package/src/rtc-error.ts +49 -0
  98. package/src/rtc-events.ts +64 -0
  99. package/src/rtc-ice-candidate.ts +115 -0
  100. package/src/rtc-ice-transport.ts +104 -0
  101. package/src/rtc-peer-connection.ts +1017 -0
  102. package/src/rtc-rtp-receiver.ts +122 -0
  103. package/src/rtc-rtp-sender.ts +444 -0
  104. package/src/rtc-rtp-transceiver.ts +127 -0
  105. package/src/rtc-sctp-transport.ts +48 -0
  106. package/src/rtc-session-description.ts +64 -0
  107. package/src/rtc-stats-report.ts +39 -0
  108. package/src/rtc-track-event.ts +45 -0
  109. package/src/rtp-capabilities.ts +48 -0
  110. package/src/tee-multiplexer.ts +75 -0
  111. package/src/test.mts +11 -0
  112. package/src/webrtc.spec.ts +1186 -0
  113. package/src/wpt-helpers.ts +156 -0
  114. package/src/wpt-media.spec.ts +1154 -0
  115. package/src/wpt.spec.ts +1136 -0
  116. package/tsconfig.json +36 -0
  117. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,75 @@
1
+ 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
+ };
26
+ }
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
75
+ };
@@ -0,0 +1,96 @@
1
+ import "@gjsify/dom-events/register/event-target";
2
+ import { RTCIceCandidate } from "./rtc-ice-candidate.js";
3
+ class RTCIceTransport extends EventTarget {
4
+ _state = "new";
5
+ _gatheringState = "new";
6
+ _role = "unknown";
7
+ _component = "rtp";
8
+ _localCandidates = [];
9
+ _remoteCandidates = [];
10
+ _localParams = null;
11
+ _remoteParams = null;
12
+ _onstatechange = null;
13
+ _ongatheringstatechange = null;
14
+ _onselectedcandidatepairchange = null;
15
+ get state() {
16
+ return this._state;
17
+ }
18
+ get gatheringState() {
19
+ return this._gatheringState;
20
+ }
21
+ get role() {
22
+ return this._role;
23
+ }
24
+ get component() {
25
+ return this._component;
26
+ }
27
+ get onstatechange() {
28
+ return this._onstatechange;
29
+ }
30
+ set onstatechange(v) {
31
+ this._onstatechange = v;
32
+ }
33
+ get ongatheringstatechange() {
34
+ return this._ongatheringstatechange;
35
+ }
36
+ set ongatheringstatechange(v) {
37
+ this._ongatheringstatechange = v;
38
+ }
39
+ get onselectedcandidatepairchange() {
40
+ return this._onselectedcandidatepairchange;
41
+ }
42
+ set onselectedcandidatepairchange(v) {
43
+ this._onselectedcandidatepairchange = v;
44
+ }
45
+ getLocalCandidates() {
46
+ return [...this._localCandidates];
47
+ }
48
+ getRemoteCandidates() {
49
+ return [...this._remoteCandidates];
50
+ }
51
+ getSelectedCandidatePair() {
52
+ return null;
53
+ }
54
+ getLocalParameters() {
55
+ return this._localParams;
56
+ }
57
+ getRemoteParameters() {
58
+ return this._remoteParams;
59
+ }
60
+ // ---- Internal setters (called by RTCPeerConnection) ---------------------
61
+ /** @internal */
62
+ _setState(state) {
63
+ if (this._state === state) return;
64
+ this._state = state;
65
+ const ev = new Event("statechange");
66
+ this._onstatechange?.call(this, ev);
67
+ this.dispatchEvent(ev);
68
+ }
69
+ /** @internal */
70
+ _setGatheringState(state) {
71
+ if (this._gatheringState === state) return;
72
+ this._gatheringState = state;
73
+ const ev = new Event("gatheringstatechange");
74
+ this._ongatheringstatechange?.call(this, ev);
75
+ this.dispatchEvent(ev);
76
+ }
77
+ /** @internal */
78
+ _addLocalCandidate(init) {
79
+ this._localCandidates.push(new RTCIceCandidate(init));
80
+ }
81
+ /** @internal */
82
+ _addRemoteCandidate(init) {
83
+ this._remoteCandidates.push(new RTCIceCandidate(init));
84
+ }
85
+ /** @internal */
86
+ _setLocalParameters(params) {
87
+ this._localParams = params;
88
+ }
89
+ /** @internal */
90
+ _setRemoteParameters(params) {
91
+ this._remoteParams = params;
92
+ }
93
+ }
94
+ export {
95
+ RTCIceTransport
96
+ };