agora.io屏幕共享Web sdk getDisplayMedia

时间:2020-09-12 01:24:27

标签: reactjs react-hooks video-streaming live

我正在使用Agora来创建屏幕共享操作,但是我无法在Safari / MacOS上使用它。以下代码可在Mac / Windows上的Chrome和Firefox上使用。每当我点击此IconButton时,错误消息就会显示在下面的屏幕截图中。

可能是什么问题?我已将其与Agora的示例代码进行了比较,但无法确定导致此错误的原因。

<IconButton color='primary' onClick={shareScreenClient ? clearScreenStream : startScreenStream}>
{shareScreenClient ? <StopScreenShareOutlinedIcon fontSize='large' /> : <ScreenShareOutlinedIcon fontSize='large' />}</IconButton>

//这是startScreenStream的定义。

const startScreenStream = (e) => {
        e.preventDefault();
        screenClient.current = AgoraRTC.createClient(agoraClientObj);

        const channel = classroom;
        const token = null;
        screenClient.current.init(appID, () => {
            screenClient.current.join(
                token,
                channel,
                null,
                (screenUid) => {
                    // Create the screen-sharing stream, screenStream.
                    setScreenStreamObj((x) => ({
                        ...x,
                        streamId: screenUid,
                    }));

                    let screenStreamObj = {
                        streamID: screenUid,
                        audio: false,
                        video: false,
                        screen: true,
                        screenAudio: true,
                    };

                    if (audioDeviceId) screenStreamObj.microphoneId = audioDeviceId;
                    if (videoDeviceId) screenStreamObj.cameraId = videoDeviceId;
                    if (isFirefox) screenStreamObj.mediaSource = 'screen';

                    screenStream.current = AgoraRTC.createStream(screenStreamObj);
                    screenStream.current.setScreenProfile('480p_1');
                    screenStream.current.init(
                        () => {
                            screenStream.current.play('screen-share', { fit: 'cover' }, () => {
                                console.log('sharing screen');
                                setShareScreenClient(true);
                            });
                            screenClient.current.publish(screenStream.current, (err) => {
                                console.error('publish failed', err);
                                //clearScreenStream();
                            });
                        },
                        (err) => {
                            screenStream.current = null;
                            setScreenStreamObj({});
                            console.error('could not init stream', err);
                        }
                    );
                },
                (err) => {
                    screenClient.current = null;
                    console.error('Could not join channel', err);
                }
            );
        });
    }

enter image description here

0 个答案:

没有答案