@gcorevideo/player 0.0.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.
Files changed (192) hide show
  1. package/assets/icons/new/arrow-left.svg +5 -0
  2. package/assets/icons/new/arrow-right.svg +5 -0
  3. package/assets/icons/new/check.svg +5 -0
  4. package/assets/icons/new/close.svg +12 -0
  5. package/assets/icons/new/full.svg +8 -0
  6. package/assets/icons/new/fullscreen-off.svg +14 -0
  7. package/assets/icons/new/fullscreen-on.svg +14 -0
  8. package/assets/icons/new/gear-hd.svg +16 -0
  9. package/assets/icons/new/gear.svg +12 -0
  10. package/assets/icons/new/hd.svg +8 -0
  11. package/assets/icons/new/pause.svg +5 -0
  12. package/assets/icons/new/pip.svg +5 -0
  13. package/assets/icons/new/play.svg +10 -0
  14. package/assets/icons/new/replayleft.svg +5 -0
  15. package/assets/icons/new/replayright.svg +5 -0
  16. package/assets/icons/new/speed.svg +5 -0
  17. package/assets/icons/new/stats.svg +3 -0
  18. package/assets/icons/new/stop.svg +3 -0
  19. package/assets/icons/new/subtitles-off.svg +5 -0
  20. package/assets/icons/new/subtitles-on.svg +6 -0
  21. package/assets/icons/new/volume-max.svg +5 -0
  22. package/assets/icons/new/volume-min.svg +5 -0
  23. package/assets/icons/new/volume-off.svg +5 -0
  24. package/assets/icons/old/cardboard.svg +4 -0
  25. package/assets/icons/old/close-share.svg +13 -0
  26. package/assets/icons/old/close.svg +13 -0
  27. package/assets/icons/old/fb.svg +13 -0
  28. package/assets/icons/old/fullscreen.svg +12 -0
  29. package/assets/icons/old/language.svg +1 -0
  30. package/assets/icons/old/pause.svg +12 -0
  31. package/assets/icons/old/play.svg +12 -0
  32. package/assets/icons/old/quality-arrow.svg +13 -0
  33. package/assets/icons/old/reload.svg +4 -0
  34. package/assets/icons/old/share.svg +13 -0
  35. package/assets/icons/old/sound-off.svg +15 -0
  36. package/assets/icons/old/sound-on.svg +15 -0
  37. package/assets/icons/old/streams.svg +3 -0
  38. package/assets/icons/old/twitter.svg +13 -0
  39. package/assets/icons/old/wn.svg +15 -0
  40. package/assets/icons/standard/01-play.svg +3 -0
  41. package/assets/icons/standard/02-pause.svg +3 -0
  42. package/assets/icons/standard/03-stop.svg +3 -0
  43. package/assets/icons/standard/04-volume.svg +3 -0
  44. package/assets/icons/standard/05-mute.svg +3 -0
  45. package/assets/icons/standard/06-expand.svg +3 -0
  46. package/assets/icons/standard/07-shrink.svg +3 -0
  47. package/assets/icons/standard/08-hd.svg +3 -0
  48. package/assets/icons/standard/09-cc.svg +8 -0
  49. package/assets/icons/standard/10-reload.svg +4 -0
  50. package/assets/style/main.scss +50 -0
  51. package/assets/style/theme.scss +42 -0
  52. package/assets/style/variables.scss +7 -0
  53. package/dist/DashPlayback-6wKK0_pL.js +666 -0
  54. package/dist/DashPlayback-8U6_s4Jc.js +666 -0
  55. package/dist/DashPlayback-BeZz7mN9.js +663 -0
  56. package/dist/DashPlayback-CRdja67F.js +667 -0
  57. package/dist/DashPlayback-D0df6zGg.js +663 -0
  58. package/dist/DashPlayback-D7egS-CZ.js +664 -0
  59. package/dist/DashPlayback-DH5lZMRR.js +663 -0
  60. package/dist/DashPlayback-DZfIc9sK.js +665 -0
  61. package/dist/DashPlayback-VhCxbQhn.js +666 -0
  62. package/dist/HlsPlayback-Avwy8-0O.js +749 -0
  63. package/dist/index.css +125 -0
  64. package/dist/index.js +467 -0
  65. package/lib/Player.d.ts +50 -0
  66. package/lib/Player.d.ts.map +1 -0
  67. package/lib/Player.js +310 -0
  68. package/lib/backend.d.ts +3 -0
  69. package/lib/backend.d.ts.map +1 -0
  70. package/lib/backend.js +10 -0
  71. package/lib/constants.d.ts +19 -0
  72. package/lib/constants.d.ts.map +1 -0
  73. package/lib/constants.js +18 -0
  74. package/lib/index.d.ts +10 -0
  75. package/lib/index.d.ts.map +1 -0
  76. package/lib/index.js +9 -0
  77. package/lib/internal.types.d.ts +105 -0
  78. package/lib/internal.types.d.ts.map +1 -0
  79. package/lib/internal.types.js +1 -0
  80. package/lib/playback.types.d.ts +13 -0
  81. package/lib/playback.types.d.ts.map +1 -0
  82. package/lib/playback.types.js +1 -0
  83. package/lib/plugins/audio-selector/AudioSelector.d.ts +48 -0
  84. package/lib/plugins/audio-selector/AudioSelector.d.ts.map +1 -0
  85. package/lib/plugins/audio-selector/AudioSelector.js +282 -0
  86. package/lib/plugins/big-mute-button/BigMuteButton.d.ts +33 -0
  87. package/lib/plugins/big-mute-button/BigMuteButton.d.ts.map +1 -0
  88. package/lib/plugins/big-mute-button/BigMuteButton.js +148 -0
  89. package/lib/plugins/bottom-gear/BottomGear.d.ts +30 -0
  90. package/lib/plugins/bottom-gear/BottomGear.d.ts.map +1 -0
  91. package/lib/plugins/bottom-gear/BottomGear.js +103 -0
  92. package/lib/plugins/click-to-pause/ClickToPause.d.ts +16 -0
  93. package/lib/plugins/click-to-pause/ClickToPause.d.ts.map +1 -0
  94. package/lib/plugins/click-to-pause/ClickToPause.js +73 -0
  95. package/lib/plugins/dash-playback/DashPlayback.d.ts +81 -0
  96. package/lib/plugins/dash-playback/DashPlayback.d.ts.map +1 -0
  97. package/lib/plugins/dash-playback/DashPlayback.js +658 -0
  98. package/lib/plugins/dash-plugin/DashPlayback.d.ts +86 -0
  99. package/lib/plugins/dash-plugin/DashPlayback.d.ts.map +1 -0
  100. package/lib/plugins/dash-plugin/DashPlayback.js +659 -0
  101. package/lib/plugins/disable-controls/DisableControls.d.ts +15 -0
  102. package/lib/plugins/disable-controls/DisableControls.d.ts.map +1 -0
  103. package/lib/plugins/disable-controls/DisableControls.js +69 -0
  104. package/lib/plugins/dvr-controls/DVRControls.d.ts +27 -0
  105. package/lib/plugins/dvr-controls/DVRControls.d.ts.map +1 -0
  106. package/lib/plugins/dvr-controls/DVRControls.js +110 -0
  107. package/lib/plugins/hls-playback/HlsPlayback.d.ts +102 -0
  108. package/lib/plugins/hls-playback/HlsPlayback.d.ts.map +1 -0
  109. package/lib/plugins/hls-playback/HlsPlayback.js +747 -0
  110. package/lib/plugins/level-selector/LevelSelector.d.ts +48 -0
  111. package/lib/plugins/level-selector/LevelSelector.d.ts.map +1 -0
  112. package/lib/plugins/level-selector/LevelSelector.js +287 -0
  113. package/lib/plugins/media-control/MediaControl.d.ts +186 -0
  114. package/lib/plugins/media-control/MediaControl.d.ts.map +1 -0
  115. package/lib/plugins/media-control/MediaControl.js +1000 -0
  116. package/lib/plugins/poster/Poster.d.ts +41 -0
  117. package/lib/plugins/poster/Poster.d.ts.map +1 -0
  118. package/lib/plugins/poster/Poster.js +186 -0
  119. package/lib/trace/LogTracer.d.ts +12 -0
  120. package/lib/trace/LogTracer.d.ts.map +1 -0
  121. package/lib/trace/LogTracer.js +17 -0
  122. package/lib/trace/SentryTracer.d.ts +11 -0
  123. package/lib/trace/SentryTracer.d.ts.map +1 -0
  124. package/lib/trace/SentryTracer.js +18 -0
  125. package/lib/trace/Tracer.d.ts +13 -0
  126. package/lib/trace/Tracer.d.ts.map +1 -0
  127. package/lib/trace/Tracer.js +15 -0
  128. package/lib/trace/index.d.ts +18 -0
  129. package/lib/trace/index.d.ts.map +1 -0
  130. package/lib/trace/index.js +27 -0
  131. package/lib/trace/types.d.ts +8 -0
  132. package/lib/trace/types.d.ts.map +1 -0
  133. package/lib/trace/types.js +1 -0
  134. package/lib/types.d.ts +82 -0
  135. package/lib/types.d.ts.map +1 -0
  136. package/lib/types.js +1 -0
  137. package/lib/utils/Logger.d.ts +23 -0
  138. package/lib/utils/Logger.d.ts.map +1 -0
  139. package/lib/utils/Logger.js +81 -0
  140. package/lib/utils/canAutoplay.d.ts +6 -0
  141. package/lib/utils/canAutoplay.d.ts.map +1 -0
  142. package/lib/utils/canAutoplay.js +30 -0
  143. package/lib/utils/errors.d.ts +2 -0
  144. package/lib/utils/errors.d.ts.map +1 -0
  145. package/lib/utils/errors.js +6 -0
  146. package/lib/utils/queryParams.d.ts +2 -0
  147. package/lib/utils/queryParams.d.ts.map +1 -0
  148. package/lib/utils/queryParams.js +4 -0
  149. package/lib/utils/scripts-load.d.ts +2 -0
  150. package/lib/utils/scripts-load.d.ts.map +1 -0
  151. package/lib/utils/scripts-load.js +20 -0
  152. package/lib/utils/types.d.ts +4 -0
  153. package/lib/utils/types.d.ts.map +1 -0
  154. package/lib/utils/types.js +1 -0
  155. package/lib/utils/utils.d.ts +7 -0
  156. package/lib/utils/utils.d.ts.map +1 -0
  157. package/lib/utils/utils.js +57 -0
  158. package/package.json +57 -0
  159. package/rollup.config.js +34 -0
  160. package/src/Player.ts +390 -0
  161. package/src/backend.ts +12 -0
  162. package/src/constants.ts +17 -0
  163. package/src/index.ts +9 -0
  164. package/src/internal.types.ts +126 -0
  165. package/src/playback.types.ts +15 -0
  166. package/src/plugins/dash-playback/DashPlayback.ts +808 -0
  167. package/src/plugins/dash-playback/_DashPlayback.js +688 -0
  168. package/src/plugins/hls-playback/HlsPlayback.ts +909 -0
  169. package/src/plugins/hls-playback/hls.js +706 -0
  170. package/src/trace/LogTracer.ts +23 -0
  171. package/src/trace/SentryTracer.ts +18 -0
  172. package/src/trace/Tracer.ts +27 -0
  173. package/src/trace/index.ts +32 -0
  174. package/src/trace/types.ts +7 -0
  175. package/src/types.ts +100 -0
  176. package/src/typings/@clappr/core/error_mixin.d.ts +15 -0
  177. package/src/typings/@clappr/core/events.d.ts +7 -0
  178. package/src/typings/@clappr/core/html5_video.d.ts +28 -0
  179. package/src/typings/@clappr/core/playback.d.ts +5 -0
  180. package/src/typings/@clappr/core/player.d.ts +83 -0
  181. package/src/typings/@clappr/plugins.d.ts +29 -0
  182. package/src/typings/clappr-zepto.xd.xts +44 -0
  183. package/src/typings/globals.d.ts +8 -0
  184. package/src/utils/Logger.ts +107 -0
  185. package/src/utils/canAutoplay.ts +39 -0
  186. package/src/utils/errors.ts +6 -0
  187. package/src/utils/queryParams.ts +5 -0
  188. package/src/utils/scripts-load.ts +26 -0
  189. package/src/utils/types.ts +5 -0
  190. package/src/utils/utils.ts +64 -0
  191. package/tsconfig.json +43 -0
  192. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,23 @@
