<commit_before>function onPlayerStateChange(event)
{
    if (playerMode != 'admin') {
        return this;
    }

	var params = new Object();
	params.status = event.data;

	if (event.data != 0) {
		params.currentTime = player.getCurrentTime();
		livePlayer.sendParameters(params);
	} else {
		livePlayer.seekNextVideo(params);
	}
}

var livePlayer;
var connection;
var playlistId;
var videoId;

LivePlayer = function()
{
	this.initialize = function(currentPlaylistId)
	{
		playlistId = currentPlaylistId;
		this.getPlaylistScores(currentPlaylistId);

		$('#up-vote a').unbind('click');
		$('#up-vote a').click(function(event) {
			event.preventDefault();
			var playlistId = this.getCurrentPlaylistId();

			$.post(voteUrl, {
				playlist: playlistId,
				vote: 'up',
				current: 1
			}, function(response) {
				this.playlistScoresUpdate(response);
			}.bind(this));
		}.bind(this));

		$('#down-vote a').unbind('click');
		$('#down-vote a').click(function(event) {
			event.preventDefault();
			var playlistId = this.getCurrentPlaylistId();

			$.post(voteUrl, {
				playlist: playlistId,
				vote: 'down',
				current: 1
			}, function(response) {
				this.playlistScoresUpdate(response);
			}.bind(this));
		}.bind(this));
	},

	this.synchronizePlayerState = function(params)
	{
		if (params.action == 'update_scores') {
			var scores = JSON.parse(params.scores);
			this.updatePlaylistScores(scores);
		}

		if (playerMode == 'admin') {
            return this;
        }

        switch(params.status) {
            case 1:
                //this.checkCurrentVideoId(params);

                player.seekTo(params.currentTime);
                player.playVideo();

            break;

            case 2:
                //this.checkCurrentVideoId(params);

                player.seekTo(params.currentTime);
                player.pauseVideo();

            break;

            case 0:
                player.loadVideoById({
                    videoId: params.videoId
                });

                this.initialize(params.playlistId);

            break;
        }
	},

	this.getCurrentPlaylistId = function()
	{
		return playlistId;
	},

	this.getCurrentVideoId = function()
	{
		return videoId;
	},

	this.checkCurrentVideoId = function(params)
	{
		var videoId = this.getCurrentVideoId();
		if (videoId != params.currentVideo) {
			player.loadVideoById({
				videoId: params.currentVideo
			});
		}
	},

	this.seekNextVideo = function(params)
	{
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: nextVideoUrl,
            data: { 'volume' : player.getVolume() }
        }).done(function(data) {
            player.loadVideoById({
                videoId: data.videoId
            });

            player.setVolume(data.videoVolume);

            params.playlistId = data.playlistId;
            params.videoId = data.videoId;

            this.sendParameters(params);

            this.initialize(data.playlistId);
        }.bind(this));
	},

	this.sendParameters = function(params)
	{
		json = JSON.stringify(params);
		connection.send(json);
	},

	this.getPlaylistScores = function(playlistId)
	{
		$.get(scoreUrl, {
			playlist: playlistId<commit_msg>Live - Synchronisation du volume à la fin de chaque vidéo (issue #61)<commit_after>function onPlayerStateChange(event)
{
    if (playerMode != 'admin') {
        return this;
    }

	var params = new Object();
	params.status = event.data;

	if (event.data != 0) {
		params.currentTime = player.getCurrentTime();
		livePlayer.sendParameters(params);
	} else {
		livePlayer.seekNextVideo(params);
	}
}

var livePlayer;
var connection;
var playlistId;
var videoId;

LivePlayer = function()
{
	this.initialize = function(currentPlaylistId)
	{
		playlistId = currentPlaylistId;
		this.getPlaylistScores(currentPlaylistId);

		$('#up-vote a').unbind('click');
		$('#up-vote a').click(function(event) {
			event.preventDefault();
			var playlistId = this.getCurrentPlaylistId();

			$.post(voteUrl, {
				playlist: playlistId,
				vote: 'up',
				current: 1
			}, function(response) {
				this.playlistScoresUpdate(response);
			}.bind(this));
		}.bind(this));

		$('#down-vote a').unbind('click');
		$('#down-vote a').click(function(event) {
			event.preventDefault();
			var playlistId = this.getCurrentPlaylistId();

			$.post(voteUrl, {
				playlist: playlistId,
				vote: 'down',
				current: 1
			}, function(response) {
				this.playlistScoresUpdate(response);
			}.bind(this));
		}.bind(this));
	},

	this.synchronizePlayerState = function(params)
	{
		if (params.action == 'update_scores') {
			var scores = JSON.parse(params.scores);
			this.updatePlaylistScores(scores);
		}

		if (playerMode == 'admin') {
            return this;
        }

        switch(params.status) {
            case 1:
                player.seekTo(params.currentTime);
                player.playVideo();

            break;

            case 2:
                player.seekTo(params.currentTime);
                player.pauseVideo();

            break;

            case 0:
                player.loadVideoById({
                    videoId: params.videoId,
                    volume: params.videoVolume
                });

                this.initialize(params.playlistId);

            break;
        }
	},

	this.getCurrentPlaylistId = function()
	{
		return playlistId;
	},

	this.getCurrentVideoId = function()
	{
		return videoId;
	},

	this.checkCurrentVideoId = function(params)
	{
		var videoId = this.getCurrentVideoId();
		if (videoId != params.currentVideo) {
			player.loadVideoById({
				videoId: params.currentVideo
			});
		}
	},

	this.seekNextVideo = function(params)
	{
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: nextVideoUrl,
            data: { 'volume' : player.getVolume() }
        }).done(function(data) {
            player.loadVideoById({
                videoId: data.videoId
            });

            params.playlistId = data.playlistId;
            params.videoId = data.videoId;

            player.setVolume(data.videoVolume);
            params.videoVolume = data.videoVolume;

            this.sendParameters(params);

            this.initialize(data.playlistId);
        }.bind(this));
	},

	this.sendParameters = function(params)
	{
		json = JSON.stringify(params);
		connection.send(json);
	},

	this.getPlaylistScores = function(playlistId)
	{
		$.get(scoreUrl, {
			playlist: playlistId
{'fraction_non_alphanumeric': 0.13394098563262785, 'fraction_numerical': 0.0021628302178279004, 'mean_word_length': 2.371875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2767579', 'n_tokens_mistral': 2205, 'n_tokens_neox': 1966, 'n_words': 334}