如何在客户端使用 JavaScript 检查 webRTC 数据通道兼容性?

2024-01-08

WebRTC 数据通道仅在 Firefox nightly 中工作。如何在客户端查看?

代码如下;

if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits); 

 var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number

 if (ffversion>=5)

  document.write("You're using FF 5.x or above")

 else if (ffversion>=4)

  document.write("You're using FF 4.x or above")

 else if (ffversion>=3)

  document.write("You're using FF 3.x or above")

 else if (ffversion>=2)

  document.write("You're using FF 2.x")

 else if (ffversion>=1)

  document.write("You're using FF 1.x")
}

else
 document.write("n/a")

您可以简单地测试浏览器当前是否支持您要使用的功能。例如:

if (!window.mozRTCPeerConnection)
    // error, browser doesn't support it

如果您有兴趣,这里有一篇有趣的文章:你好 Chrome,我是 Firefox 来电! https://hacks.mozilla.org/2013/02/hello-chrome-its-firefox-calling/

你基本上可以在 Chrome 中实现相同的功能,只需使用webkit前缀而不是moz.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在客户端使用 JavaScript 检查 webRTC 数据通道兼容性? 的相关文章

随机推荐