@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/D5iA4gy8.js ADDED
@@ -0,0 +1,143 @@
1
+ import { n as e, t } from "./BsfwXDui.js";
2
+ import { t as n } from "./FYiEDBC4.js";
3
+ //#region ../../libs/cast-sender/src/CastSender.ts
4
+ var r = class extends n {
5
+ constructor(n) {
6
+ var r;
7
+ super(), r = this, e(this, "state", "not casting"), e(this, "config", void 0), e(this, "unloaded", !1), e(this, "updateAuthenticationToken", (e) => {
8
+ this.config && (this.config.options.authenticationToken = e, this.send({
9
+ type: "updateAuthToken",
10
+ token: e
11
+ }));
12
+ }), e(this, "unload", () => {
13
+ var e;
14
+ this.unloaded = !0, (e = this.getSession()) == null || e.removeMessageListener("urn:x-cast:com.vindral.castdata", this.onMessage);
15
+ }), e(this, "init", t(function* () {
16
+ return new Promise((e, t) => {
17
+ let n = !1, i = setTimeout(() => {
18
+ n = !0, t();
19
+ }, 1e4);
20
+ window.__onGCastApiAvailable = (a) => {
21
+ if (n) {
22
+ n = !1;
23
+ return;
24
+ }
25
+ if (clearTimeout(i), !a) return t();
26
+ setTimeout(() => {
27
+ try {
28
+ r.onGCastApiAvailable(), e();
29
+ } catch (e) {
30
+ t();
31
+ }
32
+ }, 1e3);
33
+ }, r.castLibrariesAdded() && window.cast ? window.__onGCastApiAvailable(!0) : r.verifyCastLibraries();
34
+ });
35
+ })), e(this, "start", t(function* () {
36
+ var e;
37
+ yield (e = r.getInstance()) == null ? void 0 : e.requestSession();
38
+ })), e(this, "stop", () => {
39
+ var e;
40
+ (e = this.getSession()) == null || e.endSession(!0);
41
+ }), e(this, "getReceiverName", () => {
42
+ var e;
43
+ return ((e = this.getSession()) == null || (e = e.getCastDevice()) == null ? void 0 : e.friendlyName) || void 0;
44
+ }), e(this, "onGCastApiAvailable", () => {
45
+ var e;
46
+ let t = this.getInstance();
47
+ if (!t) throw "cast context should exist";
48
+ let n = t.getSessionState(), r = ((e = this.config) == null ? void 0 : e.receiverApplicationId) || void 0;
49
+ t.setOptions({
50
+ receiverApplicationId: r,
51
+ autoJoinPolicy: chrome.cast.AutoJoinPolicy.TAB_AND_ORIGIN_SCOPED,
52
+ resumeSavedSession: !0
53
+ }), t.addEventListener(cast.framework.CastContextEventType.SESSION_STATE_CHANGED, this.onSessionStateChanged), n === cast.framework.SessionState.SESSION_STARTED && setTimeout(() => {
54
+ this.state = "casting", this.emit("resumed");
55
+ });
56
+ }), e(this, "send", (e) => {
57
+ var t;
58
+ (t = this.getSession()) == null || t.sendMessage("urn:x-cast:com.vindral.castdata", e);
59
+ }), e(this, "onMessage", (e, t) => {
60
+ if (e === "urn:x-cast:com.vindral.castdata") try {
61
+ let e = JSON.parse(t);
62
+ switch (e.type) {
63
+ case "metadata":
64
+ this.emit("metadata", e.metadata);
65
+ break;
66
+ case "serverWallclockTime":
67
+ this.emit("server wallclock time", e.serverWallclockTime);
68
+ break;
69
+ default: break;
70
+ }
71
+ } catch (e) {}
72
+ }), e(this, "onSessionStarted", () => {
73
+ var e;
74
+ (e = this.getSession()) == null || e.addMessageListener("urn:x-cast:com.vindral.castdata", this.onMessage), this.send({
75
+ type: "start",
76
+ config: this.config
77
+ });
78
+ }), e(this, "onSessionStateChanged", (e) => {
79
+ if (!this.unloaded) switch (e.sessionState) {
80
+ case cast.framework.SessionState.SESSION_START_FAILED:
81
+ this.state = "not casting", this.emit("failed");
82
+ break;
83
+ case cast.framework.SessionState.SESSION_ENDED:
84
+ this.state = "not casting", this.emit("disconnected");
85
+ break;
86
+ case cast.framework.SessionState.SESSION_ENDING: break;
87
+ case cast.framework.SessionState.SESSION_RESUMED:
88
+ this.onSessionStarted(), this.state = "casting", this.emit("resumed");
89
+ break;
90
+ case cast.framework.SessionState.SESSION_STARTED:
91
+ this.onSessionStarted(), this.state = "casting", this.emit("connected");
92
+ break;
93
+ case cast.framework.SessionState.SESSION_STARTING: break;
94
+ default: break;
95
+ }
96
+ }), e(this, "getInstance", () => {
97
+ var e;
98
+ return (e = window.cast) == null ? void 0 : e.framework.CastContext.getInstance();
99
+ }), e(this, "getSession", () => {
100
+ var e;
101
+ return (e = this.getInstance()) == null ? void 0 : e.getCurrentSession();
102
+ }), e(this, "castLibrariesAdded", () => !!(document.querySelector("#vindralCastFrameworkLib") && document.querySelector("#vindralCastSenderLib"))), e(this, "verifyCastLibraries", () => {
103
+ if (this.castLibrariesAdded()) return;
104
+ let e = document.createElement("script");
105
+ e.type = "text/javascript", e.id = "vindralCastFrameworkLib", e.src = "//www.gstatic.com/cast/sdk/libs/sender/1.0/cast_framework.js", document.head.appendChild(e);
106
+ let t = document.createElement("script");
107
+ t.type = "text/javascript", t.id = "vindralCastSenderLib", t.src = "//www.gstatic.com/cv/js/sender/v1/cast_sender.js", document.head.appendChild(t);
108
+ }), this.config = n;
109
+ }
110
+ get casting() {
111
+ return this.state === "casting";
112
+ }
113
+ get volume() {
114
+ var e, t;
115
+ return (e = (t = this.getSession()) == null ? void 0 : t.getVolume()) == null ? 0 : e;
116
+ }
117
+ set volume(e) {
118
+ var t;
119
+ (t = this.getSession()) == null || t.setVolume(e);
120
+ }
121
+ get language() {
122
+ var e;
123
+ return (e = this.config) == null || (e = e.options) == null ? void 0 : e.language;
124
+ }
125
+ set language(e) {
126
+ this.config && (this.config.options.language = e, this.send({
127
+ type: "setLanguage",
128
+ language: e
129
+ }));
130
+ }
131
+ get channelId() {
132
+ var e;
133
+ return ((e = this.config) == null ? void 0 : e.options.channelId) || "";
134
+ }
135
+ set channelId(e) {
136
+ this.config && (this.config.options.channelId = e, this.send({
137
+ type: "setChannelId",
138
+ channelId: e
139
+ }));
140
+ }
141
+ };
142
+ //#endregion
143
+ export { r as t };