aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-07-20 10:13:56 +0200
committerChocobozzz <me@florianbigard.com>2020-07-20 10:13:56 +0200
commit69a019968e225f1eac4a3df3041f141d0047d7f0 (patch)
tree63bf9b3b64496de4315af6ea994972c620ca37da
parent1dee8d68cb89ea98610ab61291e640991d3506e6 (diff)
downloadPeerTube-69a019968e225f1eac4a3df3041f141d0047d7f0.tar.gz
PeerTube-69a019968e225f1eac4a3df3041f141d0047d7f0.tar.zst
PeerTube-69a019968e225f1eac4a3df3041f141d0047d7f0.zip
Fallback to built in HLS if possible
-rw-r--r--client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts54
1 files changed, 33 insertions, 21 deletions
diff --git a/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts b/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts
index 46c6bbaf2..f8116f4bc 100644
--- a/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts
+++ b/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts
@@ -43,19 +43,23 @@ class P2pMediaLoaderPlugin extends Plugin {
43 43
44 // FIXME: typings https://github.com/Microsoft/TypeScript/issues/14080 44 // FIXME: typings https://github.com/Microsoft/TypeScript/issues/14080
45 if (!(videojs as any).Html5Hlsjs) { 45 if (!(videojs as any).Html5Hlsjs) {
46 const message = 'HLS.js does not seem to be supported.' 46 console.warn('HLS.js does not seem to be supported. Try to fallback to built in HLS.')
47 console.warn(message)
48 47
49 player.ready(() => player.trigger('error', new Error(message))) 48 if (!player.canPlayType('application/vnd.apple.mpegurl')) {
50 return 49 const message = 'Cannot fallback to built-in HLS'
51 } 50 console.warn(message)
52 51
53 // FIXME: typings https://github.com/Microsoft/TypeScript/issues/14080 52 player.ready(() => player.trigger('error', new Error(message)))
54 (videojs as any).Html5Hlsjs.addHook('beforeinitialize', (videojsPlayer: any, hlsjs: any) => { 53 return
55 this.hlsjs = hlsjs 54 }
56 }) 55 } else {
56 // FIXME: typings https://github.com/Microsoft/TypeScript/issues/14080
57 (videojs as any).Html5Hlsjs.addHook('beforeinitialize', (videojsPlayer: any, hlsjs: any) => {
58 this.hlsjs = hlsjs
59 })
57 60
58 initVideoJsContribHlsJsPlayer(player) 61 initVideoJsContribHlsJsPlayer(player)
62 }
59 63
60 this.startTime = timeToInt(options.startTime) 64 this.startTime = timeToInt(options.startTime)
61 65
@@ -64,11 +68,13 @@ class P2pMediaLoaderPlugin extends Plugin {
64 src: options.src 68 src: options.src
65 }) 69 })
66 70
67 player.one('play', () => { 71 player.ready(() => {
68 player.addClass('vjs-has-big-play-button-clicked') 72 this.initializeCore()
69 })
70 73
71 player.ready(() => this.initialize()) 74 if ((videojs as any).Html5Hlsjs) {
75 this.initializePlugin()
76 }
77 })
72 } 78 }
73 79
74 dispose () { 80 dispose () {
@@ -82,7 +88,19 @@ class P2pMediaLoaderPlugin extends Plugin {
82 return this.hlsjs 88 return this.hlsjs
83 } 89 }
84 90
85 private initialize () { 91 private initializeCore () {
92 this.player.one('play', () => {
93 this.player.addClass('vjs-has-big-play-button-clicked')
94 })
95
96 this.player.one('canplay', () => {
97 if (this.startTime) {
98 this.player.currentTime(this.startTime)
99 }
100 })
101 }
102
103 private initializePlugin () {
86 initHlsJsPlayer(this.hlsjs) 104 initHlsJsPlayer(this.hlsjs)
87 105
88 // FIXME: typings 106 // FIXME: typings
@@ -102,12 +120,6 @@ class P2pMediaLoaderPlugin extends Plugin {
102 this.statsP2PBytes.numPeers = 1 + this.options.redundancyUrlManager.countBaseUrls() 120 this.statsP2PBytes.numPeers = 1 + this.options.redundancyUrlManager.countBaseUrls()
103 121
104 this.runStats() 122 this.runStats()
105
106 this.player.one('canplay', () => {
107 if (this.startTime) {
108 this.player.currentTime(this.startTime)
109 }
110 })
111 } 123 }
112 124
113 private runStats () { 125 private runStats () {