@genai-fi/base 3.0.1

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 (99) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +18 -0
  3. package/dist/Button-DQwRVw4a.js +1918 -0
  4. package/dist/DefaultPropsProvider-C0Ib4Mye.js +520 -0
  5. package/dist/DialogQR-BU45QB3i.js +1625 -0
  6. package/dist/FileSaver.min-DhePf63e.js +2397 -0
  7. package/dist/FlashWifi-CaAOKd3g.js +33 -0
  8. package/dist/_commonjsHelpers-DaMA6jEr.js +8 -0
  9. package/dist/assets/AlertPara.css +1 -0
  10. package/dist/assets/ConnectionStatus.css +1 -0
  11. package/dist/assets/DialogQR.css +1 -0
  12. package/dist/assets/Motd.css +1 -0
  13. package/dist/assets/Privacy.css +1 -0
  14. package/dist/assets/Spinner.css +1 -0
  15. package/dist/assets/Webcam.css +1 -0
  16. package/dist/assets/style.css +1 -0
  17. package/dist/assets/theme.css +1 -0
  18. package/dist/colours.module.css +19 -0
  19. package/dist/components/AlertPara/AlertPara.d.ts +8 -0
  20. package/dist/components/AlertPara/AlertPara.js +19 -0
  21. package/dist/components/BusyButton/BusyButton.d.ts +7 -0
  22. package/dist/components/BusyButton/BusyButton.js +25 -0
  23. package/dist/components/Button/Button.d.ts +6 -0
  24. package/dist/components/Button/Button.js +6 -0
  25. package/dist/components/ConnectionStatus/ConnectionStatus.d.ts +12 -0
  26. package/dist/components/ConnectionStatus/ConnectionStatus.js +82 -0
  27. package/dist/components/ConnectionStatus/FlashWifi.d.ts +1 -0
  28. package/dist/components/ConnectionStatus/FlashWifi.js +6 -0
  29. package/dist/components/ConnectionStatus/check.d.ts +1 -0
  30. package/dist/components/ConnectionStatus/check.js +10 -0
  31. package/dist/components/ConnectionStatus/ice.d.ts +13 -0
  32. package/dist/components/ConnectionStatus/ice.js +12 -0
  33. package/dist/components/ContentLoader/ContentError.d.ts +5 -0
  34. package/dist/components/ContentLoader/ContentError.js +21 -0
  35. package/dist/components/ContentLoader/ContentLoader.d.ts +8 -0
  36. package/dist/components/ContentLoader/ContentLoader.js +51 -0
  37. package/dist/components/ContentLoader/ContentProgress.d.ts +6 -0
  38. package/dist/components/ContentLoader/ContentProgress.js +31 -0
  39. package/dist/components/Motd/Motd.d.ts +5 -0
  40. package/dist/components/Motd/Motd.js +48 -0
  41. package/dist/components/Privacy/Privacy.d.ts +7 -0
  42. package/dist/components/Privacy/Privacy.js +57 -0
  43. package/dist/components/QRCode/DialogQR.d.ts +7 -0
  44. package/dist/components/QRCode/DialogQR.js +14 -0
  45. package/dist/components/QRCode/QRCode.d.ts +9 -0
  46. package/dist/components/QRCode/QRCode.js +61 -0
  47. package/dist/components/Spinner/Spinner.d.ts +6 -0
  48. package/dist/components/Spinner/Spinner.js +33 -0
  49. package/dist/components/Webcam/Webcam.d.ts +15 -0
  50. package/dist/components/Webcam/Webcam.js +397 -0
  51. package/dist/components/Webcam/webcamClass.d.ts +32 -0
  52. package/dist/components/Webcam/webcamClass.js +76 -0
  53. package/dist/createSvgIcon-BfF8yuCp.js +249 -0
  54. package/dist/createTheme-BIcG8YPQ.js +2895 -0
  55. package/dist/hooks/id.d.ts +1 -0
  56. package/dist/hooks/id.js +16 -0
  57. package/dist/hooks/onlyOnce.d.ts +1 -0
  58. package/dist/hooks/onlyOnce.js +7 -0
  59. package/dist/hooks/peer.d.ts +25 -0
  60. package/dist/hooks/peer.js +70 -0
  61. package/dist/hooks/random.d.ts +1 -0
  62. package/dist/hooks/random.js +9 -0
  63. package/dist/hooks/useTabActive.d.ts +1 -0
  64. package/dist/hooks/useTabActive.js +17 -0
  65. package/dist/index-SOhdqzHq.js +113 -0
  66. package/dist/main.d.ts +21 -0
  67. package/dist/main.js +49 -0
  68. package/dist/react-D-b-Xrzv.js +98 -0
  69. package/dist/services/peer2peer/Incoming.d.ts +13 -0
  70. package/dist/services/peer2peer/Incoming.js +39 -0
  71. package/dist/services/peer2peer/Outgoing.d.ts +25 -0
  72. package/dist/services/peer2peer/Outgoing.js +65 -0
  73. package/dist/services/peer2peer/Peer2Peer.d.ts +80 -0
  74. package/dist/services/peer2peer/Peer2Peer.js +3367 -0
  75. package/dist/services/peer2peer/PeerConnection.d.ts +40 -0
  76. package/dist/services/peer2peer/PeerConnection.js +155 -0
  77. package/dist/services/peer2peer/error.d.ts +2 -0
  78. package/dist/services/peer2peer/error.js +5 -0
  79. package/dist/services/peer2peer/types.d.ts +38 -0
  80. package/dist/services/peer2peer/types.js +1 -0
  81. package/dist/state/webrtcState.d.ts +12 -0
  82. package/dist/state/webrtcState.js +6 -0
  83. package/dist/style/theme.d.ts +1 -0
  84. package/dist/style/theme.js +33 -0
  85. package/dist/style.module-DSFm2eLD.js +9 -0
  86. package/dist/util/backoff.d.ts +1 -0
  87. package/dist/util/backoff.js +6 -0
  88. package/dist/util/base64.d.ts +2 -0
  89. package/dist/util/base64.js +19 -0
  90. package/dist/util/canvas.d.ts +7 -0
  91. package/dist/util/canvas.js +92 -0
  92. package/dist/util/crypto.d.ts +7 -0
  93. package/dist/util/crypto.js +50 -0
  94. package/dist/util/randomId.d.ts +1 -0
  95. package/dist/util/randomId.js +8 -0
  96. package/dist/util/zip.d.ts +13 -0
  97. package/dist/util/zip.js +94 -0
  98. package/dist/webrtcState-D0nJpE9Z.js +406 -0
  99. package/package.json +88 -0
