aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/standalone/videos/embed.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/standalone/videos/embed.ts')
-rw-r--r--client/src/standalone/videos/embed.ts26
1 files changed, 16 insertions, 10 deletions
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts
index 89903aa35..8b00be790 100644
--- a/client/src/standalone/videos/embed.ts
+++ b/client/src/standalone/videos/embed.ts
@@ -1,6 +1,7 @@
1import './embed.scss' 1import './embed.scss'
2import videojs from 'video.js' 2import videojs from 'video.js'
3import { objectToUrlEncoded, peertubeLocalStorage, PureAuthUser } from '@root-helpers/index' 3import { objectToUrlEncoded, peertubeLocalStorage } from '@root-helpers/index'
4import { Tokens } from '@root-helpers/users'
4import { peertubeTranslate } from '../../../../shared/core-utils/i18n' 5import { peertubeTranslate } from '../../../../shared/core-utils/i18n'
5import { 6import {
6 ResultList, 7 ResultList,
@@ -39,7 +40,7 @@ export class PeerTubeEmbed {
39 mode: PlayerMode 40 mode: PlayerMode
40 scope = 'peertube' 41 scope = 'peertube'
41 42
42 user: PureAuthUser 43 userTokens: Tokens
43 headers = new Headers() 44 headers = new Headers()
44 LOCAL_STORAGE_OAUTH_CLIENT_KEYS = { 45 LOCAL_STORAGE_OAUTH_CLIENT_KEYS = {
45 CLIENT_ID: 'client_id', 46 CLIENT_ID: 'client_id',
@@ -74,7 +75,7 @@ export class PeerTubeEmbed {
74 const headers = new Headers() 75 const headers = new Headers()
75 headers.set('Content-Type', 'application/x-www-form-urlencoded') 76 headers.set('Content-Type', 'application/x-www-form-urlencoded')
76 const data = { 77 const data = {
77 refresh_token: this.user.getRefreshToken(), 78 refresh_token: this.userTokens.refreshToken,
78 client_id: clientId, 79 client_id: clientId,
79 client_secret: clientSecret, 80 client_secret: clientSecret,
80 response_type: 'code', 81 response_type: 'code',
@@ -88,9 +89,12 @@ export class PeerTubeEmbed {
88 }) 89 })
89 .then(res => res.json()) 90 .then(res => res.json())
90 .then((obj: UserRefreshToken) => { 91 .then((obj: UserRefreshToken) => {
91 this.user.refreshTokens(obj.access_token, obj.refresh_token) 92 this.userTokens.accessToken = obj.access_token
92 this.user.save() 93 this.userTokens.refreshToken = obj.refresh_token
93 this.headers.set('Authorization', `${this.user.getTokenType()} ${this.user.getAccessToken()}`) 94 this.userTokens.save()
95
96 this.setHeadersFromTokens()
97
94 resolve() 98 resolve()
95 }) 99 })
96 .catch((refreshTokenError: any) => { 100 .catch((refreshTokenError: any) => {
@@ -165,7 +169,7 @@ export class PeerTubeEmbed {
165 169
166 async init () { 170 async init () {
167 try { 171 try {
168 this.user = PureAuthUser.load() 172 this.userTokens = Tokens.load()
169 await this.initCore() 173 await this.initCore()
170 } catch (e) { 174 } catch (e) {
171 console.error(e) 175 console.error(e)
@@ -218,9 +222,7 @@ export class PeerTubeEmbed {
218 const urlParts = window.location.pathname.split('/') 222 const urlParts = window.location.pathname.split('/')
219 const videoId = urlParts[ urlParts.length - 1 ] 223 const videoId = urlParts[ urlParts.length - 1 ]
220 224
221 if (this.user) { 225 if (this.userTokens) this.setHeadersFromTokens()
222 this.headers.set('Authorization', `${this.user.getTokenType()} ${this.user.getAccessToken()}`)
223 }
224 226
225 const videoPromise = this.loadVideoInfo(videoId) 227 const videoPromise = this.loadVideoInfo(videoId)
226 const captionsPromise = this.loadVideoCaptions(videoId) 228 const captionsPromise = this.loadVideoCaptions(videoId)
@@ -381,6 +383,10 @@ export class PeerTubeEmbed {
381 private getPlaceholderElement () { 383 private getPlaceholderElement () {
382 return document.getElementById('placeholder-preview') 384 return document.getElementById('placeholder-preview')
383 } 385 }
386
387 private setHeadersFromTokens () {
388 this.headers.set('Authorization', `${this.userTokens.tokenType} ${this.userTokens.accessToken}`)
389 }
384} 390}
385 391
386PeerTubeEmbed.main() 392PeerTubeEmbed.main()