webrtc-test-suite
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -1,38 +0,21 @@ | ||
/** | ||
* Test Internet download speed | ||
* @param {checkFile} String, a file on the internet, that can be downloaded via AJAX (has access-control-allow-origin header) | ||
* @param {verbose} Boolean, prints out logs | ||
* @param {callback} Function, gets called once the function finishes or fails | ||
* @returns Promise | ||
*/ | ||
function checkInternetSpeed(checkerFile, verbose = false, callback){ | ||
export default function checkInternetSpeed(checkerFile, verbose = false){ | ||
return new Promise((resolve,reject)=>{ | ||
if(!checkerFile) reject(new Error("Please provide a filename to download and check internet")); | ||
function _log(){ | ||
if(!verbose) return false; | ||
console.log(...arguments); | ||
} | ||
function _err(err){ | ||
if(callback) return callback(false); | ||
return reject(err); | ||
} | ||
if(!checkerFile) return reject(new Error("Please provide a filename to download and check internet")); | ||
if(typeof fetch !== "function") return reject(new Error("Fetch API support is required for this check")); | ||
let startTime = Date.now(); | ||
_log(`🧲 Fetching the test file`); | ||
verbose && console.log(`[internet-connection]: Will fetch the check file`); | ||
fetch(`${checkerFile}?rtccheckertimestamp_noconflict=${startTime}`) | ||
.then(resp=>resp.blob()) | ||
.then(bl=>{ | ||
_log(`😇 Test file fetched successfully`); | ||
verbose && console.log(`[internet-connection]: Fetched the checker file`); | ||
let endTime = Date.now(); | ||
let timeDiff = (endTime - startTime)/1000; //convert millesecond diff to seconds | ||
let timeDiff = (endTime - startTime) / 1000; //convert millesecond diff to seconds | ||
let fileSize = bl.size * 8; // bits | ||
let bps = fileSize / timeDiff; | ||
let mbps = (bps / 1048576).toFixed(2); // 1024*1024 | ||
_log(`🌎 Internet speed observed during fetch: ${mbps} Mbps`); | ||
if(callback) return callback(mbps); | ||
verbose && console.log(`[internet-connection]: Speed observed: ${mbps}mbps`); | ||
return resolve(mbps); | ||
}) | ||
.catch(_err); | ||
}) | ||
} | ||
export default checkInternetSpeed; | ||
.catch(reject); | ||
}); | ||
} |
@@ -1,21 +0,8 @@ | ||
/** | ||
* Tests media capture by calling getUserMedia and analyzing the media stream | ||
* Created by Anam Ahmed (https://anam.co) | ||
* @param {MediaStreamConstraints} constraints | ||
* @param {Boolean} verbose | ||
* @param {Function} callback | ||
*/ | ||
function checkMediaCapture(constraints = {video: true, audio: true},verbose = false, callback){ | ||
export default function checkMediaCapture(constraints, verbose = false){ | ||
return new Promise((resolve,reject)=>{ | ||
function _err(err){ | ||
if(callback) return callback(false); | ||
return reject(err); | ||
} | ||
function _log(){ | ||
if(!verbose) return false; | ||
console.log(...arguments); | ||
} | ||
if(!constraints.audio && !constraints.video) return reject(new Error("Constraints are not correct")); | ||
verbose && console.log(`[media-capture]: Requesting user media`); | ||
navigator.mediaDevices.getUserMedia(constraints) | ||
.then(stream=>{ | ||
_log("🏞 Got Media stream"); | ||
verbose && console.log(`[media-capture]: Received media Stream`); | ||
if(stream.active){ | ||
@@ -30,16 +17,13 @@ let tracks = stream.getTracks(); | ||
}); | ||
tracks.forEach(_track=>_track.stop()); | ||
if(!functional) return _err(new Error("All requested tracks are not active")); | ||
if(constraints.video && !videoTrack) return _err(new Error("Video Track not found")); | ||
if(constraints.audio && !audioTrack) return _err(new Error("Audio Track not found")); | ||
verbose && console.log(`[media-capture]: Received ${tracks.length} track(s)`); | ||
verbose && console.log(`[media-capture]: Stopping media track(s)`); | ||
Array.prototype.forEach.call(tracks, _track=>_track.stop()); | ||
if(!functional) return reject(new Error("All requested tracks are not active")); | ||
if(constraints.video && !videoTrack) return reject(new Error("Video Track not found")); | ||
if(constraints.audio && !audioTrack) return reject(new Error("Audio Track not found")); | ||
return resolve(true); | ||
} | ||
}) | ||
.catch(e=>{ | ||
_log("🛑 Failed at getting media stream"); | ||
_err(e); | ||
}) | ||
}) | ||
} | ||
export default checkMediaCapture; | ||
.catch(reject); | ||
}); | ||
} |
@@ -1,30 +0,10 @@ | ||
/** | ||
* Created By Anam Ahmed (https://anam.co) | ||
* Test the browser's capability to establish RTCPeerConnection with supplied RTC Configuration | ||
* How to use: probeRTC(RTCParam,false, callback) // will call callback function with true or false. | ||
* If you don't supply the callback function it will return a Promise. | ||
* The promise will resolve (with total time required for the whole round trip ,in ms) or reject (with error) based on the result. | ||
* Setting verbose = true will print logs in console | ||
* @param {RTCConfiguration} rtcConfig | ||
* @param {Boolean} verbose | ||
* @param {Function} callback [optional] | ||
* @return {Promise} | ||
*/ | ||
function checkPeerConnection(rtcConfig = {}, verbose = false, callback){ | ||
export default function checkPeerConnection(rtcConfig = {}, verbose = false){ | ||
return new Promise((resolve,reject)=>{ | ||
let rtc1 = new RTCPeerConnection(); | ||
let rtc2 = new RTCPeerConnection(); | ||
let rtc1 = new RTCPeerConnection(rtcConfig); | ||
let rtc2 = new RTCPeerConnection(rtcConfig); | ||
let dc = rtc1.createDataChannel("sender"); | ||
let _ts = Date.now(); | ||
function _err(err){ | ||
if(callback) return callback(false); | ||
return reject(err); | ||
} | ||
function _log(){ | ||
if(!verbose) return false; | ||
console.log(...arguments); | ||
} | ||
rtc1.addEventListener("icecandidate",ice=>{ | ||
if(!ice.candidate) return false; | ||
_log("🚖 First Peer Generated Candidate:",ice.candidate); | ||
verbose && console.log("[peer-connection]: First Peer Generated Candidate:",ice.candidate); | ||
rtc2.addIceCandidate(ice.candidate); | ||
@@ -34,3 +14,3 @@ }); | ||
if(!ice.candidate) return false; | ||
_log("🚖 Second Peer Generated Candidate:",ice.candidate); | ||
verbose && console.log("[peer-connection]: Second Peer Generated Candidate:",ice.candidate); | ||
rtc1.addIceCandidate(ice.candidate); | ||
@@ -40,5 +20,4 @@ }); | ||
evt.channel.addEventListener("message",(msg)=>{ | ||
_log("✉️ Message Transmission successful"); | ||
verbose && console.log("[peer-connection]: Message Transmission successful"); | ||
if(msg.data === _ts.toString()){ | ||
if(callback) return callback(true); | ||
let _rcvTS = Date.now(); | ||
@@ -49,3 +28,3 @@ rtc1.close(); | ||
} | ||
_err(new Error("message integrity failure")); | ||
return reject(new Error("message integrity failure")); | ||
}); | ||
@@ -56,3 +35,3 @@ }); | ||
.then(offer=>{ | ||
_log("🍎 Created RTC Offer"); | ||
verbose && console.log("[peer-connection]: First peer connection created RTC offer"); | ||
rtc1.setLocalDescription(offer) | ||
@@ -62,11 +41,9 @@ .then(()=>rtc2.setRemoteDescription(offer)) | ||
.then(answer=>{ | ||
_log("🍏 Created RTC Answer"); | ||
verbose && console.log("[peer-connection]: Seocond peer connection created RTC answer"); | ||
rtc2.setLocalDescription(answer) | ||
.then(()=>rtc1.setRemoteDescription(answer)) | ||
.catch(e=>_err(e)); | ||
}).catch(e=>_err(e))); | ||
}).catch(e=>_err(e)); | ||
.then(rtc1.setRemoteDescription(answer)) | ||
.catch(reject); | ||
}).catch(reject)); | ||
}).catch(reject); | ||
}); | ||
} | ||
export default checkPeerConnection; |
import checkPeerConnection from "./checks/peerConnection"; | ||
import checkMediaCapture from "./checks/mediaCapture"; | ||
import checkInternetSpeed from "./checks/internet"; | ||
import countDevies from "./checks/count_devices"; | ||
let _RTCTest = { | ||
checkPeerConnection, | ||
checkMediaCapture, | ||
checkInternetSpeed | ||
checkInternetSpeed, | ||
countDevies | ||
} | ||
@@ -10,0 +11,0 @@ if(typeof window !== "undefined") window._RTCTest = _RTCTest; |
{ | ||
"name": "webrtc-test-suite", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"main": "index.js", | ||
@@ -23,5 +23,5 @@ "repository": "git@github.com:theanam/webrtc-test-suite.git", | ||
"build": "parcel build index.js", | ||
"watch-example": "parcel test/index.html -d test-temp", | ||
"run-example": "parcel test/index.html -d test-temp", | ||
"build-example": "parcel build test/index.html -d test-dist" | ||
} | ||
} |
@@ -19,15 +19,16 @@ # webrtc-test-suite | ||
```html | ||
<script src="https://unpkg.com/webrtc-test-suite@1.0.2/dist/index.js"></script> | ||
<script src="https://unpkg.com/webrtc-test-suite@1.1.0/dist/index.js"></script> | ||
``` | ||
Yoou will get a global object called: `_RTCTest` | ||
All the check functions return a promise, or optionally you can supply a callback function as well. | ||
All the check functions return a promise. | ||
```js | ||
// Function signatures: | ||
// check peer connection capabilities | ||
checkPeerConnection(iceConfiguration,verbose[boolean],callback) // all the params are optional. Verbose creates logs | ||
checkPeerConnection(iceConfiguration,verbose[boolean]) // all the params are optional. If you chose to go verbose, pass a blank obe. Verbose creates logs | ||
// Check media capture | ||
checkMediaCapture(mediaConstraints,verbose[boolean],callback) // all the params are optional. Verbose creates logs | ||
checkMediaCapture(mediaConstraints,verbose[boolean]) // Constraints is required. Verbose creates logs | ||
// make sure testDownload is a file and can be downloaded with AJAX (this test uses fetch) | ||
checkInternetSpeed(testDownload,verbose[boolean],callback) // testDownload is required, return value in Mbps (Megabits Per second) | ||
checkInternetSpeed(testDownload,verbose[boolean]) // testDownload is required, return value in Mbps (Megabits Per second) | ||
countDevices([verbose = false]) // counts the number of audio video input output devices | ||
``` | ||
@@ -34,0 +35,0 @@ ## A better documentation is comming soon |
import _test from "../index"; | ||
function init(){ | ||
// _test.checkMediaCapture({audio:true,video: true},true) | ||
// .then(_test.checkPeerConnection({},true)) | ||
// .then(result=>console.log("All tests passed")) | ||
// .catch(err=>console.log("err",err)) | ||
_test.countDevies(true).then(list=>console.log(list)); | ||
} | ||
document.querySelector(".start").addEventListener("click",init); | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75946
18
39
675
6