@vindral/web-sdk 3.4.4 → 4.0.0-191-g9f7294ed
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/1PRs0vho.js +127 -0
- package/AXCpqROO.js +4311 -0
- package/B-HFfmiu.js +6783 -0
- package/BTxJOjm9.js +32 -0
- package/CayXch2-.js +312 -0
- package/F-U5JXpv.js +231 -0
- package/README.md +74 -30
- package/api-client.d.ts +217 -0
- package/api-client.js +4 -0
- package/cast-sender.d.ts +410 -0
- package/cast-sender.js +230 -0
- package/core.d.ts +1444 -0
- package/core.js +14 -0
- package/{index.d.ts → legacy.d.ts} +794 -716
- package/legacy.es.js +12805 -0
- package/legacy.umd.js +60 -0
- package/package.json +25 -9
- package/player.d.ts +1691 -0
- package/player.js +3784 -0
- package/vindral-player-component.js +2 -0
- package/index.js +0 -7716
- package/index.umd.cjs +0 -59
package/cast-sender.d.ts
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
type MatchingKeys<TRecord, TMatch, K extends keyof TRecord = keyof TRecord> = K extends (TRecord[K] extends TMatch ? K : never) ? K : never;
|
|
2
|
+
type VoidKeys<Record> = MatchingKeys<Record, void>;
|
|
3
|
+
type EventListenerReturnType = (() => void) | void;
|
|
4
|
+
declare class Emitter<TEvents, TEmits = TEvents, ArgLessEvents extends VoidKeys<TEvents> = VoidKeys<TEvents>, ArgEvents extends Exclude<keyof TEvents, ArgLessEvents> = Exclude<keyof TEvents, ArgLessEvents>, ArgLessEmits extends VoidKeys<TEmits> = VoidKeys<TEmits>, ArgEmits extends Exclude<keyof TEmits, ArgLessEmits> = Exclude<keyof TEmits, ArgLessEmits>> {
|
|
5
|
+
private listeners;
|
|
6
|
+
emit<T extends ArgLessEmits>(eventName: T): void;
|
|
7
|
+
emit<T extends ArgEmits>(eventName: T, args: TEmits[T]): void;
|
|
8
|
+
off<T extends ArgLessEvents>(eventName: T, fn: () => EventListenerReturnType): void;
|
|
9
|
+
off<T extends ArgEvents>(eventName: T, fn: (args: TEvents[T]) => EventListenerReturnType): void;
|
|
10
|
+
/**
|
|
11
|
+
* Add an event listener to `eventName`
|
|
12
|
+
*
|
|
13
|
+
* Event listeners may optionally return a "defer function" that will be called once all other listeners have been called.
|
|
14
|
+
* This is useful when one listener may want everone to have reacted to an event before calling something.
|
|
15
|
+
*/
|
|
16
|
+
on<T extends ArgLessEvents>(eventName: T, fn: () => void): void;
|
|
17
|
+
on<T extends ArgEvents>(eventName: T, fn: (args: TEvents[T]) => void): void;
|
|
18
|
+
/**
|
|
19
|
+
* Add an event listener to `eventName` that will be called once only
|
|
20
|
+
*
|
|
21
|
+
* Event listeners may optionally return a "defer function" that will be called once all other listeners have been called.
|
|
22
|
+
* This is useful when one listener may want everone to have reacted to an event before calling something.
|
|
23
|
+
*/
|
|
24
|
+
once<T extends ArgLessEvents>(eventName: T, fn: () => void): void;
|
|
25
|
+
once<T extends ArgEvents>(eventName: T, fn: (args: TEvents[T]) => void): void;
|
|
26
|
+
reset(): void;
|
|
27
|
+
private add;
|
|
28
|
+
}
|
|
29
|
+
declare const Levels: readonly [
|
|
30
|
+
"off",
|
|
31
|
+
"error",
|
|
32
|
+
"warn",
|
|
33
|
+
"info",
|
|
34
|
+
"debug",
|
|
35
|
+
"trace"
|
|
36
|
+
];
|
|
37
|
+
type Level = (typeof Levels)[number];
|
|
38
|
+
declare const Level: {
|
|
39
|
+
ERROR: "error";
|
|
40
|
+
WARN: "warn";
|
|
41
|
+
INFO: "info";
|
|
42
|
+
DEBUG: "debug";
|
|
43
|
+
TRACE: "trace";
|
|
44
|
+
OFF: "off";
|
|
45
|
+
};
|
|
46
|
+
type VideoCodec = "h264" | "av1";
|
|
47
|
+
interface Metadata {
|
|
48
|
+
/**
|
|
49
|
+
* The raw string content as it was ingested (if using JSON, it needs to be parsed on your end)
|
|
50
|
+
*/
|
|
51
|
+
content: string;
|
|
52
|
+
/**
|
|
53
|
+
* Timestamp in ms
|
|
54
|
+
*/
|
|
55
|
+
timestamp: number;
|
|
56
|
+
}
|
|
57
|
+
interface ReconnectState {
|
|
58
|
+
/**
|
|
59
|
+
* The number or retry attempts so far.
|
|
60
|
+
* This gets reset on every successful connect, so it will start from zero every
|
|
61
|
+
* time the client instance gets disconnected and will increment until the
|
|
62
|
+
* client instance makes a connection attempt is successful.
|
|
63
|
+
*/
|
|
64
|
+
reconnectRetries: number;
|
|
65
|
+
}
|
|
66
|
+
interface Size {
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
}
|
|
70
|
+
interface VideoConstraint {
|
|
71
|
+
width: number;
|
|
72
|
+
height: number;
|
|
73
|
+
bitRate: number;
|
|
74
|
+
codec?: VideoCodec;
|
|
75
|
+
codecString?: string;
|
|
76
|
+
}
|
|
77
|
+
interface AdvancedOptions {
|
|
78
|
+
/**
|
|
79
|
+
* Constrains wasm decoding to this resolution.
|
|
80
|
+
* By default it is set to 1280 in width and height.
|
|
81
|
+
* This guarantees better performance on older devices and reduces battery drain in general.
|
|
82
|
+
*/
|
|
83
|
+
wasmDecodingConstraint: Partial<VideoConstraint>;
|
|
84
|
+
}
|
|
85
|
+
interface DrmOptions {
|
|
86
|
+
/**
|
|
87
|
+
* Headers to be added to requests to license servers
|
|
88
|
+
*/
|
|
89
|
+
headers?: Record<string, string>;
|
|
90
|
+
/**
|
|
91
|
+
* Query parameters to be added to requests to license servers
|
|
92
|
+
*/
|
|
93
|
+
queryParams?: Record<string, string>;
|
|
94
|
+
}
|
|
95
|
+
type Media = "audio" | "video" | "audio+video";
|
|
96
|
+
interface Options {
|
|
97
|
+
/**
|
|
98
|
+
* URL to use when connecting to the stream
|
|
99
|
+
*/
|
|
100
|
+
url: string;
|
|
101
|
+
/**
|
|
102
|
+
* Channel ID to connect to initially - can be changed later mid-stream when connected to a channel group.
|
|
103
|
+
*/
|
|
104
|
+
channelId: string;
|
|
105
|
+
/**
|
|
106
|
+
* Channel group to connect to
|
|
107
|
+
* Note: Only needed for fast channel switching
|
|
108
|
+
*/
|
|
109
|
+
channelGroupId?: string;
|
|
110
|
+
/**
|
|
111
|
+
* A container to attach the video view in - can be provided later with .attach() on the vindral core instance
|
|
112
|
+
*/
|
|
113
|
+
container?: HTMLElement;
|
|
114
|
+
/**
|
|
115
|
+
* An authentication token to provide to the server when connecting - only needed for channels with authentication enabled
|
|
116
|
+
* Note: If not supplied when needed, an "Authentication Failed" error will be raised.
|
|
117
|
+
*/
|
|
118
|
+
authenticationToken?: string;
|
|
119
|
+
/**
|
|
120
|
+
* Language to use initially - can be changed during during runtime on the vindral instance
|
|
121
|
+
* Note: Only needed when multiple languages are provided - if no language is specified, one will be automatically selected.
|
|
122
|
+
*/
|
|
123
|
+
language?: string;
|
|
124
|
+
/**
|
|
125
|
+
* TextTrack to use initially - can be changed during during runtime on the vindral instance
|
|
126
|
+
*/
|
|
127
|
+
textTrack?: string;
|
|
128
|
+
/**
|
|
129
|
+
* Sets the log level - defaults to info
|
|
130
|
+
*/
|
|
131
|
+
logLevel?: Level;
|
|
132
|
+
/**
|
|
133
|
+
* Sets the minimum and initial buffer time
|
|
134
|
+
*/
|
|
135
|
+
minBufferTime?: number;
|
|
136
|
+
/**
|
|
137
|
+
* Sets the maximum buffer time allowed. The vindral instance will automatically slowly increase
|
|
138
|
+
* the buffer time if the use experiences to much buffering with the initial buffer time.
|
|
139
|
+
*/
|
|
140
|
+
maxBufferTime?: number;
|
|
141
|
+
/**
|
|
142
|
+
* Enables or disables user bandwidth savings by capping the video resolution to the size of the video element.
|
|
143
|
+
*
|
|
144
|
+
* Is enabled by default.
|
|
145
|
+
*
|
|
146
|
+
* Note: This is automatically set to false when abrEnabled is set to false.
|
|
147
|
+
*/
|
|
148
|
+
sizeBasedResolutionCapEnabled?: boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Enables or disables picture in picture support.
|
|
151
|
+
*/
|
|
152
|
+
pictureInPictureEnabled?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Enable bursting for initial connection and channel switches. This makes time to first frame faster at the
|
|
155
|
+
* cost of stability (more demanding due to the sudden burst of live content)
|
|
156
|
+
*
|
|
157
|
+
* Is disabled by default.
|
|
158
|
+
*
|
|
159
|
+
*/
|
|
160
|
+
burstEnabled?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Enable usage of the MediaSource API on supported browsers.
|
|
163
|
+
*
|
|
164
|
+
* Is enabled by default.
|
|
165
|
+
*
|
|
166
|
+
* Note: We recommend to keep this at the default value unless you have very specific needs.
|
|
167
|
+
*/
|
|
168
|
+
mseEnabled?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Enable Opus with the MediaSource API on supported browsers.
|
|
171
|
+
*
|
|
172
|
+
* Is enabled by default.
|
|
173
|
+
*
|
|
174
|
+
*/
|
|
175
|
+
mseOpusEnabled?: boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Enable or disable support for playing audio in the background for iOS devices.
|
|
178
|
+
*
|
|
179
|
+
* Is false (disabled) by default.
|
|
180
|
+
*
|
|
181
|
+
* Note: This may be enabled by default in a future (major) release
|
|
182
|
+
*/
|
|
183
|
+
iosBackgroundPlayEnabled?: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Enable or disable Adaptive Bit Rate. This allows for automatically adapting the incoming bit rate based on
|
|
186
|
+
* the viewers bandwidth and thus avoiding buffering events. This also disables the
|
|
187
|
+
* sizeBasedResolutionCapEnabled option.
|
|
188
|
+
*
|
|
189
|
+
* Is enabled by default.
|
|
190
|
+
*
|
|
191
|
+
* Note: It is strongly recommended to keep this enabled as user experience can greatly suffer without ABR.
|
|
192
|
+
*/
|
|
193
|
+
abrEnabled?: boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Enable or disable telemetry. This allows for telemetry and errors being collected.
|
|
196
|
+
*
|
|
197
|
+
* Is enabled by default.
|
|
198
|
+
*
|
|
199
|
+
* We appreciate you turning it off during development/staging to not bloat real telemetry data.
|
|
200
|
+
*
|
|
201
|
+
* Note: It is strongly recommended to keep this enabled in production as it is required for insights and KPIs.
|
|
202
|
+
*/
|
|
203
|
+
telemetryEnabled?: boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Set a cap on the maximum video size.
|
|
206
|
+
* This can be used to provide user options to limit the video bandwidth usage.
|
|
207
|
+
*
|
|
208
|
+
* Note: This takes presedence over any size based resolution caps.
|
|
209
|
+
*/
|
|
210
|
+
maxSize?: Size;
|
|
211
|
+
/**
|
|
212
|
+
* Maximum audio bit rate allowed.
|
|
213
|
+
* This can be used to provide user options to limit the audio bandwidth usage.
|
|
214
|
+
*/
|
|
215
|
+
maxAudioBitRate?: number;
|
|
216
|
+
/**
|
|
217
|
+
* Maximum video bit rate allowed.
|
|
218
|
+
* This can be used to provide user options to limit the video bandwidth usage.
|
|
219
|
+
*/
|
|
220
|
+
maxVideoBitRate?: number;
|
|
221
|
+
/**
|
|
222
|
+
* Controls video element background behaviour while loading.
|
|
223
|
+
* - If `false`, a black background will be shown.
|
|
224
|
+
* - If undefined or `true`, a live thumbnail will be shown.
|
|
225
|
+
* - If set to a string containing a URL (https://urltoimage), use that.
|
|
226
|
+
* Default `true` - meaning a live thumbnail is shown
|
|
227
|
+
*/
|
|
228
|
+
poster?: boolean | string;
|
|
229
|
+
/**
|
|
230
|
+
* Whether to start the player muted or to try to start playing audio automatically.
|
|
231
|
+
*/
|
|
232
|
+
muted?: boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Provide a custom reconnect handler to control when the instance should stop trying to
|
|
235
|
+
* reconnect. The reconnect handler should either return true to allow the reconnect or
|
|
236
|
+
* false to stop reconnecting. It can also return a promise with true or false if it needs
|
|
237
|
+
* to make any async calls before determining wether to reconnect.
|
|
238
|
+
*
|
|
239
|
+
* The default reconnect handler allows 30 reconnects before stopping.
|
|
240
|
+
*
|
|
241
|
+
* Note: the ReconnectState gets reset every time the client instance makes a successful connection.
|
|
242
|
+
* This means the default reconnect handler will only stop reconnecting after 30 _consecutive_ failed connections.
|
|
243
|
+
*
|
|
244
|
+
* ```typescript
|
|
245
|
+
* // An example reconnect handler that will reconnect forever
|
|
246
|
+
* const reconnectHandler = (state: ReconnectState) => true
|
|
247
|
+
*
|
|
248
|
+
* // An example reconnect handler that will fetch an url and determine whether to reconnect
|
|
249
|
+
* const reconnectHandler = async (state: ReconnectState) => {
|
|
250
|
+
* const result = await fetch("https://should-i-reconnect-now.com")
|
|
251
|
+
* return result.ok
|
|
252
|
+
* },
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
reconnectHandler?: (state: ReconnectState) => Promise<boolean> | boolean;
|
|
256
|
+
tags?: string[];
|
|
257
|
+
ownerSessionId?: string;
|
|
258
|
+
edgeUrl?: string;
|
|
259
|
+
logShippingEnabled?: boolean;
|
|
260
|
+
statsShippingEnabled?: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Enable wake lock for iOS devices.
|
|
263
|
+
* The wake lock requires that the audio has been activated at least once for the instance, othwerwise it will not work.
|
|
264
|
+
* Other devices already provide wake lock by default.
|
|
265
|
+
*
|
|
266
|
+
* This option is redundant and has no effect if iosMediaElementEnabled is enabled since that automatically enables wake lock.
|
|
267
|
+
*
|
|
268
|
+
* Disabled by default.
|
|
269
|
+
*/
|
|
270
|
+
iosWakeLockEnabled?: boolean;
|
|
271
|
+
/**
|
|
272
|
+
* Disabling this will revert to legacy behaviour where Vindral will try to always keep the video element playing.
|
|
273
|
+
*/
|
|
274
|
+
pauseSupportEnabled?: boolean;
|
|
275
|
+
/**
|
|
276
|
+
* Enables iOS devices to use a media element for playback. This enables fullscreen and picture in picture support on iOS.
|
|
277
|
+
*/
|
|
278
|
+
iosMediaElementEnabled?: boolean;
|
|
279
|
+
/**
|
|
280
|
+
* Advanced options to override default behaviour.
|
|
281
|
+
*/
|
|
282
|
+
advanced?: AdvancedOptions;
|
|
283
|
+
media?: Media;
|
|
284
|
+
videoCodecs?: VideoCodec[];
|
|
285
|
+
/**
|
|
286
|
+
* DRM options to provide to the Vindral instance
|
|
287
|
+
*/
|
|
288
|
+
drm?: DrmOptions;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Available events to listen to
|
|
292
|
+
*/
|
|
293
|
+
export interface CastSenderEvents {
|
|
294
|
+
/**
|
|
295
|
+
* When a connection has been established with a CastReceiver
|
|
296
|
+
*/
|
|
297
|
+
["connected"]: void;
|
|
298
|
+
/**
|
|
299
|
+
* When a previous session has been resumed
|
|
300
|
+
*/
|
|
301
|
+
["resumed"]: void;
|
|
302
|
+
/**
|
|
303
|
+
* When a CastReceiver has lost or stopped a connection
|
|
304
|
+
*/
|
|
305
|
+
["disconnected"]: void;
|
|
306
|
+
/**
|
|
307
|
+
* When a connection attempt was initiated unsuccessfully
|
|
308
|
+
*/
|
|
309
|
+
["failed"]: void;
|
|
310
|
+
/**
|
|
311
|
+
* When the remote connection emits a metadata event
|
|
312
|
+
*/
|
|
313
|
+
["metadata"]: Metadata;
|
|
314
|
+
/**
|
|
315
|
+
* When the remote connection receives a server wallclock time event
|
|
316
|
+
*/
|
|
317
|
+
["server wallclock time"]: number;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Used for initializing the CastSender
|
|
321
|
+
*/
|
|
322
|
+
export interface CastConfig {
|
|
323
|
+
/**
|
|
324
|
+
* The [Vindral Options](./Options) to use for the Cast Receiver
|
|
325
|
+
*/
|
|
326
|
+
options: Options;
|
|
327
|
+
/**
|
|
328
|
+
* URL to a background image.
|
|
329
|
+
* Example: "https://via.placeholder.com/256x144"
|
|
330
|
+
*/
|
|
331
|
+
background?: string;
|
|
332
|
+
/**
|
|
333
|
+
* Override this if you have your own custom receiver
|
|
334
|
+
*/
|
|
335
|
+
receiverApplicationId?: string;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* CastSender handles initiation of and communication with the Google Cast Receiver
|
|
339
|
+
*/
|
|
340
|
+
export declare class CastSender extends Emitter<CastSenderEvents> {
|
|
341
|
+
private state;
|
|
342
|
+
private config;
|
|
343
|
+
private unloaded;
|
|
344
|
+
constructor(config: CastConfig);
|
|
345
|
+
/**
|
|
346
|
+
* True if the instance is casting right now
|
|
347
|
+
*/
|
|
348
|
+
get casting(): boolean;
|
|
349
|
+
/**
|
|
350
|
+
* The current volume
|
|
351
|
+
*/
|
|
352
|
+
get volume(): number;
|
|
353
|
+
/**
|
|
354
|
+
* Set the current volume. Setting this to zero is equivalent to muting the video
|
|
355
|
+
*/
|
|
356
|
+
set volume(volume: number);
|
|
357
|
+
/**
|
|
358
|
+
* The current language
|
|
359
|
+
*/
|
|
360
|
+
get language(): string | undefined;
|
|
361
|
+
/**
|
|
362
|
+
* Set the current language
|
|
363
|
+
*/
|
|
364
|
+
set language(language: string | undefined);
|
|
365
|
+
/**
|
|
366
|
+
* The current channelId
|
|
367
|
+
*/
|
|
368
|
+
get channelId(): string;
|
|
369
|
+
/**
|
|
370
|
+
* Set the current channelId
|
|
371
|
+
*/
|
|
372
|
+
set channelId(channelId: string);
|
|
373
|
+
/**
|
|
374
|
+
* Update authentication token on an already established and authenticated connection
|
|
375
|
+
*/
|
|
376
|
+
updateAuthenticationToken: (token: string) => void;
|
|
377
|
+
/**
|
|
378
|
+
* Fully unloads the instance. This disconnects the current listener but lets the
|
|
379
|
+
* cast session continue on the receiving device
|
|
380
|
+
*/
|
|
381
|
+
unload: () => void;
|
|
382
|
+
/**
|
|
383
|
+
* Initiates the CastSender.
|
|
384
|
+
* Will reject if Cast is not available on the device or the network.
|
|
385
|
+
*/
|
|
386
|
+
init: () => Promise<void>;
|
|
387
|
+
/**
|
|
388
|
+
* Requests a session. It will open the native cast receiver chooser dialog
|
|
389
|
+
*/
|
|
390
|
+
start: () => Promise<void>;
|
|
391
|
+
/**
|
|
392
|
+
* Stops a session. It will stop playback on device as well.
|
|
393
|
+
*/
|
|
394
|
+
stop: () => void;
|
|
395
|
+
/**
|
|
396
|
+
* Returns a string representing the name of the Cast receiver device or undefined if no receiver exists
|
|
397
|
+
*/
|
|
398
|
+
getReceiverName: () => string | undefined;
|
|
399
|
+
private onGCastApiAvailable;
|
|
400
|
+
private send;
|
|
401
|
+
private onMessage;
|
|
402
|
+
private onSessionStarted;
|
|
403
|
+
private onSessionStateChanged;
|
|
404
|
+
private getInstance;
|
|
405
|
+
private getSession;
|
|
406
|
+
private castLibrariesAdded;
|
|
407
|
+
private verifyCastLibraries;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export {};
|
package/cast-sender.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
var u = Object.defineProperty;
|
|
2
|
+
var l = (n, i, e) => i in n ? u(n, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[i] = e;
|
|
3
|
+
var s = (n, i, e) => l(n, typeof i != "symbol" ? i + "" : i, e);
|
|
4
|
+
var h = (n, i, e) => new Promise((t, a) => {
|
|
5
|
+
var o = (r) => {
|
|
6
|
+
try {
|
|
7
|
+
c(e.next(r));
|
|
8
|
+
} catch (S) {
|
|
9
|
+
a(S);
|
|
10
|
+
}
|
|
11
|
+
}, d = (r) => {
|
|
12
|
+
try {
|
|
13
|
+
c(e.throw(r));
|
|
14
|
+
} catch (S) {
|
|
15
|
+
a(S);
|
|
16
|
+
}
|
|
17
|
+
}, c = (r) => r.done ? t(r.value) : Promise.resolve(r.value).then(o, d);
|
|
18
|
+
c((e = e.apply(n, i)).next());
|
|
19
|
+
});
|
|
20
|
+
import { E as g } from "./BTxJOjm9.js";
|
|
21
|
+
class p extends g {
|
|
22
|
+
constructor(e) {
|
|
23
|
+
super();
|
|
24
|
+
s(this, "state", "not casting");
|
|
25
|
+
s(this, "config");
|
|
26
|
+
s(this, "unloaded", !1);
|
|
27
|
+
/**
|
|
28
|
+
* Update authentication token on an already established and authenticated connection
|
|
29
|
+
*/
|
|
30
|
+
s(this, "updateAuthenticationToken", (e) => {
|
|
31
|
+
this.config && (this.config.options.authenticationToken = e, this.send({
|
|
32
|
+
type: "updateAuthToken",
|
|
33
|
+
token: e
|
|
34
|
+
}));
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Fully unloads the instance. This disconnects the current listener but lets the
|
|
38
|
+
* cast session continue on the receiving device
|
|
39
|
+
*/
|
|
40
|
+
s(this, "unload", () => {
|
|
41
|
+
var e;
|
|
42
|
+
this.unloaded = !0, (e = this.getSession()) == null || e.removeMessageListener("urn:x-cast:com.vindral.castdata", this.onMessage);
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* Initiates the CastSender.
|
|
46
|
+
* Will reject if Cast is not available on the device or the network.
|
|
47
|
+
*/
|
|
48
|
+
s(this, "init", () => h(this, null, function* () {
|
|
49
|
+
return new Promise((e, t) => {
|
|
50
|
+
let a = !1;
|
|
51
|
+
const o = setTimeout(() => {
|
|
52
|
+
a = !0, t();
|
|
53
|
+
}, 1e4);
|
|
54
|
+
window.__onGCastApiAvailable = (d) => {
|
|
55
|
+
if (a) {
|
|
56
|
+
a = !1;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (clearTimeout(o), !d)
|
|
60
|
+
return t();
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
try {
|
|
63
|
+
this.onGCastApiAvailable(), e();
|
|
64
|
+
} catch (c) {
|
|
65
|
+
t();
|
|
66
|
+
}
|
|
67
|
+
}, 1e3);
|
|
68
|
+
}, this.castLibrariesAdded() && window.cast ? window.__onGCastApiAvailable(!0) : this.verifyCastLibraries();
|
|
69
|
+
});
|
|
70
|
+
}));
|
|
71
|
+
/**
|
|
72
|
+
* Requests a session. It will open the native cast receiver chooser dialog
|
|
73
|
+
*/
|
|
74
|
+
s(this, "start", () => h(this, null, function* () {
|
|
75
|
+
var e;
|
|
76
|
+
yield (e = this.getInstance()) == null ? void 0 : e.requestSession();
|
|
77
|
+
}));
|
|
78
|
+
/**
|
|
79
|
+
* Stops a session. It will stop playback on device as well.
|
|
80
|
+
*/
|
|
81
|
+
s(this, "stop", () => {
|
|
82
|
+
var e;
|
|
83
|
+
(e = this.getSession()) == null || e.endSession(!0);
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Returns a string representing the name of the Cast receiver device or undefined if no receiver exists
|
|
87
|
+
*/
|
|
88
|
+
s(this, "getReceiverName", () => {
|
|
89
|
+
var e, t;
|
|
90
|
+
return ((t = (e = this.getSession()) == null ? void 0 : e.getCastDevice()) == null ? void 0 : t.friendlyName) || void 0;
|
|
91
|
+
});
|
|
92
|
+
s(this, "onGCastApiAvailable", () => {
|
|
93
|
+
var o;
|
|
94
|
+
const e = this.getInstance();
|
|
95
|
+
if (!e)
|
|
96
|
+
throw "cast context should exist";
|
|
97
|
+
const t = e.getSessionState(), a = ((o = this.config) == null ? void 0 : o.receiverApplicationId) || void 0;
|
|
98
|
+
e.setOptions({
|
|
99
|
+
receiverApplicationId: a,
|
|
100
|
+
autoJoinPolicy: chrome.cast.AutoJoinPolicy.TAB_AND_ORIGIN_SCOPED,
|
|
101
|
+
resumeSavedSession: !0
|
|
102
|
+
}), e.addEventListener(cast.framework.CastContextEventType.SESSION_STATE_CHANGED, this.onSessionStateChanged), t === cast.framework.SessionState.SESSION_STARTED && setTimeout(() => {
|
|
103
|
+
this.state = "casting", this.emit("resumed");
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
s(this, "send", (e) => {
|
|
107
|
+
var t;
|
|
108
|
+
(t = this.getSession()) == null || t.sendMessage("urn:x-cast:com.vindral.castdata", e);
|
|
109
|
+
});
|
|
110
|
+
s(this, "onMessage", (e, t) => {
|
|
111
|
+
if (e === "urn:x-cast:com.vindral.castdata")
|
|
112
|
+
try {
|
|
113
|
+
const a = JSON.parse(t);
|
|
114
|
+
switch (a.type) {
|
|
115
|
+
case "metadata":
|
|
116
|
+
this.emit("metadata", a.metadata);
|
|
117
|
+
break;
|
|
118
|
+
case "serverWallclockTime":
|
|
119
|
+
this.emit("server wallclock time", a.serverWallclockTime);
|
|
120
|
+
break;
|
|
121
|
+
default:
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
} catch (a) {
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
s(this, "onSessionStarted", () => {
|
|
128
|
+
var e;
|
|
129
|
+
(e = this.getSession()) == null || e.addMessageListener("urn:x-cast:com.vindral.castdata", this.onMessage), this.send({
|
|
130
|
+
type: "start",
|
|
131
|
+
config: this.config
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
s(this, "onSessionStateChanged", (e) => {
|
|
135
|
+
if (!this.unloaded)
|
|
136
|
+
switch (e.sessionState) {
|
|
137
|
+
case cast.framework.SessionState.SESSION_START_FAILED:
|
|
138
|
+
this.state = "not casting", this.emit("failed");
|
|
139
|
+
break;
|
|
140
|
+
case cast.framework.SessionState.SESSION_ENDED:
|
|
141
|
+
this.state = "not casting", this.emit("disconnected");
|
|
142
|
+
break;
|
|
143
|
+
case cast.framework.SessionState.SESSION_ENDING:
|
|
144
|
+
break;
|
|
145
|
+
case cast.framework.SessionState.SESSION_RESUMED:
|
|
146
|
+
this.onSessionStarted(), this.state = "casting", this.emit("resumed");
|
|
147
|
+
break;
|
|
148
|
+
case cast.framework.SessionState.SESSION_STARTED:
|
|
149
|
+
this.onSessionStarted(), this.state = "casting", this.emit("connected");
|
|
150
|
+
break;
|
|
151
|
+
case cast.framework.SessionState.SESSION_STARTING:
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
s(this, "getInstance", () => {
|
|
156
|
+
var e;
|
|
157
|
+
return (e = window.cast) == null ? void 0 : e.framework.CastContext.getInstance();
|
|
158
|
+
});
|
|
159
|
+
s(this, "getSession", () => {
|
|
160
|
+
var e;
|
|
161
|
+
return (e = this.getInstance()) == null ? void 0 : e.getCurrentSession();
|
|
162
|
+
});
|
|
163
|
+
// check if cast libraries are already added
|
|
164
|
+
s(this, "castLibrariesAdded", () => !!(document.querySelector("#vindralCastFrameworkLib") && document.querySelector("#vindralCastSenderLib")));
|
|
165
|
+
s(this, "verifyCastLibraries", () => {
|
|
166
|
+
if (this.castLibrariesAdded())
|
|
167
|
+
return;
|
|
168
|
+
const e = document.createElement("script");
|
|
169
|
+
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);
|
|
170
|
+
const t = document.createElement("script");
|
|
171
|
+
t.type = "text/javascript", t.id = "vindralCastSenderLib", t.src = "//www.gstatic.com/cv/js/sender/v1/cast_sender.js", document.head.appendChild(t);
|
|
172
|
+
});
|
|
173
|
+
this.config = e;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* True if the instance is casting right now
|
|
177
|
+
*/
|
|
178
|
+
get casting() {
|
|
179
|
+
return this.state === "casting";
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The current volume
|
|
183
|
+
*/
|
|
184
|
+
get volume() {
|
|
185
|
+
var e, t;
|
|
186
|
+
return (t = (e = this.getSession()) == null ? void 0 : e.getVolume()) != null ? t : 0;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Set the current volume. Setting this to zero is equivalent to muting the video
|
|
190
|
+
*/
|
|
191
|
+
set volume(e) {
|
|
192
|
+
var t;
|
|
193
|
+
(t = this.getSession()) == null || t.setVolume(e);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The current language
|
|
197
|
+
*/
|
|
198
|
+
get language() {
|
|
199
|
+
var e, t;
|
|
200
|
+
return (t = (e = this.config) == null ? void 0 : e.options) == null ? void 0 : t.language;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Set the current language
|
|
204
|
+
*/
|
|
205
|
+
set language(e) {
|
|
206
|
+
this.config && (this.config.options.language = e, this.send({
|
|
207
|
+
type: "setLanguage",
|
|
208
|
+
language: e
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* The current channelId
|
|
213
|
+
*/
|
|
214
|
+
get channelId() {
|
|
215
|
+
var e;
|
|
216
|
+
return ((e = this.config) == null ? void 0 : e.options.channelId) || "";
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Set the current channelId
|
|
220
|
+
*/
|
|
221
|
+
set channelId(e) {
|
|
222
|
+
this.config && (this.config.options.channelId = e, this.send({
|
|
223
|
+
type: "setChannelId",
|
|
224
|
+
channelId: e
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
export {
|
|
229
|
+
p as CastSender
|
|
230
|
+
};
|