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