Firefox 22 mozGetUserMedia使用“屏幕”作为设备源 [英] Firefox 22 mozGetUserMedia using 'screen' as device source

查看:168
本文介绍了Firefox 22 mozGetUserMedia使用“屏幕”作为设备源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Firefox 22中,WebRTC支持方面有一些嗡嗡声。这是针对Firefox开发人员的:Firefox是否支持桌面屏幕截图? b

Chrome 26+技术确实存在,它为屏幕捕获提供了实验支持(使用屏幕作为设备源)。用于实现此目的的代码(代码片段)是:

$ p $ //选择任何支持的getUserMedia函数
navigator.getMedia = (navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);

//如果不支持getUserMedia,则不执行
if(!navigator.getMedia)return;

//用户媒体请求
navigator.getMedia(
{
video:{
mandatory:{
// request'screen '作为源媒体
chromeMediaSource:'screen'
}
}
},

//成功
函数(localMediaStream)
{
//处理本地媒体流...
},

//失败
函数(错误)
{
//错误处理
});

查看W3C文档,对象 MediaSourceConstraints,MediaTrackConstraints,MediaTrackConstraintsSet 还没有被标准化。这可能仅仅是因为这个功能出现在Firefox生产环境中,这个API太雾了。这只是很好的知道当前的支持状态。
解决方案

现在可以在Firefox中使用,但是由于安全问题,支持隐藏在一些偏好背后。特别是 about:config 中 media.getusermedia。* 偏好设置。

对Mozilla错误报告的评论说明了其中的一些关注:
$ b


现在我们重新设计了< input type =file> 不能在屏幕上绘制完整的路径,事情会更好。我们仍然在绘制交叉图像和< iframe> s之类的问题上存在问题。

选择加入,我会担心的情况,如用户加载应用程序页面A在一个选项卡和应用程序页面B在另一个选项卡,页面B要求屏幕共享页面A,看起来很好,用户接受,然后应用程序交换FB或gmail的< iframe> 或者其他任何东西进入页面A并抓取内容。

尽管在发行版频道中,默认情况下, media.getusermedia.screensharing.enabled 当前 true > media.getusermedia.screensharing.allowed_domains 下列入白名单的网域实际上允许使用它。

在允许列表中,您可以通过使用视频属性中的以下键来使用它。

  video:{
mozMediaSource:screen,
mediaSource:screen
}

Mozilla托管一个 getUserMedia测试页,由Firefox Nightly和Firefox Developer Edition列出的域名。如果你使用这两个版本的Firefox,你可以看到它的实际应用。或者,您可以将域添加到 about:config 下的白名单中,然后在发布版和测试版渠道中使用它。


There have been some buzz in the air for the WebRTC support in Firefox 22. This is for someone who's in the know about Firefox development: Are there any support in Firefox for desktop screen capture todate?

The technology does exist for Chrome 26+, which provides experimental support for screen capturing (using 'screen' as device source); the code (snippet) for making this happen is:

   // select any supported getUserMedia function
   navigator.getMedia = (navigator.getUserMedia || 
                         navigator.webkitGetUserMedia ||
                         navigator.mozGetUserMedia ||
                         navigator.msGetUserMedia);

  // if getUserMedia is not supported, do nothing 
  if( !navigator.getMedia ) return;

  // request for user media
  navigator.getMedia(
  {
     video : {
        mandatory : {
           // request 'screen' as a source media
           chromeMediaSource : 'screen'
        }
     }
  },

  // success
  function( localMediaStream )
  {
     // process local media stream...
  },

  // failure
  function( error )
  {
     // error handling
  });

Looking at W3C docs, the objects MediaSourceConstraints, MediaTrackConstraints, MediaTrackConstraintsSet have not yet been standardized. It might simply be that the API is all too foggy for this feature to appear in Firefox production. It would just be good to know the current state of support.

解决方案

This is now possible in Firefox, however due to security concerns, support is hidden behind some preferences. Specifically the media.getusermedia.* preferences under about:config.

This comment on a Mozilla bug report illustrates some of those concerns:

Now that we've redesigned <input type="file"> to not draw the full path on the screen, things are better. We still have problems with things like drawing cross-origin images and <iframe>s.

Even with user opt-in, I'd worry about situations like "user loads app page A in one tab and app page B in another tab, page B asks for permission to screen-share page A which looks fine, user accepts, then app swaps an <iframe> of FB or gmail or whatever into page A and grabs the contents.

Though media.getusermedia.screensharing.enabled is currently true by default in the release channel, only those domains whitelisted under media.getusermedia.screensharing.allowed_domains are actually allowed to use it.

If your domain is on the allowed list, you can use it by using the following keys in the video property.

video: {
    mozMediaSource: "screen",
    mediaSource: "screen"
}

Mozilla hosts a getUserMedia Test Page, on a domain that is white-listed by Firefox Nightly and Firefox Developer Edition. If you use either of these versions of Firefox, you can see it in action. Alternately you could add the domain to the whitelist under about:config and use it in the release and beta channels.

这篇关于Firefox 22 mozGetUserMedia使用“屏幕”作为设备源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