@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,207 @@
|
|
|
1
|
+
// An example implementation of client side performancestatistics
|
|
2
|
+
import { Container, ContainerPlugin, Events, Playback } from '@clappr/core'
|
|
3
|
+
import type { TimePosition, TimeValue } from '../..//playback.types'
|
|
4
|
+
import type { PlaybackType } from '../..//types'
|
|
5
|
+
import { reportError } from '@gcorevideo/utils'
|
|
6
|
+
import assert from 'assert'
|
|
7
|
+
|
|
8
|
+
import { CLAPPR_VERSION } from '../build.js'
|
|
9
|
+
|
|
10
|
+
const CUSTOM_EVENTS_CONTAINER_START = 'container:start'
|
|
11
|
+
|
|
12
|
+
const WATCH_CUTOFF = 5
|
|
13
|
+
|
|
14
|
+
const HEATMAP_INTERVAL = 10
|
|
15
|
+
|
|
16
|
+
type StatisticsEventData = Record<string, string | number | boolean>
|
|
17
|
+
|
|
18
|
+
type StatisticsRecord = {
|
|
19
|
+
event: StatisticsEvent
|
|
20
|
+
type: PlaybackType
|
|
21
|
+
} & StatisticsEventData
|
|
22
|
+
|
|
23
|
+
export type PluginSettings = {
|
|
24
|
+
/**
|
|
25
|
+
* Sends the statistics record to the storage.
|
|
26
|
+
* The actual delivery is presumably async and batched.
|
|
27
|
+
* @param data - The statistics record to send.
|
|
28
|
+
*/
|
|
29
|
+
send: (data: StatisticsRecord) => void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type StatisticsEvent = 'init' | 'start' | 'watch' | 'heatmap'
|
|
33
|
+
|
|
34
|
+
// TODO rewrite as core plugin
|
|
35
|
+
export class Statistics extends ContainerPlugin {
|
|
36
|
+
get name() {
|
|
37
|
+
return 'statistics_gplayer'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get supportedVersion() {
|
|
41
|
+
return { min: CLAPPR_VERSION }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private started = false
|
|
45
|
+
|
|
46
|
+
private timeStart = 0
|
|
47
|
+
|
|
48
|
+
private heatmapSent = false
|
|
49
|
+
|
|
50
|
+
private heatmapLastTime = 0
|
|
51
|
+
|
|
52
|
+
private watchSent = false
|
|
53
|
+
|
|
54
|
+
private bufTracking = false
|
|
55
|
+
|
|
56
|
+
private lags = 0
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The time when buffering last started.
|
|
60
|
+
*/
|
|
61
|
+
private bufLastStarted = 0
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The accumulated buffering duration.
|
|
65
|
+
*/
|
|
66
|
+
private bufAccDuration = 0
|
|
67
|
+
|
|
68
|
+
constructor(container: Container) {
|
|
69
|
+
super(container)
|
|
70
|
+
assert(
|
|
71
|
+
this.options.statistics &&
|
|
72
|
+
typeof this.options.statistics.send === 'function',
|
|
73
|
+
'Statistics plugin requires statistics options',
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
override bindEvents() {
|
|
78
|
+
// TODO remove this
|
|
79
|
+
this.listenToOnce(
|
|
80
|
+
this.container,
|
|
81
|
+
CUSTOM_EVENTS_CONTAINER_START,
|
|
82
|
+
this.onStart,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
this.listenToOnce(this.container, Events.CONTAINER_READY, this.onReady)
|
|
86
|
+
this.listenTo(
|
|
87
|
+
this.container,
|
|
88
|
+
Events.CONTAINER_STATE_BUFFERING,
|
|
89
|
+
this.onBuffering,
|
|
90
|
+
)
|
|
91
|
+
this.listenTo(
|
|
92
|
+
this.container,
|
|
93
|
+
Events.CONTAINER_STATE_BUFFERFULL,
|
|
94
|
+
this.onBufferFull,
|
|
95
|
+
)
|
|
96
|
+
this.listenTo(
|
|
97
|
+
this.container.playback,
|
|
98
|
+
Events.PLAYBACK_TIMEUPDATE,
|
|
99
|
+
this.onTimeUpdateLive,
|
|
100
|
+
)
|
|
101
|
+
this.listenTo(
|
|
102
|
+
this.container.playback,
|
|
103
|
+
Events.PLAYBACK_LEVEL_SWITCH_START,
|
|
104
|
+
this.startLevelSwitch,
|
|
105
|
+
)
|
|
106
|
+
this.listenTo(
|
|
107
|
+
this.container.playback,
|
|
108
|
+
Events.PLAYBACK_LEVEL_SWITCH_END,
|
|
109
|
+
this.stopLevelSwitch,
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private startLevelSwitch() {
|
|
114
|
+
this.bufTracking = false
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private stopLevelSwitch() {
|
|
118
|
+
this.bufTracking = true
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private onBuffering() {
|
|
122
|
+
if (this.bufTracking) {
|
|
123
|
+
this.bufLastStarted = performance.now()
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private onBufferFull() {
|
|
128
|
+
if (this.bufTracking && this.bufLastStarted) {
|
|
129
|
+
this.bufAccDuration += performance.now() - this.bufLastStarted
|
|
130
|
+
this.lags++
|
|
131
|
+
}
|
|
132
|
+
this.bufTracking = true
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private onReady() {
|
|
136
|
+
this.initEvent()
|
|
137
|
+
if (this.options.autoPlay) {
|
|
138
|
+
this.onStart()
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private initEvent() {
|
|
143
|
+
this.sendMessage('init')
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private sendMessage(state: StatisticsEvent) {
|
|
147
|
+
this.send(state, {
|
|
148
|
+
// embed_url: this.options.referer,
|
|
149
|
+
// user_agent: Browser.userAgent
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private send(event: StatisticsEvent, data: StatisticsEventData = {}) {
|
|
154
|
+
;(this.options.statistics as PluginSettings).send({
|
|
155
|
+
event,
|
|
156
|
+
type: this.container.getPlaybackType(),
|
|
157
|
+
...data,
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private sendHeatmap(time: TimeValue) {
|
|
162
|
+
const res: StatisticsEventData = {
|
|
163
|
+
buffering: Math.round(this.bufAccDuration),
|
|
164
|
+
lags: this.lags,
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
this.bufAccDuration = 0
|
|
168
|
+
this.lags = 0
|
|
169
|
+
if (this.container.getPlaybackType() === Playback.VOD) {
|
|
170
|
+
res.timestamp = time
|
|
171
|
+
}
|
|
172
|
+
this.send('heatmap', res)
|
|
173
|
+
this.heatmapSent = true
|
|
174
|
+
this.heatmapLastTime = time
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private onTimeUpdateLive({ current }: TimePosition) {
|
|
178
|
+
// TODO check the `current` values for the live streams
|
|
179
|
+
if (!this.timeStart) {
|
|
180
|
+
this.timeStart = current
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
const elapsed = current - this.timeStart
|
|
184
|
+
const heatmapElapsed = current - this.heatmapLastTime
|
|
185
|
+
|
|
186
|
+
// TODO check if the heatmap is only needed for the live streams
|
|
187
|
+
if (!this.heatmapSent || heatmapElapsed >= HEATMAP_INTERVAL) {
|
|
188
|
+
this.sendHeatmap(current)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (!this.watchSent && elapsed >= WATCH_CUTOFF) {
|
|
192
|
+
this.watchSent = true
|
|
193
|
+
this.sendMessage('watch')
|
|
194
|
+
}
|
|
195
|
+
} catch (error) {
|
|
196
|
+
reportError(error)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private onStart() {
|
|
201
|
+
if (this.started) {
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
this.started = true
|
|
205
|
+
this.sendMessage('start')
|
|
206
|
+
}
|
|
207
|
+
}
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Container,
|
|
3
|
+
Events,
|
|
4
|
+
Playback,
|
|
5
|
+
UICorePlugin,
|
|
6
|
+
Browser,
|
|
7
|
+
template,
|
|
8
|
+
$,
|
|
9
|
+
} from '@clappr/core'
|
|
10
|
+
import { type TimeValue } from '../..//playback.types'
|
|
11
|
+
import { reportError } from '@gcorevideo/utils'
|
|
12
|
+
import assert from 'assert'
|
|
13
|
+
|
|
14
|
+
import { CLAPPR_VERSION } from '../build.js'
|
|
15
|
+
|
|
16
|
+
import '../../../assets/subtitles/style.scss'
|
|
17
|
+
import subtitlesOffIcon from '../../../assets/icons/new/subtitles-off.svg'
|
|
18
|
+
import subtitlesOnIcon from '../../../assets/icons/new/subtitles-on.svg'
|
|
19
|
+
import comboboxHTML from '../../../assets/subtitles/combobox.ejs'
|
|
20
|
+
import stringHTML from '../../../assets/subtitles/string.ejs'
|
|
21
|
+
|
|
22
|
+
import { isFullscreen } from '../utils.js'
|
|
23
|
+
import type { ZeptoResult } from '../types.js'
|
|
24
|
+
|
|
25
|
+
const VERSION: string = '0.0.1'
|
|
26
|
+
|
|
27
|
+
const LOCAL_STORAGE_SUBTITLES_ID = 'subtitles_select'
|
|
28
|
+
|
|
29
|
+
const T = 'plugins.subtitles'
|
|
30
|
+
|
|
31
|
+
type TextTrackInfo = {
|
|
32
|
+
language: string
|
|
33
|
+
mode?: 'showing' | 'hidden' | 'disabled'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type TimelyPlayback = Playback & {
|
|
37
|
+
getCurrentTime(): TimeValue
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const NO_TRACK = { language: 'off' }
|
|
41
|
+
|
|
42
|
+
export class Subtitles extends UICorePlugin {
|
|
43
|
+
private currentContainer: Container | undefined
|
|
44
|
+
|
|
45
|
+
private currentLevel: TextTrackInfo | undefined
|
|
46
|
+
|
|
47
|
+
private currentPlayback: TimelyPlayback | undefined
|
|
48
|
+
|
|
49
|
+
private isShowing = false
|
|
50
|
+
|
|
51
|
+
private tracks: TextTrackList | undefined
|
|
52
|
+
|
|
53
|
+
private $string: ZeptoResult | undefined
|
|
54
|
+
|
|
55
|
+
get name() {
|
|
56
|
+
return 'subtitles'
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get supportedVersion() {
|
|
60
|
+
return { min: CLAPPR_VERSION }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static get version() {
|
|
64
|
+
return VERSION
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get template() {
|
|
68
|
+
return template(comboboxHTML)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get templateString() {
|
|
72
|
+
return template(stringHTML)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
override get attributes() {
|
|
76
|
+
return {
|
|
77
|
+
class: this.name,
|
|
78
|
+
'data-subtitles': '',
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
override get events() {
|
|
83
|
+
return {
|
|
84
|
+
'click [data-subtitles-select]': 'onLevelSelect',
|
|
85
|
+
'click [data-subtitles-button]': 'onShowLevelSelectMenu',
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private isPreselectedApplied = false
|
|
90
|
+
|
|
91
|
+
private track: TextTrackInfo = { ...NO_TRACK }
|
|
92
|
+
|
|
93
|
+
get preselectedLanguage(): string {
|
|
94
|
+
return this.core.options.subtitles?.language ?? 'off'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
override bindEvents() {
|
|
98
|
+
this.listenTo(this.core, Events.CORE_RESIZE, this.playerResize)
|
|
99
|
+
this.listenToOnce(this.core, Events.CORE_READY, this.bindPlaybackEvents)
|
|
100
|
+
this.listenTo(
|
|
101
|
+
this.core.mediaControl,
|
|
102
|
+
Events.MEDIACONTROL_CONTAINERCHANGED,
|
|
103
|
+
this.reload,
|
|
104
|
+
)
|
|
105
|
+
this.listenTo(
|
|
106
|
+
this.core.mediaControl,
|
|
107
|
+
Events.MEDIACONTROL_RENDERED,
|
|
108
|
+
this.render,
|
|
109
|
+
)
|
|
110
|
+
this.listenTo(
|
|
111
|
+
this.core.mediaControl,
|
|
112
|
+
Events.MEDIACONTROL_HIDE,
|
|
113
|
+
this.hideSelectLevelMenu,
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
unBindEvents() {
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
this.stopListening(this.core, Events.CORE_READY)
|
|
120
|
+
// @ts-ignore
|
|
121
|
+
this.stopListening(
|
|
122
|
+
this.core.mediaControl,
|
|
123
|
+
Events.MEDIACONTROL_CONTAINERCHANGED,
|
|
124
|
+
)
|
|
125
|
+
// @ts-ignore
|
|
126
|
+
this.stopListening(this.core.mediaControl, Events.MEDIACONTROL_RENDERED)
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
this.stopListening(this.core.mediaControl, Events.MEDIACONTROL_HIDE)
|
|
129
|
+
// @ts-ignore
|
|
130
|
+
this.stopListening(this.core.mediaControl, Events.MEDIACONTROL_SHOW)
|
|
131
|
+
if (this.currentContainer) {
|
|
132
|
+
// @ts-ignore
|
|
133
|
+
this.stopListening(this.currentContainer, Events.CONTAINER_FULLSCREEN)
|
|
134
|
+
// @ts-ignore
|
|
135
|
+
this.stopListening(
|
|
136
|
+
this.currentContainer,
|
|
137
|
+
'container:advertisement:start',
|
|
138
|
+
this.onStartAd,
|
|
139
|
+
)
|
|
140
|
+
// @ts-ignore
|
|
141
|
+
this.stopListening(
|
|
142
|
+
this.currentContainer,
|
|
143
|
+
'container:advertisement:finish',
|
|
144
|
+
this.onFinishAd,
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private bindPlaybackEvents() {
|
|
150
|
+
if (
|
|
151
|
+
this.currentPlayback &&
|
|
152
|
+
this.currentPlayback === this.core.activePlayback
|
|
153
|
+
) {
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
this.currentPlayback = this.core.activePlayback
|
|
158
|
+
this.currentContainer = this.core.activeContainer
|
|
159
|
+
|
|
160
|
+
this.listenTo(
|
|
161
|
+
this.currentContainer,
|
|
162
|
+
Events.CONTAINER_FULLSCREEN,
|
|
163
|
+
this.playerResize,
|
|
164
|
+
)
|
|
165
|
+
this.listenToOnce(
|
|
166
|
+
this.currentPlayback,
|
|
167
|
+
Events.PLAYBACK_PLAY,
|
|
168
|
+
this.getTracks,
|
|
169
|
+
)
|
|
170
|
+
this.listenTo(
|
|
171
|
+
this.currentContainer,
|
|
172
|
+
'container:advertisement:start',
|
|
173
|
+
this.onStartAd,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
// fix for iOS
|
|
177
|
+
const video = this.currentPlayback?.el
|
|
178
|
+
assert(video, 'video element is required')
|
|
179
|
+
|
|
180
|
+
video.addEventListener('webkitbeginfullscreen', () => {
|
|
181
|
+
if (Browser.isiOS) {
|
|
182
|
+
video.classList.add('ios-fullscreen')
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
video.addEventListener('webkitendfullscreen', () => {
|
|
187
|
+
if (Browser.isiOS) {
|
|
188
|
+
video.classList.remove('ios-fullscreen')
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private getTracks() {
|
|
194
|
+
if (this.currentPlayback) {
|
|
195
|
+
try {
|
|
196
|
+
const tracks = (this.currentPlayback.el as HTMLMediaElement).textTracks
|
|
197
|
+
|
|
198
|
+
tracks.length > 0 && this.fillLevels(tracks)
|
|
199
|
+
} catch (error) {
|
|
200
|
+
reportError(error)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
private onStartAd() {
|
|
206
|
+
if (this.isShowing && this.currentContainer) {
|
|
207
|
+
this.hide()
|
|
208
|
+
this.listenTo(
|
|
209
|
+
this.currentContainer,
|
|
210
|
+
'container:advertisement:finish',
|
|
211
|
+
this.onFinishAd,
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private onFinishAd() {
|
|
217
|
+
this.show()
|
|
218
|
+
this.stopListening(
|
|
219
|
+
this.currentContainer,
|
|
220
|
+
'container:advertisement:finish',
|
|
221
|
+
this.onFinishAd,
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
reload() {
|
|
226
|
+
this.unBindEvents()
|
|
227
|
+
this.bindEvents()
|
|
228
|
+
this.bindPlaybackEvents()
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private playerResize() {
|
|
232
|
+
const shouldShow =
|
|
233
|
+
this.currentContainer &&
|
|
234
|
+
isFullscreen(this.currentContainer.el) &&
|
|
235
|
+
this.currentLevel &&
|
|
236
|
+
this.currentLevel.mode &&
|
|
237
|
+
Browser.isiOS &&
|
|
238
|
+
this.isShowing
|
|
239
|
+
|
|
240
|
+
if (shouldShow) {
|
|
241
|
+
this.show()
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
try {
|
|
245
|
+
this.resizeFont()
|
|
246
|
+
} catch (error) {
|
|
247
|
+
reportError(error)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
hide() {
|
|
252
|
+
this.isShowing = false
|
|
253
|
+
this.renderIcon()
|
|
254
|
+
this.$string.hide()
|
|
255
|
+
if (this.tracks) {
|
|
256
|
+
for (const t of this.tracks) {
|
|
257
|
+
t.mode = 'hidden'
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
show() {
|
|
263
|
+
this.isShowing = true
|
|
264
|
+
this.renderIcon()
|
|
265
|
+
if (
|
|
266
|
+
this.currentContainer &&
|
|
267
|
+
isFullscreen(this.currentContainer.el) &&
|
|
268
|
+
this.currentLevel &&
|
|
269
|
+
this.currentLevel.mode &&
|
|
270
|
+
Browser.isiOS
|
|
271
|
+
) {
|
|
272
|
+
this.$string.hide()
|
|
273
|
+
this.currentLevel.mode = 'showing'
|
|
274
|
+
} else {
|
|
275
|
+
this.$string.show()
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
private shouldRender() {
|
|
280
|
+
if (!this.currentContainer) {
|
|
281
|
+
return false
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (!this.currentPlayback) {
|
|
285
|
+
return false
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Only care if we have at least 2 to choose from
|
|
289
|
+
const hasLevels = !!(this.tracks && this.tracks.length > 0)
|
|
290
|
+
|
|
291
|
+
return hasLevels
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
private resizeFont() {
|
|
295
|
+
if (!this.currentContainer) {
|
|
296
|
+
return
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (!this.$string) {
|
|
300
|
+
return
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const skinWidth = this.currentContainer.$el.width()
|
|
304
|
+
|
|
305
|
+
this.$string.find('p').css('font-size', skinWidth * 0.03)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
override render() {
|
|
309
|
+
if (this.shouldRender()) {
|
|
310
|
+
this.$el.html(this.template({ tracks: this.tracks }))
|
|
311
|
+
this.currentContainer?.$el.find('.subtitle-string').remove()
|
|
312
|
+
this.$string = $(this.templateString())
|
|
313
|
+
this.resizeFont()
|
|
314
|
+
|
|
315
|
+
this.currentContainer?.$el.append(this.$string[0])
|
|
316
|
+
if (
|
|
317
|
+
this.core.mediaControl.$subtitlesSelector &&
|
|
318
|
+
this.core.mediaControl.$subtitlesSelector.length > 0
|
|
319
|
+
) {
|
|
320
|
+
this.core.mediaControl.$subtitlesSelector.append(this.el)
|
|
321
|
+
} else {
|
|
322
|
+
this.core.mediaControl.$('.media-control-right-panel').append(this.el)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
this.updateCurrentLevel(this.track)
|
|
326
|
+
this.highlightCurrentSubtitles()
|
|
327
|
+
|
|
328
|
+
this.applyPreselectedSubtitles()
|
|
329
|
+
}
|
|
330
|
+
if (
|
|
331
|
+
this.core.mediaControl.$subtitlesSelector?.find('span.subtitle-text')
|
|
332
|
+
.length > 0
|
|
333
|
+
) {
|
|
334
|
+
this.renderIcon()
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return this
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
private fillLevels(tracks: TextTrackList) {
|
|
341
|
+
this.tracks = tracks
|
|
342
|
+
this.render()
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
private findLevelBy(id: string) {
|
|
346
|
+
if (this.tracks) {
|
|
347
|
+
for (let i = 0; i < this.tracks.length; i++) {
|
|
348
|
+
if (this.tracks[i].language === id) {
|
|
349
|
+
return this.tracks[i] // TODO TrackInfo?
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
private selectLevel(id: string) {
|
|
356
|
+
this.clearSubtitleText()
|
|
357
|
+
this.track = this.findLevelBy(id) || { ...NO_TRACK }
|
|
358
|
+
|
|
359
|
+
this.hideSelectLevelMenu()
|
|
360
|
+
if (!this.track) {
|
|
361
|
+
this.track = { language: 'off' }
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
this.updateCurrentLevel(this.track)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
private onLevelSelect(event: MouseEvent) {
|
|
368
|
+
const id = (event.target as HTMLElement).dataset.subtitlesSelect
|
|
369
|
+
|
|
370
|
+
if (id) {
|
|
371
|
+
localStorage.setItem(LOCAL_STORAGE_SUBTITLES_ID, id)
|
|
372
|
+
this.selectLevel(id)
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return false
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
private applyPreselectedSubtitles() {
|
|
379
|
+
if (!this.isPreselectedApplied) {
|
|
380
|
+
this.isPreselectedApplied = true
|
|
381
|
+
setTimeout(() => {
|
|
382
|
+
this.selectLevel(this.preselectedLanguage)
|
|
383
|
+
}, 300)
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
private onShowLevelSelectMenu() {
|
|
388
|
+
this.toggleContextMenu()
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
private hideSelectLevelMenu() {
|
|
392
|
+
;(this.$('.subtitles ul') as ZeptoResult).hide()
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
private toggleContextMenu() {
|
|
396
|
+
;(this.$('.subtitles ul') as ZeptoResult).toggle()
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
buttonElement(): ZeptoResult {
|
|
400
|
+
return this.$('.subtitles button')
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
levelElement(id?: string): ZeptoResult {
|
|
404
|
+
return (
|
|
405
|
+
this.$(
|
|
406
|
+
'.subtitles ul a' + (id ? '[data-subtitles-select="' + id + '"]' : ''),
|
|
407
|
+
) as ZeptoResult
|
|
408
|
+
).parent()
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
startLevelSwitch() {
|
|
412
|
+
this.buttonElement().addClass('changing')
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
stopLevelSwitch() {
|
|
416
|
+
this.buttonElement().removeClass('changing')
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
selectSubtitles() {
|
|
420
|
+
if (!this.currentLevel) {
|
|
421
|
+
return
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (this.tracks) {
|
|
425
|
+
for (let i = 0; i < this.tracks.length; i++) {
|
|
426
|
+
const track = this.tracks[i]
|
|
427
|
+
if (track.language === this.currentLevel.language) {
|
|
428
|
+
track.mode = 'showing'
|
|
429
|
+
|
|
430
|
+
const currentTime = this.currentPlayback?.getCurrentTime() ?? 0
|
|
431
|
+
const cues = track.cues
|
|
432
|
+
let subtitleText = ''
|
|
433
|
+
|
|
434
|
+
if (cues && cues.length) {
|
|
435
|
+
for (const cue of cues) {
|
|
436
|
+
if (currentTime >= cue.startTime && currentTime <= cue.endTime) {
|
|
437
|
+
subtitleText +=
|
|
438
|
+
(cue as VTTCue).getCueAsHTML().textContent + '\n'
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
this.setSubtitleText(subtitleText)
|
|
444
|
+
|
|
445
|
+
track.oncuechange = (e) => {
|
|
446
|
+
try {
|
|
447
|
+
if (track.activeCues?.length) {
|
|
448
|
+
const html = (track.activeCues[0] as VTTCue).getCueAsHTML()
|
|
449
|
+
|
|
450
|
+
this.setSubtitleText(html)
|
|
451
|
+
} else {
|
|
452
|
+
this.clearSubtitleText()
|
|
453
|
+
}
|
|
454
|
+
} catch (error) {
|
|
455
|
+
// console.error(error);
|
|
456
|
+
reportError(error)
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
continue
|
|
460
|
+
}
|
|
461
|
+
this.tracks[i].oncuechange = null
|
|
462
|
+
this.tracks[i].mode = 'hidden'
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
private setSubtitleText(text: string | DocumentFragment) {
|
|
468
|
+
this.$string.find('p').html(text)
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
private clearSubtitleText() {
|
|
472
|
+
this.setSubtitleText('')
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
private updateCurrentLevel(track: TextTrackInfo) {
|
|
476
|
+
this.currentLevel = track
|
|
477
|
+
if (track.language === 'off') {
|
|
478
|
+
this.hide()
|
|
479
|
+
} else {
|
|
480
|
+
this.show()
|
|
481
|
+
}
|
|
482
|
+
this.selectSubtitles()
|
|
483
|
+
this.highlightCurrentSubtitles()
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
private highlightCurrentSubtitles() {
|
|
487
|
+
this.levelElement().removeClass('current')
|
|
488
|
+
this.levelElement().find('a').removeClass('gcore-skin-active')
|
|
489
|
+
|
|
490
|
+
if (this.currentLevel) {
|
|
491
|
+
const currentLevelElement = this.levelElement(this.currentLevel.language)
|
|
492
|
+
|
|
493
|
+
currentLevelElement.addClass('current')
|
|
494
|
+
currentLevelElement.find('a').addClass('gcore-skin-active')
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
private renderIcon() {
|
|
499
|
+
const icon = this.isShowing ? subtitlesOnIcon : subtitlesOffIcon
|
|
500
|
+
|
|
501
|
+
this.core.mediaControl.$subtitlesSelector
|
|
502
|
+
.find('span.subtitle-text')
|
|
503
|
+
.html(icon)
|
|
504
|
+
}
|
|
505
|
+
}
|