forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Ad 1645 - Completed init method #11
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7112184
Finished init for videojs provider
AnirudhRahul 59bbb95
Setup videojs init unit tests
AnirudhRahul 7e5682b
Formatting to pass linter
AnirudhRahul d7e45db
Removed comments/redundant tests, clarified some sections of code
AnirudhRahul 573af87
Added semicolon
AnirudhRahul 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
This file contains hidden or 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 |
---|---|---|
|
@@ -140,4 +140,4 @@ export function pbVideoFactory() { | |
return pbVideo; | ||
} | ||
|
||
pbVideoFactory(); | ||
pbVideoFactory(); |
This file contains hidden or 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 |
---|---|---|
@@ -1,14 +1,3 @@ | ||
import { | ||
PROTOCOLS, API_FRAMEWORKS, VIDEO_MIME_TYPE, PLAYBACK_METHODS, PLACEMENT, VPAID_MIME_TYPE | ||
} from './videoModule/constants/ortb.js'; | ||
import { | ||
SETUP_COMPLETE, SETUP_FAILED, DESTROYED, AD_REQUEST, AD_BREAK_START, AD_LOADED, AD_STARTED, AD_IMPRESSION, AD_PLAY, | ||
AD_TIME, AD_PAUSE, AD_CLICK, AD_SKIPPED, AD_ERROR, AD_COMPLETE, AD_BREAK_END, PLAYLIST, PLAYBACK_REQUEST, | ||
AUTOSTART_BLOCKED, PLAY_ATTEMPT_FAILED, CONTENT_LOADED, PLAY, PAUSE, BUFFER, TIME, SEEK_START, SEEK_END, MUTE, VOLUME, | ||
RENDITION_UPDATE, ERROR, COMPLETE, PLAYLIST_COMPLETE, FULLSCREEN, PLAYER_RESIZE, VIEWABLE, CAST, PLAYBACK_MODE | ||
} from './videoModule/constants/events.js'; | ||
import stateFactory from './videoModule/shared/state.js'; | ||
import { adStateFactory, timeStateFactory, callbackStorageFactory} from './jwplayerVideoProvider.js'; | ||
import { VIDEO_JS_VENDOR } from './videoModule/constants/vendorCodes.js'; | ||
import { videoVendorDirectory } from './videoModule/vendorDirectory.js'; | ||
|
||
|
@@ -18,62 +7,40 @@ export function VideojsProvider(config, videojs_, adState_, timeState_, callback | |
let playerVersion = null; | ||
const {playerConfig, divId} = config; | ||
|
||
let adState = adState_; | ||
let timeState = timeState_; | ||
let callbackStorage = callbackStorage_; | ||
let minimumSupportedPlayerVersion = 'v7.17.0'; | ||
|
||
// TODO: test with older videojs versions | ||
let minimumSupportedPlayerVersion = '7.17.0'; | ||
|
||
function init() { | ||
console.log("Initialized videojs provider") | ||
|
||
if (!videojs) { | ||
triggerSetupFailure(-1); // TODO: come up with code for player absent | ||
// TODO: come up with code for player absent | ||
return; | ||
} | ||
|
||
// playerVersion = videojs.version; | ||
playerVersion = videojs.VERSION; | ||
|
||
// if (playerVersion < minimumSupportedPlayerVersion) { | ||
// triggerSetupFailure(-2); // TODO: come up with code for version not supported | ||
// return; | ||
// } | ||
if (playerVersion < minimumSupportedPlayerVersion) { | ||
// TODO: come up with code for version not supported | ||
return; | ||
} | ||
|
||
// player = videojs(divId); | ||
// if (player.getState() === undefined) { | ||
// setupPlayer(playerConfig); | ||
// } else { | ||
// setupCompleteCallback && setupCompleteCallback(SETUP_COMPLETE, getSetupCompletePayload()); | ||
// } | ||
// returns the player if it exists, or attempts to instantiate a new one | ||
player = videojs(divId, playerConfig, function() { | ||
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. in either case, is the callback called ? |
||
// callback runs in both cases | ||
}); | ||
} | ||
|
||
function getId() { | ||
return divId; | ||
} | ||
|
||
function getOrtbParams() { | ||
console.log("Requested ortb params") | ||
// if (!player) { | ||
// return; | ||
// } | ||
// const config = player.getConfig(); | ||
// const adConfig = config.advertising || {}; | ||
supportedMediaTypes = supportedMediaTypes || utils.getSupportedMediaTypes(MEDIA_TYPES); | ||
|
||
const video = { | ||
mimes: [], | ||
w: 0, | ||
w: 0, | ||
h: 0, | ||
}; | ||
|
||
const content = { | ||
id: item.mediaid, | ||
url: item.file, | ||
title: item.title, | ||
cat: item.iabCategories, | ||
keywords: item.tags, | ||
len: duration, | ||
}; | ||
const content = {}; | ||
|
||
return { | ||
video, | ||
|
@@ -82,24 +49,15 @@ export function VideojsProvider(config, videojs_, adState_, timeState_, callback | |
} | ||
|
||
function setAdTagUrl(adTagUrl, options) { | ||
console.log("Set ad tag url:", adTagUrl) | ||
// if (!player) { | ||
// return; | ||
// } | ||
// player.playAd(adTagUrl || options.adXml, options); | ||
} | ||
|
||
function onEvents(events, callback) { | ||
console.log("Added callback for", events) | ||
} | ||
|
||
function offEvents(events, callback) { | ||
console.log("Removed callback for", events) | ||
|
||
} | ||
|
||
function destroy() { | ||
console.log("Destroying player") | ||
if (!player) { | ||
return; | ||
} | ||
|
@@ -118,15 +76,15 @@ export function VideojsProvider(config, videojs_, adState_, timeState_, callback | |
}; | ||
} | ||
|
||
|
||
|
||
const videojsSubmoduleFactory = function (config) { | ||
const adState = adStateFactory(); | ||
const timeState = timeStateFactory(); | ||
const callbackStorage = callbackStorageFactory(); | ||
return VideojsProvider(config, null, adState, timeState, callbackStorage, {}); | ||
const adState = null; | ||
const timeState = null; | ||
const callbackStorage = null; | ||
// videojs factory is stored to window by default | ||
const vjs = window.videojs | ||
return VideojsProvider(config, vjs, adState, timeState, callbackStorage, {}); | ||
} | ||
videojsSubmoduleFactory.vendorCode = VIDEO_JS_VENDOR; | ||
|
||
videoVendorDirectory[VIDEO_JS_VENDOR] = videojsSubmoduleFactory; | ||
export default videojsSubmoduleFactory; | ||
export default videojsSubmoduleFactory; |
78 changes: 78 additions & 0 deletions
78
test/spec/modules/videoModule/submodules/videojsVideoProvier_spec.js
This file contains hidden or 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,78 @@ | ||
import { | ||
VideojsProvider | ||
} from 'modules/videojsVideoProvider'; | ||
|
||
function videojsMock(overrides) { | ||
const players = {} | ||
const vjs = function(id) { | ||
if (!players[id]) { | ||
players[id] = { | ||
controls: function() {}, | ||
getViewable: function () {}, | ||
getPercentViewable: function () {}, | ||
getMute: function () {}, | ||
volume: function () {}, | ||
getConfig: function () {}, | ||
videoHeight: function () {}, | ||
videoWidth: function () {}, | ||
getFullscreen: function () {}, | ||
getPlaylistItem: function () {}, | ||
playAd: function () {}, | ||
on: function () {}, | ||
off: function () {}, | ||
remove: function () {}, | ||
...overrides | ||
} | ||
} | ||
return players[id] | ||
}; | ||
vjs.players = players | ||
vjs.version = '7.17.0'; | ||
return vjs; | ||
} | ||
|
||
describe('videojsProvider', function () { | ||
describe('init', function () { | ||
let config; | ||
let adState; | ||
let timeState; | ||
let callbackStorage; | ||
let utilsMock; | ||
|
||
beforeEach(() => { | ||
config = {}; | ||
// adState = adStateFactory(); | ||
// timeState = timeStateFactory(); | ||
// callbackStorage = callbackStorageFactory(); | ||
utilsMock = null; | ||
}); | ||
|
||
it('should trigger failure when videojs is missing', function () { | ||
// TODO: Implement when callbacks are added | ||
}); | ||
|
||
it('should trigger failure when videojs version is under min supported version', function () { | ||
// TODO: Implement when callbacks are added | ||
}); | ||
|
||
it('should instantiate the player when uninstantied', function () { | ||
config.playerConfig = {}; | ||
config.divId = 'test-div' | ||
const videojs = videojsMock(); | ||
const provider = VideojsProvider(config, videojs, adState, timeState, callbackStorage, utilsMock); | ||
provider.init(); | ||
expect(videojs.players['test-div']).to.be.an('object') | ||
}); | ||
|
||
it('should trigger setup complete when player is already instantied', function () { | ||
// TODO: Implement when callbacks are added | ||
}); | ||
}); | ||
|
||
describe('getId', function () { | ||
it('should return configured div id', function () { | ||
const provider = VideojsProvider({ divId: 'test_id' }); | ||
expect(provider.getId()).to.be.equal('test_id'); | ||
}); | ||
}); | ||
}); |
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.
Uh oh!
There was an error while loading. Please reload this page.