@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.
- package/assets/icons/new/arrow-left.svg +5 -0
- package/assets/icons/new/arrow-right.svg +5 -0
- package/assets/icons/new/check.svg +5 -0
- package/assets/icons/new/close.svg +12 -0
- package/assets/icons/new/full.svg +8 -0
- package/assets/icons/new/fullscreen-off.svg +14 -0
- package/assets/icons/new/fullscreen-on.svg +14 -0
- package/assets/icons/new/gear-hd.svg +16 -0
- package/assets/icons/new/gear.svg +12 -0
- package/assets/icons/new/hd.svg +8 -0
- package/assets/icons/new/pause.svg +5 -0
- package/assets/icons/new/pip.svg +5 -0
- package/assets/icons/new/play.svg +10 -0
- package/assets/icons/new/replayleft.svg +5 -0
- package/assets/icons/new/replayright.svg +5 -0
- package/assets/icons/new/speed.svg +5 -0
- package/assets/icons/new/stats.svg +3 -0
- package/assets/icons/new/stop.svg +3 -0
- package/assets/icons/new/subtitles-off.svg +5 -0
- package/assets/icons/new/subtitles-on.svg +6 -0
- package/assets/icons/new/volume-max.svg +5 -0
- package/assets/icons/new/volume-min.svg +5 -0
- package/assets/icons/new/volume-off.svg +5 -0
- package/assets/icons/old/cardboard.svg +4 -0
- package/assets/icons/old/close-share.svg +13 -0
- package/assets/icons/old/close.svg +13 -0
- package/assets/icons/old/fb.svg +13 -0
- package/assets/icons/old/fullscreen.svg +12 -0
- package/assets/icons/old/language.svg +1 -0
- package/assets/icons/old/pause.svg +12 -0
- package/assets/icons/old/play.svg +12 -0
- package/assets/icons/old/quality-arrow.svg +13 -0
- package/assets/icons/old/reload.svg +4 -0
- package/assets/icons/old/share.svg +13 -0
- package/assets/icons/old/sound-off.svg +15 -0
- package/assets/icons/old/sound-on.svg +15 -0
- package/assets/icons/old/streams.svg +3 -0
- package/assets/icons/old/twitter.svg +13 -0
- package/assets/icons/old/wn.svg +15 -0
- package/assets/icons/standard/01-play.svg +3 -0
- package/assets/icons/standard/02-pause.svg +3 -0
- package/assets/icons/standard/03-stop.svg +3 -0
- package/assets/icons/standard/04-volume.svg +3 -0
- package/assets/icons/standard/05-mute.svg +3 -0
- package/assets/icons/standard/06-expand.svg +3 -0
- package/assets/icons/standard/07-shrink.svg +3 -0
- package/assets/icons/standard/08-hd.svg +3 -0
- package/assets/icons/standard/09-cc.svg +8 -0
- package/assets/icons/standard/10-reload.svg +4 -0
- package/assets/style/main.scss +50 -0
- package/assets/style/theme.scss +42 -0
- package/assets/style/variables.scss +7 -0
- package/dist/DashPlayback-6wKK0_pL.js +666 -0
- package/dist/DashPlayback-8U6_s4Jc.js +666 -0
- package/dist/DashPlayback-BeZz7mN9.js +663 -0
- package/dist/DashPlayback-CRdja67F.js +667 -0
- package/dist/DashPlayback-D0df6zGg.js +663 -0
- package/dist/DashPlayback-D7egS-CZ.js +664 -0
- package/dist/DashPlayback-DH5lZMRR.js +663 -0
- package/dist/DashPlayback-DZfIc9sK.js +665 -0
- package/dist/DashPlayback-VhCxbQhn.js +666 -0
- package/dist/HlsPlayback-Avwy8-0O.js +749 -0
- package/dist/index.css +125 -0
- package/dist/index.js +467 -0
- package/lib/Player.d.ts +50 -0
- package/lib/Player.d.ts.map +1 -0
- package/lib/Player.js +310 -0
- package/lib/backend.d.ts +3 -0
- package/lib/backend.d.ts.map +1 -0
- package/lib/backend.js +10 -0
- package/lib/constants.d.ts +19 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +18 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +9 -0
- package/lib/internal.types.d.ts +105 -0
- package/lib/internal.types.d.ts.map +1 -0
- package/lib/internal.types.js +1 -0
- package/lib/playback.types.d.ts +13 -0
- package/lib/playback.types.d.ts.map +1 -0
- package/lib/playback.types.js +1 -0
- package/lib/plugins/audio-selector/AudioSelector.d.ts +48 -0
- package/lib/plugins/audio-selector/AudioSelector.d.ts.map +1 -0
- package/lib/plugins/audio-selector/AudioSelector.js +282 -0
- package/lib/plugins/big-mute-button/BigMuteButton.d.ts +33 -0
- package/lib/plugins/big-mute-button/BigMuteButton.d.ts.map +1 -0
- package/lib/plugins/big-mute-button/BigMuteButton.js +148 -0
- package/lib/plugins/bottom-gear/BottomGear.d.ts +30 -0
- package/lib/plugins/bottom-gear/BottomGear.d.ts.map +1 -0
- package/lib/plugins/bottom-gear/BottomGear.js +103 -0
- package/lib/plugins/click-to-pause/ClickToPause.d.ts +16 -0
- package/lib/plugins/click-to-pause/ClickToPause.d.ts.map +1 -0
- package/lib/plugins/click-to-pause/ClickToPause.js +73 -0
- package/lib/plugins/dash-playback/DashPlayback.d.ts +81 -0
- package/lib/plugins/dash-playback/DashPlayback.d.ts.map +1 -0
- package/lib/plugins/dash-playback/DashPlayback.js +658 -0
- package/lib/plugins/dash-plugin/DashPlayback.d.ts +86 -0
- package/lib/plugins/dash-plugin/DashPlayback.d.ts.map +1 -0
- package/lib/plugins/dash-plugin/DashPlayback.js +659 -0
- package/lib/plugins/disable-controls/DisableControls.d.ts +15 -0
- package/lib/plugins/disable-controls/DisableControls.d.ts.map +1 -0
- package/lib/plugins/disable-controls/DisableControls.js +69 -0
- package/lib/plugins/dvr-controls/DVRControls.d.ts +27 -0
- package/lib/plugins/dvr-controls/DVRControls.d.ts.map +1 -0
- package/lib/plugins/dvr-controls/DVRControls.js +110 -0
- package/lib/plugins/hls-playback/HlsPlayback.d.ts +102 -0
- package/lib/plugins/hls-playback/HlsPlayback.d.ts.map +1 -0
- package/lib/plugins/hls-playback/HlsPlayback.js +747 -0
- package/lib/plugins/level-selector/LevelSelector.d.ts +48 -0
- package/lib/plugins/level-selector/LevelSelector.d.ts.map +1 -0
- package/lib/plugins/level-selector/LevelSelector.js +287 -0
- package/lib/plugins/media-control/MediaControl.d.ts +186 -0
- package/lib/plugins/media-control/MediaControl.d.ts.map +1 -0
- package/lib/plugins/media-control/MediaControl.js +1000 -0
- package/lib/plugins/poster/Poster.d.ts +41 -0
- package/lib/plugins/poster/Poster.d.ts.map +1 -0
- package/lib/plugins/poster/Poster.js +186 -0
- package/lib/trace/LogTracer.d.ts +12 -0
- package/lib/trace/LogTracer.d.ts.map +1 -0
- package/lib/trace/LogTracer.js +17 -0
- package/lib/trace/SentryTracer.d.ts +11 -0
- package/lib/trace/SentryTracer.d.ts.map +1 -0
- package/lib/trace/SentryTracer.js +18 -0
- package/lib/trace/Tracer.d.ts +13 -0
- package/lib/trace/Tracer.d.ts.map +1 -0
- package/lib/trace/Tracer.js +15 -0
- package/lib/trace/index.d.ts +18 -0
- package/lib/trace/index.d.ts.map +1 -0
- package/lib/trace/index.js +27 -0
- package/lib/trace/types.d.ts +8 -0
- package/lib/trace/types.d.ts.map +1 -0
- package/lib/trace/types.js +1 -0
- package/lib/types.d.ts +82 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +1 -0
- package/lib/utils/Logger.d.ts +23 -0
- package/lib/utils/Logger.d.ts.map +1 -0
- package/lib/utils/Logger.js +81 -0
- package/lib/utils/canAutoplay.d.ts +6 -0
- package/lib/utils/canAutoplay.d.ts.map +1 -0
- package/lib/utils/canAutoplay.js +30 -0
- package/lib/utils/errors.d.ts +2 -0
- package/lib/utils/errors.d.ts.map +1 -0
- package/lib/utils/errors.js +6 -0
- package/lib/utils/queryParams.d.ts +2 -0
- package/lib/utils/queryParams.d.ts.map +1 -0
- package/lib/utils/queryParams.js +4 -0
- package/lib/utils/scripts-load.d.ts +2 -0
- package/lib/utils/scripts-load.d.ts.map +1 -0
- package/lib/utils/scripts-load.js +20 -0
- package/lib/utils/types.d.ts +4 -0
- package/lib/utils/types.d.ts.map +1 -0
- package/lib/utils/types.js +1 -0
- package/lib/utils/utils.d.ts +7 -0
- package/lib/utils/utils.d.ts.map +1 -0
- package/lib/utils/utils.js +57 -0
- package/package.json +57 -0
- package/rollup.config.js +34 -0
- package/src/Player.ts +390 -0
- package/src/backend.ts +12 -0
- package/src/constants.ts +17 -0
- package/src/index.ts +9 -0
- package/src/internal.types.ts +126 -0
- package/src/playback.types.ts +15 -0
- package/src/plugins/dash-playback/DashPlayback.ts +808 -0
- package/src/plugins/dash-playback/_DashPlayback.js +688 -0
- package/src/plugins/hls-playback/HlsPlayback.ts +909 -0
- package/src/plugins/hls-playback/hls.js +706 -0
- package/src/trace/LogTracer.ts +23 -0
- package/src/trace/SentryTracer.ts +18 -0
- package/src/trace/Tracer.ts +27 -0
- package/src/trace/index.ts +32 -0
- package/src/trace/types.ts +7 -0
- package/src/types.ts +100 -0
- package/src/typings/@clappr/core/error_mixin.d.ts +15 -0
- package/src/typings/@clappr/core/events.d.ts +7 -0
- package/src/typings/@clappr/core/html5_video.d.ts +28 -0
- package/src/typings/@clappr/core/playback.d.ts +5 -0
- package/src/typings/@clappr/core/player.d.ts +83 -0
- package/src/typings/@clappr/plugins.d.ts +29 -0
- package/src/typings/clappr-zepto.xd.xts +44 -0
- package/src/typings/globals.d.ts +8 -0
- package/src/utils/Logger.ts +107 -0
- package/src/utils/canAutoplay.ts +39 -0
- package/src/utils/errors.ts +6 -0
- package/src/utils/queryParams.ts +5 -0
- package/src/utils/scripts-load.ts +26 -0
- package/src/utils/types.ts +5 -0
- package/src/utils/utils.ts +64 -0
- package/tsconfig.json +43 -0
- package/tsconfig.tsbuildinfo +1 -0
package/dist/index.css
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
@import "https://fonts.googleapis.com/css?family=Roboto";
|
|
2
|
+
:root {
|
|
3
|
+
--theme-background-color: rgb(0 0 0 / 70%);
|
|
4
|
+
--theme-text-color: rgb(255 255 255 / 100%);
|
|
5
|
+
--theme-foreground-color: rgb(201 201 201 / 100%);
|
|
6
|
+
--theme-hover-color: rgb(255 255 255 / 100%);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.gcore-skin-bg-color {
|
|
10
|
+
background-color: var(--theme-background-color) !important;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.gcore-skin-text-color {
|
|
14
|
+
color: var(--theme-text-color) !important;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.gcore-skin-text-color svg {
|
|
18
|
+
fill: var(--theme-text-color) !important;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.gcore-skin-text-color svg path {
|
|
22
|
+
fill: var(--theme-text-color) !important;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.gcore-skin-border-textarea-color {
|
|
26
|
+
border-color: var(--theme-text-color) !important;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.gcore-skin-button-color {
|
|
30
|
+
color: var(--theme-foreground-color) !important;
|
|
31
|
+
}
|
|
32
|
+
.gcore-skin-button-color svg {
|
|
33
|
+
fill: var(--theme-foreground-color) !important;
|
|
34
|
+
}
|
|
35
|
+
.gcore-skin-button-color svg path {
|
|
36
|
+
fill: var(--theme-foreground-color) !important;
|
|
37
|
+
}
|
|
38
|
+
.gcore-skin-button-color svg path.icon-hover {
|
|
39
|
+
fill: var(--theme-foreground-color) !important;
|
|
40
|
+
}
|
|
41
|
+
.gcore-skin-button-color[data-fullscreen] svg {
|
|
42
|
+
stroke: var(--theme-foreground-color) !important;
|
|
43
|
+
}
|
|
44
|
+
.gcore-skin-button-color[data-fullscreen] svg path {
|
|
45
|
+
stroke: var(--theme-foreground-color) !important;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.gcore-skin-main-color {
|
|
49
|
+
background-color: var(--theme-foreground-color) !important;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.gcore-skin-border-color {
|
|
53
|
+
border-color: var(--theme-foreground-color) !important;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.gcore-skin-button-color:hover {
|
|
57
|
+
color: var(--theme-hover-color) !important;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.gcore-skin-button-color:hover svg {
|
|
61
|
+
fill: var(--theme-hover-color) !important;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.gcore-skin-button-color:hover svg path {
|
|
65
|
+
fill: var(--theme-hover-color) !important;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.gcore-skin-border-color:hover {
|
|
69
|
+
border-color: var(--theme-hover-color) !important;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.gcore-skin-button-with-bg-color:hover svg path.icon-hover {
|
|
73
|
+
fill: var(--theme-hover-color) !important;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.gcore-skin-active {
|
|
77
|
+
color: var(--theme-hover-color) !important;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.gcore-skin-active svg {
|
|
81
|
+
fill: var(--theme-hover-color) !important;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.gcore-skin-active svg path {
|
|
85
|
+
fill: var(--theme-hover-color) !important;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
* {
|
|
89
|
+
-webkit-tap-highlight-color: transparent;
|
|
90
|
+
-webkit-touch-callout: none;
|
|
91
|
+
user-select: none;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.player-poster[data-poster] {
|
|
95
|
+
background-size: contain !important;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.spinner-three-bounce > .gcore-skin-main-color {
|
|
99
|
+
box-shadow: 4px 4px 9px 1px rgba(36, 61, 81, 0.51);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.gplayer-lite-btn {
|
|
103
|
+
cursor: pointer;
|
|
104
|
+
border: none;
|
|
105
|
+
margin: 0;
|
|
106
|
+
padding: 0;
|
|
107
|
+
width: auto;
|
|
108
|
+
overflow: visible;
|
|
109
|
+
background: transparent;
|
|
110
|
+
/* inherit font & color from ancestor */
|
|
111
|
+
color: inherit;
|
|
112
|
+
font: inherit;
|
|
113
|
+
/* Normalize `line-height`. Cannot be changed from `normal` in Firefox 4+. */
|
|
114
|
+
line-height: normal;
|
|
115
|
+
/* Corrects font smoothing for webkit */
|
|
116
|
+
-webkit-font-smoothing: inherit;
|
|
117
|
+
-moz-osx-font-smoothing: inherit;
|
|
118
|
+
/* Corrects inability to style clickable `input` types in iOS */
|
|
119
|
+
appearance: none;
|
|
120
|
+
/* Remove excess padding and border in Firefox 4+ */
|
|
121
|
+
}
|
|
122
|
+
.gplayer-lite-btn::-moz-focus-inner {
|
|
123
|
+
border: 0;
|
|
124
|
+
padding: 0;
|
|
125
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import { $, Log, Loader, Player as Player$1, Browser } from '@clappr/core';
|
|
2
|
+
import assert from 'assert';
|
|
3
|
+
import HLSJS from 'hls.js';
|
|
4
|
+
import EventLite from 'event-lite';
|
|
5
|
+
|
|
6
|
+
const tracer = {
|
|
7
|
+
trace: () => { },
|
|
8
|
+
reportError: () => { },
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
* Sets a tracer implementation, e.g., LogTracer or SentryTracer
|
|
13
|
+
*/
|
|
14
|
+
function setTracer(t) {
|
|
15
|
+
tracer.trace = t.trace.bind(t);
|
|
16
|
+
tracer.reportError = t.reportError.bind(t);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
* @param e
|
|
21
|
+
*/
|
|
22
|
+
function reportError(e) {
|
|
23
|
+
tracer.reportError(e);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @public
|
|
27
|
+
* @param msg
|
|
28
|
+
* @param data
|
|
29
|
+
*/
|
|
30
|
+
function trace(msg, data = {}) {
|
|
31
|
+
tracer.trace(msg, data);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var PlayerEvent;
|
|
35
|
+
(function (PlayerEvent) {
|
|
36
|
+
PlayerEvent["Ready"] = "ready";
|
|
37
|
+
PlayerEvent["Play"] = "play";
|
|
38
|
+
PlayerEvent["Pause"] = "pause";
|
|
39
|
+
PlayerEvent["Stop"] = "stop";
|
|
40
|
+
PlayerEvent["Ended"] = "ended";
|
|
41
|
+
})(PlayerEvent || (PlayerEvent = {}));
|
|
42
|
+
const T = "Player";
|
|
43
|
+
const DEFAULT_OPTIONS = {
|
|
44
|
+
autoPlay: false,
|
|
45
|
+
mute: false,
|
|
46
|
+
loop: false,
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* @beta
|
|
50
|
+
*/
|
|
51
|
+
class Player {
|
|
52
|
+
emitter = new EventLite();
|
|
53
|
+
player = null;
|
|
54
|
+
pluginLoaders = [];
|
|
55
|
+
clapprReady = false;
|
|
56
|
+
timer = null;
|
|
57
|
+
tuneInEntered = false;
|
|
58
|
+
supportedMediaTransports = [];
|
|
59
|
+
config;
|
|
60
|
+
get playing() {
|
|
61
|
+
return this.player ? this.player.isPlaying() : false;
|
|
62
|
+
}
|
|
63
|
+
get ready() {
|
|
64
|
+
return this.clapprReady;
|
|
65
|
+
}
|
|
66
|
+
constructor(config) {
|
|
67
|
+
this.config = $.extend(true, {}, DEFAULT_OPTIONS, config);
|
|
68
|
+
}
|
|
69
|
+
on(event, handler) {
|
|
70
|
+
this.emitter.on(event, handler);
|
|
71
|
+
}
|
|
72
|
+
off(event, handler) {
|
|
73
|
+
this.emitter.off(event, handler);
|
|
74
|
+
}
|
|
75
|
+
async init(playerElement) {
|
|
76
|
+
assert.ok(!this.player, 'Player already initialized');
|
|
77
|
+
assert.ok(playerElement, 'Player element is required');
|
|
78
|
+
if (this.config.debug === 'all' ||
|
|
79
|
+
this.config.debug === 'clappr') {
|
|
80
|
+
Log.setLevel(0);
|
|
81
|
+
}
|
|
82
|
+
Log.debug('Config', this.config);
|
|
83
|
+
this.configurePlugins();
|
|
84
|
+
return this.loadPlugins().then(async () => {
|
|
85
|
+
const coreOpts = this.buildCoreOptions(playerElement);
|
|
86
|
+
const { core, container, } = Loader.registeredPlugins;
|
|
87
|
+
coreOpts.plugins = {
|
|
88
|
+
core: Object.values(core),
|
|
89
|
+
container: Object.values(container),
|
|
90
|
+
playback: Loader.registeredPlaybacks,
|
|
91
|
+
};
|
|
92
|
+
console.log('plugins', coreOpts.plugins);
|
|
93
|
+
return this.initPlayer(coreOpts);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
destroy() {
|
|
97
|
+
trace(`${T} destroy`, { player: !!this.player });
|
|
98
|
+
if (this.player) {
|
|
99
|
+
this.player.destroy();
|
|
100
|
+
this.player = null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
pause() {
|
|
104
|
+
assert.ok(this.player, 'Player not initialized');
|
|
105
|
+
this.player.pause();
|
|
106
|
+
}
|
|
107
|
+
play() {
|
|
108
|
+
assert.ok(this.player, 'Player not initialized');
|
|
109
|
+
this.player.play();
|
|
110
|
+
}
|
|
111
|
+
seekTo(time) {
|
|
112
|
+
assert.ok(this.player, 'Player not initialized');
|
|
113
|
+
this.player.seek(time);
|
|
114
|
+
}
|
|
115
|
+
stop() {
|
|
116
|
+
assert.ok(this.player, 'Player not initialized');
|
|
117
|
+
this.player.stop();
|
|
118
|
+
}
|
|
119
|
+
static registerPlugin(plugin) {
|
|
120
|
+
Loader.registerPlugin(plugin);
|
|
121
|
+
}
|
|
122
|
+
loadPlugins() {
|
|
123
|
+
return Promise.all(this.pluginLoaders.map((loader) => loader())).then(() => { });
|
|
124
|
+
}
|
|
125
|
+
initPlayer(coreOptions) {
|
|
126
|
+
assert.ok(!this.player, 'Player already initialized');
|
|
127
|
+
const player = new Player$1(coreOptions);
|
|
128
|
+
this.player = player;
|
|
129
|
+
this.timer = globalThis.setTimeout(() => {
|
|
130
|
+
try {
|
|
131
|
+
if (!this.clapprReady &&
|
|
132
|
+
player.core &&
|
|
133
|
+
player.core
|
|
134
|
+
.activePlayback) {
|
|
135
|
+
this.tuneIn();
|
|
136
|
+
// player.onReady = null; // TODO ?
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
reportError(e);
|
|
141
|
+
}
|
|
142
|
+
}, 4000);
|
|
143
|
+
}
|
|
144
|
+
// TODO sort this out
|
|
145
|
+
async tuneIn() {
|
|
146
|
+
assert.ok(this.player);
|
|
147
|
+
trace(`${T} tuneIn enter`, {
|
|
148
|
+
ready: this.clapprReady,
|
|
149
|
+
tuneInEntered: this.tuneInEntered,
|
|
150
|
+
});
|
|
151
|
+
if (this.tuneInEntered) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
this.tuneInEntered = true;
|
|
155
|
+
const player = this.player;
|
|
156
|
+
if (Browser.isiOS &&
|
|
157
|
+
player.core.activePlayback) {
|
|
158
|
+
player.core.activePlayback.$el.on('webkitendfullscreen', () => {
|
|
159
|
+
try {
|
|
160
|
+
player.core.handleFullscreenChange();
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
reportError(e);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
configurePlugins() {
|
|
169
|
+
if (!Browser.isiOS && this.config.multisources.some((el) => el.sourceDash)) {
|
|
170
|
+
this.scheduleLoad(async () => {
|
|
171
|
+
const module = await import('./DashPlayback-BeZz7mN9.js');
|
|
172
|
+
Loader.registerPlayback(module.default);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
// TODO remove !isiOS?
|
|
176
|
+
// if (!Browser.isiOS && this.config.multisources.some((el) => el.hls_mpegts_url)) {
|
|
177
|
+
if (this.config.multisources.some((el) => el.hlsMpegtsUrl || el.hlsCmafUrl || el.source.endsWith('.m3u8'))) {
|
|
178
|
+
this.scheduleLoad(async () => {
|
|
179
|
+
const module = await import('./HlsPlayback-Avwy8-0O.js');
|
|
180
|
+
Loader.registerPlayback(module.default);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
events = {
|
|
185
|
+
onReady: () => {
|
|
186
|
+
if (this.clapprReady) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
this.clapprReady = true;
|
|
190
|
+
if (this.timer) {
|
|
191
|
+
clearTimeout(this.timer);
|
|
192
|
+
this.timer = null;
|
|
193
|
+
}
|
|
194
|
+
trace(`${T} onReady`);
|
|
195
|
+
setTimeout(() => this.tuneIn(), 0);
|
|
196
|
+
try {
|
|
197
|
+
this.emitter.emit(PlayerEvent.Ready);
|
|
198
|
+
}
|
|
199
|
+
catch (e) {
|
|
200
|
+
reportError(e);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
onPlay: () => {
|
|
204
|
+
try {
|
|
205
|
+
this.emitter.emit(PlayerEvent.Play);
|
|
206
|
+
}
|
|
207
|
+
catch (e) {
|
|
208
|
+
reportError(e);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
onPause: () => {
|
|
212
|
+
try {
|
|
213
|
+
this.emitter.emit(PlayerEvent.Pause);
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
reportError(e);
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
onEnded: () => {
|
|
220
|
+
try {
|
|
221
|
+
this.emitter.emit(PlayerEvent.Ended);
|
|
222
|
+
}
|
|
223
|
+
catch (e) {
|
|
224
|
+
reportError(e);
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
onStop: () => {
|
|
228
|
+
try {
|
|
229
|
+
this.emitter.emit(PlayerEvent.Stop);
|
|
230
|
+
}
|
|
231
|
+
catch (e) {
|
|
232
|
+
reportError(e);
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
buildCoreOptions(playerElement) {
|
|
237
|
+
this.checkMediaTransportsSupport();
|
|
238
|
+
const multisources = this.processMultisources(this.config.priorityTransport);
|
|
239
|
+
const mediaSources = multisources.map(ms => ms.source);
|
|
240
|
+
const mainSource = this.findMainSource();
|
|
241
|
+
const mainSourceUrl = unwrapSource(mainSource ? this.selectMediaTransport(mainSource, this.config.priorityTransport) : undefined);
|
|
242
|
+
const poster = mainSource?.poster ?? this.config.poster;
|
|
243
|
+
const coreOptions = {
|
|
244
|
+
autoPlay: this.config.autoPlay,
|
|
245
|
+
debug: this.config.debug || 'none',
|
|
246
|
+
events: this.events,
|
|
247
|
+
multisources,
|
|
248
|
+
mute: this.config.mute,
|
|
249
|
+
...this.config.pluginSettings,
|
|
250
|
+
playback: {
|
|
251
|
+
controls: false,
|
|
252
|
+
preload: Browser.isiOS ? 'metadata' : 'none',
|
|
253
|
+
playInline: true,
|
|
254
|
+
crossOrigin: 'anonymous', // TODO
|
|
255
|
+
hlsjsConfig: {
|
|
256
|
+
debug: this.config.debug === 'all' || this.config.debug === 'hls',
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
parent: playerElement,
|
|
260
|
+
playbackType: this.config.playbackType,
|
|
261
|
+
poster,
|
|
262
|
+
width: playerElement.clientWidth,
|
|
263
|
+
height: playerElement.clientHeight,
|
|
264
|
+
loop: this.config.loop,
|
|
265
|
+
strings: this.config.strings,
|
|
266
|
+
source: mainSourceUrl,
|
|
267
|
+
sources: mediaSources,
|
|
268
|
+
};
|
|
269
|
+
trace(`${T} buildCoreOptions`, coreOptions);
|
|
270
|
+
return coreOptions;
|
|
271
|
+
}
|
|
272
|
+
findMainSource() {
|
|
273
|
+
return this.config.multisources.find(ms => ms.live !== false);
|
|
274
|
+
}
|
|
275
|
+
scheduleLoad(cb) {
|
|
276
|
+
this.pluginLoaders.push(cb);
|
|
277
|
+
}
|
|
278
|
+
selectMediaTransport(ms, priorityTransport = ms.priorityTransport) {
|
|
279
|
+
const cmafUrl = ms.hlsCmafUrl || ms.source; // source is default url for hls
|
|
280
|
+
const mpegtsUrl = ms.hlsMpegtsUrl; // no-low-latency HLS
|
|
281
|
+
const dashUrl = ms.sourceDash;
|
|
282
|
+
const masterSource = ms.source;
|
|
283
|
+
const mts = this.getAvailableTransportsPreference(priorityTransport);
|
|
284
|
+
for (const mt of mts) {
|
|
285
|
+
switch (mt) {
|
|
286
|
+
case 'dash':
|
|
287
|
+
if (dashUrl) {
|
|
288
|
+
return dashUrl;
|
|
289
|
+
}
|
|
290
|
+
break;
|
|
291
|
+
case 'hls':
|
|
292
|
+
if (cmafUrl) {
|
|
293
|
+
return cmafUrl;
|
|
294
|
+
}
|
|
295
|
+
break;
|
|
296
|
+
default:
|
|
297
|
+
return mpegtsUrl || masterSource;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// no supported transport found
|
|
301
|
+
return '';
|
|
302
|
+
}
|
|
303
|
+
getAvailableTransportsPreference(priorityTransport) {
|
|
304
|
+
const mtp = [];
|
|
305
|
+
if (priorityTransport !== 'auto' && this.supportedMediaTransports.includes(priorityTransport)) {
|
|
306
|
+
mtp.push(priorityTransport);
|
|
307
|
+
}
|
|
308
|
+
for (const mt of this.supportedMediaTransports) {
|
|
309
|
+
if (mt !== priorityTransport) {
|
|
310
|
+
mtp.push(mt);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return mtp;
|
|
314
|
+
}
|
|
315
|
+
checkMediaTransportsSupport() {
|
|
316
|
+
const isDashSupported = typeof (globalThis.MediaSource || globalThis.WebKitMediaSource) === 'function';
|
|
317
|
+
if (isDashSupported) {
|
|
318
|
+
this.supportedMediaTransports.push('dash');
|
|
319
|
+
}
|
|
320
|
+
if (HLSJS.isSupported()) {
|
|
321
|
+
this.supportedMediaTransports.push('hls');
|
|
322
|
+
}
|
|
323
|
+
this.supportedMediaTransports.push('mpegts');
|
|
324
|
+
}
|
|
325
|
+
processMultisources(transport) {
|
|
326
|
+
return this.config.multisources.map((ms) => ({
|
|
327
|
+
...ms,
|
|
328
|
+
source: this.selectMediaTransport(ms, transport),
|
|
329
|
+
})).filter((el) => !!el.source);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
function unwrapSource(s) {
|
|
333
|
+
if (!s) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
return typeof s === "string" ? s : s.source;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function fromStreamMediaSourceDto(s) {
|
|
340
|
+
return ({
|
|
341
|
+
...s,
|
|
342
|
+
hlsCmafUrl: s.hls_cmaf_url,
|
|
343
|
+
hlsMpegtsUrl: s.hls_mpegts_url,
|
|
344
|
+
priorityTransport: s.priority_transport,
|
|
345
|
+
sourceDash: s.source_dash,
|
|
346
|
+
vtt: s.vtt,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const APP_NAME = "gplayer";
|
|
351
|
+
class DebuggerWrapper {
|
|
352
|
+
writer;
|
|
353
|
+
namespace;
|
|
354
|
+
currentWriter;
|
|
355
|
+
constructor(writer, namespace, enabled = true) {
|
|
356
|
+
this.writer = writer;
|
|
357
|
+
this.namespace = namespace;
|
|
358
|
+
this.currentWriter = enabled ? writer : nullWriter;
|
|
359
|
+
}
|
|
360
|
+
enable() {
|
|
361
|
+
this.currentWriter = this.writer;
|
|
362
|
+
}
|
|
363
|
+
disable() {
|
|
364
|
+
this.currentWriter = nullWriter;
|
|
365
|
+
}
|
|
366
|
+
write = (m, ...args) => {
|
|
367
|
+
const tokens = args.map((_) => "%s");
|
|
368
|
+
if (typeof m === "string" || args.length > 0) {
|
|
369
|
+
tokens.unshift("%s");
|
|
370
|
+
}
|
|
371
|
+
this.currentWriter(`${this.namespace}: ${tokens.join(' ')}`, m, ...args.map(a => JSON.stringify(a)));
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
const currentPatterns = [];
|
|
375
|
+
function parsePattern(pattern) {
|
|
376
|
+
if (pattern === "*") {
|
|
377
|
+
return /.?/;
|
|
378
|
+
}
|
|
379
|
+
return new RegExp("^" + pattern.replace(/\*/g, "[@\\w-]+"), "i");
|
|
380
|
+
}
|
|
381
|
+
function pass(namespace) {
|
|
382
|
+
return currentPatterns.some((p) => p.test(namespace));
|
|
383
|
+
}
|
|
384
|
+
function nullWriter() { }
|
|
385
|
+
/**
|
|
386
|
+
* Logging utility with [debug](https://www.npmjs.com/package/debug)-like API
|
|
387
|
+
* @beta
|
|
388
|
+
*/
|
|
389
|
+
class Logger {
|
|
390
|
+
info;
|
|
391
|
+
warn;
|
|
392
|
+
error;
|
|
393
|
+
debug;
|
|
394
|
+
static items = [];
|
|
395
|
+
constructor(namespace, appName = APP_NAME) {
|
|
396
|
+
const ns = namespace ? `:${namespace}` : "";
|
|
397
|
+
const info = new DebuggerWrapper(console.info.bind(console), `${appName}:INFO${ns}`, pass(namespace));
|
|
398
|
+
this.info = info.write;
|
|
399
|
+
const warn = new DebuggerWrapper(console.warn.bind(console), `${appName}:WARN${ns}`, pass(namespace));
|
|
400
|
+
this.warn = warn.write;
|
|
401
|
+
const error = new DebuggerWrapper(console.error.bind(console), `${appName}:ERROR${ns}`, pass(namespace));
|
|
402
|
+
this.error = error.write;
|
|
403
|
+
const debug = new DebuggerWrapper(console.debug.bind(console), `${appName}:DEBUG${ns}`, pass(namespace));
|
|
404
|
+
this.debug = debug.write;
|
|
405
|
+
Logger.items.push(warn);
|
|
406
|
+
Logger.items.push(info);
|
|
407
|
+
Logger.items.push(error);
|
|
408
|
+
Logger.items.push(debug);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* @param patterns - comma-separated list of patterns, can contain '*' as a wildcard
|
|
412
|
+
*/
|
|
413
|
+
static enable(patterns) {
|
|
414
|
+
currentPatterns.splice(0, currentPatterns.length, ...patterns.split(",").filter(Boolean).map(parsePattern));
|
|
415
|
+
Logger.toggleItems();
|
|
416
|
+
}
|
|
417
|
+
static disable() {
|
|
418
|
+
currentPatterns.splice(0, currentPatterns.length);
|
|
419
|
+
}
|
|
420
|
+
static toggleItems() {
|
|
421
|
+
for (const w of Logger.items) {
|
|
422
|
+
if (pass(w.namespace)) {
|
|
423
|
+
w.enable();
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
w.disable();
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* A tracer that logs to the console
|
|
434
|
+
* @public
|
|
435
|
+
*/
|
|
436
|
+
class LogTracer {
|
|
437
|
+
logger;
|
|
438
|
+
constructor(ns = "") {
|
|
439
|
+
this.logger = new Logger(ns);
|
|
440
|
+
}
|
|
441
|
+
reportError(e) {
|
|
442
|
+
this.logger.error(e);
|
|
443
|
+
}
|
|
444
|
+
trace(msg, data) {
|
|
445
|
+
this.logger.debug(msg, data);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* @beta
|
|
451
|
+
*/
|
|
452
|
+
class SentryTracer {
|
|
453
|
+
client;
|
|
454
|
+
constructor(client) {
|
|
455
|
+
this.client = client;
|
|
456
|
+
}
|
|
457
|
+
reportError(e) {
|
|
458
|
+
this.client.captureException(e);
|
|
459
|
+
}
|
|
460
|
+
trace(msg, data) {
|
|
461
|
+
this.client.captureMessage(msg, "info", {
|
|
462
|
+
data,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export { LogTracer, Logger, Player, PlayerEvent, SentryTracer, fromStreamMediaSourceDto, reportError, setTracer, trace };
|
package/lib/Player.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import '../assets/style/main.scss';
|
|
2
|
+
import type { PlayerPlugin } from "./types";
|
|
3
|
+
import { PlayerConfig } from "./types.js";
|
|
4
|
+
export declare enum PlayerEvent {
|
|
5
|
+
Ready = "ready",
|
|
6
|
+
Play = "play",
|
|
7
|
+
Pause = "pause",
|
|
8
|
+
Stop = "stop",
|
|
9
|
+
Ended = "ended"
|
|
10
|
+
}
|
|
11
|
+
type PlayerEventHandler<T extends PlayerEvent> = () => void;
|
|
12
|
+
/**
|
|
13
|
+
* @beta
|
|
14
|
+
*/
|
|
15
|
+
export declare class Player {
|
|
16
|
+
private emitter;
|
|
17
|
+
private player;
|
|
18
|
+
private pluginLoaders;
|
|
19
|
+
private clapprReady;
|
|
20
|
+
private timer;
|
|
21
|
+
private tuneInEntered;
|
|
22
|
+
private supportedMediaTransports;
|
|
23
|
+
private config;
|
|
24
|
+
get playing(): boolean;
|
|
25
|
+
get ready(): boolean;
|
|
26
|
+
constructor(config: PlayerConfig);
|
|
27
|
+
on<T extends PlayerEvent>(event: T, handler: PlayerEventHandler<T>): void;
|
|
28
|
+
off<T extends PlayerEvent>(event: T, handler: PlayerEventHandler<T>): void;
|
|
29
|
+
init(playerElement: HTMLElement): Promise<void>;
|
|
30
|
+
destroy(): void;
|
|
31
|
+
pause(): void;
|
|
32
|
+
play(): void;
|
|
33
|
+
seekTo(time: number): void;
|
|
34
|
+
stop(): void;
|
|
35
|
+
static registerPlugin(plugin: PlayerPlugin): void;
|
|
36
|
+
private loadPlugins;
|
|
37
|
+
private initPlayer;
|
|
38
|
+
private tuneIn;
|
|
39
|
+
private configurePlugins;
|
|
40
|
+
private events;
|
|
41
|
+
private buildCoreOptions;
|
|
42
|
+
private findMainSource;
|
|
43
|
+
private scheduleLoad;
|
|
44
|
+
private selectMediaTransport;
|
|
45
|
+
private getAvailableTransportsPreference;
|
|
46
|
+
private checkMediaTransportsSupport;
|
|
47
|
+
private processMultisources;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=Player.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Player.d.ts","sourceRoot":"","sources":["../src/Player.ts"],"names":[],"mappings":"AAWA,OAAO,2BAA2B,CAAC;AAQnC,OAAO,KAAK,EACV,YAAY,EAEb,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,YAAY,EAGb,MAAM,YAAY,CAAC;AAEpB,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,KAAK,UAAU;IACf,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAID,KAAK,kBAAkB,CAAC,CAAC,SAAS,WAAW,IAAI,MAAM,IAAI,CAAC;AAY5D;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,OAAO,CAAmB;IAElC,OAAO,CAAC,MAAM,CAA6B;IAE3C,OAAO,CAAC,aAAa,CAAkC;IAEvD,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO,CAAC,KAAK,CAA8C;IAE3D,OAAO,CAAC,aAAa,CAAS;IAE9B,OAAO,CAAC,wBAAwB,CAAwB;IAExD,OAAO,CAAC,MAAM,CAAe;IAE7B,IAAI,OAAO,YAEV;IAED,IAAI,KAAK,YAER;gBAGC,MAAM,EAAE,YAAY;IAKtB,EAAE,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAIlE,GAAG,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAI7D,IAAI,CAAC,aAAa,EAAE,WAAW;IA6BrC,OAAO;IAQP,KAAK;IAKL,IAAI;IAKJ,MAAM,CAAC,IAAI,EAAE,MAAM;IAKnB,IAAI;IAKJ,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,YAAY;IAI1C,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,UAAU;YA0BJ,MAAM;IA4BpB,OAAO,CAAC,gBAAgB;IAiBxB,OAAO,CAAC,MAAM,CA8CZ;IAEF,OAAO,CAAC,gBAAgB;IAsCxB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,oBAAoB;IA2B5B,OAAO,CAAC,gCAAgC;IAaxC,OAAO,CAAC,2BAA2B;IAWnC,OAAO,CAAC,mBAAmB;CAM5B"}
|