@gcorevideo/player 2.18.3 → 2.19.0
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/audio-selector/style.scss +156 -0
- package/assets/audio-selector/track-selector.ejs +12 -0
- package/assets/big-mute-button/big-mute-button.ejs +3 -0
- package/assets/big-mute-button/big-mute-button.scss +57 -0
- package/assets/bottom-gear/bottomgear.ejs +12 -0
- package/assets/bottom-gear/gear-sub-menu.scss +95 -0
- package/assets/bottom-gear/gear.scss +79 -0
- package/assets/clappr-nerd-stats/button.ejs +4 -0
- package/assets/clappr-nerd-stats/clappr-nerd-stats.ejs +212 -0
- package/assets/clappr-nerd-stats/clappr-nerd-stats.scss +488 -0
- package/assets/clappr-nerd-stats/options-list.ejs +9 -0
- package/assets/clappr-nerd-stats/settings.ejs +12 -0
- package/assets/clappr-nerd-stats/speedtest/speedtest.worker.js +775 -0
- package/assets/clips/clips.scss +3 -0
- package/assets/context-menu/context_menu.ejs +8 -0
- package/assets/context-menu/context_menu.scss +31 -0
- package/assets/dvr-controls/dvr_controls.scss +136 -0
- package/assets/dvr-controls/index.ejs +2 -0
- package/assets/error-screen/error_screen.ejs +13 -0
- package/assets/error-screen/error_screen.scss +40 -0
- 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/level-selector/button.ejs +8 -0
- package/assets/level-selector/list.ejs +22 -0
- package/assets/level-selector/style.scss +4 -0
- package/assets/logo/styles/logo.scss +10 -0
- package/assets/logo/templates/logo.ejs +3 -0
- package/assets/media-control/closed-hand.cur +0 -0
- package/assets/media-control/container.scss +57 -0
- package/assets/media-control/media-control.ejs +133 -0
- package/assets/media-control/media-control.scss +390 -0
- package/assets/media-control/plugins.scss +94 -0
- package/assets/media-control/width270.scss +50 -0
- package/assets/media-control/width370.scss +263 -0
- package/assets/multi-camera/multicamera.ejs +29 -0
- package/assets/multi-camera/style.scss +176 -0
- package/assets/picture-in-picture/button.ejs +3 -0
- package/assets/picture-in-picture/button.scss +11 -0
- package/assets/playback-rate/button.ejs +6 -0
- package/assets/playback-rate/list.ejs +14 -0
- package/assets/playback-rate/playback-rate-selector.ejs +9 -0
- package/assets/poster/poster.ejs +1 -0
- package/assets/poster/poster.scss +32 -0
- package/assets/seek-time/seek-time.html +2 -0
- package/assets/seek-time/seek-time.scss +38 -0
- package/assets/share/share.ejs +37 -0
- package/assets/share/style.scss +104 -0
- package/assets/skip-time/skip-time.ejs +8 -0
- package/assets/skip-time/style.scss +24 -0
- package/assets/spinner-three-bounce/spinner.ejs +3 -0
- package/assets/spinner-three-bounce/spinner.scss +44 -0
- package/assets/style/main.scss +50 -0
- package/assets/style/theme.scss +42 -0
- package/assets/style/variables.scss +7 -0
- package/assets/subtitles/combobox copy.ejs +16 -0
- package/assets/subtitles/combobox.ejs +16 -0
- package/assets/subtitles/string.ejs +3 -0
- package/assets/subtitles/style.scss +99 -0
- package/assets/thumbnails/scrub-thumbnails.ejs +10 -0
- package/assets/thumbnails/style.scss +75 -0
- package/assets/vast-ads/style.scss +112 -0
- package/assets/video360/button.ejs +1 -0
- package/assets/video360/style.scss +8 -0
- package/build/vite-raw-plugin.js +18 -0
- package/dist/index.js +1 -1
- package/dist/plugins/index.css +2164 -0
- package/dist/plugins/index.js/index.plugins.js +40837 -0
- package/dist/plugins/index.plugins.js +40837 -0
- package/lib/index.core.d.ts +15 -0
- package/lib/index.core.d.ts.map +1 -0
- package/lib/index.core.js +14 -0
- package/lib/index.d.ts +2 -14
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -14
- package/lib/index.plugins.d.ts +38 -0
- package/lib/index.plugins.d.ts.map +1 -0
- package/lib/index.plugins.js +40 -0
- package/lib/plugins/audio-selector/AudioSelector.d.ts +3 -3
- package/lib/plugins/audio-selector/AudioSelector.d.ts.map +1 -1
- package/lib/plugins/audio-selector/AudioSelector.js +6 -12
- package/lib/plugins/big-mute-button/BigMuteButton.d.ts +2 -2
- package/lib/plugins/big-mute-button/BigMuteButton.d.ts.map +1 -1
- package/lib/plugins/big-mute-button/BigMuteButton.js +7 -12
- package/lib/plugins/bottom-gear/BottomGear.d.ts +4 -3
- package/lib/plugins/bottom-gear/BottomGear.d.ts.map +1 -1
- package/lib/plugins/bottom-gear/BottomGear.js +11 -16
- package/lib/plugins/build.d.ts +2 -0
- package/lib/plugins/build.d.ts.map +1 -0
- package/lib/plugins/build.js +1 -0
- package/lib/plugins/clappr-nerd-stats/ClapprNerdStats.d.ts +44 -0
- package/lib/plugins/clappr-nerd-stats/ClapprNerdStats.d.ts.map +1 -0
- package/lib/plugins/clappr-nerd-stats/ClapprNerdStats.js +294 -0
- package/lib/plugins/clappr-nerd-stats/formatter.d.ts +8 -0
- package/lib/plugins/clappr-nerd-stats/formatter.d.ts.map +1 -0
- package/lib/plugins/clappr-nerd-stats/formatter.js +91 -0
- package/lib/plugins/clappr-nerd-stats/speedtest/Speedtest.d.ts +54 -0
- package/lib/plugins/clappr-nerd-stats/speedtest/Speedtest.d.ts.map +1 -0
- package/lib/plugins/clappr-nerd-stats/speedtest/Speedtest.js +335 -0
- package/lib/plugins/clappr-nerd-stats/speedtest/index.d.ts +9 -0
- package/lib/plugins/clappr-nerd-stats/speedtest/index.d.ts.map +1 -0
- package/lib/plugins/clappr-nerd-stats/speedtest/index.js +154 -0
- package/lib/plugins/clappr-nerd-stats/speedtest/types.d.ts +6 -0
- package/lib/plugins/clappr-nerd-stats/speedtest/types.d.ts.map +1 -0
- package/lib/plugins/clappr-nerd-stats/speedtest/types.js +1 -0
- package/lib/plugins/clappr-nerd-stats/types.d.ts +4 -0
- package/lib/plugins/clappr-nerd-stats/types.d.ts.map +1 -0
- package/lib/plugins/clappr-nerd-stats/types.js +1 -0
- package/lib/plugins/clappr-stats/ClapprStats.d.ts +56 -0
- package/lib/plugins/clappr-stats/ClapprStats.d.ts.map +1 -0
- package/lib/plugins/clappr-stats/ClapprStats.js +332 -0
- package/lib/plugins/clappr-stats/types.d.ts +50 -0
- package/lib/plugins/clappr-stats/types.d.ts.map +1 -0
- package/lib/plugins/clappr-stats/types.js +5 -0
- package/lib/plugins/clappr-stats/utils.d.ts +3 -0
- package/lib/plugins/clappr-stats/utils.d.ts.map +1 -0
- package/lib/plugins/clappr-stats/utils.js +40 -0
- package/lib/plugins/click-to-pause/ClickToPause.d.ts +2 -2
- package/lib/plugins/click-to-pause/ClickToPause.d.ts.map +1 -1
- package/lib/plugins/click-to-pause/ClickToPause.js +4 -6
- package/lib/plugins/clips/Clips.d.ts +23 -0
- package/lib/plugins/clips/Clips.d.ts.map +1 -0
- package/lib/plugins/clips/Clips.js +109 -0
- package/lib/plugins/context-menu/ContextMenu.d.ts +36 -0
- package/lib/plugins/context-menu/ContextMenu.d.ts.map +1 -0
- package/lib/plugins/context-menu/ContextMenu.js +102 -0
- package/lib/plugins/disable-controls/DisableControls.d.ts +1 -1
- package/lib/plugins/disable-controls/DisableControls.d.ts.map +1 -1
- package/lib/plugins/disable-controls/DisableControls.js +3 -5
- package/lib/plugins/dvr-controls/DVRControls.d.ts +4 -4
- package/lib/plugins/dvr-controls/DVRControls.d.ts.map +1 -1
- package/lib/plugins/dvr-controls/DVRControls.js +5 -4
- package/lib/plugins/error-screen/ErrorScreen.d.ts +44 -0
- package/lib/plugins/error-screen/ErrorScreen.d.ts.map +1 -0
- package/lib/plugins/error-screen/ErrorScreen.js +179 -0
- package/lib/plugins/favicon/Favicon.d.ts +24 -0
- package/lib/plugins/favicon/Favicon.d.ts.map +1 -0
- package/lib/plugins/favicon/Favicon.js +106 -0
- package/lib/plugins/google-analytics/GoogleAnalytics.d.ts +30 -0
- package/lib/plugins/google-analytics/GoogleAnalytics.d.ts.map +1 -0
- package/lib/plugins/google-analytics/GoogleAnalytics.js +114 -0
- package/lib/plugins/index.d.ts +38 -0
- package/lib/plugins/index.d.ts.map +1 -0
- package/lib/plugins/index.js +40 -0
- package/lib/plugins/kibo/index.d.ts +23 -0
- package/lib/plugins/kibo/index.d.ts.map +1 -0
- package/lib/plugins/kibo/index.js +199 -0
- package/lib/plugins/level-selector/LevelSelector.d.ts +48 -17
- package/lib/plugins/level-selector/LevelSelector.d.ts.map +1 -1
- package/lib/plugins/level-selector/LevelSelector.js +169 -155
- package/lib/plugins/logo/Logo.d.ts +29 -0
- package/lib/plugins/logo/Logo.d.ts.map +1 -0
- package/lib/plugins/logo/Logo.js +181 -0
- package/lib/plugins/logo/utils/index.d.ts +22 -0
- package/lib/plugins/logo/utils/index.d.ts.map +1 -0
- package/lib/plugins/logo/utils/index.js +32 -0
- package/lib/plugins/media-control/MediaControl.d.ts +20 -25
- package/lib/plugins/media-control/MediaControl.d.ts.map +1 -1
- package/lib/plugins/media-control/MediaControl.js +136 -106
- package/lib/plugins/multi-camera/MultiCamera.d.ts +59 -0
- package/lib/plugins/multi-camera/MultiCamera.d.ts.map +1 -0
- package/lib/plugins/multi-camera/MultiCamera.js +353 -0
- package/lib/plugins/picture-in-picture/PictureInPicture.d.ts +20 -0
- package/lib/plugins/picture-in-picture/PictureInPicture.d.ts.map +1 -0
- package/lib/plugins/picture-in-picture/PictureInPicture.js +68 -0
- package/lib/plugins/playback-rate/PlaybackRate.d.ts +42 -0
- package/lib/plugins/playback-rate/PlaybackRate.d.ts.map +1 -0
- package/lib/plugins/playback-rate/PlaybackRate.js +205 -0
- package/lib/plugins/poster/Poster.d.ts +18 -17
- package/lib/plugins/poster/Poster.d.ts.map +1 -1
- package/lib/plugins/poster/Poster.js +83 -37
- package/lib/plugins/seek-time/SeekTime.d.ts +38 -0
- package/lib/plugins/seek-time/SeekTime.d.ts.map +1 -0
- package/lib/plugins/seek-time/SeekTime.js +153 -0
- package/lib/plugins/share/Share.d.ts +38 -0
- package/lib/plugins/share/Share.d.ts.map +1 -0
- package/lib/plugins/share/Share.js +122 -0
- package/lib/plugins/skip-time/SkipTime.d.ts +28 -0
- package/lib/plugins/skip-time/SkipTime.d.ts.map +1 -0
- package/lib/plugins/skip-time/SkipTime.js +86 -0
- package/lib/plugins/source-controller/SourceController.d.ts +41 -0
- package/lib/plugins/source-controller/SourceController.d.ts.map +1 -0
- package/lib/plugins/source-controller/SourceController.js +199 -0
- package/lib/plugins/spinner-three-bounce/SpinnerThreeBounce.d.ts +26 -0
- package/lib/plugins/spinner-three-bounce/SpinnerThreeBounce.d.ts.map +1 -0
- package/lib/plugins/spinner-three-bounce/SpinnerThreeBounce.js +117 -0
- package/lib/plugins/statistics/Statistics.d.ts +52 -0
- package/lib/plugins/statistics/Statistics.d.ts.map +1 -0
- package/lib/plugins/statistics/Statistics.js +130 -0
- package/lib/plugins/subtitles/Subtitles.d.ts +61 -0
- package/lib/plugins/subtitles/Subtitles.d.ts.map +1 -0
- package/lib/plugins/subtitles/Subtitles.js +354 -0
- package/lib/plugins/thumbnails/Thumbnails.d.ts +47 -0
- package/lib/plugins/thumbnails/Thumbnails.d.ts.map +1 -0
- package/lib/plugins/thumbnails/Thumbnails.js +414 -0
- package/lib/plugins/types.d.ts +8 -0
- package/lib/plugins/types.d.ts.map +1 -0
- package/lib/plugins/types.js +1 -0
- package/lib/plugins/utils.d.ts +5 -0
- package/lib/plugins/utils.d.ts.map +1 -0
- package/lib/plugins/utils.js +68 -0
- package/lib/plugins/vast-ads/VastAds.d.ts +72 -0
- package/lib/plugins/vast-ads/VastAds.d.ts.map +1 -0
- package/lib/plugins/vast-ads/VastAds.js +686 -0
- package/lib/plugins/vast-ads/loaderxml.d.ts +32 -0
- package/lib/plugins/vast-ads/loaderxml.d.ts.map +1 -0
- package/lib/plugins/vast-ads/loaderxml.js +226 -0
- package/lib/plugins/vast-ads/roll.d.ts +60 -0
- package/lib/plugins/vast-ads/roll.d.ts.map +1 -0
- package/lib/plugins/vast-ads/roll.js +415 -0
- package/lib/plugins/vast-ads/rollmanager.d.ts +62 -0
- package/lib/plugins/vast-ads/rollmanager.d.ts.map +1 -0
- package/lib/plugins/vast-ads/rollmanager.js +347 -0
- package/lib/plugins/vast-ads/sctemanager.d.ts +18 -0
- package/lib/plugins/vast-ads/sctemanager.d.ts.map +1 -0
- package/lib/plugins/vast-ads/sctemanager.js +116 -0
- package/lib/plugins/vast-ads/types.d.ts +12 -0
- package/lib/plugins/vast-ads/types.d.ts.map +1 -0
- package/lib/plugins/vast-ads/types.js +1 -0
- package/lib/plugins/vast-ads/urlhandler.d.ts +4 -0
- package/lib/plugins/vast-ads/urlhandler.d.ts.map +1 -0
- package/lib/plugins/vast-ads/urlhandler.js +30 -0
- package/lib/plugins/vast-ads/xmlhttprequest.d.ts +6 -0
- package/lib/plugins/vast-ads/xmlhttprequest.d.ts.map +1 -0
- package/lib/plugins/vast-ads/xmlhttprequest.js +39 -0
- package/lib/plugins/vast-ads/xmlmerge.d.ts +12 -0
- package/lib/plugins/vast-ads/xmlmerge.d.ts.map +1 -0
- package/lib/plugins/vast-ads/xmlmerge.js +82 -0
- package/lib/plugins/volume-fade/VolumeFade.d.ts +21 -0
- package/lib/plugins/volume-fade/VolumeFade.d.ts.map +1 -0
- package/lib/plugins/volume-fade/VolumeFade.js +90 -0
- package/package.json +10 -2
- package/rollup.config.js +32 -2
- package/src/index.core.ts +15 -0
- package/src/index.plugins.ts +42 -0
- package/src/index.ts +2 -15
- package/src/plugins/audio-selector/AudioSelector.ts +370 -0
- package/src/plugins/big-mute-button/BigMuteButton.ts +187 -0
- package/src/plugins/bottom-gear/BottomGear.ts +122 -0
- package/src/plugins/build.ts +1 -0
- package/src/plugins/clappr-nerd-stats/ClapprNerdStats.ts +369 -0
- package/src/plugins/clappr-nerd-stats/formatter.ts +109 -0
- package/src/plugins/clappr-nerd-stats/speedtest/Speedtest.ts +414 -0
- package/src/plugins/clappr-nerd-stats/speedtest/index.ts +183 -0
- package/src/plugins/clappr-nerd-stats/speedtest/types.ts +5 -0
- package/src/plugins/clappr-nerd-stats/types.ts +3 -0
- package/src/plugins/clappr-stats/ClapprStats.ts +441 -0
- package/src/plugins/clappr-stats/types.ts +52 -0
- package/src/plugins/clappr-stats/utils.ts +42 -0
- package/src/plugins/click-to-pause/ClickToPause.ts +93 -0
- package/src/plugins/clips/Clips.ts +152 -0
- package/src/plugins/context-menu/ContextMenu.ts +134 -0
- package/src/plugins/disable-controls/DisableControls.ts +81 -0
- package/src/plugins/dvr-controls/DvrControls.ts +131 -0
- package/src/plugins/error-screen/ErrorScreen.ts +241 -0
- package/src/plugins/favicon/Favicon.ts +137 -0
- package/src/plugins/ga-events/GaEvents.js +395 -0
- package/src/plugins/ga-events/ga-tracking.js +46 -0
- package/src/plugins/google-analytics/GoogleAnalytics.ts +147 -0
- package/src/plugins/index.ts +42 -0
- package/src/plugins/kibo/index.ts +244 -0
- package/src/plugins/level-selector/LevelSelector.ts +400 -0
- package/src/plugins/level-selector/__tests__/LevelSelector.test.ts +72 -0
- package/src/plugins/level-selector/__tests__/__snapshots__/LevelSelector.test.ts.snap +11 -0
- package/src/plugins/logo/Logo.ts +233 -0
- package/src/plugins/logo/utils/index.ts +46 -0
- package/src/plugins/media-control/MediaControl.ts +1383 -0
- package/src/plugins/multi-camera/MultiCamera copy.xts +414 -0
- package/src/plugins/multi-camera/MultiCamera.ts +426 -0
- package/src/plugins/picture-in-picture/PictureInPicture.ts +87 -0
- package/src/plugins/playback-rate/PlaybackRate.ts +269 -0
- package/src/plugins/poster/Poster.ts +298 -0
- package/src/plugins/seek-time/SeekTime.ts +191 -0
- package/src/plugins/share/Share.ts +148 -0
- package/src/plugins/skip-time/SkipTime.ts +109 -0
- package/src/plugins/source-controller/SourceController.ts +239 -0
- package/src/plugins/source-controller/__tests__/SourceController.test.ts +230 -0
- package/src/plugins/spinner-three-bounce/SpinnerThreeBounce.ts +135 -0
- package/src/plugins/statistics/Statistics copy.xts +296 -0
- package/src/plugins/statistics/Statistics.ts +207 -0
- package/src/plugins/subtitles/Subtitles.ts +505 -0
- package/src/plugins/thumbnails/Thumbnails.ts +530 -0
- package/src/plugins/types.ts +7 -0
- package/src/plugins/typings/globals.d.ts +10 -0
- package/src/plugins/typings/parse-srt.d.ts +14 -0
- package/src/plugins/typings/workers.d.ts +3 -0
- package/src/plugins/utils.ts +77 -0
- package/src/plugins/vast-ads/VastAds.ts +915 -0
- package/src/plugins/vast-ads/loaderxml.ts +260 -0
- package/src/plugins/vast-ads/roll.ts +492 -0
- package/src/plugins/vast-ads/rollmanager.ts +403 -0
- package/src/plugins/vast-ads/sctemanager.ts +134 -0
- package/src/plugins/vast-ads/types.ts +14 -0
- package/src/plugins/vast-ads/urlhandler.ts +37 -0
- package/src/plugins/vast-ads/xmlhttprequest.ts +44 -0
- package/src/plugins/vast-ads/xmlmerge.ts +96 -0
- package/src/plugins/video360/VRControls.js +104 -0
- package/src/plugins/video360/VREffect.js +422 -0
- package/src/plugins/video360/Video360.js +979 -0
- package/src/plugins/video360/orbit-oriention-controls.js +1002 -0
- package/src/plugins/video360/utils.js +49 -0
- package/src/plugins/volume-fade/VolumeFade.ts +109 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import { Container, ContainerPlugin, Events as CoreEvents, Log } from '@clappr/core';
|
|
2
|
+
import type { QualityLevel, TimePosition, TimeProgress } from '../../../src/playback.types';
|
|
3
|
+
import assert from 'assert';
|
|
4
|
+
|
|
5
|
+
import { CLAPPR_VERSION } from '../build.js';
|
|
6
|
+
import { TimerId } from '../types.js';
|
|
7
|
+
import type { Metrics, MetricsUpdateFn } from './types.js';
|
|
8
|
+
import { ClapprStatsEvents } from './types.js';
|
|
9
|
+
import { newMetrics } from './utils.js';
|
|
10
|
+
|
|
11
|
+
type StatsTimer = keyof Metrics['timers'];
|
|
12
|
+
|
|
13
|
+
type UriToMeasureBandwidth = {
|
|
14
|
+
url: string;
|
|
15
|
+
start: number;
|
|
16
|
+
end: number;
|
|
17
|
+
expired: boolean;
|
|
18
|
+
timeout: number;
|
|
19
|
+
timer: TimerId | null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// TODO: fix
|
|
23
|
+
const updateMetrics = () => {};
|
|
24
|
+
|
|
25
|
+
export class ClapprStats extends ContainerPlugin {
|
|
26
|
+
private bwMeasureCount = 0;
|
|
27
|
+
|
|
28
|
+
private intervalId: TimerId | null = null;
|
|
29
|
+
|
|
30
|
+
private lastDecodedFramesCount = 0;
|
|
31
|
+
|
|
32
|
+
private metrics: Metrics = newMetrics();
|
|
33
|
+
|
|
34
|
+
private completion: {
|
|
35
|
+
watch: number[];
|
|
36
|
+
calls: number[];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
private _onReport: (metrics: Metrics) => void;
|
|
40
|
+
|
|
41
|
+
private runBandwidthTestEvery: number;
|
|
42
|
+
|
|
43
|
+
private runEach: number;
|
|
44
|
+
|
|
45
|
+
private timers: Record<StatsTimer, number> = {
|
|
46
|
+
startup: 0,
|
|
47
|
+
watch: 0,
|
|
48
|
+
pause: 0,
|
|
49
|
+
buffering: 0,
|
|
50
|
+
session: 0,
|
|
51
|
+
latency: 0,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
private updateFn: MetricsUpdateFn = updateMetrics;
|
|
55
|
+
|
|
56
|
+
private urisToMeasureBandwidth: UriToMeasureBandwidth[];
|
|
57
|
+
|
|
58
|
+
private uriToMeasureLatency: string | undefined;
|
|
59
|
+
|
|
60
|
+
get name() {
|
|
61
|
+
return 'clappr_stats';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get supportedVersion() {
|
|
65
|
+
return { min: CLAPPR_VERSION };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get _playbackName() {
|
|
69
|
+
return String(this.container.playback.name || '');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get _playbackType() {
|
|
73
|
+
return this.container.getPlaybackType();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private _now() {
|
|
77
|
+
const hasPerformanceSupport = window.performance && typeof (window.performance.now) === 'function';
|
|
78
|
+
|
|
79
|
+
return (hasPerformanceSupport) ? window.performance.now() : new Date().getTime();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private _inc(counter: keyof Metrics['counters']) {
|
|
83
|
+
this.metrics.counters[counter] += 1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// _timerHasStarted(timer) {
|
|
87
|
+
// return this[`_start${timer}`] !== undefined;
|
|
88
|
+
// }
|
|
89
|
+
|
|
90
|
+
private start(timer: StatsTimer) {
|
|
91
|
+
// this[`_start${timer}`] = this._now();
|
|
92
|
+
this.timers[timer] = this._now();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private _stop(timer: StatsTimer) {
|
|
96
|
+
// this._metrics.timers[timer] += this._now() - this[`_start${timer}`];
|
|
97
|
+
this.metrics.timers[timer] += this._now() - this.timers[timer];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
setUpdateMetrics(updateMetricsFn: MetricsUpdateFn) {
|
|
101
|
+
this.updateFn = updateMetricsFn;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
_defaultReport(metrics: Metrics) {
|
|
105
|
+
this.updateFn(metrics);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
constructor(container: Container) {
|
|
109
|
+
super(container);
|
|
110
|
+
this.runEach = container.options.clapprStats?.runEach ?? 5000;
|
|
111
|
+
this._onReport = container.options.clapprStats?.onReport ?? this._defaultReport;
|
|
112
|
+
this.uriToMeasureLatency = container.options.clapprStats?.uriToMeasureLatency;
|
|
113
|
+
this.urisToMeasureBandwidth = container.options.clapprStats?.urisToMeasureBandwidth;
|
|
114
|
+
this.runBandwidthTestEvery = container.options.clapprStats?.runBandwidthTestEvery ?? 10;
|
|
115
|
+
|
|
116
|
+
this.completion = {
|
|
117
|
+
watch: container.options.clapprStats?.onCompletion ?? [],
|
|
118
|
+
calls: []
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
override bindEvents() {
|
|
123
|
+
this.listenTo(this.container, CoreEvents.CONTAINER_BITRATE, this.onBitrate);
|
|
124
|
+
this.listenTo(this.container, CoreEvents.CONTAINER_STOP, this.stopReporting);
|
|
125
|
+
this.listenTo(this.container, CoreEvents.CONTAINER_ENDED, this.stopReporting);
|
|
126
|
+
this.listenToOnce(this.container.playback, CoreEvents.PLAYBACK_PLAY_INTENT, this.startTimers);
|
|
127
|
+
this.listenToOnce(this.container, CoreEvents.CONTAINER_PLAY, this.onFirstPlaying);
|
|
128
|
+
this.listenTo(this.container, CoreEvents.CONTAINER_PLAY, this.onPlay);
|
|
129
|
+
this.listenTo(this.container, CoreEvents.CONTAINER_PAUSE, this.onPause);
|
|
130
|
+
this.listenToOnce(this.container, CoreEvents.CONTAINER_STATE_BUFFERING, this.onBuffering);
|
|
131
|
+
this.listenTo(this.container, CoreEvents.CONTAINER_SEEK, this.onSeek);
|
|
132
|
+
this.listenTo(this.container, CoreEvents.CONTAINER_ERROR, () => this._inc('error'));
|
|
133
|
+
this.listenTo(this.container, CoreEvents.CONTAINER_FULLSCREEN, () => this._inc('fullscreen'));
|
|
134
|
+
this.listenTo(this.container, CoreEvents.CONTAINER_PLAYBACKDVRSTATECHANGED, (dvrInUse: boolean) => {
|
|
135
|
+
dvrInUse && this._inc('dvrUsage');
|
|
136
|
+
});
|
|
137
|
+
this.listenTo(this.container.playback, CoreEvents.PLAYBACK_PROGRESS, this.onProgress);
|
|
138
|
+
this.listenTo(this.container.playback, CoreEvents.PLAYBACK_TIMEUPDATE, this.onTimeUpdate);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
override destroy() {
|
|
142
|
+
this.stopReporting();
|
|
143
|
+
super.destroy();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
exportMetrics() {
|
|
147
|
+
return structuredClone(this.metrics);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
onBitrate(newBitrate: QualityLevel) {
|
|
151
|
+
const bitrate = newBitrate.bitrate;
|
|
152
|
+
const now = this._now();
|
|
153
|
+
|
|
154
|
+
if (this.metrics.extra.bitratesHistory.length > 0) {
|
|
155
|
+
const beforeLast = this.metrics.extra.bitratesHistory[this.metrics.extra.bitratesHistory.length - 1];
|
|
156
|
+
|
|
157
|
+
beforeLast.end = now;
|
|
158
|
+
beforeLast.time = now - beforeLast.start;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
this.metrics.extra.bitratesHistory.push({ start: this._now(), bitrate: bitrate });
|
|
162
|
+
|
|
163
|
+
this._inc('changeLevel');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
stopReporting() {
|
|
167
|
+
this._buildReport();
|
|
168
|
+
|
|
169
|
+
if (this.intervalId !== null) {
|
|
170
|
+
clearInterval(this.intervalId);
|
|
171
|
+
this.intervalId = null;
|
|
172
|
+
}
|
|
173
|
+
this._newMetrics();
|
|
174
|
+
|
|
175
|
+
// @ts-ignore
|
|
176
|
+
this.stopListening();
|
|
177
|
+
this.bindEvents();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
startTimers() {
|
|
181
|
+
this.intervalId = setInterval(this._buildReport.bind(this), this.runEach);
|
|
182
|
+
this.start('session');
|
|
183
|
+
this.start('startup');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
onFirstPlaying() {
|
|
187
|
+
this.listenTo(this.container, CoreEvents.CONTAINER_TIMEUPDATE, this.onContainerUpdateWhilePlaying);
|
|
188
|
+
|
|
189
|
+
this.start('watch');
|
|
190
|
+
this._stop('startup');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
playAfterPause() {
|
|
194
|
+
this.listenTo(this.container, CoreEvents.CONTAINER_TIMEUPDATE, this.onContainerUpdateWhilePlaying);
|
|
195
|
+
this._stop('pause');
|
|
196
|
+
this.start('watch');
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
private onPlay() {
|
|
200
|
+
this._inc('play');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private onPause() {
|
|
204
|
+
this._stop('watch');
|
|
205
|
+
this.start('pause');
|
|
206
|
+
this._inc('pause');
|
|
207
|
+
this.listenToOnce(this.container, CoreEvents.CONTAINER_PLAY, this.playAfterPause);
|
|
208
|
+
this.stopListening(this.container, CoreEvents.CONTAINER_TIMEUPDATE, this.onContainerUpdateWhilePlaying);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private onSeek(e: number) {
|
|
212
|
+
this._inc('seek');
|
|
213
|
+
this.metrics.extra.watchHistory.push([e * 1000, e * 1000]);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private onTimeUpdate(e: TimePosition) {
|
|
217
|
+
const current = e.current * 1000,
|
|
218
|
+
total = e.total * 1000,
|
|
219
|
+
l = this.metrics.extra.watchHistory.length;
|
|
220
|
+
|
|
221
|
+
this.metrics.extra.duration = total;
|
|
222
|
+
this.metrics.extra.currentTime = current;
|
|
223
|
+
this.metrics.extra.watchedPercentage = (current / total) * 100;
|
|
224
|
+
|
|
225
|
+
if (l === 0) {
|
|
226
|
+
this.metrics.extra.watchHistory.push([current, current]);
|
|
227
|
+
} else {
|
|
228
|
+
this.metrics.extra.watchHistory[l - 1][1] = current;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (this.metrics.extra.bitratesHistory.length > 0) {
|
|
232
|
+
const lastBitrate = this.metrics.extra.bitratesHistory[this.metrics.extra.bitratesHistory.length - 1];
|
|
233
|
+
|
|
234
|
+
if (!lastBitrate.end) {
|
|
235
|
+
lastBitrate.time = this._now() - lastBitrate.start;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
this._onCompletion();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
private onContainerUpdateWhilePlaying() {
|
|
243
|
+
if (this.container.playback.isPlaying()) {
|
|
244
|
+
this._stop('watch');
|
|
245
|
+
this.start('watch');
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private onBuffering() {
|
|
250
|
+
this._inc('buffering');
|
|
251
|
+
this.start('buffering');
|
|
252
|
+
this.listenToOnce(this.container, CoreEvents.CONTAINER_STATE_BUFFERFULL, this.onBufferfull);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private onBufferfull() {
|
|
256
|
+
this._stop('buffering');
|
|
257
|
+
this.listenToOnce(this.container, CoreEvents.CONTAINER_STATE_BUFFERING, this.onBuffering);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
private onProgress(progress: TimeProgress) {
|
|
261
|
+
this.metrics.extra.buffersize = progress.current * 1000;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private _newMetrics() {
|
|
265
|
+
this.metrics = newMetrics();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
private _onCompletion() {
|
|
269
|
+
const currentPercentage = this.metrics.extra.watchedPercentage;
|
|
270
|
+
const allPercentages = this.completion.watch;
|
|
271
|
+
const isCalled = this.completion.calls.indexOf(currentPercentage) !== -1;
|
|
272
|
+
|
|
273
|
+
if (allPercentages.indexOf(currentPercentage) !== -1 && !isCalled) {
|
|
274
|
+
Log.info(this.name + ' PERCENTAGE_EVENT: ' + currentPercentage);
|
|
275
|
+
this.completion.calls.push(currentPercentage);
|
|
276
|
+
this.trigger(ClapprStatsEvents.PERCENTAGE_EVENT, currentPercentage);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
_buildReport() {
|
|
281
|
+
this._stop('session');
|
|
282
|
+
this.start('session');
|
|
283
|
+
|
|
284
|
+
this.metrics.extra.playbackName = this._playbackName;
|
|
285
|
+
this.metrics.extra.playbackType = this._playbackType;
|
|
286
|
+
|
|
287
|
+
this._calculateBitrates();
|
|
288
|
+
this._calculatePercentages();
|
|
289
|
+
this._fetchFPS();
|
|
290
|
+
this._measureLatency();
|
|
291
|
+
this._measureBandwidth();
|
|
292
|
+
|
|
293
|
+
this._onReport(this.metrics);
|
|
294
|
+
this.trigger(ClapprStatsEvents.REPORT_EVENT, structuredClone(this.metrics));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
private _fetchFPS() {
|
|
298
|
+
// flashls ??? - hls.droppedFramesl hls.stream.bufferLength (seconds)
|
|
299
|
+
// hls ??? (use the same?)
|
|
300
|
+
const fetchFPS = {
|
|
301
|
+
'html5_video': this._html5FetchFPS,
|
|
302
|
+
'hls': this._html5FetchFPS,
|
|
303
|
+
'dash_shaka_playback': this._html5FetchFPS
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
if (this._playbackName in fetchFPS) {
|
|
307
|
+
fetchFPS[this._playbackName as keyof typeof fetchFPS].call(this);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
private _calculateBitrates() {
|
|
312
|
+
const { bitratesHistory } = this.metrics.extra;
|
|
313
|
+
|
|
314
|
+
if (bitratesHistory.length === 0) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
let totalTime = 0;
|
|
319
|
+
let weightedTotal = 0;
|
|
320
|
+
|
|
321
|
+
for (const { bitrate, time = 0 } of bitratesHistory) {
|
|
322
|
+
totalTime += time;
|
|
323
|
+
weightedTotal += bitrate * time;
|
|
324
|
+
}
|
|
325
|
+
this.metrics.extra.bitrateWeightedMean = weightedTotal / totalTime;
|
|
326
|
+
|
|
327
|
+
this.metrics.extra.bitrateMostUsed = bitratesHistory.reduce((mostUsed, current) =>
|
|
328
|
+
(current.time || 0) > (mostUsed.time || 0) ? current : mostUsed,
|
|
329
|
+
{ time: 0, bitrate: 0, start: 0, end: 0 },
|
|
330
|
+
).bitrate;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
private _calculatePercentages() {
|
|
334
|
+
if (this.metrics.extra.duration > 0) {
|
|
335
|
+
this.metrics.extra.bufferingPercentage = (this.metrics.timers.buffering / this.metrics.extra.duration) * 100;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
private _html5FetchFPS() {
|
|
340
|
+
const videoTag = this.container.playback.el;
|
|
341
|
+
|
|
342
|
+
const getFirstValidValue = (...args: any[]) => args.find(val => val !== undefined);
|
|
343
|
+
|
|
344
|
+
const decodedFrames = getFirstValidValue(videoTag.webkitDecodedFrameCount, videoTag.mozDecodedFrames, 0);
|
|
345
|
+
const droppedFrames = getFirstValidValue(
|
|
346
|
+
videoTag.webkitDroppedFrameCount,
|
|
347
|
+
videoTag.mozParsedFrames && videoTag.mozDecodedFrames ? videoTag.mozParsedFrames - videoTag.mozDecodedFrames : 0,
|
|
348
|
+
0
|
|
349
|
+
);
|
|
350
|
+
const decodedFramesLastTime = decodedFrames - (this.lastDecodedFramesCount || 0);
|
|
351
|
+
|
|
352
|
+
this.metrics.counters.decodedFrames = decodedFrames;
|
|
353
|
+
this.metrics.counters.droppedFrames = droppedFrames;
|
|
354
|
+
this.metrics.counters.fps = decodedFramesLastTime / (this.runEach / 1000);
|
|
355
|
+
|
|
356
|
+
this.lastDecodedFramesCount = decodedFrames;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// originally from https://www.smashingmagazine.com/2011/11/analyzing-network-characteristics-using-javascript-and-the-dom-part-1/
|
|
360
|
+
private _measureLatency() {
|
|
361
|
+
if (this.uriToMeasureLatency) {
|
|
362
|
+
const t: number[] = [];
|
|
363
|
+
const n = 2;
|
|
364
|
+
let rtt;
|
|
365
|
+
const ld = () => {
|
|
366
|
+
t.push(this._now());
|
|
367
|
+
if (t.length > n) {
|
|
368
|
+
done();
|
|
369
|
+
} else {
|
|
370
|
+
const img = new Image;
|
|
371
|
+
|
|
372
|
+
img.onload = ld;
|
|
373
|
+
img.src = this.uriToMeasureLatency + '?' + Math.random()
|
|
374
|
+
+ '=' + this._now();
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
const done = () => {
|
|
378
|
+
rtt = t[2] - t[1];
|
|
379
|
+
this.metrics.timers.latency = rtt;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
ld();
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// originally from https://www.smashingmagazine.com/2011/11/analyzing-network-characteristics-using-javascript-and-the-dom-part-1/
|
|
387
|
+
private _measureBandwidth() {
|
|
388
|
+
if (this.urisToMeasureBandwidth && (this.bwMeasureCount % this.runBandwidthTestEvery === 0)) {
|
|
389
|
+
let i = 0;
|
|
390
|
+
|
|
391
|
+
const ld = (e?: ProgressEvent) => {
|
|
392
|
+
if (i > 0) {
|
|
393
|
+
const prev = this.urisToMeasureBandwidth[i - 1];
|
|
394
|
+
prev.end = this._now();
|
|
395
|
+
if (prev.timer !== null) {
|
|
396
|
+
clearTimeout(prev.timer);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
if (i >= this.urisToMeasureBandwidth.length || (i > 0 && this.urisToMeasureBandwidth[i - 1].expired)) {
|
|
400
|
+
assert(e, 'incorrect invocation in _measureBandwidth');
|
|
401
|
+
done(e);
|
|
402
|
+
} else {
|
|
403
|
+
const xhr = new XMLHttpRequest();
|
|
404
|
+
|
|
405
|
+
xhr.open('GET', this.urisToMeasureBandwidth[i].url, true);
|
|
406
|
+
xhr.responseType = 'arraybuffer';
|
|
407
|
+
xhr.onload = xhr.onabort = ld;
|
|
408
|
+
this.urisToMeasureBandwidth[i].start = this._now();
|
|
409
|
+
this.urisToMeasureBandwidth[i].timer = setTimeout((j) => {
|
|
410
|
+
this.urisToMeasureBandwidth[j].expired = true;
|
|
411
|
+
xhr.abort();
|
|
412
|
+
}, this.urisToMeasureBandwidth[i].timeout, i);
|
|
413
|
+
xhr.send();
|
|
414
|
+
}
|
|
415
|
+
i++;
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
const done = (e: ProgressEvent) => {
|
|
419
|
+
const timeSpent = (this.urisToMeasureBandwidth[i - 1].end - this.urisToMeasureBandwidth[i - 1].start) / 1000;
|
|
420
|
+
const bandwidthBps = (e.loaded * 8) / timeSpent;
|
|
421
|
+
|
|
422
|
+
this.metrics.extra.bandwidth = bandwidthBps;
|
|
423
|
+
this.urisToMeasureBandwidth.forEach((x) => {
|
|
424
|
+
x.start = 0;
|
|
425
|
+
x.end = 0;
|
|
426
|
+
x.expired = false;
|
|
427
|
+
if (x.timer !== null) {
|
|
428
|
+
clearTimeout(x.timer);
|
|
429
|
+
x.timer = null;
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
ld();
|
|
435
|
+
}
|
|
436
|
+
this.bwMeasureCount++;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// ClapprStats.REPORT_EVENT = 'clappr:stats:report';
|
|
441
|
+
// ClapprStats.PERCENTAGE_EVENT = 'clappr:stats:percentage';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export type Metrics = {
|
|
2
|
+
counters: {
|
|
3
|
+
play: number;
|
|
4
|
+
pause: number;
|
|
5
|
+
error: number;
|
|
6
|
+
buffering: number;
|
|
7
|
+
decodedFrames: number;
|
|
8
|
+
droppedFrames: number;
|
|
9
|
+
fps: number;
|
|
10
|
+
changeLevel: number;
|
|
11
|
+
seek: number;
|
|
12
|
+
fullscreen: number;
|
|
13
|
+
dvrUsage: number;
|
|
14
|
+
};
|
|
15
|
+
timers: {
|
|
16
|
+
startup: number;
|
|
17
|
+
watch: number;
|
|
18
|
+
pause: number;
|
|
19
|
+
buffering: number;
|
|
20
|
+
session: number;
|
|
21
|
+
latency: number;
|
|
22
|
+
};
|
|
23
|
+
extra: {
|
|
24
|
+
playbackName: string;
|
|
25
|
+
playbackType: string;
|
|
26
|
+
bitratesHistory: BitrateTrackRecord[];
|
|
27
|
+
bitrateWeightedMean: number;
|
|
28
|
+
bitrateMostUsed: number;
|
|
29
|
+
buffersize: number;
|
|
30
|
+
watchHistory: Array<[number, number]>;
|
|
31
|
+
watchedPercentage: number;
|
|
32
|
+
bufferingPercentage: number;
|
|
33
|
+
bandwidth: number;
|
|
34
|
+
duration: number;
|
|
35
|
+
currentTime: number;
|
|
36
|
+
};
|
|
37
|
+
custom: Record<string, unknown>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type BitrateTrackRecord = {
|
|
41
|
+
start: number;
|
|
42
|
+
end?: number;
|
|
43
|
+
time?: number;
|
|
44
|
+
bitrate: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type MetricsUpdateFn = (metrics: Metrics) => void;
|
|
48
|
+
|
|
49
|
+
export enum ClapprStatsEvents {
|
|
50
|
+
REPORT_EVENT = 'clappr:stats:report',
|
|
51
|
+
PERCENTAGE_EVENT = 'clappr:stats:percentage',
|
|
52
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Metrics } from "./types";
|
|
2
|
+
|
|
3
|
+
export function newMetrics(): Metrics {
|
|
4
|
+
return {
|
|
5
|
+
counters: {
|
|
6
|
+
play: 0,
|
|
7
|
+
pause: 0,
|
|
8
|
+
error: 0,
|
|
9
|
+
buffering: 0,
|
|
10
|
+
decodedFrames: 0,
|
|
11
|
+
droppedFrames: 0,
|
|
12
|
+
fps: 0,
|
|
13
|
+
changeLevel: 0,
|
|
14
|
+
seek: 0,
|
|
15
|
+
fullscreen: 0,
|
|
16
|
+
dvrUsage: 0,
|
|
17
|
+
},
|
|
18
|
+
timers: {
|
|
19
|
+
startup: 0,
|
|
20
|
+
watch: 0,
|
|
21
|
+
pause: 0,
|
|
22
|
+
buffering: 0,
|
|
23
|
+
session: 0,
|
|
24
|
+
latency: 0,
|
|
25
|
+
},
|
|
26
|
+
extra: {
|
|
27
|
+
playbackName: '',
|
|
28
|
+
playbackType: '',
|
|
29
|
+
bitratesHistory: [],
|
|
30
|
+
bitrateWeightedMean: 0,
|
|
31
|
+
bitrateMostUsed: 0,
|
|
32
|
+
buffersize: 0,
|
|
33
|
+
watchHistory: [],
|
|
34
|
+
watchedPercentage: 0,
|
|
35
|
+
bufferingPercentage: 0,
|
|
36
|
+
bandwidth: 0,
|
|
37
|
+
duration: 0,
|
|
38
|
+
currentTime: 0,
|
|
39
|
+
},
|
|
40
|
+
custom: {},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
//Copyright 2014 Globo.com Player authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style
|
|
3
|
+
// license that can be found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
import { ContainerPlugin, Events, Playback } from '@clappr/core';
|
|
6
|
+
import { trace } from '@gcorevideo/utils';
|
|
7
|
+
|
|
8
|
+
import { CLAPPR_VERSION } from '../build.js';
|
|
9
|
+
|
|
10
|
+
// const VERSION = '0.0.1';
|
|
11
|
+
|
|
12
|
+
type Timer = ReturnType<typeof setTimeout>;
|
|
13
|
+
|
|
14
|
+
const T = 'plugins.click_to_pause_custom';
|
|
15
|
+
|
|
16
|
+
export class ClickToPause extends ContainerPlugin {
|
|
17
|
+
private pointerEnabled = false;
|
|
18
|
+
|
|
19
|
+
private timer: Timer | null = null;
|
|
20
|
+
|
|
21
|
+
get name() {
|
|
22
|
+
return 'click_to_pause_custom';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get supportedVersion() {
|
|
26
|
+
return { min: CLAPPR_VERSION };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get config() {
|
|
30
|
+
return this.container.options.clickToPauseConfig || {};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
override bindEvents() {
|
|
34
|
+
this.listenTo(this.container, Events.CONTAINER_CLICK, this.click);
|
|
35
|
+
this.listenTo(this.container, Events.CONTAINER_SETTINGSUPDATE, this.settingsUpdate);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private click() {
|
|
39
|
+
const isLivePlayback = this.container.getPlaybackType() === Playback.LIVE;
|
|
40
|
+
const isDvrEnabled = this.container.isDvrEnabled();
|
|
41
|
+
|
|
42
|
+
trace(`${T} click`, {
|
|
43
|
+
isLivePlayback,
|
|
44
|
+
isDvrEnabled,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (isLivePlayback && !isDvrEnabled) {
|
|
48
|
+
this.togglePlay(true);
|
|
49
|
+
} else if (!isLivePlayback || isDvrEnabled) {
|
|
50
|
+
this.clearTimer();
|
|
51
|
+
this.timer = setTimeout(() => {
|
|
52
|
+
this.timer = null
|
|
53
|
+
this.togglePlay(false);
|
|
54
|
+
}, 300);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private settingsUpdate() {
|
|
59
|
+
const isLivePlayback = this.container.getPlaybackType() === Playback.LIVE;
|
|
60
|
+
const pointerEnabled = !isLivePlayback || this.container.isDvrEnabled();
|
|
61
|
+
|
|
62
|
+
trace(`${T} settingsUpdate`, {
|
|
63
|
+
isLivePlayback,
|
|
64
|
+
pointerEnabled,
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
if (pointerEnabled === this.pointerEnabled) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const method = pointerEnabled ? 'addClass' : 'removeClass';
|
|
72
|
+
|
|
73
|
+
this.container.$el[method]('pointer-enabled');
|
|
74
|
+
this.pointerEnabled = pointerEnabled;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private togglePlay(useStop: boolean) {
|
|
78
|
+
const isPlaying = this.container && this.container.isPlaying();
|
|
79
|
+
|
|
80
|
+
if (isPlaying) {
|
|
81
|
+
useStop ? this.container.stop() : this.container.pause();
|
|
82
|
+
} else {
|
|
83
|
+
this.container.play();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private clearTimer() {
|
|
88
|
+
if (this.timer) {
|
|
89
|
+
clearTimeout(this.timer);
|
|
90
|
+
this.timer = null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|