@vindral/web-sdk 3.4.3 → 4.0.0

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.
package/B7jz034g.js ADDED
@@ -0,0 +1,147 @@
1
+ var I = Object.defineProperty, $ = Object.defineProperties;
2
+ var k = Object.getOwnPropertyDescriptors;
3
+ var y = Object.getOwnPropertySymbols;
4
+ var C = Object.prototype.hasOwnProperty, G = Object.prototype.propertyIsEnumerable;
5
+ var p = (e, t, n) => t in e ? I(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, d = (e, t) => {
6
+ for (var n in t || (t = {}))
7
+ C.call(t, n) && p(e, n, t[n]);
8
+ if (y)
9
+ for (var n of y(t))
10
+ G.call(t, n) && p(e, n, t[n]);
11
+ return e;
12
+ }, U = (e, t) => $(e, k(t));
13
+ var u = (e, t, n) => p(e, typeof t != "symbol" ? t + "" : t, n);
14
+ var i = (e, t, n) => new Promise((r, s) => {
15
+ var a = (h) => {
16
+ try {
17
+ o(n.next(h));
18
+ } catch (l) {
19
+ s(l);
20
+ }
21
+ }, c = (h) => {
22
+ try {
23
+ o(n.throw(h));
24
+ } catch (l) {
25
+ s(l);
26
+ }
27
+ }, o = (h) => h.done ? r(h.value) : Promise.resolve(h.value).then(a, c);
28
+ o((n = n.apply(e, t)).next());
29
+ });
30
+ const v = (e) => e ? {
31
+ Authorization: `Bearer ${e}`
32
+ } : void 0, A = (e) => {
33
+ try {
34
+ return JSON.parse(e);
35
+ } catch (t) {
36
+ return;
37
+ }
38
+ }, L = (e) => typeof e == "object" && e !== null && "message" in e;
39
+ class f extends Error {
40
+ constructor({ status: n, url: r, body: s }) {
41
+ const a = A(s), c = L(a) ? a.message : `Url ${r.toString()}, Status code: ${n}, Body: ${s}`;
42
+ super(c);
43
+ u(this, "status");
44
+ u(this, "body");
45
+ u(this, "url");
46
+ this.status = n, this.body = s, this.url = r, Object.setPrototypeOf(this, new.target.prototype);
47
+ }
48
+ }
49
+ const S = (e) => typeof e.status == "number", w = (e, t) => i(void 0, null, function* () {
50
+ const n = yield fetch(e.toString(), d({ mode: "cors" }, t));
51
+ if (!n.ok)
52
+ throw new f({ status: n.status, url: e, body: yield n.text() });
53
+ return n;
54
+ }), g = (e, t) => i(void 0, null, function* () {
55
+ return yield (yield w(e, d({}, t))).json();
56
+ }), E = (e, t) => i(void 0, null, function* () {
57
+ return w(e, d({ method: "POST" }, t));
58
+ }), b = {
59
+ lbConnect: (e) => e.channelGroupId ? `connect/?channelId=${e.channelId}&channelGroupId=${e.channelGroupId}` : `connect/?channelId=${e.channelId}`,
60
+ thumbnails: (e, t) => t ? e.channelGroupId ? `thumbnail/?channelGroupId=${e.channelGroupId}&auth.token=${t}&auth.type=jwt` : e.channelId ? `thumbnail/?channelId=${e.channelId}&auth.token=${t}&auth.type=jwt` : "thumbnail" : "thumbnail"
61
+ };
62
+ class F {
63
+ constructor(t) {
64
+ u(this, "baseUrl");
65
+ u(this, "tokenFactory");
66
+ this.baseUrl = new URL("/api/v2/", t.publicEndpoint).toString(), this.tokenFactory = t.tokenFactory;
67
+ }
68
+ /**
69
+ * Returns everything needed to setup the connection of Vindral instance.
70
+ */
71
+ connect(t) {
72
+ return i(this, null, function* () {
73
+ const { channelId: n, channelGroupId: r } = t, s = { channelId: n, channelGroupId: r }, a = new URL(b.lbConnect(t), this.baseUrl), c = this.getAuthToken(s), o = yield g(a, { headers: this.getHeaders(c) });
74
+ return {
75
+ channels: o.channels.map((l) => {
76
+ const m = this.toChannel(l, s);
77
+ return U(d({}, m), {
78
+ renditions: l.renditions,
79
+ overrides: l.overrides
80
+ });
81
+ }),
82
+ edges: o.edges,
83
+ logsUrl: o.logsUrl,
84
+ statsUrl: o.statsUrl,
85
+ telemetry: o.telemetry
86
+ };
87
+ });
88
+ }
89
+ /**
90
+ * Fetches information regarding a single channel.
91
+ *
92
+ * @param channelId the channel to fetch
93
+ * @returns a [[Channel]] containing information about the requested channel.
94
+ */
95
+ getChannel(t) {
96
+ return i(this, null, function* () {
97
+ const n = { channelId: t }, r = new URL(`channel/${t}`, this.baseUrl), s = this.getAuthToken(n), a = yield g(r, { headers: this.getHeaders(s) });
98
+ return this.toChannel(a, n, s);
99
+ });
100
+ }
101
+ /**
102
+ * Fetches channels within a channel group
103
+ *
104
+ * Note: The returned list includes inactive channels - check isLive to filter out only active channels
105
+ *
106
+ * @param channelGroup the channel group to fetch channels from
107
+ * @returns an array of [[Channel]] that belong to the channel group
108
+ */
109
+ getChannels(t) {
110
+ return i(this, null, function* () {
111
+ const n = { channelGroupId: t }, r = new URL(`channels/${t}`, this.baseUrl), s = this.getAuthToken(n), a = yield g(r, { headers: this.getHeaders(s) });
112
+ return this.toChannels(a, n, s);
113
+ });
114
+ }
115
+ getHeaders(t) {
116
+ var r;
117
+ return (r = v(t)) != null ? r : {};
118
+ }
119
+ getAuthToken(t) {
120
+ return this.tokenFactory ? this.tokenFactory(t) : void 0;
121
+ }
122
+ toChannels(t, n, r) {
123
+ return t.map((s) => this.toChannel(s, n, r));
124
+ }
125
+ toChannel(t, n, r) {
126
+ const { baseUrl: s, sizes: a } = t.thumbnail, c = s || new URL(b.thumbnails(n, r), this.baseUrl), o = a.map((h) => new URL(
127
+ `?channelId=${t.channelId}&width=${h.width}&height=${h.height}${j(
128
+ n,
129
+ r
130
+ )}`,
131
+ c
132
+ ).toString());
133
+ return {
134
+ channelId: t.channelId,
135
+ name: t.name,
136
+ isLive: t.isLive,
137
+ thumbnailUrls: o
138
+ };
139
+ }
140
+ }
141
+ const j = (e, t) => t ? e.channelGroupId ? `&channelGroupId=${e.channelGroupId}&auth.token=${t}&auth.type=jwt` : `&auth.token=${t}&auth.type=jwt` : "";
142
+ export {
143
+ F as A,
144
+ S as i,
145
+ E as p,
146
+ A as t
147
+ };
package/BTxJOjm9.js ADDED
@@ -0,0 +1,32 @@
1
+ var f = Object.defineProperty;
2
+ var o = (n, s, e) => s in n ? f(n, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[s] = e;
3
+ var l = (n, s, e) => o(n, typeof s != "symbol" ? s + "" : s, e);
4
+ class c {
5
+ constructor() {
6
+ l(this, "listeners", {});
7
+ }
8
+ emit(s, e) {
9
+ const i = this.listeners[s];
10
+ i && (this.listeners[s] = i.filter((t) => !t.once), i.map((t) => t.fn(e)).map((t) => typeof t == "function" && (t == null ? void 0 : t())));
11
+ }
12
+ off(s, e) {
13
+ const i = this.listeners[s];
14
+ i && (this.listeners[s] = i.filter((r) => r.fn !== e));
15
+ }
16
+ on(s, e) {
17
+ this.add(s, e, !1);
18
+ }
19
+ once(s, e) {
20
+ this.add(s, e, !0);
21
+ }
22
+ reset() {
23
+ this.listeners = {};
24
+ }
25
+ add(s, e, i) {
26
+ const r = this.listeners[s], t = { fn: e, once: i };
27
+ r ? r.push(t) : this.listeners[s] = [t];
28
+ }
29
+ }
30
+ export {
31
+ c as E
32
+ };