@vindral/web-sdk 4.1.2 → 4.1.3

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.
@@ -1,33 +1,33 @@
1
1
  var C = Object.defineProperty, R = Object.defineProperties;
2
2
  var q = Object.getOwnPropertyDescriptors;
3
- var y = Object.getOwnPropertySymbols;
4
- var A = Object.prototype.hasOwnProperty, G = Object.prototype.propertyIsEnumerable;
3
+ var b = Object.getOwnPropertySymbols;
4
+ var A = Object.prototype.hasOwnProperty, O = Object.prototype.propertyIsEnumerable;
5
5
  var w = (e, t, n) => t in e ? C(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, u = (e, t) => {
6
6
  for (var n in t || (t = {}))
7
7
  A.call(t, n) && w(e, n, t[n]);
8
- if (y)
9
- for (var n of y(t))
10
- G.call(t, n) && w(e, n, t[n]);
8
+ if (b)
9
+ for (var n of b(t))
10
+ O.call(t, n) && w(e, n, t[n]);
11
11
  return e;
12
- }, p = (e, t) => R(e, q(t));
12
+ }, g = (e, t) => R(e, q(t));
13
13
  var d = (e, t, n) => w(e, typeof t != "symbol" ? t + "" : t, n);
14
- var l = (e, t, n) => new Promise((s, r) => {
14
+ var l = (e, t, n) => new Promise((r, s) => {
15
15
  var a = (o) => {
16
16
  try {
17
17
  i(n.next(o));
18
18
  } catch (h) {
19
- r(h);
19
+ s(h);
20
20
  }
21
21
  }, c = (o) => {
22
22
  try {
23
23
  i(n.throw(o));
24
24
  } catch (h) {
25
- r(h);
25
+ s(h);
26
26
  }
27
- }, i = (o) => o.done ? s(o.value) : Promise.resolve(o.value).then(a, c);
27
+ }, i = (o) => o.done ? r(o.value) : Promise.resolve(o.value).then(a, c);
28
28
  i((n = n.apply(e, t)).next());
29
29
  });
30
- const m = (e) => {
30
+ const y = (e) => {
31
31
  switch (e) {
32
32
  case "h264":
33
33
  case "av1":
@@ -42,60 +42,60 @@ const m = (e) => {
42
42
  throw new Error("Unknown codec");
43
43
  }
44
44
  };
45
- function g(e, t) {
45
+ function f(e, t) {
46
46
  if (!e)
47
47
  throw new Error(t);
48
48
  }
49
- const L = (e) => {
49
+ const P = (e) => {
50
50
  try {
51
51
  return JSON.parse(e);
52
52
  } catch (t) {
53
53
  return;
54
54
  }
55
55
  };
56
- function S(e) {
56
+ function J(e) {
57
57
  return !(typeof e.edges[0] == "string" || e.channels[0] && !("catalog" in e.channels[0]));
58
58
  }
59
59
  function j(e) {
60
- return e.tracks.filter((t) => !!t.codec).filter((t) => I(t.codec || "")).map((t, n) => {
61
- const s = t.codec, r = t.bitrate;
62
- g(s, "codec is required"), g(r != null, "bitrate is required");
63
- const a = I(s);
64
- if (g(a, "codec is required"), m(a) === "audio") {
60
+ return e.tracks.filter((t) => !!t.codec).filter((t) => U(t.codec || "")).map((t, n) => {
61
+ const r = t.codec, s = t.bitrate;
62
+ f(r, "codec is required"), f(s != null, "bitrate is required");
63
+ const a = U(r);
64
+ if (f(a, "codec is required"), y(a) === "audio") {
65
65
  const c = t.samplerate || 0, i = t.channelConfig === "stereo" ? 2 : 1;
66
66
  return {
67
67
  track: t,
68
68
  id: n,
69
69
  codec: a,
70
- codecString: s,
71
- bitRate: r,
70
+ codecString: r,
71
+ bitRate: s,
72
72
  channels: i,
73
73
  sampleRate: c,
74
74
  language: t.language
75
75
  };
76
76
  }
77
- return m(a) === "text" ? {
77
+ return y(a) === "text" ? {
78
78
  track: t,
79
79
  id: n,
80
80
  bitRate: 0,
81
81
  codec: a,
82
82
  kind: "subtitles",
83
- codecString: s,
83
+ codecString: r,
84
84
  label: t.label,
85
85
  language: t.language
86
- } : (g(t.width, "width is required"), g(t.height, "width is required"), g(t.framerate, "framerate is required"), {
86
+ } : (f(t.width, "width is required"), f(t.height, "width is required"), f(t.framerate, "framerate is required"), {
87
87
  track: t,
88
88
  id: n,
89
89
  codec: a,
90
- bitRate: r,
91
- codecString: s,
90
+ bitRate: s,
91
+ codecString: r,
92
92
  width: t.width,
93
93
  height: t.height,
94
94
  frameRate: t.framerate
95
95
  });
96
96
  }).sort((t, n) => t.bitRate - n.bitRate);
97
97
  }
98
- function I(e) {
98
+ function U(e) {
99
99
  if (e.startsWith("opus"))
100
100
  return "opus";
101
101
  if (e.startsWith("mp4a"))
@@ -107,38 +107,59 @@ function I(e) {
107
107
  if (e.startsWith("webvtt"))
108
108
  return "webvtt";
109
109
  }
110
- const E = (e) => e ? {
110
+ const L = (e) => e ? {
111
111
  Authorization: `Bearer ${e}`
112
- } : void 0, H = (e) => typeof e == "object" && e !== null && "message" in e;
113
- class T extends Error {
114
- constructor({ status: n, url: s, body: r }) {
115
- const a = L(r), c = H(a) ? a.message : `Url ${s.toString()}, Status code: ${n}, Body: ${r}`;
112
+ } : void 0, G = (e, t) => {
113
+ try {
114
+ const n = e.ancestorOrigins;
115
+ if (n && n.length > 0)
116
+ return Array.from(n).join(",") || void 0;
117
+ } catch (n) {
118
+ }
119
+ try {
120
+ if (t.referrer)
121
+ return new URL(t.referrer).origin || void 0;
122
+ } catch (n) {
123
+ }
124
+ }, E = (e) => typeof e == "object" && e !== null && "message" in e;
125
+ class H extends Error {
126
+ constructor({ status: n, url: r, body: s }) {
127
+ const a = P(s), c = E(a) ? a.message : `Url ${r.toString()}, Status code: ${n}, Body: ${s}`;
116
128
  super(c);
117
129
  d(this, "status");
118
130
  d(this, "body");
119
131
  d(this, "url");
120
- this.status = n, this.body = r, this.url = s, Object.setPrototypeOf(this, new.target.prototype);
132
+ this.status = n, this.body = s, this.url = r, Object.setPrototypeOf(this, new.target.prototype);
121
133
  }
122
134
  }
123
- const P = (e) => typeof e.status == "number", $ = (e, t) => l(void 0, null, function* () {
124
- const n = yield fetch(e.toString(), u({ mode: "cors" }, t));
125
- if (!n.ok)
126
- throw new T({ status: n.status, url: e, body: yield n.text() });
127
- return n;
128
- }), b = (e, t) => l(void 0, null, function* () {
135
+ const M = (e) => typeof e.status == "number", S = () => {
136
+ if (!(typeof window == "undefined" || typeof document == "undefined"))
137
+ return G(window.location, document);
138
+ }, T = (e) => {
139
+ const t = S();
140
+ if (!t || e.searchParams.has("parentOrigin"))
141
+ return e;
142
+ const n = new URL(e.toString());
143
+ return n.searchParams.append("parentOrigin", t), n;
144
+ }, $ = (e, t) => l(null, null, function* () {
145
+ const n = T(e), r = yield fetch(n.toString(), u({ mode: "cors" }, t));
146
+ if (!r.ok)
147
+ throw new H({ status: r.status, url: n, body: yield r.text() });
148
+ return r;
149
+ }), m = (e, t) => l(null, null, function* () {
129
150
  return yield (yield $(e, u({}, t))).json();
130
- }), B = (e, t) => l(void 0, null, function* () {
151
+ }), z = (e, t) => l(null, null, function* () {
131
152
  return $(e, u({ method: "POST" }, t));
132
153
  });
133
154
  function W(e) {
134
155
  var t;
135
156
  return !(typeof e.edges[0] == "string" || e.channels[0] && "catalog" in e.channels[0] && typeof ((t = e.channels[0]) == null ? void 0 : t.catalog) == "undefined");
136
157
  }
137
- const U = {
158
+ const I = {
138
159
  lbConnect: (e) => e.channelGroupId ? `connect?channelId=${e.channelId}&channelGroupId=${e.channelGroupId}` : `connect?channelId=${e.channelId}`,
139
160
  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"
140
161
  };
141
- class J {
162
+ class N {
142
163
  constructor(t) {
143
164
  d(this, "baseUrl");
144
165
  d(this, "tokenFactory");
@@ -150,19 +171,19 @@ class J {
150
171
  */
151
172
  connect(t) {
152
173
  return l(this, null, function* () {
153
- const { channelId: n, channelGroupId: s } = t, r = { channelId: n, channelGroupId: s }, a = new URL(U.lbConnect(t), this.baseUrl), c = this.getAuthToken(r), i = yield b(a, { headers: this.getHeaders(c) });
174
+ const { channelId: n, channelGroupId: r } = t, s = { channelId: n, channelGroupId: r }, a = new URL(I.lbConnect(t), this.baseUrl), c = this.getAuthToken(s), i = yield m(a, { headers: this.getHeaders(c) });
154
175
  if (W(i)) {
155
176
  const o = i.channels.map((h) => {
156
- const f = this.toChannel(h, r), v = j(h.catalog);
157
- return p(u(u({}, h), f), { renditions: v });
177
+ const p = this.toChannel(h, s), v = j(h.catalog);
178
+ return g(u(u({}, h), p), { renditions: v });
158
179
  });
159
- return p(u({}, i), { channels: o });
180
+ return g(u({}, i), { channels: o });
160
181
  } else {
161
182
  const o = i.channels.map((h) => {
162
- const f = this.toChannel(h, r);
163
- return u(u({}, h), f);
183
+ const p = this.toChannel(h, s);
184
+ return u(u({}, h), p);
164
185
  });
165
- return p(u({}, i), { channels: o });
186
+ return g(u({}, i), { channels: o });
166
187
  }
167
188
  });
168
189
  }
@@ -174,8 +195,8 @@ class J {
174
195
  */
175
196
  getChannel(t) {
176
197
  return l(this, null, function* () {
177
- const n = { channelId: t }, s = new URL(`channel/${t}`, this.baseUrl), r = this.getAuthToken(n), a = yield b(s, { headers: this.getHeaders(r) });
178
- return this.toChannel(a, n, r);
198
+ const n = { channelId: t }, r = new URL(`channel/${t}`, this.baseUrl), s = this.getAuthToken(n), a = yield m(r, { headers: this.getHeaders(s) });
199
+ return this.toChannel(a, n, s);
179
200
  });
180
201
  }
181
202
  /**
@@ -188,27 +209,27 @@ class J {
188
209
  */
189
210
  getChannels(t) {
190
211
  return l(this, null, function* () {
191
- const n = { channelGroupId: t }, s = new URL(`channels/${t}`, this.baseUrl), r = this.getAuthToken(n), a = yield b(s, {
192
- headers: this.getHeaders(r)
212
+ const n = { channelGroupId: t }, r = new URL(`channels/${t}`, this.baseUrl), s = this.getAuthToken(n), a = yield m(r, {
213
+ headers: this.getHeaders(s)
193
214
  }), c = Array.isArray(a) ? a : a.channels;
194
- return this.toChannels(c, n, r);
215
+ return this.toChannels(c, n, s);
195
216
  });
196
217
  }
197
218
  getHeaders(t) {
198
- var s;
199
- return (s = E(t)) != null ? s : {};
219
+ var r;
220
+ return (r = L(t)) != null ? r : {};
200
221
  }
201
222
  getAuthToken(t) {
202
223
  return this.tokenFactory ? this.tokenFactory(t) : void 0;
203
224
  }
204
- toChannels(t, n, s) {
205
- return t.map((r) => this.toChannel(r, n, s));
225
+ toChannels(t, n, r) {
226
+ return t.map((s) => this.toChannel(s, n, r));
206
227
  }
207
- toChannel(t, n, s) {
208
- const { baseUrl: r, sizes: a } = t.thumbnail, c = r || new URL(U.thumbnails(n, s), this.baseUrl), i = a.map((o) => new URL(
228
+ toChannel(t, n, r) {
229
+ const { baseUrl: s, sizes: a } = t.thumbnail, c = s || new URL(I.thumbnails(n, r), this.baseUrl), i = a.map((o) => new URL(
209
230
  `?channelId=${t.channelId}&width=${o.width}&height=${o.height}${F(
210
231
  n,
211
- s
232
+ r
212
233
  )}`,
213
234
  c
214
235
  ).toString());
@@ -222,13 +243,13 @@ class J {
222
243
  }
223
244
  const F = (e, t) => t ? e.channelGroupId ? `&channelGroupId=${e.channelGroupId}&auth.token=${t}&auth.type=jwt` : `&auth.token=${t}&auth.type=jwt` : "";
224
245
  export {
225
- J as A,
226
- g as a,
246
+ N as A,
247
+ f as a,
227
248
  j as b,
228
- I as c,
229
- P as d,
230
- m as e,
231
- S as i,
232
- B as p,
233
- L as t
249
+ U as c,
250
+ M as d,
251
+ y as e,
252
+ J as i,
253
+ z as p,
254
+ P as t
234
255
  };