-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dan Ziv
committed
Aug 28, 2017
1 parent
e36809b
commit a844b81
Showing
9 changed files
with
680 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// @flow | ||
import {BaseDrmProtocol} from 'playkit-js' | ||
|
||
const DrmSupport = BaseDrmProtocol.DrmSupport; | ||
const DrmScheme = BaseDrmProtocol.DrmScheme; | ||
|
||
export default class PlayReady extends BaseDrmProtocol { | ||
static _logger = BaseDrmProtocol.getLogger('PlayReady'); | ||
|
||
/** | ||
* PlayReady playback supports in case 2 conditions are met: | ||
* 1. The environment supports PlayReady playback. | ||
* 2. The drm data of the source object contains entry with PlayReady scheme. | ||
* @param {Array<Object>} drmData - The drm data to check. | ||
* @return {boolean} - Whether FairPlay can be play on the current environment. | ||
*/ | ||
static canPlayDrm(drmData: Array<Object>): boolean { | ||
PlayReady._logger.debug("Can play DRM scheme of: " + DrmScheme.PLAYREADY); | ||
return DrmSupport.isProtocolSupported(DrmScheme.PLAYREADY, drmData); | ||
} | ||
|
||
/** | ||
* Sets the PlayReady playback. | ||
* @param {Object} config - The shaka player config. | ||
* @param {Array<Object>} drmData - The drm data. | ||
* @returns {void} | ||
*/ | ||
static setDrmPlayback(config: Object, drmData: Array<Object>): void { | ||
PlayReady._logger.debug("Sets drm playback"); | ||
let prDrmEntry = drmData.find((drmEntry) => drmEntry.scheme === DrmScheme.PLAYREADY); | ||
if (prDrmEntry) { | ||
config.drm = { | ||
servers: { | ||
[DrmScheme.PLAYREADY]: prDrmEntry.licenseUrl | ||
} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// @flow | ||
import {BaseDrmProtocol, Env} from 'playkit-js' | ||
|
||
const DrmSupport = BaseDrmProtocol.DrmSupport; | ||
const DrmScheme = BaseDrmProtocol.DrmScheme; | ||
|
||
export default class Widevine extends BaseDrmProtocol { | ||
static _logger = BaseDrmProtocol.getLogger('Widevine'); | ||
|
||
/** | ||
* Widevine playback supports in case 2 conditions are met: | ||
* 1. The environment supports Widevine playback. | ||
* 2. The drm data of the source object contains entry with Widevine scheme. | ||
* @param {Array<Object>} drmData - The drm data to check. | ||
* @return {boolean} - Whether FairPlay can be play on the current environment. | ||
*/ | ||
static canPlayDrm(drmData: Array<Object>): boolean { | ||
Widevine._logger.debug("Can play DRM scheme of: " + DrmScheme.WIDEVINE); | ||
return DrmSupport.isProtocolSupported(DrmScheme.WIDEVINE, drmData); | ||
} | ||
|
||
/** | ||
* Sets the Widevine playback. | ||
* @param {Object} config - The shaka player config. | ||
* @param {Array<Object>} drmData - The drm data. | ||
* @returns {void} | ||
*/ | ||
static setDrmPlayback(config: Object, drmData: Array<Object>): void { | ||
Widevine._logger.debug("Sets drm playback"); | ||
let browser = Env.browser.name; | ||
let wwDrmEntry = drmData.find((drmEntry) => drmEntry.scheme === DrmScheme.WIDEVINE); | ||
if (wwDrmEntry) { | ||
config.drm = { | ||
servers: { | ||
[DrmScheme.WIDEVINE]: wwDrmEntry.licenseUrl | ||
}, | ||
advanced: {} | ||
}; | ||
if (browser === 'Chrome') { | ||
config.drm.advanced = { | ||
[DrmScheme.WIDEVINE]: { | ||
'videoRobustness': 'SW_SECURE_CRYPTO', | ||
'audioRobustness': 'SW_SECURE_CRYPTO' | ||
} | ||
}; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {BaseDrmProtocol} from 'playkit-js' | ||
|
||
export const wwDrmData = [{ | ||
licenseUrl: 'LICENSE_URL', | ||
scheme: BaseDrmProtocol.DrmScheme.WIDEVINE | ||
}]; | ||
|
||
export const prDrmData = [{ | ||
licenseUrl: 'LICENSE_URL', | ||
scheme: BaseDrmProtocol.DrmScheme.PLAYREADY | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import PlayReady from '../../../src/drm/playready' | ||
import {BaseDrmProtocol, Env} from 'playkit-js' | ||
import {wwDrmData, prDrmData} from './fake-drm-data' | ||
|
||
const DrmSupport = BaseDrmProtocol.DrmSupport; | ||
const DrmScheme = BaseDrmProtocol.DrmScheme; | ||
const BROWSER: string = Env.browser.name; | ||
|
||
function isValidEnvForPlayReady() { | ||
return (BROWSER === 'Edge' || BROWSER === 'IE') | ||
&& (DrmSupport._Browsers['Edge']() === DrmScheme.PLAYREADY | ||
|| DrmSupport._Browsers['IE']() === DrmScheme.PLAYREADY); | ||
} | ||
|
||
describe('PlayReady', function () { | ||
describe('canPlayDrm', function () { | ||
it('should return true for playready data on valid playready env and false otherwise', function () { | ||
if (isValidEnvForPlayReady()) { | ||
PlayReady.canPlayDrm(prDrmData).should.be.true; | ||
} else { | ||
PlayReady.canPlayDrm(prDrmData).should.be.false; | ||
} | ||
}); | ||
|
||
it('should return false for non-playready data any case', function () { | ||
PlayReady.canPlayDrm(wwDrmData).should.be.false; | ||
}); | ||
}); | ||
|
||
describe('setDrmPlayback', function () { | ||
let config = {}; | ||
let expectedConfig = { | ||
drm: { | ||
servers: { | ||
[DrmScheme.PLAYREADY]: prDrmData[0].licenseUrl | ||
} | ||
} | ||
}; | ||
|
||
afterEach(function () { | ||
config = {}; | ||
}); | ||
|
||
it('sets the correct shaka drm config for playready data', function () { | ||
PlayReady.setDrmPlayback(config, prDrmData); | ||
config.should.deep.equal(expectedConfig); | ||
}); | ||
|
||
it('sets nothing for non-playready data', function () { | ||
PlayReady.setDrmPlayback(config, wwDrmData); | ||
config.should.deep.equal({}); | ||
}); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import Widevine from '../../../src/drm/widevine' | ||
import {BaseDrmProtocol, Env} from 'playkit-js' | ||
import {wwDrmData, prDrmData} from './fake-drm-data' | ||
|
||
const DrmSupport = BaseDrmProtocol.DrmSupport; | ||
const DrmScheme = BaseDrmProtocol.DrmScheme; | ||
const BROWSER: string = Env.browser.name; | ||
|
||
function isValidEnvForWidevine() { | ||
return (BROWSER === 'Chrome' || BROWSER === 'Firefox') | ||
&& (DrmSupport._Browsers['Chrome']() === DrmScheme.WIDEVINE | ||
|| DrmSupport._Browsers['Firefox']() === DrmScheme.WIDEVINE); | ||
} | ||
|
||
describe('Widevine', function () { | ||
describe('canPlayDrm', function () { | ||
it('should return true for widevine data on valid widevine env and false otherwise', function () { | ||
if (isValidEnvForWidevine()) { | ||
Widevine.canPlayDrm(wwDrmData).should.be.true; | ||
} else { | ||
Widevine.canPlayDrm(wwDrmData).should.be.false; | ||
} | ||
}); | ||
|
||
it('should return false for non-widevine data any case', function () { | ||
Widevine.canPlayDrm(prDrmData).should.be.false; | ||
}); | ||
}); | ||
|
||
describe('setDrmPlayback', function () { | ||
let config = {}; | ||
let expectedConfig = { | ||
drm: { | ||
servers: { | ||
[DrmScheme.WIDEVINE]: wwDrmData[0].licenseUrl | ||
} | ||
} | ||
}; | ||
|
||
afterEach(function () { | ||
config = {}; | ||
}); | ||
|
||
it('sets the correct shaka drm config for widevine data', function () { | ||
Widevine.setDrmPlayback(config, wwDrmData); | ||
if (BROWSER === 'Chrome') { | ||
expectedConfig.drm.advanced = { | ||
[DrmScheme.WIDEVINE]: { | ||
'videoRobustness': 'SW_SECURE_CRYPTO', | ||
'audioRobustness': 'SW_SECURE_CRYPTO' | ||
} | ||
}; | ||
} | ||
config.should.deep.equal(expectedConfig); | ||
}); | ||
|
||
it('sets nothing for non-widevine data', function () { | ||
Widevine.setDrmPlayback(config, prDrmData); | ||
config.should.deep.equal({}); | ||
}); | ||
}); | ||
}); | ||
|
Oops, something went wrong.