<commit_before>
define(["jquery", "util", "session", "elementFinder"],
    function($, util, session, elementFinder){

    var returnMe = util.Module("videos"),
    listeners = {},
    TIME_UPDATE = 'timeupdate',
    MIRRORED_EVENTS = ['play', 'pause'],
    SYNC_CHECK = 4000,
    TOO_FAR_APART = 3000;


    function getEventSender (eventName) {
        return function (event) {
            var element = event.target;
            session.send({
                type: ('video-'+eventName),
                //'this' should refer to the video element grabbed by
                //jquery, but watch out for this
                location: elementFinder.elementLocation(element),
                position: element.currentTime
            });
        }
    };

    function setupMirroredEvents (videos) {
        var currentListener;
        MIRRORED_EVENTS.forEach(function (eventName) {
            currentListener = getEventSender(eventName);
            videos.on(eventName, currentListener);
            listeners[eventName] = currentListener;
        });
    };

    //all clo
    function getTimeUpdater () {
        var last = 0;
        return function (){
            var currentTime = event.target.currentTime;
            if(areTooFarApart(currentTime, last)){
                getEventSender(TIME_UPDATE)(event);
            }
            last = currentTime;
        };
    };

    function setupTimeSync (videos) {
        var onTimeUpdate = getTimeUpdater();
        videos.on(TIME_UPDATE, onTimeUpdate);
        listeners[TIME_UPDATE] = onTimeUpdate;
    };

    function setInit () {
        var videos = $('video');
        setupMirroredEvents(videos);
        setupTimeSync(videos);
    };

    function destroyTrackers () {
        var videos = $('video');
        Object.keys(listeners).forEach(function (eventName) {
            videos.off(eventName, listeners[eventName])
        });
        listeners = {};
    };


    function setTime (video, time) {
        video.prop('currentTime', time);
    }

    function areTooFarApart (currentTime, lastTime) {
        var secDiff = Math.abs(currentTime - lastTime),
        milliDiff = secDiff * 1000;
        return milliDiff > TOO_FAR_APART;
    }

    session.on("reinitialize", setInit);

    session.on("ui-ready", setInit);

    session.on("close", destroyTrackers);


    session.hub.on('video-timeupdate', function (msg) {
        var element = elementFinder.findElement(msg.position),
        onTimeUpdate = listeners[TIME_UPDATE],
        oldTime = element.prop('currentTime'),
        newTime = msg.position;

        //to help throttle uneccesary position changes
        if areTooFarApart(oldTime, newTime){
            element.prop('currentTime', msg.position);
        };
    })

    MIRRORED_EVENTS.forEach( function (eventName) {
        session.hub.on("video-"+eventName, function (msg) {
            var element = elementFinder.findElement(msg.location),
            state = lookupState(msg);
            setTime(element, msg.position);
            //UI tested in chromium:
            //this won't trigger an infinite event loop
            element.trigger(eventName);
        });
    })


    return returnMe;

})
<commit_msg>wrap up if statement, use setTime function<commit_after>
define(["jquery", "util", "session", "elementFinder"],
    function($, util, session, elementFinder){

    var returnMe = util.Module("videos"),
    listeners = {},
    TIME_UPDATE = 'timeupdate',
    MIRRORED_EVENTS = ['play', 'pause'],
    SYNC_CHECK = 4000,
    TOO_FAR_APART = 3000;


    function getEventSender (eventName) {
        return function (event) {
            var element = event.target;
            session.send({
                type: ('video-'+eventName),
                //'this' should refer to the video element grabbed by
                //jquery, but watch out for this
                location: elementFinder.elementLocation(element),
                position: element.currentTime
            });
        }
    };

    function setupMirroredEvents (videos) {
        var currentListener;
        MIRRORED_EVENTS.forEach(function (eventName) {
            currentListener = getEventSender(eventName);
            videos.on(eventName, currentListener);
            listeners[eventName] = currentListener;
        });
    };

    //all clo
    function getTimeUpdater () {
        var last = 0;
        return function (){
            var currentTime = event.target.currentTime;
            if(areTooFarApart(currentTime, last)){
                getEventSender(TIME_UPDATE)(event);
            }
            last = currentTime;
        };
    };

    function setupTimeSync (videos) {
        var onTimeUpdate = getTimeUpdater();
        videos.on(TIME_UPDATE, onTimeUpdate);
        listeners[TIME_UPDATE] = onTimeUpdate;
    };

    function setInit () {
        var videos = $('video');
        setupMirroredEvents(videos);
        setupTimeSync(videos);
    };

    function destroyTrackers () {
        var videos = $('video');
        Object.keys(listeners).forEach(function (eventName) {
            videos.off(eventName, listeners[eventName])
        });
        listeners = {};
    };


    function setTime (video, time) {
        video.prop('currentTime', time);
    }

    function areTooFarApart (currentTime, lastTime) {
        var secDiff = Math.abs(currentTime - lastTime),
        milliDiff = secDiff * 1000;
        return milliDiff > TOO_FAR_APART;
    }

    session.on("reinitialize", setInit);

    session.on("ui-ready", setInit);

    session.on("close", destroyTrackers);


    session.hub.on('video-timeupdate', function (msg) {
        var element = elementFinder.findElement(msg.position),
        onTimeUpdate = listeners[TIME_UPDATE],
        oldTime = element.prop('currentTime'),
        newTime = msg.position;

        //to help throttle uneccesary position changes
        if(areTooFarApart(oldTime, newTime)){
            setTime(element, msg.position);
        };
    })

    MIRRORED_EVENTS.forEach( function (eventName) {
        session.hub.on("video-"+eventName, function (msg) {
            var element = elementFinder.findElement(msg.location),
            state = lookupState(msg);
            setTime(element, msg.position);
            //UI tested in chromium:
            //this won't trigger an infinite event loop
            element.trigger(eventName);
        });
    })


    return returnMe;

})

{'fraction_non_alphanumeric': 0.11426797081198571, 'fraction_numerical': 0.004036640273249495, 'mean_word_length': 2.1749630359783145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5587610', 'n_tokens_mistral': 1838, 'n_tokens_neox': 1755, 'n_words': 377}