最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set custom virtual background on join - Stack Overflow

programmeradmin2浏览0评论

How to set the custom Virtual Background for Jitsi on user join?

I tried with blur, so far I see that it correctly selects the blur option but I can't "trigger" the actual change to be applied.

// custom-config.js
(function() {
    // Function to wait for the APP object to be available
    function waitForApp() {
        console.log('waitForApp');
        if (typeof APP !== 'undefined' && APP.conference && APP.conference._room) {
            console.log('CustomBackground - setup');
            setupVirtualBackground();
        } else {
            console.log('CustomBackground - retry');
            setTimeout(waitForApp, 100); // Check every 100ms
        }
    }

    // Function to set up the virtual background logic
    function setupVirtualBackground() {
        console.log('CustomBackground - waiting for conferenceJoined');

        // Listen for the conferenceJoined event
        APP.conference._room.on('conference.joined', function() {
            // Access the Redux store state
            const state = APP.store.getState();
            // Get the decoded JWT
            const jwt = state['features/base/jwt'].jwt;

            if (jwt) {

                console.log('CustomBackground - decodingJWT');
                try {
                    // Split the JWT
                    const parts = jwt.split('.');
                    if (parts.length !== 3) {
                        throw new Error('Invalid JWT');
                    }

                    // Decode the payload
                    const payload = parts[1];
                    decodedToken = JSON.parse(atob(payload.replace(/-/g, '+').replace(/_/g, '/')));
                    console.log('CustomBackground - JWT decoded');

                } catch (error) {
                    console.error('Error decoding JWT:', error);
                }
            }

            console.log('CustomBackground - decodedToken', decodedToken.role);

            // Check if the user has the "xyz" role
            if (decodedToken && 
                decodedToken.role && 
                decodedToken.role === 'xyz') {
                // Define the custom background image URL
                const customBackgroundUrl = '.jpg';

                // Set the virtual background
                console.log('CustomBackground - setVirtualBackground');
                const url = toDataURL(customBackgroundUrl);
                
                const store = APP.store;
                store.dispatch({
                    type: 'SET_VIRTUAL_BACKGROUND',
                    backgroundEffectEnabled: true,
                    backgroundType: 'blur',
                    blurValue: 25,
                    selectedThumbnail: 'blur'
                });
                logger.info('Image set for virtual background preview!');
            }
        });
    }

    // Start waiting for the APP object
    waitForApp();
})();
发布评论

评论列表(0)

  1. 暂无评论