@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,230 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import EventLite from 'event-lite'
|
|
4
|
+
import FakeTimers from '@sinonjs/fake-timers'
|
|
5
|
+
|
|
6
|
+
import { SourceController } from '../SourceController'
|
|
7
|
+
import { _MockPlayback, PlaybackErrorCode } from '@gcorevideo/player'
|
|
8
|
+
|
|
9
|
+
const MOCK_SOURCES = [
|
|
10
|
+
{
|
|
11
|
+
source: 'http://0eab.cdn.globo.com/1932-1447.mpd',
|
|
12
|
+
mimeType: 'application/dash+xml',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
source: 'http://0eab.cdn.globo.com/1932-1447.m3u8',
|
|
16
|
+
mimeType: 'application/vnd.apple.mpegurl',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
source: 'http://0eab.cdn.globo.com/1932-1447_mpegts.m3u8',
|
|
20
|
+
mimeType: 'application/mpegts',
|
|
21
|
+
},
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
describe('SourceController', () => {
|
|
25
|
+
let clock: ReturnType<typeof FakeTimers.install>
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
clock = FakeTimers.install()
|
|
28
|
+
})
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
clock.uninstall()
|
|
31
|
+
})
|
|
32
|
+
describe('init', () => {
|
|
33
|
+
let core: any
|
|
34
|
+
describe.each([
|
|
35
|
+
[
|
|
36
|
+
'list of sources with a selected source',
|
|
37
|
+
{
|
|
38
|
+
sources: MOCK_SOURCES,
|
|
39
|
+
source: 'http://0eab.cdn.globo.com/1932-1447.mpd',
|
|
40
|
+
},
|
|
41
|
+
{ sources: ['http://0eab.cdn.globo.com/1932-1447.mpd'] },
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
'list of sources without a selected source',
|
|
45
|
+
{
|
|
46
|
+
sources: MOCK_SOURCES,
|
|
47
|
+
source: undefined,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
sources: [
|
|
51
|
+
{
|
|
52
|
+
source: 'http://0eab.cdn.globo.com/1932-1447.mpd',
|
|
53
|
+
mimeType: 'application/dash+xml',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
])('%s', (_, inputSourcesConfig, correctedSourcesConfig) => {
|
|
59
|
+
it('should keep a single source for the core', () => {
|
|
60
|
+
core = createMockCore(inputSourcesConfig)
|
|
61
|
+
const _ = new SourceController(core)
|
|
62
|
+
expect(core.options).toEqual(expect.objectContaining(correctedSourcesConfig))
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
describe('on fatal playback failure', () => {
|
|
67
|
+
let core: any
|
|
68
|
+
let nextPlayback: any
|
|
69
|
+
|
|
70
|
+
describe('basically', () => {
|
|
71
|
+
beforeEach(() => {
|
|
72
|
+
core = createMockCore({
|
|
73
|
+
sources: MOCK_SOURCES,
|
|
74
|
+
})
|
|
75
|
+
const _ = new SourceController(core)
|
|
76
|
+
core.emit('core:ready')
|
|
77
|
+
core.activePlayback.emit('playback:error', { code: PlaybackErrorCode.MediaSourceUnavailable })
|
|
78
|
+
nextPlayback = new _MockPlayback({} as any, {} as any)
|
|
79
|
+
vi.spyOn(nextPlayback, 'consent')
|
|
80
|
+
vi.spyOn(nextPlayback, 'play')
|
|
81
|
+
core.activePlayback = nextPlayback
|
|
82
|
+
})
|
|
83
|
+
it('should load the next source after a delay', async () => {
|
|
84
|
+
expect(core.load).not.toHaveBeenCalled()
|
|
85
|
+
await clock.tickAsync(1000)
|
|
86
|
+
expect(core.load).toHaveBeenCalledWith(MOCK_SOURCES[1].source, MOCK_SOURCES[1].mimeType)
|
|
87
|
+
})
|
|
88
|
+
it('should try to play after loading the source in a random delay', async () => {
|
|
89
|
+
await clock.tickAsync(1000)
|
|
90
|
+
expect(nextPlayback.play).not.toHaveBeenCalled()
|
|
91
|
+
await clock.tickAsync(500) // TODO check randomness
|
|
92
|
+
expect(nextPlayback.play).toHaveBeenCalled()
|
|
93
|
+
})
|
|
94
|
+
it('should not call consent', async () => {
|
|
95
|
+
await clock.tickAsync(1500)
|
|
96
|
+
expect(nextPlayback.consent).not.toHaveBeenCalled()
|
|
97
|
+
})
|
|
98
|
+
describe('after reinitializing the core', () => {
|
|
99
|
+
let poster: any
|
|
100
|
+
let spinner: any
|
|
101
|
+
beforeEach(async () => {
|
|
102
|
+
poster = createMockPlugin()
|
|
103
|
+
spinner = createSpinnerPlugin()
|
|
104
|
+
core.activeContainer.getPlugin.mockImplementation((name: string) => {
|
|
105
|
+
if (name === 'poster_custom') {
|
|
106
|
+
return poster
|
|
107
|
+
}
|
|
108
|
+
if (name === 'spinner') {
|
|
109
|
+
return spinner
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
core.emit('core:ready')
|
|
113
|
+
})
|
|
114
|
+
it('should disable the poster', async () => {
|
|
115
|
+
expect(poster.disable).toHaveBeenCalled()
|
|
116
|
+
})
|
|
117
|
+
it('should show the spinner', async () => {
|
|
118
|
+
expect(spinner.show).toHaveBeenCalled()
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
describe('if the spinner plugin is present', () => {
|
|
123
|
+
let spinner: any
|
|
124
|
+
beforeEach(() => {
|
|
125
|
+
core = createMockCore({
|
|
126
|
+
sources: MOCK_SOURCES,
|
|
127
|
+
})
|
|
128
|
+
spinner = createSpinnerPlugin()
|
|
129
|
+
core.activeContainer.getPlugin.mockImplementation((name: string) => {
|
|
130
|
+
if (name === 'spinner') {
|
|
131
|
+
return spinner
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
const _ = new SourceController(core)
|
|
135
|
+
core.emit('core:ready')
|
|
136
|
+
core.activePlayback.emit('playback:error', { code: PlaybackErrorCode.MediaSourceUnavailable })
|
|
137
|
+
nextPlayback = new _MockPlayback({} as any, {} as any)
|
|
138
|
+
vi.spyOn(nextPlayback, 'consent')
|
|
139
|
+
vi.spyOn(nextPlayback, 'play')
|
|
140
|
+
core.activePlayback = nextPlayback
|
|
141
|
+
})
|
|
142
|
+
it('should sync with the spinner before reloading the source', async () => {
|
|
143
|
+
await clock.tickAsync(1000)
|
|
144
|
+
expect(core.load).not.toHaveBeenCalled()
|
|
145
|
+
spinner.emit('spinner:sync')
|
|
146
|
+
expect(core.load).toHaveBeenCalled()
|
|
147
|
+
})
|
|
148
|
+
})
|
|
149
|
+
describe('after recovery', () => {
|
|
150
|
+
// TODO
|
|
151
|
+
let poster: any
|
|
152
|
+
let spinner: any
|
|
153
|
+
beforeEach(async () => {
|
|
154
|
+
core = createMockCore({
|
|
155
|
+
sources: MOCK_SOURCES,
|
|
156
|
+
})
|
|
157
|
+
const _ = new SourceController(core)
|
|
158
|
+
core.emit('core:ready')
|
|
159
|
+
core.activePlayback.emit('playback:error', { code: PlaybackErrorCode.MediaSourceUnavailable })
|
|
160
|
+
await clock.tickAsync(1000)
|
|
161
|
+
nextPlayback = new _MockPlayback({} as any, {} as any)
|
|
162
|
+
core.activePlayback = nextPlayback
|
|
163
|
+
poster = createMockPlugin()
|
|
164
|
+
spinner = createSpinnerPlugin()
|
|
165
|
+
core.activeContainer.getPlugin.mockImplementation((name: string) => {
|
|
166
|
+
if (name === 'poster_custom') {
|
|
167
|
+
return poster
|
|
168
|
+
}
|
|
169
|
+
if (name === 'spinner') {
|
|
170
|
+
return spinner
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
core.emit('core:ready')
|
|
174
|
+
nextPlayback.emit('playback:play')
|
|
175
|
+
})
|
|
176
|
+
it('should enable the poster', async () => {
|
|
177
|
+
expect(poster.enable).toHaveBeenCalled()
|
|
178
|
+
})
|
|
179
|
+
it('should hide the spinner', async () => {
|
|
180
|
+
expect(spinner.hide).toHaveBeenCalled()
|
|
181
|
+
})
|
|
182
|
+
describe.each([
|
|
183
|
+
[
|
|
184
|
+
'buffering',
|
|
185
|
+
'playback:buffering',
|
|
186
|
+
],
|
|
187
|
+
[
|
|
188
|
+
'pause',
|
|
189
|
+
'playback:pause',
|
|
190
|
+
],
|
|
191
|
+
])('on a following playback:play event due to %s', (_, event) => {
|
|
192
|
+
it('should do nothing', async () => {
|
|
193
|
+
nextPlayback.emit(event)
|
|
194
|
+
await clock.tickAsync(1000)
|
|
195
|
+
nextPlayback.emit('playback:play')
|
|
196
|
+
await clock.tickAsync(1000)
|
|
197
|
+
expect(poster.enable).toHaveBeenCalledTimes(1)
|
|
198
|
+
expect(spinner.hide).toHaveBeenCalledTimes(1)
|
|
199
|
+
})
|
|
200
|
+
})
|
|
201
|
+
})
|
|
202
|
+
})
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
function createMockCore(options: Record<string, unknown> = {}) {
|
|
206
|
+
return Object.assign(new EventLite(), {
|
|
207
|
+
activePlayback: new _MockPlayback({} as any, {} as any),
|
|
208
|
+
activeContainer: Object.assign(new EventLite(), {
|
|
209
|
+
getPlugin: vi.fn(),
|
|
210
|
+
}),
|
|
211
|
+
options: {
|
|
212
|
+
...options,
|
|
213
|
+
},
|
|
214
|
+
load: vi.fn(),
|
|
215
|
+
})
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function createMockPlugin() {
|
|
219
|
+
return Object.assign(new EventLite(), {
|
|
220
|
+
enable: vi.fn(),
|
|
221
|
+
disable: vi.fn(),
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function createSpinnerPlugin() {
|
|
226
|
+
return Object.assign(createMockPlugin(), {
|
|
227
|
+
show: vi.fn(),
|
|
228
|
+
hide: vi.fn(),
|
|
229
|
+
})
|
|
230
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
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 { Container, Events, UIContainerPlugin, template } from '@clappr/core';
|
|
6
|
+
import { PlaybackError, PlaybackErrorCode } from '../../playback.types';
|
|
7
|
+
import { trace } from '@gcorevideo/utils';
|
|
8
|
+
|
|
9
|
+
import spinnerHTML from '../../../assets/spinner-three-bounce/spinner.ejs';
|
|
10
|
+
import '../../../assets/spinner-three-bounce/spinner.scss';
|
|
11
|
+
import { TimerId } from '../types';
|
|
12
|
+
import { CLAPPR_VERSION } from '../build.js';
|
|
13
|
+
|
|
14
|
+
const T = 'plugins.spinner'
|
|
15
|
+
|
|
16
|
+
export class SpinnerThreeBounce extends UIContainerPlugin {
|
|
17
|
+
get name() {
|
|
18
|
+
return 'spinner';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get supportedVersion() {
|
|
22
|
+
return { min: CLAPPR_VERSION };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override get attributes() {
|
|
26
|
+
return {
|
|
27
|
+
'data-spinner':'',
|
|
28
|
+
'class': 'spinner-three-bounce'
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private showTimeout: TimerId | null = null;
|
|
33
|
+
|
|
34
|
+
private template = template(spinnerHTML);
|
|
35
|
+
|
|
36
|
+
private hasFatalError = false
|
|
37
|
+
|
|
38
|
+
private hasBuffering = false
|
|
39
|
+
|
|
40
|
+
constructor(container: Container) {
|
|
41
|
+
super(container);
|
|
42
|
+
this.listenTo(this.container, Events.CONTAINER_STATE_BUFFERING, this.onBuffering);
|
|
43
|
+
this.listenTo(this.container, Events.CONTAINER_STATE_BUFFERFULL, this.onBufferFull);
|
|
44
|
+
this.listenTo(this.container, Events.CONTAINER_PLAY, this.onPlay);
|
|
45
|
+
this.listenTo(this.container, Events.CONTAINER_STOP, this.onStop);
|
|
46
|
+
this.listenTo(this.container, Events.CONTAINER_ENDED, this.onStop);
|
|
47
|
+
this.listenTo(this.container, Events.CONTAINER_ERROR, this.onError);
|
|
48
|
+
this.listenTo(this.container, Events.CONTAINER_READY, this.render);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private onBuffering() {
|
|
52
|
+
this.hasBuffering = true
|
|
53
|
+
this.show();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private onBufferFull() {
|
|
57
|
+
if (!this.hasFatalError && this.hasBuffering) {
|
|
58
|
+
this.hide();
|
|
59
|
+
}
|
|
60
|
+
this.hasBuffering = false
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private onPlay() {
|
|
64
|
+
trace(`${T} onPlay`);
|
|
65
|
+
this.hide();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private onStop() {
|
|
69
|
+
trace(`${T} onStop`, {
|
|
70
|
+
showOnError: this.options.spinner?.showOnError,
|
|
71
|
+
hasFatalError: this.hasFatalError,
|
|
72
|
+
})
|
|
73
|
+
if (!(this.hasFatalError && this.options.spinner?.showOnError)) {
|
|
74
|
+
this.hide();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private onError(e: PlaybackError) {
|
|
79
|
+
this.hasFatalError = e.code === PlaybackErrorCode.MediaSourceUnavailable
|
|
80
|
+
trace(`${T} onError`, {
|
|
81
|
+
e,
|
|
82
|
+
showOnError: this.options.spinner?.showOnError,
|
|
83
|
+
hasFatalError: this.hasFatalError,
|
|
84
|
+
error: e.code,
|
|
85
|
+
})
|
|
86
|
+
if (this.options.spinner?.showOnError) {
|
|
87
|
+
this.show();
|
|
88
|
+
} else {
|
|
89
|
+
this.hide();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
show(immediate = false) {
|
|
94
|
+
trace(`${T} show`, {
|
|
95
|
+
immediate,
|
|
96
|
+
})
|
|
97
|
+
if (immediate) {
|
|
98
|
+
if (this.showTimeout !== null) {
|
|
99
|
+
clearTimeout(this.showTimeout);
|
|
100
|
+
this.showTimeout = null;
|
|
101
|
+
}
|
|
102
|
+
this.$el.show();
|
|
103
|
+
} else if (this.showTimeout === null) {
|
|
104
|
+
this.showTimeout = setTimeout(() => this.$el.show(), 300);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
hide() {
|
|
109
|
+
if (this.showTimeout !== null) {
|
|
110
|
+
clearTimeout(this.showTimeout);
|
|
111
|
+
this.showTimeout = null;
|
|
112
|
+
}
|
|
113
|
+
this.$el.hide();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
override render() {
|
|
117
|
+
const showOnStart = this.options.spinner?.showOnStart;
|
|
118
|
+
trace(`${T} render`, {
|
|
119
|
+
buffering: this.container.buffering,
|
|
120
|
+
showOnStart,
|
|
121
|
+
})
|
|
122
|
+
this.$el.html(this.template());
|
|
123
|
+
this.el.firstElementChild?.addEventListener('animationiteration', () => {
|
|
124
|
+
this.trigger('spinner:sync')
|
|
125
|
+
})
|
|
126
|
+
this.container.$el.append(this.$el[0]);
|
|
127
|
+
if (showOnStart || this.container.buffering) {
|
|
128
|
+
this.show();
|
|
129
|
+
} else {
|
|
130
|
+
this.hide();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { Browser, Container, ContainerPlugin, Events, Playback } from '@clappr/core';
|
|
2
|
+
// import type { GcoreStreamMediaSource, TimePosition } from '@gcorevideo/player';
|
|
3
|
+
import type { TimePosition } from '@gcorevideo/player';
|
|
4
|
+
import { reportError } from '@gcorevideo/utils';
|
|
5
|
+
import Fingerprint from '@fingerprintjs/fingerprintjs'; // TODO drop
|
|
6
|
+
import { Events as HlsEvents, FragChangedData } from 'hls.js';
|
|
7
|
+
|
|
8
|
+
import { CLAPPR_VERSION } from '../build.js';
|
|
9
|
+
|
|
10
|
+
type MediaSourceInfo = {
|
|
11
|
+
id: number;
|
|
12
|
+
source: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class Statistics extends ContainerPlugin {
|
|
16
|
+
get name() {
|
|
17
|
+
return 'statistics_gplayer';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get supportedVersion() {
|
|
21
|
+
return { min: CLAPPR_VERSION };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private socketOpen = false;
|
|
25
|
+
|
|
26
|
+
private init = false;
|
|
27
|
+
|
|
28
|
+
private started = false;
|
|
29
|
+
|
|
30
|
+
private played = false;
|
|
31
|
+
|
|
32
|
+
private playerReady = false;
|
|
33
|
+
|
|
34
|
+
private prevTimeCurrent = 0;
|
|
35
|
+
|
|
36
|
+
private firstHeatmapSent = false;
|
|
37
|
+
|
|
38
|
+
private isLiveWatchSent = false;
|
|
39
|
+
|
|
40
|
+
private countBufferAvailable = false;
|
|
41
|
+
|
|
42
|
+
private startTimeRepeatableRoll = 0;
|
|
43
|
+
|
|
44
|
+
private heatmapCounter = 1;
|
|
45
|
+
|
|
46
|
+
private lags = 0;
|
|
47
|
+
|
|
48
|
+
private bufferStartTime = 0;
|
|
49
|
+
|
|
50
|
+
private bufferComputeTime = 0;
|
|
51
|
+
|
|
52
|
+
private url = '';
|
|
53
|
+
|
|
54
|
+
private uuid = '';
|
|
55
|
+
|
|
56
|
+
private socket: WebSocket | null = null;
|
|
57
|
+
|
|
58
|
+
private startTime = 0;
|
|
59
|
+
|
|
60
|
+
private streamID = 0;
|
|
61
|
+
|
|
62
|
+
constructor(container: Container) {
|
|
63
|
+
super(container);
|
|
64
|
+
this.connect();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
override bindEvents() {
|
|
68
|
+
this.listenToOnce(this.container.playback, Events.PLAYBACK_PLAY, this.onPlay);
|
|
69
|
+
this.listenToOnce(this.container, 'container:start', this.onStart);
|
|
70
|
+
|
|
71
|
+
this.listenToOnce(this.container, Events.CONTAINER_READY, this.onReady);
|
|
72
|
+
this.listenTo(this.container, Events.CONTAINER_STATE_BUFFERING, this.onBuffering);
|
|
73
|
+
this.listenTo(this.container, Events.CONTAINER_STATE_BUFFERFULL, this.onBufferFull);
|
|
74
|
+
this.listenTo(this.container.playback, Events.PLAYBACK_TIMEUPDATE, this.onTimeUpdate);
|
|
75
|
+
this.listenTo(this.container.playback, Events.PLAYBACK_TIMEUPDATE, this.onTimeUpdateLive);
|
|
76
|
+
this.listenTo(this.container.playback, Events.PLAYBACK_LEVEL_SWITCH_START, this.startLevelSwitch);
|
|
77
|
+
this.listenTo(this.container.playback, Events.PLAYBACK_LEVEL_SWITCH_END, this.stopLevelSwitch);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private startLevelSwitch() {
|
|
81
|
+
this.countBufferAvailable = false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private stopLevelSwitch() {
|
|
85
|
+
this.countBufferAvailable = true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private onBuffering() {
|
|
89
|
+
if (this.countBufferAvailable) {
|
|
90
|
+
this.bufferStartTime = performance.now();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private onBufferFull() {
|
|
95
|
+
if (this.countBufferAvailable && this.bufferStartTime) {
|
|
96
|
+
this.bufferComputeTime += Math.round(performance.now() - this.bufferStartTime);
|
|
97
|
+
this.lags++;
|
|
98
|
+
}
|
|
99
|
+
this.countBufferAvailable = true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private connect() {
|
|
103
|
+
try {
|
|
104
|
+
if (!this.options.statistics.url) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
reportError(error);
|
|
109
|
+
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
this.removeSocket();
|
|
113
|
+
this.url = this.options.statistics.url;
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
this.socket = new WebSocket(this.url);
|
|
117
|
+
this.socket.onopen = this.openHandler;
|
|
118
|
+
this.socket.onclose = this.closeHandler;
|
|
119
|
+
this.socket.onerror = this.errorHandler;
|
|
120
|
+
} catch (error) {
|
|
121
|
+
reportError(error);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private openHandler = () => {
|
|
126
|
+
this.socketOpen = true;
|
|
127
|
+
if (this.playerReady && !this.init) {
|
|
128
|
+
this.initEvent();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private closeHandler = () => {}
|
|
133
|
+
|
|
134
|
+
private errorHandler = () => {}
|
|
135
|
+
|
|
136
|
+
private removeSocket() {
|
|
137
|
+
if (this.socket) {
|
|
138
|
+
this.socket.onopen = null;
|
|
139
|
+
this.socket.onclose = null;
|
|
140
|
+
this.socket.onmessage = null;
|
|
141
|
+
this.socket.onerror = null;
|
|
142
|
+
this.socket.close();
|
|
143
|
+
this.socket = null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private onReady() {
|
|
148
|
+
this.playerReady = true;
|
|
149
|
+
const element = this.findElementBySource(this.options.source);
|
|
150
|
+
|
|
151
|
+
if (!element) {
|
|
152
|
+
this.destroy();
|
|
153
|
+
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
Fingerprint.load()
|
|
157
|
+
.then(agent => agent.get())
|
|
158
|
+
.then((res) => {
|
|
159
|
+
this.uuid = res.visitorId;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
this.streamID = element.id;
|
|
163
|
+
|
|
164
|
+
if (this.socketOpen && !this.init) {
|
|
165
|
+
this.initEvent();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private findElementBySource(source: string): MediaSourceInfo | undefined {
|
|
170
|
+
return this.options.multisources.find((s: MediaSourceInfo) => s.source === source);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private initEvent() {
|
|
174
|
+
this.init = true;
|
|
175
|
+
this.sendMessage('init');
|
|
176
|
+
if (this.options.autoPlay) {
|
|
177
|
+
this.container.trigger('container:start');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private sendMessage(state: 'init' | 'start' | 'watch') {
|
|
182
|
+
this.send(JSON.stringify({
|
|
183
|
+
event: state,
|
|
184
|
+
type: this.container.getPlaybackType(),
|
|
185
|
+
embed_url: this.options.referer,
|
|
186
|
+
user_agent: Browser.userAgent
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private send(str: string) {
|
|
191
|
+
if (this.socket) {
|
|
192
|
+
this.socket.send(str);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private onTimeUpdateLive() {
|
|
197
|
+
if (!this.streamID) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
let currentTime = 0;
|
|
202
|
+
|
|
203
|
+
try {
|
|
204
|
+
let startTime = this.startTimeRepeatableRoll;
|
|
205
|
+
|
|
206
|
+
if (!this.startTimeRepeatableRoll) {
|
|
207
|
+
if (!startTime) {
|
|
208
|
+
this.startTimeRepeatableRoll = startTime = this.container.playback.el.currentTime;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
currentTime = this.container.playback.el.currentTime - startTime;
|
|
213
|
+
this.played = true;
|
|
214
|
+
|
|
215
|
+
if (this.started && this.played && !this.firstHeatmapSent && Math.floor(currentTime) === 0) {
|
|
216
|
+
this.firstHeatmapSent = true;
|
|
217
|
+
this.sendHeatmap();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (currentTime > 0 && Math.floor(currentTime / 10) === 1 && this.uuid) {
|
|
221
|
+
this.sendHeatmap();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (this.container.getPlaybackType() === Playback.LIVE && !this.isLiveWatchSent && currentTime >= 5) {
|
|
225
|
+
this.isLiveWatchSent = true;
|
|
226
|
+
this.sendMessage('watch');
|
|
227
|
+
}
|
|
228
|
+
} catch (error) {
|
|
229
|
+
reportError(error);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private sendHeatmap() {
|
|
234
|
+
this.startTimeRepeatableRoll = this.container.playback.el.currentTime;
|
|
235
|
+
const res: Record<string, unknown> = {
|
|
236
|
+
'event': 'heatmap',
|
|
237
|
+
'uniq_id': this.uuid,
|
|
238
|
+
'type': this.container.getPlaybackType(),
|
|
239
|
+
'stream_id': this.streamID,
|
|
240
|
+
lags: this.lags,
|
|
241
|
+
buffering: this.bufferComputeTime,
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
this.bufferComputeTime = 0;
|
|
245
|
+
this.lags = 0;
|
|
246
|
+
if (this.container.getPlaybackType() === Playback.VOD) {
|
|
247
|
+
res.timestamp = this.container.playback.el.currentTime;
|
|
248
|
+
}
|
|
249
|
+
this.send(JSON.stringify(res));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
private onTimeUpdate({ current }: TimePosition) {
|
|
253
|
+
if (this.container.getPlaybackType() === Playback.LIVE) {
|
|
254
|
+
this.stopListening(this.container.playback, Events.PLAYBACK_TIMEUPDATE, this.onTimeUpdate);
|
|
255
|
+
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (!this.prevTimeCurrent) {
|
|
260
|
+
this.prevTimeCurrent = current;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (Math.abs(this.prevTimeCurrent - current) > 5 && this.socketOpen) {
|
|
264
|
+
this.stopListening(this.container.playback, Events.PLAYBACK_TIMEUPDATE, this.onTimeUpdate);
|
|
265
|
+
this.sendMessage('watch');
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
private onStart() {
|
|
270
|
+
this.sendMessage('start');
|
|
271
|
+
this.started = true;
|
|
272
|
+
if (this.started && this.played && !this.firstHeatmapSent) {
|
|
273
|
+
this.firstHeatmapSent = true;
|
|
274
|
+
this.sendHeatmap();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
private onPlay() {
|
|
279
|
+
try {
|
|
280
|
+
if (this.container.playback._hls) {
|
|
281
|
+
this.container.playback._hls.on(HlsEvents.FRAG_CHANGED, (_: HlsEvents.FRAG_CHANGED, b: FragChangedData) => {
|
|
282
|
+
if (this.options.debug === 'hls') {
|
|
283
|
+
console.warn(b.frag);
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
} catch (error) {
|
|
288
|
+
reportError(error);
|
|
289
|
+
}
|
|
290
|
+
if (this.startTime) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
this.startTime = new Date().getTime();
|
|
295
|
+
}
|
|
296
|
+
}
|