Skip to content

Commit 3bd685c

Browse files
Roee DeanRoee Dean
Roee Dean
authored and
Roee Dean
committed
FEC-14248-fix-_isAnonimous-based-on-ks-contain-user-providers
1 parent 31ef303 commit 3bd685c

File tree

6 files changed

+210
-160
lines changed

6 files changed

+210
-160
lines changed

src/k-provider/common/base-provider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import {
1414
export default class BaseProvider<MI> {
1515
private _partnerId: number;
1616
private _widgetId?: string;
17-
private _ks: string;
17+
protected _ks: string;
1818
private _uiConfId?: number;
1919
public _dataLoader!: DataLoaderManager;
2020
private _playerVersion: string;
2121
public _logger: any;
2222
public _referrer?: string;
23-
protected _isAnonymous: boolean;
23+
protected _isAnonymous: boolean | undefined;
2424

2525
public _networkRetryConfig: ProviderNetworkRetryParameters = {
2626
async: true,
@@ -56,7 +56,7 @@ export default class BaseProvider<MI> {
5656
return this._playerVersion;
5757
}
5858

59-
public get isAnonymous(): boolean {
59+
public get isAnonymous(): boolean | undefined {
6060
return this._isAnonymous;
6161
}
6262

src/k-provider/ovp/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export default class OVPConfiguration {
2626
public static get(): any {
2727
return clone(defaultConfig);
2828
}
29+
30+
public static get serviceUrl(): string {
31+
return defaultConfig.serviceUrl;
32+
}
2933
}
3034

3135
export {OVPConfiguration};

src/k-provider/ovp/provider.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import {
2323
ProviderPlaylistObject,
2424
RequestLoader
2525
} from '../../types';
26+
import OVPUserService from './services/user-service';
27+
import {KalturaUserGetResponse} from './response-types/kaltura-user-get-response';
2628

2729
export default class OVPProvider extends BaseProvider<OVPProviderMediaInfoObject> {
2830
private _filterOptionsConfig: ProviderFilterOptionsObject = {redirectFromEntryId: true};
@@ -39,12 +41,29 @@ export default class OVPProvider extends BaseProvider<OVPProviderMediaInfoObject
3941
this._setFilterOptionsConfig(options.filterOptions);
4042
this._vrTag = options.vrTag || '360';
4143
this._networkRetryConfig = Object.assign(this._networkRetryConfig, options.networkRetryParameters);
44+
45+
this._isAnonymous = !this._ks ? true : undefined;
46+
if (this._isAnonymous === undefined) {
47+
this.initializeUserResponse(OVPConfiguration.serviceUrl, this._ks).then(() => {
48+
this._logger.info('User response initialized');
49+
}).catch(err => {
50+
this._logger.error('Failed to initialize user response', err);
51+
});
52+
}
4253
}
4354

4455
public get env(): any {
4556
return OVPConfiguration.get();
4657
}
4758

59+
public async initializeUserResponse(serviceUrl: string, ks: string): Promise<void> {
60+
const request = OVPUserService.get(serviceUrl, ks);
61+
request.params = JSON.stringify(request.params);
62+
const response = await request.doHttpRequest();
63+
const userResponse = new KalturaUserGetResponse(response);
64+
this._isAnonymous = userResponse.isAnonymous();
65+
}
66+
4867
/**
4968
* Gets the backend media config object.
5069
* @param {OVPProviderMediaInfoObject} mediaInfo - ovp media info
@@ -53,10 +72,6 @@ export default class OVPProvider extends BaseProvider<OVPProviderMediaInfoObject
5372
public getMediaConfig(mediaInfo: OVPProviderMediaInfoObject): Promise<ProviderMediaConfigObject> {
5473
if (mediaInfo.ks) {
5574
this.ks = mediaInfo.ks;
56-
this._isAnonymous = false;
57-
}
58-
if (this.widgetId !== this.defaultWidgetId) {
59-
this._isAnonymous = false;
6075
}
6176
this._dataLoader = new OVPDataLoaderManager(this.playerVersion, this.partnerId, this.ks, this._networkRetryConfig);
6277
return new Promise((resolve, reject) => {
@@ -209,10 +224,6 @@ export default class OVPProvider extends BaseProvider<OVPProviderMediaInfoObject
209224
public getPlaylistConfig(playlistInfo: ProviderPlaylistInfoObject): Promise<ProviderPlaylistObject> {
210225
if (playlistInfo.ks) {
211226
this.ks = playlistInfo.ks;
212-
this._isAnonymous = false;
213-
}
214-
if (this.widgetId !== this.defaultWidgetId) {
215-
this._isAnonymous = false;
216227
}
217228
this._dataLoader = new OVPDataLoaderManager(this.playerVersion, this.partnerId, this.ks, this._networkRetryConfig);
218229
return new Promise((resolve, reject) => {
@@ -265,10 +276,6 @@ export default class OVPProvider extends BaseProvider<OVPProviderMediaInfoObject
265276
public getEntryListConfig(entryListInfo: ProviderEntryListObject): Promise<ProviderPlaylistObject> {
266277
if (entryListInfo.ks) {
267278
this.ks = entryListInfo.ks;
268-
this._isAnonymous = false;
269-
}
270-
if (this.widgetId !== this.defaultWidgetId) {
271-
this._isAnonymous = false;
272279
}
273280
this._dataLoader = new OVPDataLoaderManager(this.playerVersion, this.partnerId, this.ks, this._networkRetryConfig);
274281
return new Promise((resolve, reject) => {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export class KalturaUserGetResponse {
2+
public id: string;
3+
private static readonly INVALID_IDS = ['0', '', null, undefined];
4+
5+
constructor(response: any) {
6+
this.id = response.id;
7+
}
8+
9+
public isAnonymous(): boolean {
10+
return KalturaUserGetResponse.INVALID_IDS.includes(this.id);
11+
}
12+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import OVPService from './ovp-service';
2+
import RequestBuilder from '../../../util/request-builder';
3+
4+
const SERVICE_NAME: string = 'user';
5+
6+
export default class OVPUserService extends OVPService {
7+
/**
8+
* Creates an instance of RequestBuilder for user.get
9+
* @function getPlaybackContext
10+
* @param {string} serviceUrl The service base URL
11+
* @param {string} ks The ks
12+
* @returns {RequestBuilder} The request builder
13+
* @static
14+
*/
15+
public static get(serviceUrl: string, ks: string): RequestBuilder {
16+
const headers: Map<string, string> = new Map();
17+
headers.set('Content-Type', 'application/json');
18+
const request = new RequestBuilder(headers);
19+
request.service = SERVICE_NAME;
20+
request.action = 'get';
21+
request.method = 'POST';
22+
request.url = request.getUrl(serviceUrl);
23+
request.tag = 'user-get';
24+
request.params = { ks: ks, format: 1 };
25+
return request;
26+
}
27+
}

0 commit comments

Comments
 (0)