Skip to content

Commit

Permalink
mickey#12 fix race condition to register events
Browse files Browse the repository at this point in the history
  • Loading branch information
mickey committed Jun 3, 2014
1 parent 507d96b commit ebc4072
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 38 deletions.
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>videojs-ga DEMO</title>
<link href="../libs/video-js-4.6.1/video-js.css" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="../libs/video-js-4.6.1/video.js"></script>
<script src="../libs/video-js-4.6.1/video.dev.js"></script>
<script src="../dist/videojs.ga.js"></script>
</head>

Expand Down
52 changes: 27 additions & 25 deletions dist/videojs.ga.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* videojs-ga - v0.3.1 - 2014-06-02
* videojs-ga - v0.3.1 - 2014-06-04
* Copyright (c) 2014 Michael Bensoussan
* Licensed MIT
*/
Expand Down Expand Up @@ -77,7 +77,7 @@
if (currentTime > 0 && !seeking) {
sendbeacon('play', true, currentTime);
}
seeking = true;
seeking = false;
};
pause = function() {
var currentTime, duration;
Expand Down Expand Up @@ -124,29 +124,31 @@
console.log("Google Analytics not detected");
}
};
this.on("loadedmetadata", loaded);
this.on("timeupdate", timeupdate);
if (__indexOf.call(eventsToTrack, "end") >= 0) {
this.on("ended", end);
}
if (__indexOf.call(eventsToTrack, "play") >= 0) {
this.on("play", play);
}
if (__indexOf.call(eventsToTrack, "pause") >= 0) {
this.on("pause", pause);
}
if (__indexOf.call(eventsToTrack, "volumeChange") >= 0) {
this.on("volumechange", volumeChange);
}
if (__indexOf.call(eventsToTrack, "resize") >= 0) {
this.on("resize", resize);
}
if (__indexOf.call(eventsToTrack, "error") >= 0) {
this.on("error", error);
}
if (__indexOf.call(eventsToTrack, "fullscreen") >= 0) {
this.on("fullscreenchange", fullscreen);
}
this.ready(function() {
this.on("loadedmetadata", loaded);
this.on("timeupdate", timeupdate);
if (__indexOf.call(eventsToTrack, "end") >= 0) {
this.on("ended", end);
}
if (__indexOf.call(eventsToTrack, "play") >= 0) {
this.on("play", play);
}
if (__indexOf.call(eventsToTrack, "pause") >= 0) {
this.on("pause", pause);
}
if (__indexOf.call(eventsToTrack, "volumeChange") >= 0) {
this.on("volumechange", volumeChange);
}
if (__indexOf.call(eventsToTrack, "resize") >= 0) {
this.on("resize", resize);
}
if (__indexOf.call(eventsToTrack, "error") >= 0) {
this.on("error", error);
}
if (__indexOf.call(eventsToTrack, "fullscreen") >= 0) {
return this.on("fullscreenchange", fullscreen);
}
});
});

}).call(this);
4 changes: 2 additions & 2 deletions dist/videojs.ga.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions src/videojs.ga.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ videojs.plugin 'ga', (options = {}) ->
currentTime = Math.round(@currentTime())
if currentTime > 0 && !seeking
sendbeacon( 'play', true, currentTime )
seeking = true
seeking = false
return

pause = ->
Expand Down Expand Up @@ -128,13 +128,14 @@ videojs.plugin 'ga', (options = {}) ->
console.log("Google Analytics not detected")
return

@on("loadedmetadata", loaded)
@on("timeupdate", timeupdate)
@on("ended", end) if "end" in eventsToTrack
@on("play", play) if "play" in eventsToTrack
@on("pause", pause) if "pause" in eventsToTrack
@on("volumechange", volumeChange) if "volumeChange" in eventsToTrack
@on("resize", resize) if "resize" in eventsToTrack
@on("error", error) if "error" in eventsToTrack
@on("fullscreenchange", fullscreen) if "fullscreen" in eventsToTrack
@ready ->
@on("loadedmetadata", loaded)
@on("timeupdate", timeupdate)
@on("ended", end) if "end" in eventsToTrack
@on("play", play) if "play" in eventsToTrack
@on("pause", pause) if "pause" in eventsToTrack
@on("volumechange", volumeChange) if "volumeChange" in eventsToTrack
@on("resize", resize) if "resize" in eventsToTrack
@on("error", error) if "error" in eventsToTrack
@on("fullscreenchange", fullscreen) if "fullscreen" in eventsToTrack
return

0 comments on commit ebc4072

Please sign in to comment.