aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/standalone/videos/embed-api.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-12-17 14:20:43 +0100
committerChocobozzz <me@florianbigard.com>2019-12-18 10:14:23 +0100
commit6377a9f2b0f762be9af61f46b4f0a9efd0c4b7c2 (patch)
treec632833f4275df8d75a6df55fe8673a7dec7c0ec /client/src/standalone/videos/embed-api.ts
parentc3b937916711136cb1ce974f769205439a3d2e04 (diff)
downloadPeerTube-6377a9f2b0f762be9af61f46b4f0a9efd0c4b7c2.tar.gz
PeerTube-6377a9f2b0f762be9af61f46b4f0a9efd0c4b7c2.tar.zst
PeerTube-6377a9f2b0f762be9af61f46b4f0a9efd0c4b7c2.zip
Fix test embed page
Diffstat (limited to 'client/src/standalone/videos/embed-api.ts')
-rw-r--r--client/src/standalone/videos/embed-api.ts76
1 files changed, 63 insertions, 13 deletions
diff --git a/client/src/standalone/videos/embed-api.ts b/client/src/standalone/videos/embed-api.ts
index 259113215..61e5d0b9a 100644
--- a/client/src/standalone/videos/embed-api.ts
+++ b/client/src/standalone/videos/embed-api.ts
@@ -11,7 +11,7 @@ import { PeerTubeEmbed } from './embed'
11export class PeerTubeEmbedApi { 11export class PeerTubeEmbedApi {
12 private channel: Channel.MessagingChannel 12 private channel: Channel.MessagingChannel
13 private isReady = false 13 private isReady = false
14 private resolutions: PeerTubeResolution[] = null 14 private resolutions: PeerTubeResolution[] = []
15 15
16 constructor (private embed: PeerTubeEmbed) { 16 constructor (private embed: PeerTubeEmbed) {
17 } 17 }
@@ -35,28 +35,40 @@ export class PeerTubeEmbedApi {
35 channel.bind('play', (txn, params) => this.embed.player.play()) 35 channel.bind('play', (txn, params) => this.embed.player.play())
36 channel.bind('pause', (txn, params) => this.embed.player.pause()) 36 channel.bind('pause', (txn, params) => this.embed.player.pause())
37 channel.bind('seek', (txn, time) => this.embed.player.currentTime(time)) 37 channel.bind('seek', (txn, time) => this.embed.player.currentTime(time))
38
38 channel.bind('setVolume', (txn, value) => this.embed.player.volume(value)) 39 channel.bind('setVolume', (txn, value) => this.embed.player.volume(value))
39 channel.bind('getVolume', (txn, value) => this.embed.player.volume()) 40 channel.bind('getVolume', (txn, value) => this.embed.player.volume())
41
40 channel.bind('isReady', (txn, params) => this.isReady) 42 channel.bind('isReady', (txn, params) => this.isReady)
43
41 channel.bind('setResolution', (txn, resolutionId) => this.setResolution(resolutionId)) 44 channel.bind('setResolution', (txn, resolutionId) => this.setResolution(resolutionId))
42 channel.bind('getResolutions', (txn, params) => this.resolutions) 45 channel.bind('getResolutions', (txn, params) => this.resolutions)
46
43 channel.bind('setPlaybackRate', (txn, playbackRate) => this.embed.player.playbackRate(playbackRate)) 47 channel.bind('setPlaybackRate', (txn, playbackRate) => this.embed.player.playbackRate(playbackRate))
44 channel.bind('getPlaybackRate', (txn, params) => this.embed.player.playbackRate()) 48 channel.bind('getPlaybackRate', (txn, params) => this.embed.player.playbackRate())
45 channel.bind('getPlaybackRates', (txn, params) => this.embed.playerOptions.playbackRates) 49 channel.bind('getPlaybackRates', (txn, params) => this.embed.player.options_.playbackRates)
46 this.channel = channel 50 this.channel = channel
47 } 51 }
48 52
49 private setResolution (resolutionId: number) { 53 private setResolution (resolutionId: number) {
50 if (resolutionId === -1 && this.embed.player.webtorrent().isAutoResolutionForbidden()) return 54 console.log('set resolution %d', resolutionId)
55
56 if (this.isWebtorrent()) {
57 if (resolutionId === -1 && this.embed.player.webtorrent().isAutoResolutionPossible() === false) return
58
59 // Auto resolution
60 if (resolutionId === -1) {
61 this.embed.player.webtorrent().enableAutoResolution()
62 return
63 }
64
65 this.embed.player.webtorrent().disableAutoResolution()
66 this.embed.player.webtorrent().updateResolution(resolutionId)
51 67
52 // Auto resolution
53 if (resolutionId === -1) {
54 this.embed.player.webtorrent().enableAutoResolution()
55 return 68 return
56 } 69 }
57 70
58 this.embed.player.webtorrent().disableAutoResolution() 71 this.embed.player.p2pMediaLoader().getHLSJS().nextLevel = resolutionId
59 this.embed.player.webtorrent().updateResolution(resolutionId)
60 } 72 }
61 73
62 /** 74 /**
@@ -96,14 +108,24 @@ export class PeerTubeEmbedApi {
96 108
97 // PeerTube specific capabilities 109 // PeerTube specific capabilities
98 110
99 if (this.embed.player.webtorrent) { 111 if (this.isWebtorrent()) {
100 this.embed.player.webtorrent().on('autoResolutionUpdate', () => this.loadWebTorrentResolutions()) 112 this.embed.player.webtorrent().on('autoResolutionUpdate', () => this.loadWebTorrentResolutions())
101 this.embed.player.webtorrent().on('videoFileUpdate', () => this.loadWebTorrentResolutions()) 113 this.embed.player.webtorrent().on('videoFileUpdate', () => this.loadWebTorrentResolutions())
114 } else {
115 this.embed.player.p2pMediaLoader().on('resolutionChange', () => this.loadP2PMediaLoaderResolutions())
102 } 116 }
117
118 this.embed.player.on('volumechange', () => {
119 this.channel.notify({
120 method: 'volumeChange',
121 params: this.embed.player.volume()
122 })
123 })
103 } 124 }
104 125
105 private loadWebTorrentResolutions () { 126 private loadWebTorrentResolutions () {
106 const resolutions = [] 127 this.resolutions = []
128
107 const currentResolutionId = this.embed.player.webtorrent().getCurrentResolutionId() 129 const currentResolutionId = this.embed.player.webtorrent().getCurrentResolutionId()
108 130
109 for (const videoFile of this.embed.player.webtorrent().videoFiles) { 131 for (const videoFile of this.embed.player.webtorrent().videoFiles) {
@@ -112,18 +134,46 @@ export class PeerTubeEmbedApi {
112 label += videoFile.fps 134 label += videoFile.fps
113 } 135 }
114 136
115 resolutions.push({ 137 this.resolutions.push({
116 id: videoFile.resolution.id, 138 id: videoFile.resolution.id,
117 label, 139 label,
118 src: videoFile.magnetUri, 140 src: videoFile.magnetUri,
119 active: videoFile.resolution.id === currentResolutionId 141 active: videoFile.resolution.id === currentResolutionId,
142 height: videoFile.resolution.id
120 }) 143 })
121 } 144 }
122 145
123 this.resolutions = resolutions
124 this.channel.notify({ 146 this.channel.notify({
125 method: 'resolutionUpdate', 147 method: 'resolutionUpdate',
126 params: this.resolutions 148 params: this.resolutions
127 }) 149 })
128 } 150 }
151
152 private loadP2PMediaLoaderResolutions () {
153 this.resolutions = []
154
155 const qualityLevels = this.embed.player.qualityLevels()
156 const currentResolutionId = this.embed.player.qualityLevels().selectedIndex
157
158 for (let i = 0; i < qualityLevels.length; i++) {
159 const level = qualityLevels[i]
160
161 this.resolutions.push({
162 id: level.id,
163 label: level.height + 'p',
164 active: level.id === currentResolutionId,
165 width: level.width,
166 height: level.height
167 })
168 }
169
170 this.channel.notify({
171 method: 'resolutionUpdate',
172 params: this.resolutions
173 })
174 }
175
176 private isWebtorrent () {
177 return this.embed.player.webtorrent
178 }
129} 179}