Skip to content

Commit

Permalink
fix(FEC-14248): Anonymous session based on if ks contain user (#259)
Browse files Browse the repository at this point in the history
### Description of the Changes

- Added a new service for Kaltura User Get using it inside the
OVPProvider
- Concentrated the dealing with the flag config.session._isAnonymous in
a single place in the file, instead of several places.
- Fixed the flag config.session._isAnonymous logic:
until now, config.session._isAnonymous was set to 'false' for every
session that has ks (even if it's anonymous ks).
The fix insure that the flag config.session._isAnonymous will be set to
'false' only for sessions that have ks containing a valid user inside,
otherwise the flag will be set to 'true'.

Related PR: kaltura/kaltura-player-js#916

[FEC-14248](https://kaltura.atlassian.net/browse/FEC-14248)

[FEC-14248]:
https://kaltura.atlassian.net/browse/FEC-14248?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Co-authored-by: Roee Dean <[email protected]>
  • Loading branch information
roeedean and Roee Dean authored Feb 10, 2025
1 parent 8192607 commit ea59451
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 139 deletions.
6 changes: 3 additions & 3 deletions src/k-provider/common/base-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import {
export default class BaseProvider<MI> {
private _partnerId: number;
private _widgetId?: string;
private _ks: string;
protected _ks: string;
private _uiConfId?: number;
public _dataLoader!: DataLoaderManager;
private _playerVersion: string;
public _logger: any;
public _referrer?: string;
protected _isAnonymous: boolean;
protected _isAnonymous: boolean | undefined;

public _networkRetryConfig: ProviderNetworkRetryParameters = {
async: true,
Expand Down Expand Up @@ -56,7 +56,7 @@ export default class BaseProvider<MI> {
return this._playerVersion;
}

public get isAnonymous(): boolean {
public get isAnonymous(): boolean | undefined {
return this._isAnonymous;
}

Expand Down
4 changes: 4 additions & 0 deletions src/k-provider/ovp/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default class OVPConfiguration {
public static get(): any {
return clone(defaultConfig);
}

public static get serviceUrl(): string {
return defaultConfig.serviceUrl;
}
}

export {OVPConfiguration};
31 changes: 19 additions & 12 deletions src/k-provider/ovp/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
ProviderPlaylistObject,
RequestLoader
} from '../../types';
import OVPUserService from './services/user-service';
import {KalturaUserGetResponse} from './response-types/kaltura-user-get-response';

export default class OVPProvider extends BaseProvider<OVPProviderMediaInfoObject> {
private _filterOptionsConfig: ProviderFilterOptionsObject = {redirectFromEntryId: true};
Expand All @@ -39,12 +41,29 @@ export default class OVPProvider extends BaseProvider<OVPProviderMediaInfoObject
this._setFilterOptionsConfig(options.filterOptions);
this._vrTag = options.vrTag || '360';
this._networkRetryConfig = Object.assign(this._networkRetryConfig, options.networkRetryParameters);

this._isAnonymous = !this._ks ? true : undefined;
if (this._isAnonymous === undefined) {
this.initializeUserResponse(OVPConfiguration.serviceUrl, this._ks).then(() => {
this._logger.info('User response initialized');
}).catch(err => {
this._logger.error('Failed to initialize user response', err);
});
}
}

public get env(): any {
return OVPConfiguration.get();
}

public async initializeUserResponse(serviceUrl: string, ks: string): Promise<void> {
const request = OVPUserService.get(serviceUrl, ks);
request.params = JSON.stringify(request.params);
const response = await request.doHttpRequest();
const userResponse = new KalturaUserGetResponse(response);
this._isAnonymous = userResponse.isAnonymous();
}

/**
* Gets the backend media config object.
* @param {OVPProviderMediaInfoObject} mediaInfo - ovp media info
Expand All @@ -53,10 +72,6 @@ export default class OVPProvider extends BaseProvider<OVPProviderMediaInfoObject
public getMediaConfig(mediaInfo: OVPProviderMediaInfoObject): Promise<ProviderMediaConfigObject> {
if (mediaInfo.ks) {
this.ks = mediaInfo.ks;
this._isAnonymous = false;
}
if (this.widgetId !== this.defaultWidgetId) {
this._isAnonymous = false;
}
this._dataLoader = new OVPDataLoaderManager(this.playerVersion, this.partnerId, this.ks, this._networkRetryConfig);
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -209,10 +224,6 @@ export default class OVPProvider extends BaseProvider<OVPProviderMediaInfoObject
public getPlaylistConfig(playlistInfo: ProviderPlaylistInfoObject): Promise<ProviderPlaylistObject> {
if (playlistInfo.ks) {
this.ks = playlistInfo.ks;
this._isAnonymous = false;
}
if (this.widgetId !== this.defaultWidgetId) {
this._isAnonymous = false;
}
this._dataLoader = new OVPDataLoaderManager(this.playerVersion, this.partnerId, this.ks, this._networkRetryConfig);
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -265,10 +276,6 @@ export default class OVPProvider extends BaseProvider<OVPProviderMediaInfoObject
public getEntryListConfig(entryListInfo: ProviderEntryListObject): Promise<ProviderPlaylistObject> {
if (entryListInfo.ks) {
this.ks = entryListInfo.ks;
this._isAnonymous = false;
}
if (this.widgetId !== this.defaultWidgetId) {
this._isAnonymous = false;
}
this._dataLoader = new OVPDataLoaderManager(this.playerVersion, this.partnerId, this.ks, this._networkRetryConfig);
return new Promise((resolve, reject) => {
Expand Down
12 changes: 12 additions & 0 deletions src/k-provider/ovp/response-types/kaltura-user-get-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export class KalturaUserGetResponse {
public id: string;
private static readonly INVALID_IDS = ['0', '', null, undefined];

constructor(response: any) {
this.id = response.id;
}

public isAnonymous(): boolean {
return KalturaUserGetResponse.INVALID_IDS.includes(this.id);
}
}
27 changes: 27 additions & 0 deletions src/k-provider/ovp/services/user-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import OVPService from './ovp-service';
import RequestBuilder from '../../../util/request-builder';

const SERVICE_NAME: string = 'user';

export default class OVPUserService extends OVPService {
/**
* Creates an instance of RequestBuilder for user.get
* @function getPlaybackContext
* @param {string} serviceUrl The service base URL
* @param {string} ks The ks
* @returns {RequestBuilder} The request builder
* @static
*/
public static get(serviceUrl: string, ks: string): RequestBuilder {
const headers: Map<string, string> = new Map();
headers.set('Content-Type', 'application/json');
const request = new RequestBuilder(headers);
request.service = SERVICE_NAME;
request.action = 'get';
request.method = 'POST';
request.url = request.getUrl(serviceUrl);
request.tag = 'user-get';
request.params = { ks: ks, format: 1 };
return request;
}
}
Loading

0 comments on commit ea59451

Please sign in to comment.