Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for offline data with an online license request #878

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ shaka.offline.Storage.prototype.remove = function(content) {
drmEngine = new shaka.media.DrmEngine(
netEngine, onError, function() {}, function() {});
drmEngine.configure(this.player_.getConfiguration().drm);
return drmEngine.init(manifest, true /* isOffline */);
return drmEngine.init(
manifest, this.config_.isPersistentLicense /* isOffline */);
})
.bind(this)).then(function() {
return drmEngine.removeSessions(manifestDb.sessionIds);
Expand Down Expand Up @@ -422,7 +423,8 @@ shaka.offline.Storage.prototype.loadInternal = function(
drmEngine = new shaka.media.DrmEngine(
netEngine, onError, onKeyStatusChange, function() {});
drmEngine.configure(config.drm);
return drmEngine.init(manifest, true /* isOffline */);
return drmEngine.init(
manifest, this.config_.isPersistentLicense /* isOffline */);
}.bind(this))
.then(function() {
this.checkDestroyed_();
Expand Down Expand Up @@ -567,7 +569,8 @@ shaka.offline.Storage.prototype.defaultConfig_ = function() {
// NOTE: Chrome App Content Security Policy prohibits usage of new
// Function().
if (storedContent || percent) return null;
}
},
isPersistentLicense: true
};
};

Expand Down Expand Up @@ -706,7 +709,7 @@ shaka.offline.Storage.prototype.createOfflineManifest_ = function(
size: 0,
expiration: this.drmEngine_.getExpiration(),
periods: periods,
sessionIds: sessions,
sessionIds: this.config_.isPersistentLicense ? sessions : [],
drmInfo: drmInfo,
appMetadata: appMetadata
};
Expand Down
39 changes: 39 additions & 0 deletions test/offline/offline_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,43 @@ describe('Offline', function() {
.catch(fail)
.then(done);
});

drm_it(
'stores, plays, and deletes protected content with a temporary license',
function(done) {
if (!support['offline'] ||
!support.drm['com.widevine.alpha']) {
pending('Offline storage not supported');
}

shaka.test.TestScheme.setupPlayer(player, 'sintel-enc');

var storedContent;
storage.configure({ isPersistentLicense: false });
storage.store('test:sintel-enc')
.then(function(content) {
storedContent = content;
expect(storedContent.offlineUri).toBe('offline:0');
return player.load(storedContent.offlineUri);
})
.then(function() {
video.play();
return shaka.test.Util.delay(5);
})
.then(function() { return dbEngine.get('manifest', 0); })
.then(function(manifestDb) {
expect(manifestDb.sessionIds.length).toEqual(0);

expect(video.currentTime).toBeGreaterThan(3);
expect(video.ended).toBe(false);
return player.unload();
})
.then(function() { return storage.remove(storedContent); })
.then(function() { return dbEngine.get('manifest', 0); })
.then(function(manifestDb) {
expect(manifestDb).toBeFalsy();
})
.catch(fail)
.then(done);
});
});
49 changes: 49 additions & 0 deletions test/offline/storage_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,37 @@ describe('Storage', function() {
}).catch(fail).then(done);
});
}); // describe('default track selection callback')

describe('temporary license', function() {
var drmInfo;

beforeEach(function() {
drmInfo = {
keySystem: 'com.example.abc',
licenseServerUri: 'http://example.com',
persistentStateRequire: false,
audioRobustness: 'HARDY'
};
drmEngine.setDrmInfo(drmInfo);
drmEngine.setSessionIds(['abcd']);
storage.configure({ isPersistentLicense: false });
});

it('does not store offline sessions', function(done) {
storage.store('')
.then(function(data) {
expect(data.offlineUri).toBe('offline:0');
return fakeStorageEngine.get('manifest', 0);
})
.then(function(manifestDb) {
expect(manifestDb).toBeTruthy();
expect(manifestDb.drmInfo).toEqual(drmInfo);
expect(manifestDb.sessionIds.length).toEqual(0);
})
.catch(fail)
.then(done);
});
}); // describe('temporary license')
}); // describe('store')

describe('remove', function() {
Expand Down Expand Up @@ -963,6 +994,24 @@ describe('Storage', function() {
.then(done);
});

it('will delete content with a temporary license', function(done) {
storage.configure({ isPersistentLicense: false });
var manifestId = 0;
createAndInsertSegments(manifestId, 5)
.then(function(refs) {
var manifest = createManifest(manifestId);
manifest.periods[0].streams.push({segments: refs});
return fakeStorageEngine.insert('manifest', manifest);
})
.then(function() {
expectDatabaseCount(1, 5);
return removeManifest(manifestId);
})
.then(function() { expectDatabaseCount(0, 0); })
.catch(fail)
.then(done);
});

it('will not delete other manifest\'s segments', function(done) {
var manifestId1 = 1;
var manifestId2 = 2;
Expand Down