Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
webrtc-test-suite
Advanced tools
Testing webRTC capabilities by trying to use them. Not a feature detector. A capability tester.Also packs some utilities to make developer's live easier while making webRTC tools.
Testing webRTC capabilities by trying to use them. Not a feature detector. A capability tester.Also packs some utilities to make developer's live easier while making webRTC tools.
This is not a replacement of Modernizr or similar tools. This will not check if a feature is supported by the browser. For example a browser might have support for getUserMedia
. Which Modernizr or similar tool will find out. But having support for getUserMedia
does not mean that the user is guaranteed to access the feature. Maybe the user does not have a webcam, or the user's audio input device might be broken.
Or in a different scenario, maybe the users's firewall will block any Peer connection and you need to know if the user's internet connection supports peer connection.
this package will help you test for these real life scenarios in your webRTC application.
Please include the webRTC Adapter package in your project. This plugin tries to cover most of the variations of the API but adapter covers almost all of it.
getUserMedia
Actually works.RTCPeerConnection
getUserMedia
, adding stream to DOM.To install the package use this command.
yarn add webrtc-test-suite
Then you can import it in your code like this:
import _rtc from "webrtc-test-suite";
Add this to your HTML file:
<script src="https://unpkg.com/webrtc-test-suite@1.2.6/dist/index.js"></script>
Yoou will get a global object called: _rtc
. And you can access all the functionalities from that object.
This tool comes with a lot of capability test and utility functions. You can use them to create WebRTC enabled application and positively determine feature support. All the functions are described below.
Functions that return a promise has a
silent
version that does not reject the promise on error. Instead returns null. Good for working withasync-await
.
Functions that accepts the
verbose
(Boolean) argument, will generate logs in the console ifverbose
is set totrue
. Default isfalse
.
checkMediaCapture
and checkMediaCaptureSilent
:
checkMediaCapture(constraints, [verbose = false]); // Returns Promise
Example Use:
_rtc.checkMediaCapture({audio: true, video: true})
.then(()=>console.log("Could capture media stream"))
.catch(()=>console.error("Could not capture media stream"));
This function takes MediaTrackConstraints as argument, calls getUserMedia
API with those constraints, retrieves the Media stream, Checks if audio and video stream is active and according to the constraints provided. Then automatically stops the media capture and returns the result.
checkPeerConnection
and checkPeerConnectionSilent
:
checkPeerConnection(RTCConfiguration, [verbose = false]) // Returns Promise
Example Use:
_rtc.checkPeerConnection({})
.then(()=>console.log("Peer connection works"))
.catch(()=>console.log("Peer connection does not work"));
This function takes RTCConfiguration as argument Creates two RTCPeerConnection
with the provided RTCConfiguration and creates a data channel between those two. Check if data transfer is possible between the two RTCPeerConnection
instances. And returns the results.
Tip: If you want to test your STUN (relay) server, pass
iceTransportPolict: "relay"
(See Documentation) with your RTCConfiguration. This will force the two PeerConnection to communicate through the relay server.
checkInternetSpeed
and checkInternetSpeedSilent
:
checkInternetSpeed("probe/file.url", [verbose]) // Returns Promise
Example use:
_rtc.checkInternetSpeed("https://example-file.com/file.jpg")
.then(speed=>console.log(`Your speed is ${speed}mbps`))
.catch(()=>console.log("could not test Internet Speed"))
This function takes a file URL (Give at least >1mb for better results), somewhere in the web (better if it's in the same server as your TURN server), downloads the file and observes the download speed. This function makes use of the fetch
API, so won't work with browsers that doesn't have fetch
support (you can use a polyfill). This function returns the internet speed in mbps
.
One might Argue, Internet speed is not part of WebRTC. Well, If you don't have a decent internet connection WebRTC applications might now work. And it's always good to know if it will work or not. Hence, this function got a place here.
Make sure the file you supplied isn't too large
>2mb
and also make sure the file is CORS enabled (hasaccess-control-allow-origin
header);
Please note: The users's actual internet speed and speed measured here can be different. This measures internet speed between the user's computer and the server the file was in and can be affected by a lot of factors. In my testing roughly ~1mbps
speed was enough for a smooth video call.
countDevies
and countDeviesSilent
:
countDevies([verbose = false]) // Returns Promise
Example use:
_rtc.countDevices()
.then(result=>console.log(`You have ${result.audio.in} audio input devices`)
.catch(()=>console.log("device count failed"));
This function counts all the audio video input output devices available(sort of).It returns an object like this:
{
audio : {in: 0, out: 0},
video : {in: 0, out: 0},
unknown : 0
}
A point to note here: The current API does not give a count of video output devices In some cases doesn't give count for audio output devices too, so these counts will be 0 most of the time. The value is put there just for aesthetics. Besides, if you can see the output on your display, You definitely have at least one video output, so nothing to freak out 🤞🏼
getUserMedia
and getUserMediaSilent
:
getUserMedia(constraints, [verbose]) // Returns Promise
Example use:
_rtc.getUserMedia(MediaTrackConstraints)
.then(stream=>{
document.querySelector(".video").srcObject = stream;
})
.catch(()=>console.log("could not get media stream"));
If you are tired of handling different versions of getUserMedia
, webkitGetUserMedia
and the latest mediaDevices.getUserMedia
, this function handles it for you. No matter what version of the API your browser supports, this function will call that version of the API and returns a promise with your media stream (or error).
this function takes MediaTrackConstraints as argument.
This tool also comes with some utility functions for the app developer's convenience. The functions were made for internal use of the tool and then provided for the end user.
utils
object:Smaller utilities are in the utils object. Mostly related to webRTC.
utils.flat
:Returns Promise
this function takes a promise as argument and returns another promise. If the source promise is resolved, this functions's promise resolves with the result. If the source promise is rejected. This function's promise resoves with null
. If you are working with async-await
this will save you a lot of try-catch
block. This works with any types of promises. This function is used to generate all the silent
versions of this tool.
utils.dom
:This consists of two functions. Both are used to attach and detatch media stream to a dom element (video
or audio
tag). Why you may ask, because, new implementation has the srcObject
property, older browsers had to use createObjectURI
function to convert the stream into a Object URI. this will handle the variation for you.
Both functions return the DOM element.
utils.dom.addStreamToDOM(domElement, stream)
:Adds a media stream to a DOM element. Example use:
// Let's assume we got a media stream called `stream`
let domElement = document.querySelector("video.test");
_rtc.utils.dom.addStreamToDOM(domElement,stream);
utils.dom.addStreamToDOM(domElement, stream)
:Removes any media astream from DOM element. Example use:
// Let's assume we got a media stream called `stream`
let domElement = document.querySelector("video.test");
_rtc.utils.dom.removeStreamToDOM(domElement);
utils.stream
:this object only contains one utility function now. This namespace is kept to add more functions later.
utils.stream.stopMediaStream
and utils.stream.stopMediaStreamSilent
:This function takes a media Stream and stops all the tracks associated with it. This also releases the input devices. This is the IDEAL way to stop a media stream once you are done with it.
this does not return a promise but the silent version is there to automatically handle any errors that may appear (since they are mostly non important)
Example use:
// For example, if we have a media stream named `stream`.
_rtc.utils.stream.stopMediaStreamSilent(stream);
This package is released under the MIT license, feel free to contribute.
made with 🖤 and JavaScript by Anam Ahmed.
FAQs
Testing webRTC capabilities by trying to use them. Not a feature detector. A capability tester.Also packs some utilities to make developer's live easier while making webRTC tools.
The npm package webrtc-test-suite receives a total of 41 weekly downloads. As such, webrtc-test-suite popularity was classified as not popular.
We found that webrtc-test-suite demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.