import React, { createContext, useContext, useEffect, useState, } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { RoomSocketState } from '../store/roomSlice';
import PluginManager from '../services/context/PluginManager';
import { WebSocketContext } from '../services/MediaRoomSocketService';
export const PluginServiceContext = createContext(null);
export const PluginServiceProvider = ({ children, roomName, peerId, }) => {
    const socketContext = useContext(WebSocketContext);
    const dispatch = useDispatch();
    const [manager, setManager] = useState(null);
    const authToken = useSelector((state) => state.participant.authToken);
    useEffect(() => {
    }, []);
    const socketState = useSelector((state) => state.room.socketState);
    const context = {
        pluginManager: manager,
    };
    useEffect(() => {
        if (socketState === RoomSocketState.CONNECTED) {
            const pluginManager = new PluginManager(socketContext, roomName, dispatch, peerId, authToken);
            setManager(pluginManager);
            pluginManager.listenSocketEvents();
        }
    }, [socketState]);
    return (<PluginServiceContext.Provider value={context}>
			{children}
		</PluginServiceContext.Provider>);
};
//# sourceMappingURL=PluginService.js.map