1
+ import type { Tracer } from "./types.js";
2
+
3
+ import { Logger } from "../utils/Logger.js";
4
+
5
+ /**
6
+ * A tracer that logs to the console
7
+ * @public
8
+ */
9
+ export class LogTracer implements Tracer {
10
+ private logger: Logger;
11
+
12
+ constructor(ns = "") {
13
+ this.logger = new Logger(ns);
14
+ }
15
+
16
+ reportError(e: Error) {
17
+ this.logger.error(e);
18
+ }
19
+
20
+ trace(msg: string, data?: Record<string, unknown>) {
21
+ this.logger.debug(msg, data);
22
+ }
23
+ }
@@ -0,0 +1,18 @@
1
+ import {Client} from "@sentry/types";
2
+
3
+ /**
4
+ * @beta
5
+ */
6
+ export class SentryTracer {
7
+ constructor(private client: Client) {}
8
+
9
+ reportError(e: Error) {
10
+ this.client.captureException(e);
11
+ }
12
+
13
+ trace(msg: string, data?: Record<string, unknown>) {
14
+ this.client.captureMessage(msg, "info", {
15
+ data,
16
+ });
17
+ }
18
+ };
@@ -0,0 +1,27 @@
1
+ import { Logger } from "../utils/Logger.js";
2
+
3
+ const logger = new Logger("_");
4
+
5
+ type TagValue = string | boolean | number | null | undefined;
6
+
7
+ export interface Tracer {
8
+ reportError(e: unknown): void;
9
+ trace(msg: string, data: Record<string, unknown>): void;
10
+ }
11
+
12
+ export class LogTracer implements Tracer {
13
+ private tags: Record<string, TagValue> = {};
14
+
15
+ reportError(e: Error) {
16
+ logger.error(e, this.tags);
17
+ }
18
+
19
+ setTag(name: string, value: TagValue) {
20
+ this.tags[name] = value;
21
+ }
22
+
23
+ trace(msg: string, data?: Record<string, unknown>) {
24
+ const fullData = Object.assign({}, this.tags, data);
25
+ logger.debug(msg, fullData);
26
+ }
27
+ }
@@ -0,0 +1,32 @@
1
+ import type { Tracer } from "./types.js";
2
+
3
+ const tracer: Tracer = {
4
+ trace: () => {},
5
+ reportError: () => {},
6
+ };
7
+
8
+ /**
9
+ * @public
10
+ * Sets a tracer implementation, e.g., LogTracer or SentryTracer
11
+ */
12
+ export function setTracer(t: Tracer) {
13
+ tracer.trace = t.trace.bind(t);
14
+ tracer.reportError = t.reportError.bind(t);
15
+ }
16
+
17
+ /**
18
+ * @public
19
+ * @param e
20
+ */
21
+ export function reportError(e: unknown) {
22
+ tracer.reportError(e);
23
+ }
24
+
25
+ /**
26
+ * @public
27
+ * @param msg
28
+ * @param data
29
+ */
30
+ export function trace(msg: string, data: Record<string, unknown> = {}) {
31
+ tracer.trace(msg, data);
32
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export interface Tracer {
5
+ reportError(e: unknown): void;
6
+ trace(msg: string, data: Record<string, unknown>): void;
7
+ }
package/src/types.ts ADDED
@@ -0,0 +1,100 @@
1
+ export type PlayerDebugTag = 'all' | 'clappr' | 'dash' | 'hls' | 'none';
2
+ export type PlayerDebugSettings = PlayerDebugTag | boolean;
3
+
4
+ export type PlaybackType = 'live' | 'vod';
5
+ export type MediaTransport = 'dash' | 'hls' | 'mpegts';
6
+ export type TransportPreference = MediaTransport | 'auto';
7
+
8
+ export type PlayerPlugin = {
9
+ new(...args: any[]): unknown;
10
+ type: 'core' | 'container' | 'playback';
11
+ }
12
+
13
+ // export type PluginName = StdPluginName | string;
14
+
15
+ export type PlayerConfig = {
16
+ autoPlay?: boolean;
17
+ debug?: PlayerDebugSettings;
18
+ language?: string;
19
+ loop?: boolean;
20
+ multisources: StreamMediaSource[];
21
+ mute?: boolean;
22
+ playbackType: PlaybackType;
23
+ // plugins?: PluginName[];
24
+ pluginSettings?: Record<string, unknown>;
25
+ poster?: string;
26
+ priorityTransport?: TransportPreference;
27
+ realtimeApi?: string;
28
+ strings: TranslationSettings;
29
+ }
30
+
31
+ export type PlayerOptionsThumbnails = {
32
+ sprite?: string | null;
33
+ vtt?: string | null;
34
+
35
+ }
36
+
37
+ export type ContextMenuSettings = {
38
+ preventShowContextMenu?: boolean;
39
+ }
40
+
41
+ type LangTag = string;
42
+ type TranslationKey = string;
43
+
44
+ export type BroadcastSettings = {
45
+ status?: 'live' | 'noActiveStreams';
46
+ }
47
+
48
+ export type ClipsPluginOptions = Record<string, unknown>; // TODO
49
+
50
+ export type PlaybackSettings = {
51
+ hlsjsConfig?: Record<string, unknown>;
52
+ playInline?: boolean;
53
+ preload?: 'auto' | 'metadata' | 'none';
54
+ triggerFatalErrorOnResourceDenied?: boolean;
55
+ }
56
+
57
+ export type DashSettings = Record<string, unknown>; //
58
+
59
+ // TODO consult with the Broadcaster team
60
+ // TODO turn into camel case convert at user level
61
+ export type StreamMediaSourceDto = {
62
+ description: string;
63
+ dvr: boolean;
64
+ hls_cmaf_url?: string;
65
+ hls_mpegts_url?: string;
66
+ id: number;
67
+ live: boolean;
68
+ priority_transport: TransportPreference;
69
+ poster: string | null;
70
+ projection: ProjectionType | null;
71
+ screenshot: string | null;
72
+ source: string
73
+ source_dash: string | null;
74
+ sprite: string | null;
75
+ title: string;
76
+ vtt: string | null;
77
+ }
78
+
79
+ export type StreamMediaSource = {
80
+ description: string;
81
+ dvr: boolean;
82
+ hlsCmafUrl?: string;
83
+ hlsMpegtsUrl?: string;
84
+ id: number;
85
+ live: boolean;
86
+ priorityTransport: TransportPreference;
87
+ poster: string | null;
88
+ projection: ProjectionType | null;
89
+ screenshot: string | null;
90
+ source: string
91
+ sourceDash: string | null;
92
+ sprite: string | null;
93
+ title: string;
94
+ vtt: string | null;
95
+ }
96
+
97
+ export type SrcProjectionType = 'regular' | '360' | 'vr180' | 'vr360tb';
98
+ export type ProjectionType = '360' | '180' | '360_TB';
99
+
100
+ export type TranslationSettings = Partial<Record<LangTag, Record<TranslationKey, string>>>;
@@ -0,0 +1,15 @@
1
+ import '@clappr/core';
2
+ // import ErrorMixin from "@clappr/core/src/base/error_mixin/error_mixin";
3
+
4
+ // export as namespace "@clappr/core";
5
+ declare module "@clappr/core" {
6
+ // export ErrorMixin;
7
+
8
+ type ErrorOptions = {
9
+ useCodePrefix: boolean;
10
+ }
11
+
12
+ declare interface ErrorMixin {
13
+ createError(error: Object, options?: ErrorOptions): Error;
14
+ }
15
+ }
@@ -0,0 +1,7 @@
1
+ // // Events.Custom
2
+ // import { Events } from "@clappr/core";
3
+ // declare module "@clappr/core" {
4
+ // declare class Events {
5
+ // static Custom: Record<string, string>;
6
+ // }
7
+ // }
@@ -0,0 +1,28 @@
1
+ import '@clappr/core';
2
+
3
+ declare module "@clappr/core" {
4
+ declare type HTML5VideoSettingsItem =
5
+ | "seekbar"
6
+ | "playpause"
7
+ | "position"
8
+ | "duration"
9
+ | "fullscreen"
10
+ | "volume"
11
+ | "hd-indicator"
12
+ | "playstop";
13
+
14
+ declare type HTML5VideoSettings = {
15
+ default: HTML5VideoSettingsItem[];
16
+ left?: HTML5VideoSettingsItem[];
17
+ right?: HTML5VideoSettingsItem[];
18
+ seekEnabled?: boolean;
19
+ }
20
+
21
+ declare class HTML5Video extends Playback {
22
+ settings: HTML5VideoSettings;
23
+
24
+ readonly _minDvrSize: number;
25
+
26
+ _onDurationChange(): void;
27
+ }
28
+ }
@@ -0,0 +1,5 @@
1
+ import '@clappr/core';
2
+
3
+ declare module "@clappr/core" {
4
+ declare interface Playback extends ErrorMixin { }
5
+ }
@@ -0,0 +1,83 @@
1
+ import "@clappr/core";
2
+
3
+ declare module "@clappr/core" {
4
+ type MediacontrolStyles = {
5
+ // TODO
6
+ }
7
+
8
+ type PlayerMediaSourceDesc = {
9
+ mimeType?: string;
10
+ source: string;
11
+ }
12
+
13
+ type PlayerMediaSource = string | PlayerMediaSourceDesc;
14
+
15
+ type ExternalTrack = {
16
+ kind?: "subtitles";
17
+ src: string;
18
+ label: string;
19
+ lang: string;
20
+ }
21
+
22
+ type HlsjsConfig = {
23
+ debug?: boolean;
24
+ startLevel?: number;
25
+ } & Record<string, unknown>;
26
+
27
+ type ShakaConfig = Record<string, unknown>;
28
+
29
+ declare type CorePlaybackConfig = {
30
+ // audioOnly: boolean;
31
+ disableContextMenu?: boolean;
32
+ controls?: boolean;
33
+ crossOrigin?: 'anonymous' | 'use-credentials';
34
+ // enableAutomaticABR?: boolean;
35
+ externalTracks?: unknown[]; // TODO
36
+ hlsjsConfig?: HlsjsConfig;
37
+ // initialBandwidthEstimate?: number;
38
+ // maxBufferLength?: number;
39
+ // maxBackBufferLength?: number;
40
+ // minBufferLength?: number;
41
+ minimumDvrSize?: number; // TODO ?
42
+ // maxAdaptiveBitrate?: number;
43
+ // maxAdaptiveVideoDimensions?: unknown; // TODO
44
+ playInline: boolean;
45
+ preload?: 'metadata' | 'auto' | 'none';
46
+ // preferredTextLanguage?: string;
47
+ // preferredAudioLanguage?: string;
48
+ shakaConfiguration?: ShakaConfig;
49
+ }
50
+
51
+ type ErrorLevel = "FATAL" | "WARN" | "INFO";
52
+
53
+ declare type EventSpec = string;
54
+ declare type EventHandlerSpec = string;
55
+ declare type PluginEventsConfig = Record<EventSpec, EventHandlerSpec>;
56
+
57
+ declare type PlaybackError = {
58
+ code?: number | string;
59
+ description: string;
60
+ raw?: MediaError;
61
+ level?: ErrorLevel;
62
+ }
63
+
64
+ declare type CorePlayerEvents = {
65
+ // TODO event arguments types
66
+ onReady?: () => void;
67
+ onResize?: (data: { width: number; height: number }) => void;
68
+ onPlay?: (metadata: unknown) => void;
69
+ onPause?: (metadata: unknown) => void;
70
+ onStop?: (metadata: unknown) => void;
71
+ onEnded?: () => void;
72
+ onSeek?: (currentTime: number) => void;
73
+ onError?: (err: PlaybackError) => void;
74
+ onTimeUpdate?: (timeProgress: { current: number; total: number }) => void;
75
+ onVolumeUpdate?: (value: number) => void;
76
+ onSubtitleAvailable?: () => void;
77
+ }
78
+
79
+ declare type ClapprVersionSpec = {
80
+ min: string;
81
+ // TODO
82
+ }
83
+ }
@@ -0,0 +1,29 @@
1
+ import { Core, UICorePlugin } from "@clappr/core";
2
+ import "@clappr/plugins";
3
+
4
+ declare module "@clappr/plugins" {
5
+ declare type MediaControlOptions = {
6
+ hideMediaControlDelay?: number;
7
+ chromeless?: boolean;
8
+ source?: string;
9
+ sources?: string[];
10
+ baseUrl?: string;
11
+ disableKeyboardShortcuts?: boolean;
12
+ width?: number;
13
+ height?: number;
14
+ persistConfig?: boolean; // TODO
15
+ focusElement?: HTMLElement;
16
+ hideVolumeBar?: boolean;
17
+ parentElement?: HTMLElement;
18
+ mediacontrol?: {
19
+ buttons: string;
20
+ seekbar: string;
21
+ }
22
+ }
23
+
24
+ // declare class MediaControl extends UICorePlugin {
25
+ // constructor(core: Core);
26
+
27
+ // configure(options: MediaControlOptions): void;
28
+ // }
29
+ }
@@ -0,0 +1,44 @@
1
+ import "clappr-zepto";
2
+
3
+ declare module "clappr-zepto" {
4
+ declare type ZeptoResult = {
5
+ bind: (event: string, handler: (...args: any[]) => void) => void;
6
+ unbind: (event: string, handler: (...args: any[]) => void) => void;
7
+ // on: (event: string, handler: (...args: any[]) => void) => void;
8
+ // off: (event: string, handler: (...args: any[]) => void) => void;
9
+ find: (selector: string) => ZeptoResult;
10
+ slice: (start: number, end?: number) => ZeptoResult;
11
+ // get: () => HTMLElement[];
12
+ get: (index: number) => HTMLElement[] | HTMLElement | null;
13
+
14
+ append: (element: HTMLElement | string | ZeptoResult) => void;
15
+ remove: () => void;
16
+ empty: () => void;
17
+
18
+ attr: (name: string, value: string) => void;
19
+ // css: (property: string, value: string | number) => void;
20
+ css: (styles: Record<string, string | number>) => void;
21
+ data: (name: string, value: unknown) => void;
22
+ // html: () => string;
23
+ html: (value: string) => void;
24
+ // text: () => string;
25
+ text: (value: string) => void;
26
+
27
+ show: () => void;
28
+ hide: () => void;
29
+
30
+ addClass: (className: string) => void;
31
+ removeClass: (className: string) => void;
32
+ hasClass: (className: string) => boolean;
33
+ toggleClass: (className: string) => void;
34
+
35
+ offset: () => { top: number; left: number };
36
+ width: () => number;
37
+ height: () => number;
38
+ };
39
+
40
+ declare const $: ((selector: string | Element | Document | ZeptoResult) => ZeptoResult) & {
41
+ extend(target: Record<string, any>, ...sources: Record<string, any>[]): Record<string, any>;
42
+ extend(deep: true, target: Record<string, any>, ...sources: Record<string, any>[]): Record<string, any>;
43
+ };
44
+ }
@@ -0,0 +1,8 @@
1
+ declare interface HTMLVideoElement {
2
+ webkitDisplayingFullscreen?: boolean;
3
+ }
4
+
5
+ declare module "*.css";
6
+ declare module "*.scss";
7
+ declare module "*.svg";
8
+ declare module "*.ejs";
@@ -0,0 +1,107 @@
1
+ const APP_NAME = "gplayer";
2
+
3
+ /**
4
+ * @beta
5
+ */
6
+ export type WriteFn = (...args: any[]) => void;
7
+
8
+ class DebuggerWrapper {
9
+ private currentWriter: WriteFn;
10
+
11
+ constructor(private writer: WriteFn, public readonly namespace: string, enabled = true) {
12
+ this.currentWriter = enabled ? writer : nullWriter;
13
+ }
14
+
15
+ enable() {
16
+ this.currentWriter = this.writer;
17
+ }
18
+
19
+ disable() {
20
+ this.currentWriter = nullWriter;
21
+ }
22
+
23
+ write = (m: any, ...args: any[]) => {
24
+ const tokens = args.map((_) => "%s");
25
+ if (typeof m === "string" || args.length > 0) {
26
+ tokens.unshift("%s");
27
+ }
28
+ this.currentWriter(`${this.namespace}: ${tokens.join(' ')}`, m, ...args.map(a => JSON.stringify(a)));
29
+ }
30
+ }
31
+
32
+ type Pattern = RegExp;
33
+
34
+ const currentPatterns: Pattern[] = [];
35
+
36
+ function parsePattern(pattern: string): Pattern {
37
+ if (pattern === "*") {
38
+ return /.?/;
39
+ }
40
+ return new RegExp("^" + pattern.replace(/\*/g, "[@\\w-]+"), "i");
41
+ }
42
+
43
+ function pass(namespace: string): boolean {
44
+ return currentPatterns.some((p) => p.test(namespace));
45
+ }
46
+
47
+ function nullWriter() {}
48
+
49
+ /**
50
+ * Logging utility with [debug](https://www.npmjs.com/package/debug)-like API
51
+ * @beta
52
+ */
53
+ export class Logger {
54
+ public readonly info: WriteFn;
55
+ public readonly warn: WriteFn;
56
+ public readonly error: WriteFn;
57
+ public readonly debug: WriteFn;
58
+
59
+ private static items: DebuggerWrapper[] = [];
60
+
61
+ constructor(namespace: string, appName = APP_NAME) {
62
+ const ns = namespace ? `:${namespace}` : "";
63
+
64
+ const info = new DebuggerWrapper(console.info.bind(console), `${appName}:INFO${ns}`, pass(namespace));
65
+ this.info = info.write;
66
+
67
+ const warn = new DebuggerWrapper(console.warn.bind(console), `${appName}:WARN${ns}`, pass(namespace));
68
+ this.warn = warn.write;
69
+
70
+ const error = new DebuggerWrapper(console.error.bind(console), `${appName}:ERROR${ns}`, pass(namespace));
71
+ this.error = error.write;
72
+
73
+ const debug = new DebuggerWrapper(console.debug.bind(console), `${appName}:DEBUG${ns}`, pass(namespace));
74
+ this.debug = debug.write;
75
+
76
+ Logger.items.push(warn);
77
+ Logger.items.push(info);
78
+ Logger.items.push(error);
79
+ Logger.items.push(debug);
80
+ }
81
+
82
+ /**
83
+ * @param patterns - comma-separated list of patterns, can contain '*' as a wildcard
84
+ */
85
+ static enable(patterns: string) {
86
+ currentPatterns.splice(
87
+ 0,
88
+ currentPatterns.length,
89
+ ...patterns.split(",").filter(Boolean).map(parsePattern),
90
+ );
91
+ Logger.toggleItems();
92
+ }
93
+
94
+ static disable() {
95
+ currentPatterns.splice(0, currentPatterns.length);
96
+ }
97
+
98
+ private static toggleItems() {
99
+ for (const w of Logger.items) {
100
+ if (pass(w.namespace)) {
101
+ w.enable();
102
+ } else {
103
+ w.disable();
104
+ }
105
+ }
106
+ }
107
+ }
@@ -0,0 +1,39 @@
1
+ import { Browser } from '@clappr/core';
2
+ import canAutoPlay from 'can-autoplay';
3
+
4
+ import { reportError, trace } from "../trace/index.js";
5
+
6
+ export type CanAutoplayResult = {
7
+ autoPlay: boolean;
8
+ muted: boolean;
9
+ }
10
+
11
+ export default async function (): Promise<CanAutoplayResult> {
12
+ let autoPlay = false;
13
+ let muted = false;
14
+
15
+ trace("canAutoplay enter");
16
+
17
+ try {
18
+ const autoplay = await canAutoPlay.video();
19
+
20
+ if (autoplay.result) {
21
+ autoPlay = true;
22
+ } else {
23
+ const checkObj = Browser.isiOS ? { muted: true, inline: true } : { muted: true };
24
+ const mute = await canAutoPlay.video(checkObj);
25
+
26
+ if (!mute.result) {
27
+ autoPlay = false;
28
+ } else {
29
+ muted = true;
30
+ autoPlay = true;
31
+ }
32
+ }
33
+ } catch (e) {
34
+ reportError(e);
35
+ }
36
+
37
+ trace("canAutoplay leave", { autoPlay, muted });
38
+ return { autoPlay, muted };
39
+ }
@@ -0,0 +1,6 @@
1
+ export function wrapError(error: any): Error {
2
+ if (error instanceof Error) {
3
+ return error;
4
+ }
5
+ return new Error(String(error));
6
+ }
@@ -0,0 +1,5 @@
1
+ import { PlayerDebugTag } from "src/types";
2
+
3
+ function isValidDebugTag(tag: string): tag is PlayerDebugTag {
4
+ return ['all', 'clappr', 'dash', 'hls', 'none'].includes(tag);
5
+ }
@@ -0,0 +1,26 @@
1
+
2
+ export function request(url: string, timeout: number): Promise<void> {
3
+ return new Promise<void>((resolve) => {
4
+ const win = window, doc = document, el = 'script';
5
+
6
+ let timer: number | undefined;
7
+
8
+ const onLoad = () => {
9
+ win.clearTimeout(timer);
10
+ resolve();
11
+ };
12
+
13
+ const first = doc.getElementsByTagName(el)[0];
14
+ const script = doc.createElement(el);
15
+
16
+ script.src = url;
17
+ script.async = true;
18
+ script.onload = onLoad;
19
+ script.onerror = onLoad; // TODO reject?
20
+
21
+ first?.parentNode?.insertBefore(script, first);
22
+ if (timeout) {
23
+ timer = win.setTimeout(onLoad, timeout);
24
+ }
25
+ });
26
+ }
@@ -0,0 +1,5 @@
1
+ import { $ } from "@clappr/core";
2
+
3
+ export type ZeptoResult = ReturnType<typeof $>;
4
+
5
+ export type TimerId = ReturnType<typeof setTimeout>;