Commit 83be42ed by muhammad-ammar

once again new logic

parent c4065f7b
...@@ -32,18 +32,19 @@ ...@@ -32,18 +32,19 @@
}); });
}); });
it('can emit "play_video" event when canEmitPlayVideoEvent returns true', function () { it('can emit "play_video" event when emitPlayVideoEvent is true', function () {
spyOn(state.videoPlayer, 'canEmitPlayVideoEvent').andReturn(true); state.videoEventsPlugin.emitPlayVideoEvent = true;
state.el.trigger('play'); state.el.trigger('play');
expect(Logger.log).toHaveBeenCalledWith('play_video', { expect(Logger.log).toHaveBeenCalledWith('play_video', {
id: 'id', id: 'id',
code: 'html5', code: 'html5',
currentTime: 10 currentTime: 10
}); });
expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeFalsy();
}); });
it('can not emit "play_video" event when canEmitPlayVideoEvent returns false', function () { it('can not emit "play_video" event when emitPlayVideoEvent is false', function () {
spyOn(state.videoPlayer, 'canEmitPlayVideoEvent').andReturn(false); state.videoEventsPlugin.emitPlayVideoEvent = false;
state.el.trigger('play'); state.el.trigger('play');
expect(Logger.log).not.toHaveBeenCalled(); expect(Logger.log).not.toHaveBeenCalled();
}); });
...@@ -55,6 +56,7 @@ ...@@ -55,6 +56,7 @@
code: 'html5', code: 'html5',
currentTime: 10 currentTime: 10
}); });
expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeTruthy();
}); });
it('can emit "speed_change_video" event', function () { it('can emit "speed_change_video" event', function () {
...@@ -86,6 +88,7 @@ ...@@ -86,6 +88,7 @@
code: 'html5', code: 'html5',
currentTime: 10 currentTime: 10
}); });
expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeTruthy();
Logger.log.reset(); Logger.log.reset();
state.el.trigger('stop'); state.el.trigger('stop');
...@@ -94,6 +97,7 @@ ...@@ -94,6 +97,7 @@
code: 'html5', code: 'html5',
currentTime: 10 currentTime: 10
}); });
expect(state.videoEventsPlugin.emitPlayVideoEvent).toBeTruthy();
}); });
it('can emit "skip_video" event', function () { it('can emit "skip_video" event', function () {
......
...@@ -5,7 +5,7 @@ require( ...@@ -5,7 +5,7 @@ require(
['video/03_video_player.js'], ['video/03_video_player.js'],
function (VideoPlayer) { function (VideoPlayer) {
describe('VideoPlayer', function () { describe('VideoPlayer', function () {
var state, oldOTBD, Logger = window.Logger, YT = window.YT; var state, oldOTBD;
beforeEach(function () { beforeEach(function () {
oldOTBD = window.onTouchBasedDevice; oldOTBD = window.onTouchBasedDevice;
...@@ -333,46 +333,6 @@ function (VideoPlayer) { ...@@ -333,46 +333,6 @@ function (VideoPlayer) {
expect($.fn.trigger).toHaveBeenCalledWith('ended', {}); expect($.fn.trigger).toHaveBeenCalledWith('ended', {});
}); });
}); });
describe('Video Player', function () {
beforeEach(function () {
state = jasmine.initializePlayer();
state.videoEl = $('video, iframe');
spyOn(Logger, 'log');
});
it('will set emitPlayVideoEvent to false after onPlay is called', function () {
expect(state.videoPlayer.emitPlayVideoEvent).toBeTruthy();
state.videoPlayer.onPlay();
expect(state.videoPlayer.emitPlayVideoEvent).toBeFalsy();
});
it('will set emitPlayVideoEvent to correct value in different states', function () {
// Initially emitPlayVideoEvent should be set to true
expect(state.videoPlayer.emitPlayVideoEvent).toBeTruthy();
/**
* @param {Integer} playerState - New state of the video player.
* @param {Boolean} emitPlayVideoEvent - Expected value of emitPlayVideoEvent after
* video player goes into playerState.
*/
var verifyEmitPlayVideoEventValue = function (playerState, emitPlayVideoEvent) {
state.videoPlayer.onStateChange({
data: playerState
});
expect(state.videoPlayer.emitPlayVideoEvent).toBe(emitPlayVideoEvent);
};
verifyEmitPlayVideoEventValue(YT.PlayerState.BUFFERING, true);
verifyEmitPlayVideoEventValue(YT.PlayerState.PLAYING, false);
verifyEmitPlayVideoEventValue(YT.PlayerState.BUFFERING, false);
verifyEmitPlayVideoEventValue(YT.PlayerState.PLAYING, false);
verifyEmitPlayVideoEventValue(YT.PlayerState.PAUSED, true);
verifyEmitPlayVideoEventValue(YT.PlayerState.PLAYING, false);
verifyEmitPlayVideoEventValue(YT.PlayerState.ENDED, true);
verifyEmitPlayVideoEventValue(YT.PlayerState.PLAYING, false);
});
});
}); });
describe('onSeek Youtube', function(){ describe('onSeek Youtube', function(){
......
...@@ -51,8 +51,7 @@ function (HTML5Video, Resizer) { ...@@ -51,8 +51,7 @@ function (HTML5Video, Resizer) {
update: update, update: update,
figureOutStartEndTime: figureOutStartEndTime, figureOutStartEndTime: figureOutStartEndTime,
figureOutStartingTime: figureOutStartingTime, figureOutStartingTime: figureOutStartingTime,
updatePlayTime: updatePlayTime, updatePlayTime: updatePlayTime
canEmitPlayVideoEvent: canEmitPlayVideoEvent
}; };
VideoPlayer.prototype = methodsDict; VideoPlayer.prototype = methodsDict;
...@@ -129,8 +128,6 @@ function (HTML5Video, Resizer) { ...@@ -129,8 +128,6 @@ function (HTML5Video, Resizer) {
state.videoPlayer.PlayerState = HTML5Video.PlayerState; state.videoPlayer.PlayerState = HTML5Video.PlayerState;
} }
state.videoPlayer.emitPlayVideoEvent = true;
state.videoPlayer.currentTime = 0; state.videoPlayer.currentTime = 0;
state.videoPlayer.goToStartTime = true; state.videoPlayer.goToStartTime = true;
...@@ -201,14 +198,6 @@ function (HTML5Video, Resizer) { ...@@ -201,14 +198,6 @@ function (HTML5Video, Resizer) {
} }
} }
function canEmitPlayVideoEvent() {
if (this.videoPlayer.emitPlayVideoEvent) {
this.videoPlayer.emitPlayVideoEvent = false;
return true;
}
return false;
}
function _updateVcrAndRegion(state, isYoutube) { function _updateVcrAndRegion(state, isYoutube) {
var update = function (state) { var update = function (state) {
var duration = state.videoPlayer.duration(), var duration = state.videoPlayer.duration(),
...@@ -731,7 +720,6 @@ function (HTML5Video, Resizer) { ...@@ -731,7 +720,6 @@ function (HTML5Video, Resizer) {
case this.videoPlayer.PlayerState.PAUSED: case this.videoPlayer.PlayerState.PAUSED:
this.el.addClass('is-paused'); this.el.addClass('is-paused');
this.videoPlayer.onPause(); this.videoPlayer.onPause();
this.videoPlayer.emitPlayVideoEvent = true;
break; break;
case this.videoPlayer.PlayerState.BUFFERING: case this.videoPlayer.PlayerState.BUFFERING:
this.el.addClass('is-buffered'); this.el.addClass('is-buffered');
...@@ -740,7 +728,6 @@ function (HTML5Video, Resizer) { ...@@ -740,7 +728,6 @@ function (HTML5Video, Resizer) {
case this.videoPlayer.PlayerState.ENDED: case this.videoPlayer.PlayerState.ENDED:
this.el.addClass('is-ended'); this.el.addClass('is-ended');
this.videoPlayer.onEnded(); this.videoPlayer.onEnded();
this.videoPlayer.emitPlayVideoEvent = true;
break; break;
case this.videoPlayer.PlayerState.CUED: case this.videoPlayer.PlayerState.CUED:
this.el.addClass('is-cued'); this.el.addClass('is-cued');
......
...@@ -50,6 +50,7 @@ define('video/09_events_plugin.js', [], function() { ...@@ -50,6 +50,7 @@ define('video/09_events_plugin.js', [], function() {
'destroy': this.destroy 'destroy': this.destroy
}; };
this.bindHandlers(); this.bindHandlers();
this.emitPlayVideoEvent = true;
}, },
bindHandlers: function() { bindHandlers: function() {
...@@ -61,17 +62,20 @@ define('video/09_events_plugin.js', [], function() { ...@@ -61,17 +62,20 @@ define('video/09_events_plugin.js', [], function() {
}, },
onPlay: function () { onPlay: function () {
if (this.state.videoPlayer.canEmitPlayVideoEvent()) { if (this.emitPlayVideoEvent) {
this.log('play_video', {currentTime: this.getCurrentTime()}); this.log('play_video', {currentTime: this.getCurrentTime()});
this.emitPlayVideoEvent = false;
} }
}, },
onPause: function () { onPause: function () {
this.log('pause_video', {currentTime: this.getCurrentTime()}); this.log('pause_video', {currentTime: this.getCurrentTime()});
this.emitPlayVideoEvent = true;
}, },
onEnded: function () { onEnded: function () {
this.log('stop_video', {currentTime: this.getCurrentTime()}); this.log('stop_video', {currentTime: this.getCurrentTime()});
this.emitPlayVideoEvent = true;
}, },
onSkip: function (event, doNotShowAgain) { onSkip: function (event, doNotShowAgain) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment