检测Firefox对屏幕共享的支持 [英] Detect Firefox support for screen sharing
问题描述
Firefox(从52版开始)将通过以下方式支持屏幕共享:
navigator.mediaDevices.getUserMedia({ video: { mediaSource: 'screen' }})
.then(stream => { ... });
查看此测试页以查看实际效果.
>我想知道是否有一种方法可以检测浏览器是否支持{ mediaSource: 'screen' }
?
我只想提供与具有共享能力的用户共享屏幕的选项.因此,我希望能够进行特征检测.
一种检测浏览器是否支持{mediaSource:'screen'}的方法?
下面的学问答案将告诉您是否支持mediaSource
约束:
console.log(!!navigator.mediaDevices.getSupportedConstraints().mediaSource);
不幸的是, mediaSource
不是-standard,仅在Firefox中实现.截至本文撰写之时,Firefox是唯一一个无需插件即可启用屏幕共享的浏览器.
Chrome使用旧的约束语法,使用chromeMediaSource
作为插件提供了不同的非标准API,但是(正确地)它没有出现在新的getSupportedConstraints
中.
还是有点混乱.长期的浏览器可能最终会实现 getDisplayMedia
./p>
Firefox, since version 52, will support screen sharing via:
navigator.mediaDevices.getUserMedia({ video: { mediaSource: 'screen' }})
.then(stream => { ... });
Check out this test page to see it in action.
I would like to know whether there is a way to detect whether a browser supports { mediaSource: 'screen' }
?
I would like to only give the option to share the screen with users that have the ability to share. So I'd like to be able to feature detect this.
a way to detect whether a browser supports { mediaSource: 'screen' }?
The pedantic answer is the following will tell you if the mediaSource
constraint is supported:
console.log(!!navigator.mediaDevices.getSupportedConstraints().mediaSource);
Unfortunately, mediaSource
is non-standard, and only implemented in Firefox. Firefox is as of this writing the only browser to enable screen-sharing without a plugin.
Chrome has a different non-standard API using chromeMediaSource
available as a plug-in, using an older constraints syntax, but it (rightly) does not appear in the new getSupportedConstraints
.
It's a bit of a mess still. Long-term browsers may end up implementing getDisplayMedia
instead.
这篇关于检测Firefox对屏幕共享的支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!