Skip to content

Commit

Permalink
feat(FEC-10356): upgrade Shaka (#112)
Browse files Browse the repository at this point in the history
upgrade shaka to current latest, note this is a major change with breaking changes(see below).

issue: getManifest was marked as API which could change any time.
solution: add an extra check to make sure it's not breaking our API, keeps the tests as is to help us to be aware of changes on this API.
Some tests are not valid anymore since the last version they changed internal function to private.

Solve: FEC-10356.
  • Loading branch information
Yuvalke authored Aug 3, 2020
1 parent 136926f commit 3c3b05b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@babel/plugin-transform-property-mutators",
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-classes",
"@babel/plugin-transform-classes"
],
"presets": ["@babel/preset-env", "@babel/preset-flow"]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"mocha": "^8.0.1",
"mocha-cli": "^1.0.1",
"prettier": "^2.0.5",
"shaka-player": "2.5.9",
"shaka-player": "3.0.2",
"sinon": "^9.0.2",
"sinon-chai": "^3.5.0",
"standard-version": "^8.0.2",
Expand All @@ -85,7 +85,7 @@
},
"peerDependencies": {
"@playkit-js/playkit-js": "0.62.1-canary.2264c8f",
"shaka-player": "^2.5.5"
"shaka-player": "^3.0.2"
},
"keywords": [
"kaltura",
Expand Down
24 changes: 13 additions & 11 deletions src/dash-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
DashAdapter._logger.debug('Register response filter');
this._shaka.getNetworkingEngine().registerResponseFilter((type, response) => {
if (Object.values(RequestType).includes(type)) {
const {uri: url, ed: originalUrl, data, headers} = response;
const pkResponse: PKResponseObject = {url, originalUrl, data, headers};
const {uri: url, data, headers} = response;
const pkResponse: PKResponseObject = {url, originalUrl: this._sourceObj.url, data, headers};
let responseFilterPromise;
try {
responseFilterPromise = this._config.network.responseFilter(type, pkResponse);
Expand Down Expand Up @@ -1080,15 +1080,17 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
const activeTrack = this._getActiveTrack();
const activeTrackId = activeTrack ? activeTrack.id : NaN;
let segmentLength = 0;
const periods = this._shaka.getManifest().periods;
if (!isNaN(activeTrackId)) {
for (let i = 0; i < periods.length; i++) {
for (let j = 0; j < periods[i].variants.length; j++) {
const variant = periods[i].variants[j];
if (variant.id === activeTrackId) {
const segmentPosition = variant.video.findSegmentPosition(this._videoElement.currentTime);
let seg = variant.video.getSegmentReference(segmentPosition);
segmentLength = seg.endTime - seg.startTime;
if (this._shaka.getManifest()) {
const periods = this._shaka.getManifest().periods;
if (!isNaN(activeTrackId) && periods) {
for (let i = 0; i < periods.length; i++) {
for (let j = 0; j < periods[i].variants.length; j++) {
const variant = periods[i].variants[j];
if (variant.id === activeTrackId) {
const segmentPosition = variant.video.findSegmentPosition(this._videoElement.currentTime);
let seg = variant.video.getSegmentReference(segmentPosition);
segmentLength = seg.endTime - seg.startTime;
}
}
}
}
Expand Down
125 changes: 67 additions & 58 deletions test/src/dash-adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {loadPlayer, VideoTrack, AudioTrack, TextTrack, Utils, RequestType, Event
import {Widevine} from '../../src/drm/widevine';
import {PlayReady} from '../../src/drm/playready';
import {wwDrmData, prDrmData} from './drm/fake-drm-data';

import shaka from 'shaka-player';
const targetId = 'player-placeholder_dash-adapter.spec';

let vodSource = {
Expand Down Expand Up @@ -318,7 +318,7 @@ describe('DashAdapter: targetBuffer', () => {
dashInstance._shaka.getManifest().presentationTimeline.getSeekRangeEnd() -
(video.currentTime - dashInstance._getLiveEdge());

dashInstance.targetBuffer.should.equal(targetBufferVal);
(dashInstance.targetBuffer.toFixed(2) === targetBufferVal.toFixed(2)).should.be.true;
done();
});

Expand All @@ -340,7 +340,7 @@ describe('DashAdapter: targetBuffer', () => {
video.addEventListener(EventType.PLAYING, () => {
let targetBufferVal = dashInstance._shaka.getConfiguration().streaming.bufferingGoal + dashInstance._getCurrentSegmentLength();

dashInstance.targetBuffer.should.equal(targetBufferVal);
(dashInstance.targetBuffer.toFixed(2) === targetBufferVal.toFixed(2)).should.be.true;
done();
});

Expand Down Expand Up @@ -1388,61 +1388,6 @@ describe('DashAdapter: request filter', () => {
dashInstance.load();
});

it('should apply void filter for manifest', done => {
dashInstance = DashAdapter.createAdapter(
video,
vodSource,
Utils.Object.mergeDeep(config, {
network: {
requestFilter: function (type, request) {
if (type === RequestType.MANIFEST) {
request.url += '?test';
}
}
}
})
);
sandbox.stub(dashInstance._shakaLib.net.HttpFetchPlugin, 'g').callsFake(value => {
// stub HttpFetchPlugin.fetch_ method complied to g
try {
value.indexOf('?test').should.be.gt(-1);
done();
} catch (e) {
done(e);
}
});
dashInstance.load();
});

it('should apply promise filter for manifest', done => {
dashInstance = DashAdapter.createAdapter(
video,
vodSource,
Utils.Object.mergeDeep(config, {
network: {
requestFilter: function (type, request) {
if (type === RequestType.MANIFEST) {
return new Promise(resolve => {
request.url += '?test';
resolve(request);
});
}
}
}
})
);
sandbox.stub(dashInstance._shakaLib.net.HttpFetchPlugin, 'g').callsFake(value => {
// stub HttpFetchPlugin.fetch_ method complied to g
try {
value.indexOf('?test').should.be.gt(-1);
done();
} catch (e) {
done(e);
}
});
dashInstance.load();
});

it('should handle error thrown from void filter', done => {
dashInstance = DashAdapter.createAdapter(
video,
Expand Down Expand Up @@ -1539,6 +1484,70 @@ describe('DashAdapter: request filter', () => {
});
dashInstance.load();
});

describe('http request', () => {
after(() => {
shaka.net.NetworkingEngine.registerScheme('http', shaka.net.HttpFetchPlugin.parse, shaka.net.NetworkingEngine.PluginPriority.PREFERRED);
shaka.net.NetworkingEngine.registerScheme('https', shaka.net.HttpFetchPlugin.parse, shaka.net.NetworkingEngine.PluginPriority.PREFERRED);
});

it('should apply void filter for manifest', done => {
dashInstance = DashAdapter.createAdapter(
video,
vodSource,
Utils.Object.mergeDeep(config, {
network: {
requestFilter: function (type, request) {
if (type === RequestType.MANIFEST) {
request.url += '?test';
}
}
}
})
);
const httpFetchRequest = url => {
try {
url.indexOf('?test').should.be.gt(-1);
done();
} catch (e) {
done(e);
}
};
shaka.net.NetworkingEngine.registerScheme('http', httpFetchRequest, shaka.net.NetworkingEngine.PluginPriority.PREFERRED);
shaka.net.NetworkingEngine.registerScheme('https', httpFetchRequest, shaka.net.NetworkingEngine.PluginPriority.PREFERRED);
dashInstance.load();
});

it('should apply promise filter for manifest', done => {
dashInstance = DashAdapter.createAdapter(
video,
vodSource,
Utils.Object.mergeDeep(config, {
network: {
requestFilter: function (type, request) {
if (type === RequestType.MANIFEST) {
return new Promise(resolve => {
request.url += '?test';
resolve(request);
});
}
}
}
})
);
const httpFetchRequest = url => {
try {
url.indexOf('?test').should.be.gt(-1);
done();
} catch (e) {
done(e);
}
};
shaka.net.NetworkingEngine.registerScheme('http', httpFetchRequest, shaka.net.NetworkingEngine.PluginPriority.PREFERRED);
shaka.net.NetworkingEngine.registerScheme('https', httpFetchRequest, shaka.net.NetworkingEngine.PluginPriority.PREFERRED);
dashInstance.load();
});
});
});

describe('DashAdapter: response filter', () => {
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2825,7 +2825,7 @@ elliptic@^6.0.0, elliptic@^6.5.2:
minimalistic-assert "^1.0.0"
minimalistic-crypto-utils "^1.0.0"

eme-encryption-scheme-polyfill@^2.0.0:
eme-encryption-scheme-polyfill@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/eme-encryption-scheme-polyfill/-/eme-encryption-scheme-polyfill-2.0.1.tgz#b080b01bffd74c75c9cf8044c1cabedf3b83954f"
integrity sha512-Wz+Ro1c0/2Wsx2RLFvTOO0m4LvYn+7cSnq3XOvRvLLBq8jbvUACH/zpU9s0/5+mQa5oaelkU69x+q0z/iWYrFA==
Expand Down Expand Up @@ -6837,12 +6837,12 @@ sha.js@^2.4.0, sha.js@^2.4.8:
inherits "^2.0.1"
safe-buffer "^5.0.1"

shaka-player@2.5.9:
version "2.5.9"
resolved "https://registry.yarnpkg.com/shaka-player/-/shaka-player-2.5.9.tgz#007dc19df2bb5d3d959d278b2d894af05adffe38"
integrity sha512-XavLBqxvIbvLOPfk7VKZu5fbMJyVko9bBfzxmMWdX5bvQwUSjU7ZhV8v2tHqXQYafpHml1hlGHzKkLs7idouNQ==
shaka-player@3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/shaka-player/-/shaka-player-3.0.2.tgz#f8d21e8af11a654bc26dcb5d34e2e674912ea947"
integrity sha512-GOVSnktrsRFS7dGPULDuk3fYwvht7MrNGaAD51XYQ2NhEE6x/cdO4P0x6aIp/9+83EJgSDdo/uvvaLUtOxSe7g==
dependencies:
eme-encryption-scheme-polyfill "^2.0.0"
eme-encryption-scheme-polyfill "^2.0.1"

shallow-clone@^3.0.0:
version "3.0.1"
Expand Down

0 comments on commit 3c3b05b

Please sign in to comment.