Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebRTC: Fail to publish RTC automatically for HTML5. Unable to obtain permission for automatic streaming, but it does not fail. #2732

Closed
winlinvip opened this issue Nov 14, 2021 · 3 comments
Assignees
Labels
TransByAI Translated by AI/GPT. WebRTC WebRTC, RTC2RTMP or RTMP2RTC.
Milestone

Comments

@winlinvip
Copy link
Member

winlinvip commented Nov 14, 2021

Reproduction path:

  1. Run SRS: ./objs/srs -c conf/rtc.conf
  2. Open the webpage for streaming: http://localhost:8080/players/rtc_publisher.html?autostart=true
  3. Phenomenon: The camera permission dialog box does not pop up, it keeps spinning and there are no errors or success.

Solution:

    if (query.autostart === 'true') {
        var autoStartPublish = async function() {
            // For autostart, solution #1.
            const detectStream = await navigator.mediaDevices.getUserMedia({audio:true, video:true});
            detectStream.getTracks().map(track => track.stop());

            // For autostart, solution #2.
            //await new Promise(resolve => setTimeout(resolve, 1000));

            await startPublish();
        };
        autoStartPublish();
    }
});
</script>
</body>
</html>

In JavaScript, it is not possible to retrieve it. It must be done in an HTML page by adding the code in the HTML page.

  1. When calling getUserMedia in an HTML page, a permission dialog box will definitely pop up.
  2. When calling setTimeout in an HTML page, it will also pop up after waiting for a certain amount of time, but if the duration is too short, it won't work.

The main issue is with permissions. If the dialog box below pops up, then there won't be any problem.

image

This issue is only encountered for the first time, so it affects newcomers.

TRANS_BY_GPT3

@winlinvip winlinvip self-assigned this Nov 14, 2021
@winlinvip winlinvip added the WebRTC WebRTC, RTC2RTMP or RTMP2RTC. label Nov 14, 2021
@winlinvip winlinvip added this to the 4.0 milestone Nov 14, 2021
@winlinvip winlinvip changed the title WebRTC: Fail to publish RTC automatically WebRTC: Fail to publish RTC automatically for HTML5. Nov 14, 2021
@winlinvip winlinvip changed the title WebRTC: Fail to publish RTC automatically for HTML5. WebRTC: Fail to publish RTC automatically for HTML5. 自动推流无法获取权限。 Nov 14, 2021
@winlinvip winlinvip changed the title WebRTC: Fail to publish RTC automatically for HTML5. 自动推流无法获取权限。 WebRTC: Fail to publish RTC automatically for HTML5. 自动推流无法获取权限,但也不失败。 Nov 14, 2021
@winlinvip
Copy link
Member Author

winlinvip commented Nov 14, 2021

We discussed in the WebRTC group with everyone:

  1. Is it an HTTPS issue? No, it's not. It's on localhost, and even when switched to HTTPS, the same problem occurs.
  2. Can the WebRTC example be used? No, it can't. It requires manual clicking to start streaming, not automatic.
  3. Does manual streaming work? Yes, it works fine.

TRANS_BY_GPT3

@winlinvip
Copy link
Member Author

winlinvip commented Nov 14, 2021

With the help of the ringing, wait for the page to load and finish parsing before calling getUserMedia.

image

If it is not convenient to update the code, you can consider setting autostart=false.

TRANS_BY_GPT3

@winlinvip
Copy link
Member Author

winlinvip commented Nov 14, 2021

Fixed by 7771fbe

Thank you again @notedit

TRANS_BY_GPT3

winlinvip added a commit that referenced this issue Nov 14, 2021
@winlinvip winlinvip changed the title WebRTC: Fail to publish RTC automatically for HTML5. 自动推流无法获取权限,但也不失败。 WebRTC: Fail to publish RTC automatically for HTML5. Unable to obtain permission for automatic streaming, but it does not fail. Jul 28, 2023
@winlinvip winlinvip added the TransByAI Translated by AI/GPT. label Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TransByAI Translated by AI/GPT. WebRTC WebRTC, RTC2RTMP or RTMP2RTC.
Projects
None yet
Development

No branches or pull requests

1 participant