legacynet 1.0.0 → 1.0.2

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 (3) hide show
  1. package/LegacyNet.js +1 -1
  2. package/docs.html +412 -0
  3. package/package.json +2 -1
package/LegacyNet.js CHANGED
@@ -2493,7 +2493,7 @@
2493
2493
  }
2494
2494
 
2495
2495
  var LegacyNet = {
2496
- version: "1.0.0 BETA",
2496
+ version: "1.0.2",
2497
2497
  capabilities: capabilities,
2498
2498
  limits: freezeSafe({
2499
2499
  missingProtocols: [
package/docs.html ADDED
@@ -0,0 +1,412 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>LegacyNet (v1.0.2) — Full Technical Documentation</title>
7
+ <style>
8
+ :root {
9
+ --bg: #0f172a;
10
+ --surface: #1e293b;
11
+ --surface-alt: #162032;
12
+ --border: #334155;
13
+ --text: #e2e8f0;
14
+ --muted: #94a3b8;
15
+ --accent: #38bdf8;
16
+ --accent-2: #818cf8;
17
+ --code-bg: #0b1120;
18
+ --badge-bg: rgba(56, 189, 248, 0.12);
19
+ --badge-border: rgba(56, 189, 248, 0.35);
20
+ }
21
+
22
+ * {
23
+ box-sizing: border-box;
24
+ }
25
+
26
+ body {
27
+ margin: 0;
28
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
29
+ background: var(--bg);
30
+ color: var(--text);
31
+ line-height: 1.65;
32
+ }
33
+
34
+ .layout {
35
+ display: flex;
36
+ min-height: 100vh;
37
+ }
38
+
39
+ aside.sidebar {
40
+ width: 280px;
41
+ flex-shrink: 0;
42
+ background: var(--surface-alt);
43
+ border-right: 1px solid var(--border);
44
+ padding: 24px 18px;
45
+ position: sticky;
46
+ top: 0;
47
+ height: 100vh;
48
+ overflow-y: auto;
49
+ }
50
+
51
+ .brand {
52
+ font-size: 1.25rem;
53
+ font-weight: 700;
54
+ color: #ffffff;
55
+ margin: 0 0 6px;
56
+ letter-spacing: -0.01em;
57
+ }
58
+
59
+ .version-pill {
60
+ display: inline-block;
61
+ font-size: 0.78rem;
62
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
63
+ color: var(--accent);
64
+ background: var(--badge-bg);
65
+ border: 1px solid var(--badge-border);
66
+ padding: 2px 8px;
67
+ border-radius: 999px;
68
+ margin-bottom: 18px;
69
+ }
70
+
71
+ .nav-title {
72
+ font-size: 0.72rem;
73
+ text-transform: uppercase;
74
+ letter-spacing: 0.08em;
75
+ color: var(--muted);
76
+ margin: 16px 0 8px;
77
+ font-weight: 600;
78
+ }
79
+
80
+ nav a {
81
+ display: block;
82
+ color: var(--text);
83
+ text-decoration: none;
84
+ padding: 6px 10px;
85
+ border-radius: 6px;
86
+ font-size: 0.9rem;
87
+ margin-bottom: 2px;
88
+ }
89
+
90
+ nav a:hover {
91
+ background: rgba(148, 163, 184, 0.12);
92
+ color: #ffffff;
93
+ }
94
+
95
+ main.content {
96
+ flex: 1;
97
+ max-width: 960px;
98
+ margin: 0 auto;
99
+ padding: 36px 40px 80px;
100
+ }
101
+
102
+ header.doc-header {
103
+ border-bottom: 1px solid var(--border);
104
+ padding-bottom: 20px;
105
+ margin-bottom: 28px;
106
+ }
107
+
108
+ header.doc-header h1 {
109
+ margin: 0 0 8px;
110
+ font-size: 2rem;
111
+ color: #ffffff;
112
+ }
113
+
114
+ header.doc-header p {
115
+ margin: 0;
116
+ color: var(--muted);
117
+ font-size: 1rem;
118
+ }
119
+
120
+ section {
121
+ margin-bottom: 42px;
122
+ }
123
+
124
+ h2 {
125
+ font-size: 1.4rem;
126
+ color: #ffffff;
127
+ border-bottom: 1px solid var(--border);
128
+ padding-bottom: 8px;
129
+ margin: 0 0 16px;
130
+ }
131
+
132
+ h3 {
133
+ font-size: 1.08rem;
134
+ color: var(--accent);
135
+ margin: 22px 0 10px;
136
+ }
137
+
138
+ ul {
139
+ padding-left: 22px;
140
+ margin: 8px 0 16px;
141
+ }
142
+
143
+ li {
144
+ margin-bottom: 7px;
145
+ }
146
+
147
+ code {
148
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
149
+ font-size: 0.88em;
150
+ background: rgba(15, 23, 42, 0.75);
151
+ border: 1px solid rgba(148, 163, 184, 0.22);
152
+ color: #7dd3fc;
153
+ padding: 1px 6px;
154
+ border-radius: 4px;
155
+ }
156
+
157
+ pre {
158
+ background: var(--code-bg);
159
+ border: 1px solid var(--border);
160
+ border-radius: 8px;
161
+ padding: 16px 18px;
162
+ overflow-x: auto;
163
+ margin: 14px 0 20px;
164
+ }
165
+
166
+ pre code {
167
+ background: transparent;
168
+ border: none;
169
+ padding: 0;
170
+ color: #e2e8f0;
171
+ font-size: 0.86rem;
172
+ line-height: 1.55;
173
+ }
174
+
175
+ .callout {
176
+ background: var(--surface);
177
+ border-left: 4px solid var(--accent-2);
178
+ border-radius: 6px;
179
+ padding: 14px 16px;
180
+ margin: 16px 0;
181
+ }
182
+
183
+ @media (max-width: 820px) {
184
+ .layout {
185
+ flex-direction: column;
186
+ }
187
+ aside.sidebar {
188
+ position: static;
189
+ width: 100%;
190
+ height: auto;
191
+ border-right: none;
192
+ border-bottom: 1px solid var(--border);
193
+ }
194
+ main.content {
195
+ padding: 24px 20px 60px;
196
+ }
197
+ }
198
+ </style>
199
+ </head>
200
+ <body>
201
+ <div class="layout">
202
+ <aside class="sidebar">
203
+ <div class="brand">LegacyNet</div>
204
+ <div class="version-pill">v1.0.2</div>
205
+ <div class="nav-title">Contents</div>
206
+ <nav>
207
+ <a href="#architecture">1. Architecture &amp; ES3 Contract</a>
208
+ <a href="#metadata">2. Metadata &amp; Capabilities</a>
209
+ <a href="#async">3. Async Flow &amp; Combinators</a>
210
+ <a href="#json">4. JSON &amp; Raw JSON</a>
211
+ <a href="#http">5. HTTP Client (request)</a>
212
+ <a href="#websockets">6. WebSockets (connectSocket)</a>
213
+ <a href="#webrtc">7. WebRTC, STUN/TURN &amp; SDP</a>
214
+ <a href="#utils">8. Utility Reference</a>
215
+ <a href="#example">9. End-to-End Example</a>
216
+ </nav>
217
+ </aside>
218
+
219
+ <main class="content">
220
+ <header class="doc-header">
221
+ <h1><code>LegacyNet</code> (<code>v1.0.2</code>) Full Technical Documentation</h1>
222
+ <p>Single-file networking, asynchronous flow, WebRTC/STUN/TURN engine, and cross-edition JavaScript utility library targeting ECMAScript 3 through ECMAScript 2026 (ES26).</p>
223
+ </header>
224
+
225
+ <section id="architecture">
226
+ <h2>1. Architecture &amp; ES3 Compatibility Contract</h2>
227
+ <p><code>LegacyNet</code> (<code>v1.0.2</code>) is a self-contained networking, asynchronous flow, WebRTC/STUN/TURN engine, and cross-edition JavaScript utility library targeting <strong>ECMAScript 3 through ECMAScript 2026 (ES26)</strong>.</p>
228
+
229
+ <h3>Syntax &amp; Runtime Rules</h3>
230
+ <ul>
231
+ <li><strong>Strict ES3 source syntax:</strong> Uses <code>var</code>, <code>function</code>, plain prototype methods, and bracket property access (<code>["catch"]</code>, <code>["finally"]</code>, <code>["try"]</code>, <code>["delete"]</code>) so legacy engines and strict ES3 parsers can parse the file without <code>SyntaxError</code>. No <code>let</code>/<code>const</code>, arrow functions, <code>async</code>/<code>await</code>, classes, optional chaining, or nullish coalescing are used in the library source.</li>
232
+ <li><strong>Feature-bridged execution:</strong> At load time, <code>detectCapabilities()</code> inspects the host environment and populates <code>LegacyNet.capabilities</code>. Methods delegate to native host APIs when present and fall back to from-scratch ES3 implementations when absent.</li>
233
+ <li><strong>Host &amp; protocol boundaries (<code>LegacyNet.limits</code>):</strong> Plain ES3 JavaScript cannot open raw UDP/TCP sockets or execute native DTLS/SRTP crypto or ICE packet transport on its own; connecting over real networks and STUN/TURN/WebRTC relies on host capabilities (<code>fetch</code>, <code>XMLHttpRequest</code> / <code>ActiveXObject</code>, <code>WebSocket</code>, <code>RTCPeerConnection</code> and prefixed variants), while Same-Origin Policy, CORS, and TLS are enforced by the host.</li>
234
+ </ul>
235
+ </section>
236
+
237
+ <section id="metadata">
238
+ <h2>2. Top-Level Metadata &amp; Capability Inspection</h2>
239
+
240
+ <h3><code>LegacyNet.version</code></h3>
241
+ <p>String identifier currently set to <code>"1.0.2"</code>.</p>
242
+
243
+ <h3><code>LegacyNet.capabilities</code></h3>
244
+ <p>Snapshot object returned by <code>detectCapabilities()</code> at startup:</p>
245
+ <ul>
246
+ <li><strong>Edition summary:</strong> <code>detectedEdition</code> reports the highest detected feature tier across <code>"ES2026/ES17+"</code>, <code>"ES16/ES2025+"</code>, <code>"ES15/ES2024+"</code>, <code>"ES14/ES2023+"</code>, <code>"ES13/ES2022+"</code>, <code>"ES12/ES2021+"</code>, <code>"ES11/ES2020+"</code>, <code>"ES10/ES2019+"</code>, <code>"ES8/ES2017+"</code>, <code>"ES7/ES2016+"</code>, <code>"ES6+"</code>, <code>"ES5+"</code>, and <code>"ES3"</code>.</li>
247
+ <li><strong>Language &amp; standard flags:</strong> <code>es5ArrayIsArray</code>, <code>es5Json</code>, <code>es5ObjectKeys</code>, <code>es5DateNow</code>, <code>es6Promise</code>, <code>es6ObjectAssign</code>, <code>es7Includes</code>, <code>es8ObjectEntries</code>, <code>es10Flat</code>, <code>es11GlobalThis</code>, <code>es12ReplaceAll</code>, <code>es13At</code>, <code>es14ArrayCopy</code>, <code>es15GroupBy</code>, <code>es16PromiseTry</code>.</li>
248
+ <li><strong>ES2026 flags:</strong> <code>es2026ErrorIsError</code>, <code>es2026MathSumPrecise</code>, <code>es2026FromAsync</code>, <code>es2026Uint8Base64</code>, <code>es2026JsonRaw</code>, <code>es2026MapGetOrInsert</code>, <code>es2026IteratorConcat</code>.</li>
249
+ <li><strong>Transport &amp; media flags:</strong> <code>fetch</code>, <code>xhr</code> (<code>XMLHttpRequest</code> or IE <code>ActiveXObject</code> XMLHTTP), <code>abortController</code>, <code>webSocket</code>, <code>rtcPeerConnection</code>, <code>rtcPrefixed</code>, <code>formData</code>, <code>blob</code>, <code>arrayBuffer</code>, and <code>streams</code>.</li>
250
+ </ul>
251
+
252
+ <h3><code>LegacyNet.limits</code></h3>
253
+ <p>Frozen (when <code>Object.freeze</code> is available) reference object exposing <code>missingProtocols</code> and <code>securityEnforcedByHost</code>.</p>
254
+ </section>
255
+
256
+ <section id="async">
257
+ <h2>3. Asynchronous Flow &amp; Combinators</h2>
258
+ <p><code>Deferred</code> provides promise-like chaining (<code>then</code>, <code>["catch"]</code>, <code>["finally"]</code>), async reaction scheduling via <code>setTimeout(..., 0)</code> (falling back to direct invocation when unavailable), self-resolution guards, thenable unwrapping, and cancellation.</p>
259
+
260
+ <h3><code>Deferred</code> Methods</h3>
261
+ <ul>
262
+ <li><code>.then(onFulfilled, onRejected)</code> -&gt; <code>Deferred</code>: Registers fulfillment and rejection handlers and returns a chained <code>Deferred</code>.</li>
263
+ <li><code>["catch"](onRejected)</code> -&gt; <code>Deferred</code>: Equivalent to <code>.then(null, onRejected)</code>.</li>
264
+ <li><code>["finally"](onFinally)</code> -&gt; <code>Deferred</code>: Runs a cleanup callback on fulfillment or rejection (awaiting returned thenables) while preserving the original value or error.</li>
265
+ <li><code>.abort(reason)</code> -&gt; <code>void</code>: Marks the <code>Deferred</code> aborted, calls <code>onAbort(reason)</code> if provided, and rejects with an <code>Error</code> having <code>err.code = "ABORTED"</code>.</li>
266
+ <li><code>.toNativePromise()</code> -&gt; <code>Promise | null</code>: Wraps the <code>Deferred</code> in <code>root.Promise</code> when available, or returns <code>null</code>.</li>
267
+ </ul>
268
+
269
+ <h3>Top-Level Async Helpers</h3>
270
+ <ul>
271
+ <li><code>LegacyNet.deferred(onAbort)</code> -&gt; <code>Deferred</code>: Creates a new <code>Deferred</code>.</li>
272
+ <li><code>LegacyNet.all(items)</code> -&gt; <code>Deferred</code>: Resolves with an array of values when all items fulfill; rejects on the first rejection.</li>
273
+ <li><code>LegacyNet.race(items)</code> -&gt; <code>Deferred</code>: Settles with the first item to fulfill or reject.</li>
274
+ <li><code>LegacyNet.any(items)</code> -&gt; <code>Deferred</code>: Resolves with the first fulfilled item; if all reject, rejects with an <code>Error</code> whose <code>.errors</code> array contains each rejection reason.</li>
275
+ <li><code>LegacyNet.allSettled(items)</code> -&gt; <code>Deferred</code>: Resolves with <code>{ status: "fulfilled", value }</code> or <code>{ status: "rejected", reason }</code> objects once all items settle.</li>
276
+ <li><code>LegacyNet.withResolvers()</code> -&gt; <code>object</code>: Returns <code>{ promise, nativePromise, resolve, reject }</code>, coordinating with <code>Promise.withResolvers</code> when present.</li>
277
+ <li><code>LegacyNet.tryCall(fn, thisArg, argsArr)</code> -&gt; <code>Deferred</code>: Executes <code>fn</code> asynchronously and resolves with its result or rejects with any thrown error.</li>
278
+ <li><code>LegacyNet.fromAsync(source, mapFn, thisArg)</code> -&gt; <code>Deferred</code>: Uses <code>Array.fromAsync</code> when available, or maps array-like/single values into a resolved <code>Deferred</code> array.</li>
279
+ </ul>
280
+ </section>
281
+
282
+ <section id="json">
283
+ <h2>4. JSON &amp; Raw JSON (<code>LegacyNet.json</code>)</h2>
284
+ <ul>
285
+ <li><code>LegacyNet.json.stringify(val)</code> -&gt; <code>string</code>: Serializes raw JSON wrappers directly, delegates to <code>JSON.stringify</code> when present, or uses <code>es3Stringify</code> across primitives, arrays, and own enumerable keys.</li>
286
+ <li><code>LegacyNet.json.parse(text, reviver)</code> -&gt; <code>any</code>: Delegates to <code>JSON.parse</code> when present, or runs regex-validated <code>es3Parse</code> with recursive <code>reviver</code> support and <code>{ source }</code> context metadata.</li>
287
+ <li><code>LegacyNet.json.rawJSON(rawText)</code> -&gt; <code>object</code>: Uses <code>JSON.rawJSON</code> when available, or returns <code>{ __legacyRawJson: String(rawText) }</code>.</li>
288
+ <li><code>LegacyNet.json.isRawJSON(val)</code> -&gt; <code>boolean</code>: Checks <code>JSON.isRawJSON</code> when available or detects the internal raw JSON wrapper.</li>
289
+ </ul>
290
+ </section>
291
+
292
+ <section id="http">
293
+ <h2>5. HTTP Client (<code>LegacyNet.request</code>)</h2>
294
+ <p><code>LegacyNet.request(opts, callback)</code> returns a <code>Deferred</code> and optionally invokes <code>callback(err, payload)</code>.</p>
295
+
296
+ <h3>Options (<code>opts</code>)</h3>
297
+ <ul>
298
+ <li><code>url</code> (<code>string</code>), <code>method</code> (<code>string</code>, default <code>"GET"</code>), <code>params</code> (<code>object</code> serialized to <code>key=value</code> query string).</li>
299
+ <li><code>headers</code> (<code>object</code>): Sets <code>Content-Type: application/json</code> automatically for non-binary/<code>FormData</code> plain objects or raw JSON wrappers on non-<code>GET</code>/<code>HEAD</code> requests unless already specified.</li>
300
+ <li><code>body</code> (<code>any</code>): Stringifies plain objects/raw JSON wrappers; passes <code>FormData</code>, <code>Blob</code>, <code>ArrayBuffer</code>, <code>ArrayBufferView</code>, or strings through.</li>
301
+ <li><code>transport</code> (<code>string</code>): Set to <code>"xhr"</code> to bypass <code>fetch</code> even if <code>fetch</code> exists; otherwise <code>fetch</code> is preferred, falling back to <code>XMLHttpRequest</code> and then IE <code>ActiveXObject</code> (<code>Msxml2.XMLHTTP.6.0</code>, <code>Msxml2.XMLHTTP.3.0</code>, <code>Microsoft.XMLHTTP</code>).</li>
302
+ <li><code>responseType</code> (<code>string</code>): <code>"text"</code> (default), <code>"json"</code>, <code>"arraybuffer"</code>, or <code>"blob"</code>.</li>
303
+ <li><code>parseJson</code> (<code>boolean</code>) and <code>reviver</code> (<code>function</code>): Parses string bodies into <code>payload.json</code> via <code>safeParse</code>.</li>
304
+ <li><code>credentials</code> (<code>string</code>), <code>withCredentials</code> (<code>boolean</code>), <code>failOnHttpError</code> (<code>boolean</code>), and <code>cause</code> (<code>any</code>, attached via <code>withCause</code>).</li>
305
+ <li><code>timeout</code> (<code>number</code> in ms), <code>retries</code> (<code>number</code>), and <code>retryDelay</code> (<code>number</code>, default <code>250</code> ms): Retries transient transport failures, timeouts (<code>err.timeout = true</code>), and HTTP statuses <code>408</code>, <code>429</code>, and <code>500&ndash;599</code> with linear backoff (<code>retryDelay * attempt</code>), without retrying user aborts (<code>err.code === "ABORTED"</code>).</li>
306
+ </ul>
307
+
308
+ <h3>Response &amp; Cancellation</h3>
309
+ <ul>
310
+ <li>Resolved payload: <code>{ status, ok, body, stream, transport, readStream }</code> (plus <code>.json</code> when parsed).</li>
311
+ <li><code>payload.readStream(onChunk, onDone)</code> streams chunks via <code>ReadableStream.getReader()</code> when available or emits the buffered XHR text once.</li>
312
+ <li>Calling <code>req.abort(reason)</code> clears timers, aborts <code>AbortController</code> or <code>xhr</code>, and rejects the <code>Deferred</code>.</li>
313
+ </ul>
314
+ </section>
315
+
316
+ <section id="websockets">
317
+ <h2>6. WebSockets (<code>LegacyNet.connectSocket</code>)</h2>
318
+ <p><code>LegacyNet.connectSocket(url, protocols, sockOpts)</code> -&gt; <code>Deferred</code>:</p>
319
+ <ul>
320
+ <li>Rejects if <code>root.WebSocket</code> is unavailable or construction fails.</li>
321
+ <li>Applies optional <code>sockOpts.binaryType</code> and optional <code>sockOpts.pingInterval</code> + <code>sockOpts.pingPayload</code> (default <code>'{"type":"ping"}'</code>), sending heartbeats while <code>socket.readyState === 1</code> and clearing the interval on close, error, or <code>stopPing()</code>.</li>
322
+ <li>Resolves with <code>{ socket, event, stopPing }</code>.</li>
323
+ </ul>
324
+ </section>
325
+
326
+ <section id="webrtc">
327
+ <h2>7. WebRTC, STUN/TURN, SDP &amp; Signaling Engine (<code>LegacyNet.rtc</code>)</h2>
328
+ <p><code>LegacyNet.rtc</code> provides ES3-written helpers and a peer/signaling engine that connects to real STUN/TURN servers and remote WebRTC peers through the host's peer connection implementation (<code>RTCPeerConnection</code>, <code>webkitRTCPeerConnection</code>, or <code>mozRTCPeerConnection</code>).</p>
329
+
330
+ <h3>ICE, STUN &amp; TURN Helpers</h3>
331
+ <ul>
332
+ <li><code>LegacyNet.rtc.hasNativeWebRtc</code> (<code>boolean</code>): Whether a supported peer connection constructor was detected at load time.</li>
333
+ <li><code>LegacyNet.rtc.parseIceUrl(rawUrl)</code> -&gt; <code>object | null</code>: Parses <code>stun:</code>, <code>stuns:</code>, <code>turn:</code>, and <code>turns:</code> URLs (IPv4, bracketed IPv6, explicit or default ports <code>3478</code>/<code>5349</code>, and <code>?transport=</code> query params) into <code>{ raw, scheme, isTurn, isTls, host, port, transport }</code>.</li>
334
+ <li><code>LegacyNet.rtc.normalizeIceServers(input)</code> -&gt; <code>object</code>: Normalizes string or <code>{ urls, username, credential, credentialType }</code> server entries and returns <code>{ iceServers, stunServers, turnServers }</code>.</li>
335
+ <li><code>LegacyNet.rtc.createStunTransactionId()</code> -&gt; <code>string</code>: Generates a 12-byte (96-bit) hex transaction ID.</li>
336
+ </ul>
337
+
338
+ <h3>SDP &amp; ICE Candidate Helpers</h3>
339
+ <ul>
340
+ <li><code>LegacyNet.rtc.buildSdp(opts)</code> -&gt; <code>string</code>: Builds a CRLF-delimited SDP offer or answer with session/media lines (<code>v=</code>, <code>o=</code>, <code>s=</code>, <code>t=</code>, <code>m=application ... UDP/DTLS/SCTP webrtc-datachannel</code>, <code>c=</code>, <code>a=ice-ufrag:</code>, <code>a=ice-pwd:</code>, <code>a=fingerprint:</code>, <code>a=setup:</code>, <code>a=mid:</code>, <code>a=sctp-port:</code>, <code>a=max-message-size:</code>, and optional <code>a=candidate:</code> lines).</li>
341
+ <li><code>LegacyNet.rtc.parseSdp(sdpText)</code> -&gt; <code>object</code>: Extracts <code>version</code>, <code>origin</code>, <code>sessionName</code>, <code>iceUfrag</code>, <code>icePwd</code>, <code>fingerprint</code>, <code>setup</code>, <code>mid</code>, <code>sctpPort</code>, <code>mediaSections</code>, and <code>candidates</code>.</li>
342
+ <li><code>LegacyNet.rtc.normalizeCandidate(candInput)</code> -&gt; <code>object | null</code>: Normalizes string or object candidates into <code>{ candidate, sdpMid, sdpMLineIndex, usernameFragment }</code>.</li>
343
+ </ul>
344
+
345
+ <h3><code>LegacyNet.rtc.createEngine(opts)</code></h3>
346
+ <p>Creates a peer and signaling controller configured with <code>{ iceServers, rtcConfig, sendSignal, autoAnswer, emitEndOfCandidates }</code>:</p>
347
+ <ul>
348
+ <li><strong>Properties:</strong> <code>hasNativeWebRtc</code>, <code>peerConnection</code>, <code>iceServers</code>, <code>stunServers</code>, <code>turnServers</code>, <code>localCandidates</code>, <code>channels</code>.</li>
349
+ <li><strong>State &amp; channels:</strong> <code>getState()</code> returns <code>{ connectionState, iceGatheringState, remoteDescriptionSet, queuedCandidates }</code>; <code>createDataChannel(label, channelOpts)</code> creates and wraps a channel with <code>{ label, channel, readyState, send, close }</code>.</li>
350
+ <li><strong>Negotiation &amp; signaling:</strong>
351
+ <ul>
352
+ <li><code>createOffer(offerOpts)</code> -&gt; <code>Deferred</code> and <code>createAnswer(answerOpts)</code> -&gt; <code>Deferred</code>: Support both Promise-returning and callback-style host WebRTC APIs, set local descriptions, emit/send <code>{ type, sdp, parsed }</code> signals, and mark ICE gathering as <code>"gathering"</code>.</li>
353
+ <li><code>handleSignal(signalMsg)</code> -&gt; <code>Deferred</code>: Parses JSON strings via <code>safeParse</code> if needed and handles <code>"offer"</code>, <code>"answer"</code> (auto-answering when <code>autoAnswer !== false</code>), <code>"candidate"</code> (buffering candidates until <code>setRemoteDescription</code> completes, then flushing them), and <code>"end-of-candidates"</code>.</li>
354
+ <li><code>addRemoteCandidate(rawCandidate)</code> -&gt; <code>Deferred</code>: Normalizes and queues or adds a remote ICE candidate.</li>
355
+ </ul>
356
+ </li>
357
+ <li><strong>Events &amp; teardown:</strong> <code>on(eventName, fn)</code>, <code>off(eventName, fn)</code> for <code>"stateChange"</code>, <code>"iceGatheringStateChange"</code>, <code>"iceCandidate"</code>, <code>"signal"</code>, <code>"dataChannel"</code>, <code>"message"</code>, <code>"track"</code>, <code>"error"</code>, and <code>"close"</code>; <code>close()</code> closes data channels and the peer connection and emits <code>"close"</code>.</li>
358
+ </ul>
359
+ </section>
360
+
361
+ <section id="utils">
362
+ <h2>8. Utility Reference (<code>LegacyNet.utils</code>)</h2>
363
+ <ul>
364
+ <li><strong>Objects, errors &amp; maps:</strong> <code>globalObj</code>, <code>isArray</code>, <code>isError</code>, <code>merge</code>, <code>keys</code>, <code>values</code>, <code>entries</code>, <code>fromEntries</code>, <code>freezeSafe</code>, <code>now</code>, <code>withCause</code>, <code>mapGetOrInsert</code>, <code>mapGetOrInsertComputed</code>.</li>
365
+ <li><strong>Arrays &amp; iterables:</strong> <code>includes</code>, <code>flat</code>, <code>flatMap</code>, <code>at</code>, <code>toReversed</code>, <code>toSorted</code>, <code>toSpliced</code>, <code>withItem</code>, <code>findLast</code>, <code>findLastIndex</code>, <code>groupBy</code>, <code>concatIterables</code>.</li>
366
+ <li><strong>Strings, precision math &amp; binary:</strong> <code>replaceAll</code>, <code>isWellFormed</code>, <code>toWellFormed</code>, <code>sumPrecise</code>, <code>toHex</code>, <code>fromHex</code>, <code>toBase64</code>, <code>fromBase64</code>, <code>isBinaryOrFormData</code>, <code>readStreamChunks</code>.</li>
367
+ </ul>
368
+ </section>
369
+
370
+ <section id="example">
371
+ <h2>9. End-to-End Usage Example</h2>
372
+ <pre><code>var rtc = LegacyNet.rtc.createEngine({
373
+ iceServers: [
374
+ { urls: "stun:stun.l.google.com:19302" },
375
+ {
376
+ urls: ["turn:turn.example.com:3478?transport=udp", "turns:turn.example.com:5349?transport=tcp"],
377
+ username: "ephemeral-user",
378
+ credential: "ephemeral-secret"
379
+ }
380
+ ],
381
+ sendSignal: function (msg) {
382
+ LegacyNet.request({
383
+ url: "https://example.com/signal",
384
+ method: "POST",
385
+ body: msg,
386
+ timeout: 3000,
387
+ retries: 1
388
+ });
389
+ }
390
+ });
391
+
392
+ rtc.on("dataChannel", function (ch) {
393
+ ch.send(LegacyNet.json.stringify({
394
+ edition: LegacyNet.capabilities.detectedEdition,
395
+ preciseSum: LegacyNet.utils.sumPrecise([0.1, 0.2, 0.3]),
396
+ b64: LegacyNet.utils.toBase64([111, 107])
397
+ }));
398
+ });
399
+
400
+ rtc.on("message", function (ev) {
401
+ // Handle incoming data channel message ev.data on channel ev.label
402
+ });
403
+
404
+ rtc.createDataChannel("control");
405
+ rtc.createOffer()["catch"](function (err) {
406
+ // Handle missing WebRTC support or negotiation error
407
+ });</code></pre>
408
+ </section>
409
+ </main>
410
+ </div>
411
+ </body>
412
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "legacynet",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "LegacyNet package",
5
5
  "type": "module",
6
6
  "main": "./LegacyNet.js",
@@ -9,6 +9,7 @@
9
9
  },
10
10
  "files": [
11
11
  "LegacyNet.js",
12
+ "docs.html",
12
13
  "LICENSE"
13
14
  ],
14
15
  "keywords": [],