Request Screen Share Within iframe

Viewed 1654

I have built a Chrome Extension which successfully implements screen sharing with WebRTC, however there is a requirement for the site which uses the extension to function within an iframe.

Is it possible to achieve this? An example of my code is below - the 'unknown' case is always executing when within an iframe.

function getUserScreen(sources, extensionId) {
    const request = {
            type: 'getUserScreen',
            sources: sources
    };
    return new Promise((resolve, reject) => {
        chrome.runtime.sendMessage(extensionId, request, response => {
            switch (response && response.type) {
                case 'success':
                    log('success!');
                    resolve(response.streamId);
                    break;
                case 'error':
                    log('error!');
                    reject(new Error(error.message));
                    break;
                default:
                    log('unknown!');
                    reject(new Error('Unknown response'));
                    break;
            }
        });
    }).then(streamId => {
        return navigator.mediaDevices.getUserMedia({
            video: {
                mandatory: {
                    chromeMediaSource: 'desktop',
                    chromeMediaSourceId: streamId,
                    maxWidth: window.screen.width,
                    maxHeight: window.screen.height                         
                }
            }
        });
    });
}
1 Answers
Related