@vindral/web-sdk 4.2.0-5-g7d2f2421 → 4.2.0-7-g7d6ca07f

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/CgCFv2k5.js ADDED
@@ -0,0 +1,208 @@
1
+ import { n as e, t } from "./DTteQSVE.js";
2
+ import { t as n } from "./Dexfb10F.js";
3
+ //#region ../../libs/utils/src/assert.ts
4
+ function r(e, t) {
5
+ if (!e) throw Error(t);
6
+ }
7
+ //#endregion
8
+ //#region ../../libs/utils/src/tryJsonParse.ts
9
+ var i = (e) => {
10
+ try {
11
+ return JSON.parse(e);
12
+ } catch (e) {
13
+ return;
14
+ }
15
+ }, a = (e) => {
16
+ switch (e) {
17
+ case "h264":
18
+ case "av1": return "video";
19
+ case "aac":
20
+ case "opus":
21
+ case "mp3": return "audio";
22
+ case "webvtt": return "text";
23
+ default: throw Error("Unknown codec");
24
+ }
25
+ };
26
+ function o(e) {
27
+ if (e.startsWith("opus")) return "opus";
28
+ if (e.startsWith("mp4a")) return "aac";
29
+ if (e.startsWith("avc1")) return "h264";
30
+ if (e.startsWith("av01")) return "av1";
31
+ if (e.startsWith("webvtt")) return "webvtt";
32
+ }
33
+ //#endregion
34
+ //#region ../../libs/data-types/src/ConnectInfo.ts
35
+ function s(e) {
36
+ return !(typeof e.edges[0] == "string" || e.channels[0] && !("catalog" in e.channels[0]));
37
+ }
38
+ function c(e) {
39
+ return e.tracks.filter((e) => !!e.codec).filter((e) => o(e.codec || "")).map((e, t) => {
40
+ let n = e.codec, i = e.bitrate;
41
+ r(n, "codec is required"), r(i !== void 0, "bitrate is required");
42
+ let s = o(n);
43
+ if (r(s, "codec is required"), a(s) === "audio") {
44
+ let r = e.samplerate || 0;
45
+ return {
46
+ track: e,
47
+ id: t,
48
+ codec: s,
49
+ codecString: n,
50
+ bitRate: i,
51
+ channels: e.channelConfig === "stereo" ? 2 : 1,
52
+ sampleRate: r,
53
+ language: e.language
54
+ };
55
+ }
56
+ return a(s) === "text" ? {
57
+ track: e,
58
+ id: t,
59
+ bitRate: 0,
60
+ codec: s,
61
+ kind: "subtitles",
62
+ codecString: n,
63
+ label: e.label,
64
+ language: e.language
65
+ } : (r(e.width, "width is required"), r(e.height, "width is required"), r(e.framerate, "framerate is required"), {
66
+ track: e,
67
+ id: t,
68
+ codec: s,
69
+ bitRate: i,
70
+ codecString: n,
71
+ width: e.width,
72
+ height: e.height,
73
+ frameRate: e.framerate
74
+ });
75
+ }).sort((e, t) => e.bitRate - t.bitRate);
76
+ }
77
+ //#endregion
78
+ //#region ../../libs/api-client/src/auth.ts
79
+ var l = (e) => e ? { Authorization: `Bearer ${e}` } : void 0, u = (e, t) => {
80
+ try {
81
+ let t = e.ancestorOrigins;
82
+ if (t && t.length > 0) return Array.from(t).join(",") || void 0;
83
+ } catch (e) {}
84
+ try {
85
+ if (t.referrer) return new URL(t.referrer).origin || void 0;
86
+ } catch (e) {}
87
+ }, d = (e) => typeof e == "object" && !!e && "message" in e, f = class extends Error {
88
+ constructor({ status: t, url: n, body: r }) {
89
+ let a = i(r), o = d(a) ? a.message : `Url ${n.toString()}, Status code: ${t}, Body: ${r}`;
90
+ super(o), e(this, "status", void 0), e(this, "body", void 0), e(this, "url", void 0), this.status = t, this.body = r, this.url = n, Object.setPrototypeOf(this, new.target.prototype);
91
+ }
92
+ }, p = (e) => typeof e.status == "number", m = () => {
93
+ if (!(typeof window > "u" || typeof document > "u")) return u(window.location, document);
94
+ }, h = (e) => {
95
+ let t = m();
96
+ if (!t || e.searchParams.has("parentOrigin")) return e;
97
+ let n = new URL(e.toString());
98
+ return n.searchParams.append("parentOrigin", t), n;
99
+ }, g = function() {
100
+ var e = t(function* (e, t) {
101
+ let r = h(e), i = yield fetch(r.toString(), n({ mode: "cors" }, t));
102
+ if (!i.ok) throw new f({
103
+ status: i.status,
104
+ url: r,
105
+ body: yield i.text()
106
+ });
107
+ return i;
108
+ });
109
+ return function(t, n) {
110
+ return e.apply(this, arguments);
111
+ };
112
+ }(), _ = function() {
113
+ var e = t(function* (e, t) {
114
+ return yield (yield g(e, n({}, t))).json();
115
+ });
116
+ return function(t, n) {
117
+ return e.apply(this, arguments);
118
+ };
119
+ }();
120
+ (function() {
121
+ var e = t(function* (e) {
122
+ return g(e);
123
+ });
124
+ return function(t) {
125
+ return e.apply(this, arguments);
126
+ };
127
+ })();
128
+ var v = function() {
129
+ var e = t(function* (e, t) {
130
+ return g(e, n({ method: "POST" }, t));
131
+ });
132
+ return function(t, n) {
133
+ return e.apply(this, arguments);
134
+ };
135
+ }();
136
+ //#endregion
137
+ //#region ../../libs/api-client/src/responses/connect.ts
138
+ function y(e) {
139
+ var t;
140
+ return !(typeof e.edges[0] == "string" || e.channels[0] && "catalog" in e.channels[0] && ((t = e.channels[0]) == null ? void 0 : t.catalog) === void 0);
141
+ }
142
+ //#endregion
143
+ //#region ../../libs/api-client/src/client.ts
144
+ var b = {
145
+ lbConnect: (e) => e.channelGroupId ? `connect?channelId=${e.channelId}&channelGroupId=${e.channelGroupId}` : `connect?channelId=${e.channelId}`,
146
+ 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"
147
+ }, x = class {
148
+ constructor(t) {
149
+ e(this, "baseUrl", void 0), e(this, "tokenFactory", void 0), this.baseUrl = new URL("/api/v4/", t.publicEndpoint).toString(), this.tokenFactory = t.tokenFactory;
150
+ }
151
+ connect(e) {
152
+ var r = this;
153
+ return t(function* () {
154
+ let { channelId: t, channelGroupId: i } = e, a = {
155
+ channelId: t,
156
+ channelGroupId: i
157
+ }, o = new URL(b.lbConnect(e), r.baseUrl), s = r.getAuthToken(a), l = yield _(o, { headers: r.getHeaders(s) });
158
+ if (y(l)) {
159
+ let e = l.channels.map((e) => {
160
+ let t = r.toChannel(e, a), i = c(e.catalog);
161
+ return n(n(n({}, e), t), {}, { renditions: i });
162
+ });
163
+ return n(n({}, l), {}, { channels: e });
164
+ } else {
165
+ let e = l.channels.map((e) => {
166
+ let t = r.toChannel(e, a);
167
+ return n(n({}, e), t);
168
+ });
169
+ return n(n({}, l), {}, { channels: e });
170
+ }
171
+ })();
172
+ }
173
+ getChannel(e) {
174
+ var n = this;
175
+ return t(function* () {
176
+ let t = { channelId: e }, r = new URL(`channel/${e}`, n.baseUrl), i = n.getAuthToken(t), a = yield _(r, { headers: n.getHeaders(i) });
177
+ return n.toChannel(a, t, i);
178
+ })();
179
+ }
180
+ getChannels(e) {
181
+ var n = this;
182
+ return t(function* () {
183
+ let t = { channelGroupId: e }, r = new URL(`channels/${e}`, n.baseUrl), i = n.getAuthToken(t), a = yield _(r, { headers: n.getHeaders(i) }), o = Array.isArray(a) ? a : a.channels;
184
+ return n.toChannels(o, t, i);
185
+ })();
186
+ }
187
+ getHeaders(e) {
188
+ var t;
189
+ return (t = l(e)) == null ? {} : t;
190
+ }
191
+ getAuthToken(e) {
192
+ return this.tokenFactory ? this.tokenFactory(e) : void 0;
193
+ }
194
+ toChannels(e, t, n) {
195
+ return e.map((e) => this.toChannel(e, t, n));
196
+ }
197
+ toChannel(e, t, n) {
198
+ let { baseUrl: r, sizes: i } = e.thumbnail, a = r || new URL(b.thumbnails(t, n), this.baseUrl), o = i.map((r) => new URL(`?channelId=${e.channelId}&width=${r.width}&height=${r.height}${S(t, n)}`, a).toString());
199
+ return {
200
+ channelId: e.channelId,
201
+ name: e.name,
202
+ isLive: e.isLive,
203
+ thumbnailUrls: o
204
+ };
205
+ }
206
+ }, S = (e, t) => t ? e.channelGroupId ? `&channelGroupId=${e.channelGroupId}&auth.token=${t}&auth.type=jwt` : `&auth.token=${t}&auth.type=jwt` : "";
207
+ //#endregion
208
+ export { s as a, i as c, c as i, r as l, p as n, o, v as r, a as s, x as t };