@tidal-music/player-web-components 0.1.2 → 0.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.
@@ -1,89 +0,0 @@
1
- function y() {
2
- let o = [], t, r, d, c;
3
- const i = /* @__PURE__ */ new Map();
4
- function l() {
5
- return ("10000000-1000-4000-8000" + -1e11).replace(/[018]/g, (a) => {
6
- const e = crypto.getRandomValues(new Uint8Array(1))[0];
7
- return (a ^ (e ?? 0) & 15 >> a / 4).toString(16);
8
- });
9
- }
10
- async function p(a, e) {
11
- if (i.has(e))
12
- return i.get(e);
13
- i.clear();
14
- const n = await (await fetch(a + "/sessions", {
15
- headers: new Headers({
16
- Authorization: "Bearer " + e
17
- }),
18
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
19
- // @ts-ignore - It is a thing.
20
- importance: "low"
21
- })).json();
22
- return i.set(e, n), n;
23
- }
24
- setInterval(async () => {
25
- if (o.length > 0 && t && c) {
26
- const a = {
27
- batchId: l(),
28
- events: [...o]
29
- };
30
- try {
31
- const e = new Headers();
32
- if (t && e.append("authorization", "Bearer " + t), r && e.append("x-tidal-token", r), e.append("content-type", "application/json; boundary=player-sdk"), (await fetch(c, {
33
- body: JSON.stringify(a),
34
- headers: e,
35
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
36
- // @ts-ignore - It is a thing.
37
- importance: "low",
38
- method: "POST"
39
- })).ok)
40
- o.forEach((n) => {
41
- "streamingSessionId" in n.payload && postMessage({
42
- command: "cleanUp",
43
- eventName: n.name,
44
- streamingSessionId: n.payload.streamingSessionId
45
- });
46
- }), o = [];
47
- else
48
- throw new Error("Response not ok");
49
- } catch (e) {
50
- console.warn(e);
51
- }
52
- }
53
- }, 15e3), onmessage = async (a) => {
54
- const e = JSON.parse(a.data);
55
- c = e.eventUrl;
56
- const n = await p(e.apiUrl, e.accessToken);
57
- e.accessToken && (t = e.accessToken), t || console.trace(
58
- "An accessToken is missing. Make sure to send at least one commit-payload with it defined, we cannot send events unless we have an access token."
59
- ), e.clientId && (r = e.clientId), e.clientPlatform && (d = e.clientPlatform), e.events.forEach((s) => {
60
- s.name === "progress" && "streamingSessionId" in s.payload && (postMessage({
61
- command: "cleanUp",
62
- eventName: s.name,
63
- streamingSessionId: s.payload.streamingSessionId
64
- }), delete s.payload.streamingSessionId);
65
- const m = {
66
- client: {
67
- platform: d,
68
- token: r,
69
- version: e.appVersion
70
- },
71
- group: e.type,
72
- name: s.name,
73
- payload: s.payload,
74
- ts: e.ts,
75
- user: {
76
- accessToken: t,
77
- clientId: n?.client.id,
78
- id: n?.userId
79
- },
80
- uuid: l(),
81
- version: e.type === "playback" ? 1 : 2
82
- };
83
- o.push(m);
84
- });
85
- };
86
- }
87
- export {
88
- y as beacon
89
- };