WebRTC datachannel works only in Firefox nightly. How can I check it in client side?
Code is shown as follows;
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")
WebRTC datachannel works only in Firefox nightly. How can I check it in client side?
Code is shown as follows;
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")
Share
Improve this question
edited Feb 8, 2013 at 14:17
sam46
372 silver badges7 bronze badges
asked Feb 8, 2013 at 14:09
usercodeusercode
3091 gold badge4 silver badges20 bronze badges
6
|
Show 1 more comment
8 Answers
Reset to default 7You can simply test if the browser currently supports the features you're going to use. For example:
if (!window.mozRTCPeerConnection)
// error, browser doesn't support it
If you're interested, here an interesting article: Hello Chrome, it’s Firefox calling!
You basically can implement the same feature in Chrome just using webkit
prefix instead of moz
.
There's a Chrome RTCDataChannel
demo now at simpl.info/dc.
This isn't very robust or complete, but you could create a webkitRTCPeerConnection
object and then check if it has a createDataChannel
member:
try { // or if (webkitRTCPeerConnection) {...}
var pc = new webkitRTCPeerConnection(null);
if (pc && pc.createDataChannel) {
var dc = pc.createDataChannel("sendDataChannel", {reliable: false});
if (!!dc) {
// doSomething()
}
}
} catch (e) {
// try some other instantiation
}
Check the webrtcsupport package. It seems to be cross-browser (Chrome & FF). https://www.npmjs.org/package/webrtcsupport
If you don't wanna use the NPM package, the main logic can be found here. https://github.com/HenrikJoreteg/webrtcsupport/blob/master/index-browser.js
Using JavaScript
var prefix;
var version;
if (window.mozRTCPeerConnection || navigator.mozGetUserMedia) {
prefix = 'moz';
version = parseInt(navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1], 10);
} else if (window.webkitRTCPeerConnection || navigator.webkitGetUserMedia) {
prefix = 'webkit';
version = navigator.userAgent.match(/Chrom(e|ium)/) && parseInt(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)[2], 10);
}
if(prefix == 'moz' || prefix == 'webkit' && version > 41){
console.log("Browser Support WebRTC")
} else {
console.log("This Browser Not Support WebRTC")
}
The top answer is not right.
if (window.RTCDataChannel) {
// the browser support dataChannel
} else {
// the browser does not support dataChannel
}
If browser support RTCPeerConnection, it not means also support for RTCDataChannel。Such as Edge, createDataChannel
on instance of RTCPeerConnection
will throw an exception.
Surprised no one mentions checking the prototype.
You can check if createDataChannel exists by doing this:
if (!window.RTCPeerConnection.prototype.createDataChannel) {
// Data Channels not supported
}
I just figured out. Thanks for all your help. http://mozilla.github.com/webrtc-landing/
Another package that checks for WebRTC support is DetectRTC https://github.com/muaz-khan/DetectRTC
RTCPeerConnection
? – Bergi Commented Feb 8, 2013 at 14:40