@@ -0,0 +1 @@
1
+ export declare function useID(size?: number): string;
@@ -0,0 +1,16 @@
1
+ import t from "../util/randomId.js";
2
+ import { useMemo as r } from "react";
3
+ function m(e) {
4
+ return r(() => {
5
+ const o = window.sessionStorage.getItem(`genai-sm-idcode-${e}`);
6
+ if (o)
7
+ return o;
8
+ {
9
+ const n = t(e);
10
+ return window.sessionStorage.setItem(`genai-sm-idcode-${e}`, n), n;
11
+ }
12
+ }, [e]);
13
+ }
14
+ export {
15
+ m as useID
16
+ };
@@ -0,0 +1 @@
1
+ export declare function useOnlyOnce(key: string, value: boolean): boolean;
@@ -0,0 +1,7 @@
1
+ import { useMemo as e } from "react";
2
+ function s(r, t) {
3
+ return e(() => window.sessionStorage.getItem(r) ? !0 : (t && window.sessionStorage.setItem(r, "true"), t), [r, t]);
4
+ }
5
+ export {
6
+ s as useOnlyOnce
7
+ };
@@ -0,0 +1,25 @@
1
+ import { default as Peer2Peer, P2POptions } from '../services/peer2peer/Peer2Peer';
2
+ import { Connection, PeerEvent } from '../services/peer2peer/types';
3
+ interface Callbacks<T extends PeerEvent> {
4
+ onOpen?: () => void;
5
+ onConnect?: (conn: Connection<T>) => void;
6
+ onClose?: (conn?: Connection<T>) => void;
7
+ onError?: (e: unknown) => void;
8
+ onData?: (data: T, conn: Connection<T>) => void;
9
+ }
10
+ interface Props<T extends PeerEvent> extends Callbacks<T>, P2POptions {
11
+ code?: string;
12
+ server?: string;
13
+ host: string;
14
+ secure?: boolean;
15
+ key?: string;
16
+ port?: number;
17
+ disabled?: boolean;
18
+ }
19
+ export type PeerProps<T extends PeerEvent> = Props<T>;
20
+ export default function usePeer<T extends PeerEvent>({ code, server, host, secure, port, key, disabled, onOpen, onClose, onError, onData, onConnect, forceTURN, forceWebsocket, }: Props<T>): {
21
+ send: ((data: T, exclude?: string[]) => void) | undefined;
22
+ ready: boolean;
23
+ peer: Peer2Peer<T> | undefined;
24
+ };
25
+ export {};
@@ -0,0 +1,70 @@
1
+ import { useState as S, useRef as x, useEffect as D } from "react";
2
+ import { i as E, w as T } from "../webrtcState-D0nJpE9Z.js";
3
+ import V from "../services/peer2peer/Peer2Peer.js";
4
+ import { u as q, a as z } from "../react-D-b-Xrzv.js";
5
+ function I({
6
+ code: u,
7
+ server: i,
8
+ host: f,
9
+ secure: l,
10
+ port: d,
11
+ key: m,
12
+ disabled: p,
13
+ onOpen: C,
14
+ onClose: b,
15
+ onError: w,
16
+ onData: A,
17
+ onConnect: P,
18
+ forceTURN: g,
19
+ forceWebsocket: y
20
+ }) {
21
+ const [s, R] = S(), e = x({}), [o, c] = q(T), a = z(E), [j, n] = S("connecting");
22
+ return D(() => {
23
+ e.current.onClose = b, e.current.onOpen = C, e.current.onConnect = P, e.current.onError = w, e.current.onData = A;
24
+ }, [A, C, b, w, P]), D(() => {
25
+ if (p) {
26
+ n("failed"), c("disabled");
27
+ return;
28
+ } else
29
+ n("connecting");
30
+ if (o === "unset") return;
31
+ if (o === "disabled") {
32
+ c("unset");
33
+ return;
34
+ }
35
+ if (!u) return;
36
+ if (!a) {
37
+ setTimeout(() => {
38
+ n("failed");
39
+ }, 5e3), n("failed");
40
+ return;
41
+ }
42
+ const t = new V(
43
+ u,
44
+ f,
45
+ l || !1,
46
+ m || "peerjs",
47
+ d || 443,
48
+ a,
49
+ o === "relay",
50
+ i,
51
+ { forceTURN: g, forceWebsocket: y }
52
+ );
53
+ return t.on("status", n), t.on("data", (r, v) => {
54
+ e.current.onData && e.current.onData(r, v);
55
+ }), t.on("close", (r) => {
56
+ e.current.onClose && e.current.onClose(r);
57
+ }), t.on("connect", (r) => {
58
+ e.current.onConnect && e.current.onConnect(r);
59
+ }), R(t), () => {
60
+ t.destroy();
61
+ };
62
+ }, [u, i, o, a, f, m, d, l, p, c, g, y]), {
63
+ send: s ? s.boundSendAll : void 0,
64
+ ready: j === "ready",
65
+ peer: s
66
+ };
67
+ }
68
+ export {
69
+ I as default
70
+ };
@@ -0,0 +1 @@
1
+ export default function useRandom(size: number): string;
@@ -0,0 +1,9 @@
1
+ import o from "../util/randomId.js";
2
+ import { useRef as t } from "react";
3
+ function f(e) {
4
+ const r = t();
5
+ return r.current === void 0 && (r.current = o(e)), r.current;
6
+ }
7
+ export {
8
+ f as default
9
+ };
@@ -0,0 +1 @@
1
+ export declare function useTabActive(): boolean;
@@ -0,0 +1,17 @@
1
+ import { useState as r, useEffect as i } from "react";
2
+ function u() {
3
+ const [o, e] = r(!0);
4
+ return i(() => {
5
+ const t = () => {
6
+ e(!1);
7
+ }, n = () => {
8
+ e(!0);
9
+ };
10
+ return window.addEventListener("blur", t), window.addEventListener("focus", n), () => {
11
+ window.removeEventListener("blur", t), window.removeEventListener("focus", n);
12
+ };
13
+ }, [e]), o;
14
+ }
15
+ export {
16
+ u as useTabActive
17
+ };
@@ -0,0 +1,113 @@
1
+ import { g as L } from "./_commonjsHelpers-DaMA6jEr.js";
2
+ var x = { exports: {} }, E;
3
+ function C() {
4
+ return E || (E = 1, function(g) {
5
+ var w = Object.prototype.hasOwnProperty, c = "~";
6
+ function h() {
7
+ }
8
+ Object.create && (h.prototype = /* @__PURE__ */ Object.create(null), new h().__proto__ || (c = !1));
9
+ function d(s, t, n) {
10
+ this.fn = s, this.context = t, this.once = n || !1;
11
+ }
12
+ function m(s, t, n, r, l) {
13
+ if (typeof n != "function")
14
+ throw new TypeError("The listener must be a function");
15
+ var u = new d(n, r || s, l), o = c ? c + t : t;
16
+ return s._events[o] ? s._events[o].fn ? s._events[o] = [s._events[o], u] : s._events[o].push(u) : (s._events[o] = u, s._eventsCount++), s;
17
+ }
18
+ function y(s, t) {
19
+ --s._eventsCount === 0 ? s._events = new h() : delete s._events[t];
20
+ }
21
+ function f() {
22
+ this._events = new h(), this._eventsCount = 0;
23
+ }
24
+ f.prototype.eventNames = function() {
25
+ var t = [], n, r;
26
+ if (this._eventsCount === 0) return t;
27
+ for (r in n = this._events)
28
+ w.call(n, r) && t.push(c ? r.slice(1) : r);
29
+ return Object.getOwnPropertySymbols ? t.concat(Object.getOwnPropertySymbols(n)) : t;
30
+ }, f.prototype.listeners = function(t) {
31
+ var n = c ? c + t : t, r = this._events[n];
32
+ if (!r) return [];
33
+ if (r.fn) return [r.fn];
34
+ for (var l = 0, u = r.length, o = new Array(u); l < u; l++)
35
+ o[l] = r[l].fn;
36
+ return o;
37
+ }, f.prototype.listenerCount = function(t) {
38
+ var n = c ? c + t : t, r = this._events[n];
39
+ return r ? r.fn ? 1 : r.length : 0;
40
+ }, f.prototype.emit = function(t, n, r, l, u, o) {
41
+ var a = c ? c + t : t;
42
+ if (!this._events[a]) return !1;
43
+ var e = this._events[a], v = arguments.length, p, i;
44
+ if (e.fn) {
45
+ switch (e.once && this.removeListener(t, e.fn, void 0, !0), v) {
46
+ case 1:
47
+ return e.fn.call(e.context), !0;
48
+ case 2:
49
+ return e.fn.call(e.context, n), !0;
50
+ case 3:
51
+ return e.fn.call(e.context, n, r), !0;
52
+ case 4:
53
+ return e.fn.call(e.context, n, r, l), !0;
54
+ case 5:
55
+ return e.fn.call(e.context, n, r, l, u), !0;
56
+ case 6:
57
+ return e.fn.call(e.context, n, r, l, u, o), !0;
58
+ }
59
+ for (i = 1, p = new Array(v - 1); i < v; i++)
60
+ p[i - 1] = arguments[i];
61
+ e.fn.apply(e.context, p);
62
+ } else {
63
+ var b = e.length, _;
64
+ for (i = 0; i < b; i++)
65
+ switch (e[i].once && this.removeListener(t, e[i].fn, void 0, !0), v) {
66
+ case 1:
67
+ e[i].fn.call(e[i].context);
68
+ break;
69
+ case 2:
70
+ e[i].fn.call(e[i].context, n);
71
+ break;
72
+ case 3:
73
+ e[i].fn.call(e[i].context, n, r);
74
+ break;
75
+ case 4:
76
+ e[i].fn.call(e[i].context, n, r, l);
77
+ break;
78
+ default:
79
+ if (!p) for (_ = 1, p = new Array(v - 1); _ < v; _++)
80
+ p[_ - 1] = arguments[_];
81
+ e[i].fn.apply(e[i].context, p);
82
+ }
83
+ }
84
+ return !0;
85
+ }, f.prototype.on = function(t, n, r) {
86
+ return m(this, t, n, r, !1);
87
+ }, f.prototype.once = function(t, n, r) {
88
+ return m(this, t, n, r, !0);
89
+ }, f.prototype.removeListener = function(t, n, r, l) {
90
+ var u = c ? c + t : t;
91
+ if (!this._events[u]) return this;
92
+ if (!n)
93
+ return y(this, u), this;
94
+ var o = this._events[u];
95
+ if (o.fn)
96
+ o.fn === n && (!l || o.once) && (!r || o.context === r) && y(this, u);
97
+ else {
98
+ for (var a = 0, e = [], v = o.length; a < v; a++)
99
+ (o[a].fn !== n || l && !o[a].once || r && o[a].context !== r) && e.push(o[a]);
100
+ e.length ? this._events[u] = e.length === 1 ? e[0] : e : y(this, u);
101
+ }
102
+ return this;
103
+ }, f.prototype.removeAllListeners = function(t) {
104
+ var n;
105
+ return t ? (n = c ? c + t : t, this._events[n] && y(this, n)) : (this._events = new h(), this._eventsCount = 0), this;
106
+ }, f.prototype.off = f.prototype.removeListener, f.prototype.addListener = f.prototype.on, f.prefixed = c, f.EventEmitter = f, g.exports = f;
107
+ }(x)), x.exports;
108
+ }
109
+ var O = C();
110
+ const k = /* @__PURE__ */ L(O);
111
+ export {
112
+ k as E
113
+ };
package/dist/main.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ export { default as ConnectionStatus } from './components/ConnectionStatus/ConnectionStatus';
2
+ export { Button, LargeButton } from './components/Button/Button';
3
+ export { default as usePeer } from './hooks/peer';
4
+ export type { SenderType, PeerEvent, PeerErrorType, PeerStatus, BuiltinEvent, Connection, PeerConnectionType, } from './services/peer2peer/types';
5
+ export { default as Peer2Peer } from './services/peer2peer/Peer2Peer';
6
+ export { useID } from './hooks/id';
7
+ export { useOnlyOnce } from './hooks/onlyOnce';
8
+ export { default as useRandom } from './hooks/random';
9
+ export { theme } from './style/theme';
10
+ export { default as randomId } from './util/randomId';
11
+ export { cropTo, canvasFromFile, canvasesFromFiles, canvasFromImage, canvasFromURL, canvasFromDataTransfer, urlFromDataTransfer, } from './util/canvas';
12
+ export { loadZipFile, saveZipFile, createZipBlob } from './util/zip';
13
+ export type { ZipData } from './util/zip';
14
+ export { useTabActive } from './hooks/useTabActive';
15
+ export { default as Spinner } from './components/Spinner/Spinner';
16
+ export { default as Privacy } from './components/Privacy/Privacy';
17
+ export { default as BusyButton } from './components/BusyButton/BusyButton';
18
+ export { default as AlertPara } from './components/AlertPara/AlertPara';
19
+ export { default as QRCode } from './components/QRCode/QRCode';
20
+ export { default as Webcam } from './components/Webcam/Webcam';
21
+ export { default as ContentLoader } from './components/ContentLoader/ContentLoader';
package/dist/main.js ADDED
@@ -0,0 +1,49 @@
1
+ import { default as o } from "./components/ConnectionStatus/ConnectionStatus.js";
2
+ import { B as t, L as f } from "./Button-DQwRVw4a.js";
3
+ import { default as m } from "./hooks/peer.js";
4
+ import { default as u } from "./services/peer2peer/Peer2Peer.js";
5
+ import { useID as n } from "./hooks/id.js";
6
+ import { useOnlyOnce as d } from "./hooks/onlyOnce.js";
7
+ import { default as i } from "./hooks/random.js";
8
+ import { theme as v } from "./style/theme.js";
9
+ import { default as P } from "./util/randomId.js";
10
+ import { canvasFromDataTransfer as T, canvasFromFile as b, canvasFromImage as y, canvasFromURL as C, canvasesFromFiles as D, cropTo as I, urlFromDataTransfer as R } from "./util/canvas.js";
11
+ import { createZipBlob as g, loadZipFile as A, saveZipFile as O } from "./util/zip.js";
12
+ import { useTabActive as h } from "./hooks/useTabActive.js";
13
+ import { default as U } from "./components/Spinner/Spinner.js";
14
+ import { default as j } from "./components/Privacy/Privacy.js";
15
+ import { default as q } from "./components/BusyButton/BusyButton.js";
16
+ import { default as z } from "./components/AlertPara/AlertPara.js";
17
+ import { default as G } from "./components/QRCode/QRCode.js";
18
+ import { default as J } from "./components/Webcam/Webcam.js";
19
+ import { default as M } from "./components/ContentLoader/ContentLoader.js";
20
+ export {
21
+ z as AlertPara,
22
+ q as BusyButton,
23
+ t as Button,
24
+ o as ConnectionStatus,
25
+ M as ContentLoader,
26
+ f as LargeButton,
27
+ u as Peer2Peer,
28
+ j as Privacy,
29
+ G as QRCode,
30
+ U as Spinner,
31
+ J as Webcam,
32
+ T as canvasFromDataTransfer,
33
+ b as canvasFromFile,
34
+ y as canvasFromImage,
35
+ C as canvasFromURL,
36
+ D as canvasesFromFiles,
37
+ g as createZipBlob,
38
+ I as cropTo,
39
+ A as loadZipFile,
40
+ P as randomId,
41
+ O as saveZipFile,
42
+ v as theme,
43
+ R as urlFromDataTransfer,
44
+ n as useID,
45
+ d as useOnlyOnce,
46
+ m as usePeer,
47
+ i as useRandom,
48
+ h as useTabActive
49
+ };
@@ -0,0 +1,98 @@
1
+ import w, { useReducer as v, useEffect as R, useDebugValue as S, useCallback as P, useContext as x, createContext as y } from "react";
2
+ import { g as C, I as h } from "./webrtcState-D0nJpE9Z.js";
3
+ const F = {}, V = y(
4
+ void 0
5
+ );
6
+ function A(t) {
7
+ return x(V) || C();
8
+ }
9
+ const b = (t) => typeof (t == null ? void 0 : t.then) == "function", g = (t) => {
10
+ t.status || (t.status = "pending", t.then(
11
+ (o) => {
12
+ t.status = "fulfilled", t.value = o;
13
+ },
14
+ (o) => {
15
+ t.status = "rejected", t.reason = o;
16
+ }
17
+ ));
18
+ }, j = w.use || // A shim for older React versions
19
+ ((t) => {
20
+ if (t.status === "pending")
21
+ throw t;
22
+ if (t.status === "fulfilled")
23
+ return t.value;
24
+ throw t.status === "rejected" ? t.reason : (g(t), t);
25
+ }), d = /* @__PURE__ */ new WeakMap(), _ = (t, o) => {
26
+ let s = d.get(t);
27
+ return s || (s = new Promise((r, n) => {
28
+ let l = t;
29
+ const a = (e) => (u) => {
30
+ l === e && r(u);
31
+ }, f = (e) => (u) => {
32
+ l === e && n(u);
33
+ }, c = () => {
34
+ try {
35
+ const e = o();
36
+ b(e) ? (d.set(e, s), l = e, e.then(a(e), f(e)), h(e, c)) : r(e);
37
+ } catch (e) {
38
+ n(e);
39
+ }
40
+ };
41
+ t.then(a(t), f(t)), h(t, c);
42
+ }), d.set(t, s)), s;
43
+ };
44
+ function k(t, o) {
45
+ const { delay: s, unstable_promiseStatus: r = !w.use } = {}, n = A(), [[l, a, f], c] = v(
46
+ (u) => {
47
+ const i = n.get(t);
48
+ return Object.is(u[0], i) && u[1] === n && u[2] === t ? u : [i, n, t];
49
+ },
50
+ void 0,
51
+ () => [n.get(t), n, t]
52
+ );
53
+ let e = l;
54
+ if ((a !== n || f !== t) && (c(), e = n.get(t)), R(() => {
55
+ const u = n.sub(t, () => {
56
+ if (r)
57
+ try {
58
+ const i = n.get(t);
59
+ b(i) && g(
60
+ _(i, () => n.get(t))
61
+ );
62
+ } catch {
63
+ }
64
+ if (typeof s == "number") {
65
+ setTimeout(c, s);
66
+ return;
67
+ }
68
+ c();
69
+ });
70
+ return c(), u;
71
+ }, [n, t, s, r]), S(e), b(e)) {
72
+ const u = _(e, () => n.get(t));
73
+ return r && g(u), j(u);
74
+ }
75
+ return e;
76
+ }
77
+ function E(t, o) {
78
+ const s = A();
79
+ return P(
80
+ (...n) => {
81
+ if ((F ? "production" : void 0) !== "production" && !("write" in t))
82
+ throw new Error("not writable atom");
83
+ return s.set(t, ...n);
84
+ },
85
+ [s, t]
86
+ );
87
+ }
88
+ function L(t, o) {
89
+ return [
90
+ k(t),
91
+ // We do wrong type assertion here, which results in throwing an error.
92
+ E(t)
93
+ ];
94
+ }
95
+ export {
96
+ k as a,
97
+ L as u
98
+ };
@@ -0,0 +1,13 @@
1
+ import { default as EventEmitter } from 'eventemitter3';
2
+ import { default as PeerConnection, IConnectionIO } from './PeerConnection';
3
+ import { PeerStatus } from './types';
4
+ export default class Incoming extends EventEmitter<'connect' | 'close' | 'data'> implements IConnectionIO {
5
+ private _connection;
6
+ readonly direction: 'outgoing' | 'incoming';
7
+ private _status;
8
+ constructor(connection: PeerConnection);
9
+ get status(): PeerStatus;
10
+ private addHandlers;
11
+ get connection(): PeerConnection;
12
+ close(): void;
13
+ }
@@ -0,0 +1,39 @@
1
+ var s = Object.defineProperty;
2
+ var i = (n, e, t) => e in n ? s(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var o = (n, e, t) => i(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { E as c } from "../../index-SOhdqzHq.js";
5
+ function r(n) {
6
+ return typeof n.event == "string";
7
+ }
8
+ class _ extends c {
9
+ constructor(t) {
10
+ super();
11
+ o(this, "_connection");
12
+ o(this, "direction", "incoming");
13
+ o(this, "_status", "connecting");
14
+ this._connection = t, this.addHandlers();
15
+ }
16
+ get status() {
17
+ return this._status;
18
+ }
19
+ addHandlers() {
20
+ this._connection.on("open", () => {
21
+ this._connection.send({ event: "eter:welcome" }), this._status = "ready", this.emit("connect", this._connection);
22
+ }), this._connection.on("data", async (t) => {
23
+ r(t) && this.emit("data", t, this._connection);
24
+ }), this._connection.on("error", (t) => {
25
+ console.error(t.type);
26
+ }), this._connection.on("close", () => {
27
+ this._connection.removeAllListeners(), this._connection.close(), this._status = "failed", this.emit("close");
28
+ });
29
+ }
30
+ get connection() {
31
+ return this._connection;
32
+ }
33
+ close() {
34
+ this._connection.removeAllListeners(), this._connection.close(), this._status = "failed", this.emit("close");
35
+ }
36
+ }
37
+ export {
38
+ _ as default
39
+ };
@@ -0,0 +1,25 @@
1
+ import { default as EventEmitter } from 'eventemitter3';
2
+ import { default as PeerConnection, IConnectionIO } from './PeerConnection';
3
+ import { PeerStatus } from './types';
4
+ interface OutgoingOptions {
5
+ retryDelay?: number;
6
+ }
7
+ export default class Outgoing extends EventEmitter<'connect' | 'retry' | 'close' | 'data'> implements IConnectionIO {
8
+ private _connection;
9
+ private timeout;
10
+ private retryCount;
11
+ private timeouts;
12
+ private options?;
13
+ readonly direction: 'outgoing' | 'incoming';
14
+ private connectionCount;
15
+ private _status;
16
+ constructor(connection: PeerConnection, options?: OutgoingOptions);
17
+ get status(): PeerStatus;
18
+ private delayedRecreate;
19
+ private recreate;
20
+ private addHandlers;
21
+ get connection(): PeerConnection;
22
+ /** Close and do not reconnect */
23
+ close(): void;
24
+ }
25
+ export {};
@@ -0,0 +1,65 @@
1
+ var s = Object.defineProperty;
2
+ var c = (i, o, t) => o in i ? s(i, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[o] = t;
3
+ var n = (i, o, t) => c(i, typeof o != "symbol" ? o + "" : o, t);
4
+ import { E as r } from "../../index-SOhdqzHq.js";
5
+ import h from "./PeerConnection.js";
6
+ import { expBackoff as a } from "../../util/backoff.js";
7
+ function u(i) {
8
+ return typeof i.event == "string";
9
+ }
10
+ class p extends r {
11
+ constructor(t, e) {
12
+ super();
13
+ n(this, "_connection");
14
+ n(this, "timeout", -1);
15
+ n(this, "retryCount", 0);
16
+ n(this, "timeouts", 0);
17
+ n(this, "options");
18
+ n(this, "direction", "outgoing");
19
+ n(this, "connectionCount", 0);
20
+ n(this, "_status", "connecting");
21
+ this._connection = t, this.options = e, this.addHandlers();
22
+ }
23
+ get status() {
24
+ return this._status;
25
+ }
26
+ delayedRecreate() {
27
+ var t;
28
+ this._status = "connecting", this.timeout >= 0 && clearTimeout(this.timeout), this.timeout = window.setTimeout(() => {
29
+ this.recreate();
30
+ }, ((t = this.options) == null ? void 0 : t.retryDelay) || a(this.retryCount++));
31
+ }
32
+ recreate(t = !1) {
33
+ this._status = "connecting";
34
+ const e = this._connection;
35
+ e.removeAllListeners(), e.close(), !e.peerInstance.destroyed && (this._connection = new h(
36
+ e.peer,
37
+ e.peerInstance,
38
+ !0,
39
+ t || e.connectionType === "server" ? void 0 : e.peerInstance.connect(e.peer, { reliable: !0 })
40
+ ), this.addHandlers());
41
+ }
42
+ addHandlers() {
43
+ this._connection.on("timeout", () => {
44
+ this.emit("retry"), this.timeouts += 1, this.recreate(this.timeouts > 1);
45
+ }), this._connection.on("open", () => {
46
+ this.retryCount = 0, this.timeouts = 0, this._connection.send({ event: "eter:join" }), this.connectionCount += 1, this._status = "ready", this.emit("connect", this._connection);
47
+ }), this._connection.on("data", async (t) => {
48
+ u(t) && this.emit("data", t, this._connection);
49
+ }), this._connection.on("error", (t) => {
50
+ console.error(t.type);
51
+ }), this._connection.on("close", (t, e) => {
52
+ e ? this.close() : (this.emit("retry"), this.delayedRecreate());
53
+ });
54
+ }
55
+ get connection() {
56
+ return this._connection;
57
+ }
58
+ /** Close and do not reconnect */
59
+ close() {
60
+ this.timeout >= 0 && clearTimeout(this.timeout), this._connection.removeAllListeners(), this._connection.close(), this._status = "failed", this.emit("close");
61
+ }
62
+ }
63
+ export {
64
+ p as default
65
+ };
@@ -0,0 +1,80 @@
1
+ import { CommunicationRelayConfiguration } from '../../components/ConnectionStatus/ice';
2
+ import { Connection, PeerErrorType, PeerEvent, PeerStatus } from './types';
3
+ import { IConnectionIO } from './PeerConnection';
4
+ type P2PDataEvent<T extends PeerEvent> = {
5
+ data: [data: T, conn: Connection<T>];
6
+ };
7
+ type P2PStatusEvent = {
8
+ status: [status: PeerStatus];
9
+ };
10
+ type P2PQualityEvent = {
11
+ quality: [quality: number];
12
+ };
13
+ type P2PErrorEvent = {
14
+ error: [error: PeerErrorType];
15
+ };
16
+ type P2PConnectEvent<T extends PeerEvent> = {
17
+ connect: [conn: Connection<T>];
18
+ };
19
+ type P2PCloseEvent<T extends PeerEvent> = {
20
+ close: [conn: Connection<T>];
21
+ };
22
+ type P2POpenEvent = {
23
+ open: [];
24
+ };
25
+ type P2PRetryEvent = {
26
+ retry: [];
27
+ };
28
+ type P2PEvents<T extends PeerEvent> = P2PDataEvent<T> & P2PErrorEvent & P2PStatusEvent & P2PConnectEvent<T> & P2PCloseEvent<T> & P2POpenEvent & P2PRetryEvent & P2PQualityEvent;
29
+ export interface P2POptions {
30
+ forceWebsocket?: boolean;
31
+ forceTURN?: boolean;
32
+ dropICE?: boolean;
33
+ }
34
+ export default class Peer2Peer<T extends PeerEvent> {
35
+ private emitter;
36
+ private peer;
37
+ private connections;
38
+ private heatbeatTimeout;
39
+ private retryTimeout;
40
+ status: PeerStatus;
41
+ private connRetryCount;
42
+ isRelay: boolean;
43
+ error: PeerErrorType;
44
+ private peerRetryCount;
45
+ private idRetryCount;
46
+ private server?;
47
+ private host;
48
+ private secure;
49
+ private port;
50
+ private key;
51
+ private ice;
52
+ private relay;
53
+ readonly code: string;
54
+ private _quality;
55
+ private options?;
56
+ boundSendAll: (typeof this)['sendAll'];
57
+ private failed;
58
+ constructor(code: string, host: string, secure: boolean, key: string, port: number, ice: CommunicationRelayConfiguration, relay: boolean, server?: string, options?: P2POptions);
59
+ get quality(): number;
60
+ get size(): number;
61
+ private update;
62
+ private emit;
63
+ on<TEventName extends keyof P2PEvents<T> & string>(eventName: TEventName, handler: (...eventArg: P2PEvents<T>[TEventName]) => void): void;
64
+ off<TEventName extends keyof P2PEvents<T> & string>(eventName: TEventName, handler: (...eventArg: P2PEvents<T>[TEventName]) => void): void;
65
+ private createPeerServer;
66
+ /** Completely restart the connection from scratch. */
67
+ reset(): void;
68
+ destroy(): void;
69
+ private setError;
70
+ private retryConnection;
71
+ /** Initiate a connection to a peer */
72
+ createPeer(code: string, useServer?: boolean): void;
73
+ private retry;
74
+ private onOpen;
75
+ getConnection(id: string): IConnectionIO | undefined;
76
+ private onConnection;
77
+ private onError;
78
+ sendAll(data: T, exclude?: string[]): void;
79
+ }
80
+ export {};