Skip to content

Commit

Permalink
feat(FEC-11761): expose stream timed metadata - phase 2 (#15)
Browse files Browse the repository at this point in the history
pass `CuePoint` to addCuePoints api

Depends on kaltura/kaltura-player-js#512
  • Loading branch information
yairans committed Jan 12, 2022
1 parent 737d625 commit 9d42702
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/providers/live/live-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class LiveProvider extends Provider {
// fix endTime and replace VTTCue
if (cue.endTime === Number.MAX_SAFE_INTEGER && index !== cuePoints.length - 1) {
const fixedCue = {...cue, endTime: cuePoints[index + 1].startTime};
this._player.cuePointManager.addCuePoints([fixedCue]);
this._addCuePointToPlayer([fixedCue]);
return fixedCue;
}
return cue;
Expand All @@ -138,7 +138,7 @@ export class LiveProvider extends Provider {
};
this._thumbCuePoints.push(newThumbCue);
this._thumbCuePoints = this._fixCuePointEndTime(this._thumbCuePoints);
this._player.cuePointManager.addCuePoints([newThumbCue]);
this._addCuePointToPlayer([newThumbCue]);
};

private _prepareViewChangeCuePoints = (viewChange: SlideViewChangePushNotificationData) => {
Expand All @@ -151,7 +151,7 @@ export class LiveProvider extends Provider {
};
this._slideViewChangeCuePoints.push(newViewChangeCue);
this._slideViewChangeCuePoints = this._fixCuePointEndTime(this._slideViewChangeCuePoints);
this._player.cuePointManager.addCuePoints([newViewChangeCue]);
this._addCuePointToPlayer([newViewChangeCue]);
} catch (e) {
this._logger.error('Unnable parse slide-view change cue-point');
}
Expand Down
8 changes: 8 additions & 0 deletions src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export class Provider {
this._eventManager = eventManager;
this._logger = logger;
}

protected _addCuePointToPlayer(cuePoints: any[]) {
const playerCuePoints = cuePoints.map(cuePoint => {
const {startTime, endTime, id, ...metadata} = cuePoint;
return {startTime, endTime, id, metadata};
});
this._player.cuePointManager.addCuePoints(playerCuePoints);
}

public destroy() {}
}
6 changes: 3 additions & 3 deletions src/providers/vod/vod-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export class VodProvider extends Provider {
viewChangeCuePoints = this._sortCuePoints(viewChangeCuePoints);
viewChangeCuePoints = this._fixCuePointsEndTime(viewChangeCuePoints);

this._player.cuePointManager.addCuePoints(viewChangeCuePoints);
this._player.cuePointManager.addCuePoints(lockedCuePoints);
this._addCuePointToPlayer(viewChangeCuePoints);
this._addCuePointToPlayer(lockedCuePoints);
}
}

Expand All @@ -130,7 +130,7 @@ export class VodProvider extends Provider {
let cuePoints = createCuePointList(thumbCuePoints);
cuePoints = this._sortCuePoints(cuePoints);
cuePoints = this._fixCuePointsEndTime(cuePoints);
this._player.cuePointManager.addCuePoints(cuePoints);
this._addCuePointToPlayer(cuePoints);
}
}
}
30 changes: 27 additions & 3 deletions test/src/providers/live/live-provider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ describe('Check Live provider', () => {
const addCuePoints = sinon.spy();
liveProvider._player = {
currentTime: 5,
config: {session: {ks: 'test_ks'}, provider: {env: {serviceUrl: 'test_url'}}},
config: {session: {ks: 'test_ks'}},
provider: {env: {serviceUrl: 'test_url'}},
cuePointManager: {addCuePoints}
};
liveProvider._currentTimeLive = 100;
Expand All @@ -144,8 +145,20 @@ describe('Check Live provider', () => {
assetUrl: 'test_url/index.php/service/thumbAsset/action/serve/thumbAssetId/test_id/ks/test_ks'
}
];
const playerResult = [
{
id: '1',
startTime: 1,
endTime: Number.MAX_SAFE_INTEGER,
metadata: {
assetId: 'test_id',
createdAt: 96,
assetUrl: 'test_url/index.php/service/thumbAsset/action/serve/thumbAssetId/test_id/ks/test_ks'
}
}
];
expect(liveProvider._thumbCuePoints).to.eql(result);
addCuePoints.should.have.been.calledOnceWithExactly(result);
addCuePoints.should.have.been.calledOnceWithExactly(playerResult);
});

it('should test _prepareViewChangeCuePoints method', () => {
Expand All @@ -169,8 +182,19 @@ describe('Check Live provider', () => {
partnerData: {viewModeLockState: 'locked'}
}
];
const playerResult = [
{
id: '1',
startTime: 1,
endTime: Number.MAX_SAFE_INTEGER,
metadata: {
createdAt: 96,
partnerData: {viewModeLockState: 'locked'}
}
}
];
expect(liveProvider._slideViewChangeCuePoints).to.eql(result);
addCuePoints.should.have.been.calledOnceWithExactly(result);
addCuePoints.should.have.been.calledOnceWithExactly(playerResult);
});
});
});

0 comments on commit 9d42702

Please sign in to comment.