-
Notifications
You must be signed in to change notification settings - Fork 51
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
feat(kaltura player): export setup method #2
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e4bcc71
export create player api
yairans 12b837a
chore: update dist
yairans 6b92a59
remove player from window on error
yairans 317244d
jsdoc
yairans f46deaa
chore: update dist
yairans 65041e9
change create to setup
yairans c3f1c7d
chore: update dist
yairans File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,30 @@ | ||
//@flow | ||
import * as Playkit from 'playkit-js'; | ||
import OvpProvider from 'playkit-js-providers/dist/ovpProvider'; | ||
import handleSessionId from './session-id' | ||
|
||
/** | ||
* | ||
* @param {Object} config - contains partnerId and entryID | ||
* @return {Promise<*>} - player promise | ||
*/ | ||
function create(config: Object): Promise<*> { | ||
let player = Playkit.playkit(); | ||
player.addEventListener(player.Event.SOURCE_SELECTED, (event) => { | ||
handleSessionId(event.payload.selectedSource, player); | ||
}); | ||
if (config) { | ||
let provider = new OvpProvider(config.partnerId); | ||
return provider.getConfig(config.entryID) | ||
.then(data => { | ||
player.configure(data); | ||
return Promise.resolve(player); | ||
}).catch(error => { | ||
return Promise.reject(error); | ||
}); | ||
} else { | ||
return Promise.resolve(player); | ||
} | ||
} | ||
|
||
export default create; |
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 |
---|---|---|
|
@@ -14,7 +14,8 @@ import '../node_modules/playkit-js-ui/src/styles/style.css'; | |
import 'playkit-js-hls'; | ||
import 'playkit-js-dash'; | ||
|
||
import create from './create' | ||
// TODO: Import plugins | ||
|
||
export {Playkit, OvpProvider, PlaykitUI}; | ||
export {Playkit, OvpProvider, PlaykitUI, create}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
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 @@ | ||
//@flow | ||
/** | ||
* @return {string} - GUID | ||
* @private | ||
*/ | ||
function _generateGUID(): string { | ||
let S4 = () => { | ||
return (((1+Math.random())*0x10000)|0).toString(16).substring(1); | ||
}; | ||
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()); | ||
} | ||
|
||
/** | ||
* @param {Object} selectedSource - selected source | ||
* @param {Player} player - player | ||
* @return {void} | ||
* @private | ||
*/ | ||
function _addSessionId(selectedSource: Object, player: Player): void { | ||
let delimiter = selectedSource.url.indexOf('?') === -1 ? '?' : '&'; | ||
let primaryGUID = _generateGUID(); | ||
let secondGUID = _generateGUID(); | ||
let sessionId = primaryGUID + ':' + secondGUID; | ||
selectedSource.url += delimiter + 'playSessionId=' + sessionId; | ||
player.sessionId = sessionId; | ||
} | ||
|
||
/** | ||
* @param {Object} selectedSource - selected source | ||
* @param {string} sessionId - session id | ||
* @param {Player} player - player | ||
* @return {void} | ||
* @private | ||
*/ | ||
function _replaceSecondGUID(selectedSource: Object, sessionId: string, player: Player): void { | ||
let secondGUIDRegex = /:((?:[a-z0-9]|-)*)/i; | ||
let secondGUID = secondGUIDRegex.exec(sessionId); | ||
if (secondGUID && secondGUID[1]) { | ||
let newSessionId = sessionId.replace(secondGUID[1], _generateGUID()); | ||
selectedSource.url = selectedSource.url.replace(sessionId, newSessionId); | ||
player.sessionId = newSessionId; | ||
} | ||
} | ||
|
||
/** | ||
* @param {Object} selectedSource - selected source | ||
* @param {Player} player - player | ||
* @return {void} | ||
* @public | ||
*/ | ||
function handleSessionId(selectedSource: Object = {}, player: Player): void { | ||
if (typeof selectedSource.url === 'string' && selectedSource.url.toLowerCase().indexOf('playmanifest/') !== -1) { | ||
let sessionIdRegex = /playSessionId=((?:[a-z0-9]|-|:)*)/i; | ||
let sessionId = sessionIdRegex.exec(selectedSource.url); | ||
if (sessionId && sessionId[1]) { | ||
_replaceSecondGUID(selectedSource, sessionId[1], player); | ||
} else { | ||
_addSessionId(selectedSource, player); | ||
} | ||
} | ||
} | ||
|
||
export default handleSessionId |
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,53 @@ | ||
import handleSessionId from '../../src/session-id' | ||
|
||
describe('handleSessionId', function () { | ||
|
||
it('should add session id for playManifest source', function () { | ||
let selectedSource = {url: 'a/b/c/playmanifest/source'}; | ||
let player = {}; | ||
handleSessionId(selectedSource, player); | ||
selectedSource.url.should.be.equal('a/b/c/playmanifest/source?playSessionId=' + player.sessionId); | ||
}); | ||
|
||
it('should add session id for playManifest source with query param', function () { | ||
let selectedSource = {url: 'a/b/c/playmanifest/source?a'}; | ||
let player = {}; | ||
handleSessionId(selectedSource, player); | ||
selectedSource.url.should.be.equal('a/b/c/playmanifest/source?a&playSessionId=' + player.sessionId); | ||
}); | ||
|
||
it('should add session id for PLAYMANIFEST source', function () { | ||
let selectedSource = {url: 'a/b/c/PLAYMANIFEST/source'}; | ||
let player = {}; | ||
handleSessionId(selectedSource, player); | ||
selectedSource.url.should.be.equal('a/b/c/PLAYMANIFEST/source?playSessionId=' + player.sessionId); | ||
}); | ||
|
||
it('should add session id for PLAYMANIFEST source with query param', function () { | ||
let selectedSource = {url: 'a/b/c/PLAYMANIFEST/source?a'}; | ||
let player = {}; | ||
handleSessionId(selectedSource, player); | ||
selectedSource.url.should.be.equal('a/b/c/PLAYMANIFEST/source?a&playSessionId=' + player.sessionId); | ||
}); | ||
|
||
it('should not add session id for no playManifest source', function () { | ||
let selectedSource = {url: 'a/b/c'}; | ||
let player = {}; | ||
handleSessionId(selectedSource, player); | ||
selectedSource.url.should.be.equal('a/b/c'); | ||
}); | ||
|
||
it('should replace the second GUID for existing session id as first query param', function () { | ||
let selectedSource = {url: 'a/b/c/playmanifest/source?playSessionId=8a18888e-4110-d61b-5285-c601c51b70e3:b892a45b-23dc-7f3b-0ca1-5381a88e0c81&a'}; | ||
let player = {}; | ||
handleSessionId(selectedSource, player); | ||
selectedSource.url.should.be.equal('a/b/c/playmanifest/source?playSessionId=8a18888e-4110-d61b-5285-c601c51b70e3' + player.sessionId.substr(player.sessionId.indexOf(':')) + '&a'); | ||
}); | ||
|
||
it('should replace the second GUID for existing session id as second query param', function () { | ||
let selectedSource = {url: 'a/b/c/playmanifest/source?a&playSessionId=8a18888e-4110-d61b-5285-c601c51b70e3:b892a45b-23dc-7f3b-0ca1-5381a88e0c81'}; | ||
let player = {}; | ||
handleSessionId(selectedSource, player); | ||
selectedSource.url.should.be.equal('a/b/c/playmanifest/source?a&playSessionId=8a18888e-4110-d61b-5285-c601c51b70e3' + player.sessionId.substr(player.sessionId.indexOf(':'))); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently don't pass the
config
data we pass tocreate
method to theplaykit.configure
, which can contain player config as well as config to the provider.Need to handle the entire config object that we defined for playkit