Skip to content

Commit

Permalink
Merged and Closed #71 (to return end-of-icecandidate signal)
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Oct 31, 2018
1 parent f354738 commit bf28ff7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 42 deletions.
3 changes: 1 addition & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
!DetectRTC.min.js
!index.html
!package.json
!bower.json
!npm-test.js
!server.js
!README.md
!README.md
23 changes: 16 additions & 7 deletions DetectRTC.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

// Last Updated On: 2018-10-26 9:36:48 AM UTC
// Last Updated On: 2018-10-31 5:21:01 AM UTC

// ________________
// DetectRTC v1.3.7
// DetectRTC v1.3.8

// Open-Sourced: https://github.com/muaz-khan/DetectRTC

Expand Down Expand Up @@ -529,7 +529,9 @@
var isPublic = true,
isIpv4 = true;
getIPs(function(ip) {
if (ip.match(regexIpv4Local)) {
if (!ip) {
callback(); // Pass nothing to tell that ICE-gathering-ended
} else if (ip.match(regexIpv4Local)) {
isPublic = false;
callback('Local: ' + ip, isPublic, isIpv4);
} else if (ip.match(regexIpv6)) { //via https://ourcodeworld.com/articles/read/257/how-to-get-the-client-ip-address-with-javascript-only
Expand Down Expand Up @@ -591,6 +593,11 @@
}

function handleCandidate(candidate) {
if (!candidate) {
callback(); // Pass nothing to tell that ICE-gathering-ended
return;
}

var match = regexIpv4.exec(candidate);
if (!match) {
return;
Expand All @@ -607,9 +614,11 @@
}

// listen for candidate events
pc.onicecandidate = function(ice) {
if (ice.candidate) {
handleCandidate(ice.candidate.candidate);
pc.onicecandidate = function(event) {
if (event.candidate && event.candidate.candidate) {
handleCandidate(event.candidate.candidate);
} else {
handleCandidate(); // Pass nothing to tell that ICE-gathering-ended
}
};

Expand Down Expand Up @@ -1099,7 +1108,7 @@
DetectRTC.isPromisesSupported = !!('Promise' in window);

// version is generated by "grunt"
DetectRTC.version = '1.3.7';
DetectRTC.version = '1.3.8';

if (typeof DetectRTC === 'undefined') {
window.DetectRTC = {};
Expand Down
6 changes: 3 additions & 3 deletions DetectRTC.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "detectrtc",
"version": "1.3.7",
"version": "1.3.8",
"authors": [
{
"name": "Muaz Khan",
"email": "[email protected]",
"homepage": "http://www.muazkhan.com/"
"homepage": "https://muazkhan.com/"
},
{
"name": "Kenneth Miles",
Expand Down
17 changes: 13 additions & 4 deletions dev/DetectLocalIPAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ function DetectLocalIPAddress(callback, stream) {
var isPublic = true,
isIpv4 = true;
getIPs(function(ip) {
if (ip.match(regexIpv4Local)) {
if (!ip) {
callback(); // Pass nothing to tell that ICE-gathering-ended
} else if (ip.match(regexIpv4Local)) {
isPublic = false;
callback('Local: ' + ip, isPublic, isIpv4);
} else if (ip.match(regexIpv6)) { //via https://ourcodeworld.com/articles/read/257/how-to-get-the-client-ip-address-with-javascript-only
Expand Down Expand Up @@ -73,6 +75,11 @@ function getIPs(callback, stream) {
}

function handleCandidate(candidate) {
if (!candidate) {
callback(); // Pass nothing to tell that ICE-gathering-ended
return;
}

var match = regexIpv4.exec(candidate);
if (!match) {
return;
Expand All @@ -89,9 +96,11 @@ function getIPs(callback, stream) {
}

// listen for candidate events
pc.onicecandidate = function(ice) {
if (ice.candidate) {
handleCandidate(ice.candidate.candidate);
pc.onicecandidate = function(event) {
if (event.candidate && event.candidate.candidate) {
handleCandidate(event.candidate.candidate);
} else {
handleCandidate(); // Pass nothing to tell that ICE-gathering-ended
}
};

Expand Down
36 changes: 14 additions & 22 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script>window.demoVersion = '2018.10.09';</script>
<script>window.demoVersion = '2018.10.31';</script>

<!--
> Muaz Khan - www.MuazKhan.com
Expand Down Expand Up @@ -115,13 +115,6 @@ <h1>

<div class="github-stargazers"></div>

<section class="experiment" style="padding: 10px 20px; text-align: center;">
<a href="https://chrome.google.com/webstore/detail/detectrtc/infnkpmpcmmofkmndpheeplkcghgdjbf" target="_blank">
<img alt="DetectRTC" src="https://webrtcweb.com/DetectRTC/icon.png" style="width: 20px;vertical-align: middle;margin-right: 3px;">
DetectRTC Google Chrome Extension
</a>
</section>

<section class="experiment" id="detectrtc-output">
<button id="generate-image" style="float:right;">Open as Image</button>
<h2 id="welcome">DetectRTC!</h2>
Expand All @@ -131,6 +124,13 @@ <h2 id="welcome">DetectRTC!</h2>
<!-- dirty trick to bypass webrtc blockers -->
<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>

<section class="experiment" style="padding: 10px 20px; text-align: center;">
<a href="https://chrome.google.com/webstore/detail/detectrtc/infnkpmpcmmofkmndpheeplkcghgdjbf" target="_blank">
<img alt="DetectRTC" src="https://webrtcweb.com/DetectRTC/icon.png" style="width: 20px;vertical-align: middle;margin-right: 3px;">
DetectRTC Google Chrome Extension
</a>
</section>

<script>
var browserFeaturesTable = document.querySelector('#browser-features');

Expand Down Expand Up @@ -280,6 +280,8 @@ <h2 id="welcome">DetectRTC!</h2>

function detectIpAddresses(stream) {
DetectRTC.DetectLocalIPAddress(function(ipAddress, isPublic, isIpv4) {
if(!ipAddress) return;

// console.log(ipAddress, isPublic, isIpv4);
if (ipAddress.indexOf('Local') !== -1) {
appendTR('Your <strong>Local</strong> IP Address', ipAddress);
Expand Down Expand Up @@ -330,7 +332,6 @@ <h2 id="welcome">DetectRTC!</h2>
# Chrome+Opera desktopCapture API i.e. extension';
this.parentNode.appendChild(pre);
pre.focus();
sh_highlightDocument();
};

document.getElementById('infoIcon-set-sink-id').onclick = function() {
Expand All @@ -349,7 +350,6 @@ <h2 id="welcome">DetectRTC!</h2>
}';
this.parentNode.appendChild(pre);
pre.focus();
sh_highlightDocument();
};

document.getElementById('infoIcon-apply-constraints').onclick = function() {
Expand All @@ -371,7 +371,6 @@ <h2 id="welcome">DetectRTC!</h2>
});';
this.parentNode.appendChild(pre);
pre.focus();
sh_highlightDocument();
};

document.getElementById('infoIcon-replace-tracks').onclick = function() {
Expand All @@ -389,7 +388,6 @@ <h2 id="welcome">DetectRTC!</h2>
rtpSenders.replaceTrack(newTrack);';
this.parentNode.appendChild(pre);
pre.focus();
sh_highlightDocument();
};
}

Expand Down Expand Up @@ -506,6 +504,10 @@ <h2 class="header">
How to use <a href="https://github.com/muaz-khan/DetectRTC" target="_blank">DetectRTC</a>?</h2>
<pre class="sh_html">
&lt;script src="https://cdn.WebRTC-Experiment.com/DetectRTC.js"&gt;&lt;/script&gt;
&lt;script&gt;
// OR otherwise use <a href="https://www.npmjs.com/package/detectrtc">NPM</a>
var DetectRTC = require('detectrtc');
&lt;/script&gt;
</pre>
</section>
<section class="experiment">
Expand Down Expand Up @@ -571,15 +573,5 @@ <h2 class="header">
window.useThisGithubPath = 'muaz-khan/DetectRTC';
</script>
<script src="https://cdn.webrtc-experiment.com/commits.js" async> </script>

<!-- scripts to highlight syntax -->
<script src="https://cdn.webrtc-experiment.com/syntax/sh_main.min.js" type="text/javascript"> </script>
<script src="https://cdn.webrtc-experiment.com/syntax/sh_javascript.min.js" type="text/javascript"> </script>
<script src="https://cdn.webrtc-experiment.com/syntax/sh_html.min.js" type="text/javascript"> </script>
<link href="https://cdn.webrtc-experiment.com/syntax/sh_style.css" type="text/css" rel="stylesheet">

<script>
sh_highlightDocument();
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "detectrtc",
"preferGlobal": false,
"version": "1.3.7",
"version": "1.3.8",
"author": {
"name": "Muaz Khan",
"email": "[email protected]",
"url": "http://www.muazkhan.com/"
"url": "https://muazkhan.com/"
},
"description": "A tiny JavaScript library that can be used to detect WebRTC features e.g. system having speakers, microphone or webcam, screen capturing is supported, number of audio/video devices etc.",
"repository": {
Expand Down

0 comments on commit bf28ff7

Please sign in to comment.