PageSourceSearch

https://ver.movistarplus.es/js/yomvi/player/cdnmanager.js?type=module&m=1788497367

js movistarplus.es collected 2026-09-24 08:54:44 UTC 8,299 bytes, 169 lines download raw bytes

1import { CDNManager } from '../../dist/tcdnlib.js';
2
3(function (window) {
4    yomvi.addPackage('yomvi.player.cdnmanager', function () {
5        this.cdnManagerService = 'cuenta/renovacion_cdntoken2';
6        this.manager = {};
7        this.managerInStorage = JSON.parse(localStorage.getItem('cdnmanager')) || {};
8        /*CDN SECURIZATHION*/
9        this.tcdnsecurizathion = function (){
10            /*Solo hay que securizar si existe el endpoint en el SD*/
11            return  yomvi.system.directorio.endpointExists(yomvi.player.cdnmanager.cdnManagerService);
12        }
13        this.getAccessToken = function (){
14            const legacy = yomvi.system.directorio.getIndicadorLegacyAccessToken(yomvi.player.cdnmanager.cdnManagerService) || false;
15            if (yomvi.usuario.estaLogado()) {
16
17                //para FAU es accessToken
18                if (!legacy) {
19                    return yomvi.usuario.prefs('accessToken') || null;
20                } else {
21                    return yomvi.usuario.prefs('legacyAccessToken') || null;
22                }
23            }
24            return null;
25        }
26
27        this.updateStorage = function (){
28            localStorage.setItem('cdnmanager',JSON.stringify(this.manager));
29            this.managerInStorage = JSON.parse(localStorage.getItem('cdnmanager')) || {};
30        }
31        this.clear = function(){
32            this.manager = {};
33            localStorage.setItem('cdnmanager',JSON.stringify(this.manager));
34            this.managerInStorage = {};
35        }
36
37        this.hasError = function(){
38
39            const tokenCDN = yomvi.player.cdnmanager.managerInStorage._tokenCDN || {};
40            const tokenError = yomvi.player.cdnmanager.managerInStorage._tokenError || {};
41            let error = false;
42
43            if (tokenCDN && typeof tokenCDN === "object" && Object.prototype.hasOwnProperty.call(tokenCDN, "errorCode")){
44                error = true
45            }else if (tokenError && typeof tokenError === "object" && Object.prototype.hasOwnProperty.call(tokenError, "errorCode")){
46                error =  true
47            }
48            return error;
49        }
50
51        this.setUrl = function (url = false){
52            if (!url){
53                return false;
54            }
55            this.manager._url = url;
56        }
57
58        this.getTimeOfExpiration = function (){
59            const expirationTimeStamp =  this.managerInStorage._refreshTimestamp + (this.managerInStorage._expiresInSeconds - this.managerInStorage._timeOffset) * 1000
60            let hour =  new Date(expirationTimeStamp).toLocaleTimeString();
61            let day = new Date(expirationTimeStamp).toLocaleDateString();
62            return day + ' ' + hour;
63        }
64        this.hasTCDNToken = function (){
65            if (this.managerInStorage && '_tokenCDN' in this.managerInStorage && !this.hasError()){
66                return true;
67            }
68            return false;
69        }
70        this.getTCDNToken = function (){
71            if (this.managerInStorage && '_tokenCDN' in this.managerInStorage && !this.hasError()){
72                return this.managerInStorage._tokenCDN.token || null;
73            }
74            return null;
75        }
76        this.configureCDNManager = function (){
77            return new Promise((resolve, reject) => {
78                if (!this.tcdnsecurizathion()){
79                    resolve();
80                }
81                const service = yomvi.player.cdnmanager.cdnManagerService;
82                const replace_params = {  ACCOUNTNUMBER: yomvi.usuario.cuentaSeleccionada() };
83                const url = yomvi.system.directorio.getEndpoint(service, replace_params);
84                const legacy_mode = yomvi.system.directorio.getIndicadorLegacyAccessToken(service);
85                const timeOffset = yomvi.system.directorio.getContext('t_tcdn')||280;
86
87                //TODO: Revisar si es los parámetros storeParams podrían venir en config.ua.
88                const storeParams = {
89                    version: yomvi.config.version,
90                    name: yomvi.config.name,
91                    timestamp: yomvi.config.timestamp,
92                    language: yomvi.config.language
93                }
94                const clonedUA = { ...yomvi.config.ua, ...storeParams };
95                this.manager = new CDNManager(url, timeOffset, clonedUA, legacy_mode);
96
97                //Si tenemos datos del manager en el localStorage los cargamos para mantener la persistencia.
98                if('_tokenCDN' in this.managerInStorage){
99                    this.manager._tokenCDN = this.managerInStorage._tokenCDN || null;
100                    this.manager._expiresInSeconds = this.managerInStorage._expiresInSeconds || null;
101                    this.manager._refreshTimestamp = this.managerInStorage._refreshTimestamp || null;
102                    //Parámetro del intervalo de actualización del token
103                    this.manager._timeoutID =  this.managerInStorage._timeoutID || null;
104                    this.manager._access_token = this.getAccessToken();
105
106                    //Si el token está caducado o es error se renueva
107                    if (this.manager.isTokenExpired() || this.hasError() !== false){
108
109                        //PETICIÓN DE REFRESCO
110                        const force_refresh = true;
111                        this.manager.getTCDNToken(this.getAccessToken(), force_refresh).then((tokenCDN)=>{
112                            this.updateStorage();
113                            if (this.hasError()) {
114                                tokenCDN.url = yomvi.player.cdnmanager.manager._url;
115                                yomvi.system.errorManager.dispatchError(tokenCDN);
116                            }
117                            resolve();
118                        })
119                    } else  {
120                        //Hay un token válido
121                        //Forzamos reseteo del timeOut de refresco automático
122
123                        this.manager.clearTokenRefreshInterval()
124                        this.manager.setupTokenRefreshInterval()
125                        resolve()
126                    }
127                    yomvi.player.cdnmanager.manager.emitter.addListener ('tokenTCDNRefreshed', ()=>{
128                        this.updateStorage()
129                    })
130                    yomvi.player.cdnmanager.manager.emitter.addListener ('tokenTCDNRefreshedError', (_error)=>{
131                        if (_error.errorCode && _error.errorCode === 418){
132                            this.updateStorage();
133                        }
134                        _error.code = _error.errorCode || 700;
135                        _error.status = _error.errorCode || 700;
136                        _error.registeredError = _error.errorCode || 700;
137                        _error.url = yomvi.player.cdnmanager.manager._url;
138                        yomvi.system.errorManager.dispatchError(_error);
139                    })
140
141                }else {
142                    yomvi.player.cdnmanager.manager.emitter.addListener ('tokenTCDNRefreshed', ()=>{
143                        this.updateStorage()
144                    })
145                    yomvi.player.cdnmanager.manager.emitter.addListener ('tokenTCDNRefreshedError', (_error)=>{
146                       if (_error.errorCode && _error.errorCode === 418){
147                            this.updateStorage();
148                        }
149                        _error.code = _error.errorCode || 700;
150                        _error.status = _error.errorCode || 700;
151                        _error.registeredError = _error.errorCode || 700;
152                        _error.url = yomvi.player.cdnmanager.manager._url;
153                        yomvi.system.errorManager.dispatchError(_error);
154                    })
155                    const force_refresh = true;
156                    this.manager.getTCDNToken(this.getAccessToken(force_refresh)).then((tokenCDN)=>{
157                        this.updateStorage();
158
159                        if (this.hasError()) {
160                            tokenCDN.url = yomvi.player.cdnmanager.manager._url;
161                            yomvi.system.errorManager.dispatchError(tokenCDN);
162                        }
163                        resolve();
164                    })
165                }
166            })
167        }
168    })
169})(window);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.