{"size": 1749, "ext": "js", "max_stars_repo_path": "react/features/room-background/subscriber.js", "max_stars_repo_name": "ivicos-GmbH/jitsi-meet", "max_stars_repo_stars_event_min_datetime": "2021-04-13T17:49:39.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-13T17:49:39.000Z", "max_issues_repo_path": "react/features/room-background/subscriber.js", "max_issues_repo_name": "ivicos-GmbH/jitsi-meet", "max_issues_repo_issues_event_min_datetime": "2021-03-08T07:33:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-16T11:38:15.000Z", "max_forks_repo_path": "react/features/room-background/subscriber.js", "max_forks_repo_name": "ivicos-GmbH/jitsi-meet", "max_forks_repo_forks_event_min_datetime": "2021-04-10T11:21:38.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-10T11:21:38.000Z"}
{"max_stars_count": 1, "max_issues_count": 17, "max_forks_count": 1, "avg_line_length": 28.2096774194, "max_line_length": 85, "alphanum_fraction": 0.627787307}
// @flow

// import { getLocalParticipant } from '../base/participants';
import { StateListenerRegistry } from '../base/redux';

import {
    refreshResizingLargeVideo
} from './../large-video';
import { updateBackgroundData } from './actions';
import { extractBackgroundProperties } from './functions';

declare var APP: Object;

/**
 * Updates the room background when participants backgroundData property is updated
 */
StateListenerRegistry.register(
    /* selector */ state => state['features/base/participants'],
    /* listener */(state, { dispatch }) => {


        // if (!state.length) {
        //     return;
        // }

        // const localParticipant = getLocalParticipant(state);
        const backgroundData = state.local?.backgroundData;


        // if (backgroundData === previousState.local?.backgroundData) {
        //     return;
        // }


        // Updating the background of the room
        dispatch(updateBackgroundData(backgroundData));

        // Sending an event to the client to communicate the background change
        if (typeof APP !== 'undefined') {
            const backgroundProperties = extractBackgroundProperties(backgroundData);


            APP.API.notifyBackgroundChanged(
                state.local.id,
                {
                    backgroundImageUrl: backgroundProperties.backgroundImageUrl,
                    backgroundColor: backgroundProperties.backgroundColor
                });
        }
    }
);

/**
 * When the background of the room is updated, resize the video.
 */
StateListenerRegistry.register(
    /* selector */ state => state['features/room-background'],
    /* listener */(state, { dispatch }) => {
        dispatch(refreshResizingLargeVideo(true));
    }
);
