Skip to content

Commit

Permalink
Added detectrtc@1.3.0 Now supporting AMD modules + NPM
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed May 4, 2016
1 parent e745f78 commit dfbd400
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 11 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ node_js:
- "0.11"
install: npm install
before_script:
- npm install grunt-cli
- npm install grunt
- npm install grunt-cli@0.1.13 -g
- npm install grunt@0.4.5
- grunt
after_failure: npm install && grunt
matrix:
fast_finish: true
fast_finish: true
60 changes: 58 additions & 2 deletions DetectRTC.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated: 2016-04-26 1:45:40 PM UTC
// Last time updated: 2016-05-04 3:50:22 PM UTC

// Latest file can be found here: https://cdn.webrtc-experiment.com/DetectRTC.js

Expand All @@ -16,6 +16,53 @@

'use strict';

var browserFakeUserAgent = 'Fake/5.0 (FakeOS) AppleWebKit/123 (KHTML, like Gecko) Fake/12.3.4567.89 Fake/123.45';

(function(that) {
if (typeof window !== 'undefined') {
return;
}

if (typeof window === 'undefined' && typeof global !== 'undefined') {
global.navigator = {
userAgent: browserFakeUserAgent,
getUserMedia: function() {}
};

/*global window:true */
that.window = global;
} else if (typeof window === 'undefined') {
// window = this;
}

if (typeof document === 'undefined') {
/*global document:true */
that.document = {};

document.createElement = document.captureStream = document.mozCaptureStream = function() {
return {};
};
}

if (typeof location === 'undefined') {
/*global location:true */
that.location = {
protocol: 'file:',
href: '',
hash: ''
};
}

if (typeof screen === 'undefined') {
/*global screen:true */
that.screen = {
width: 0,
height: 0
};
}
})(typeof global !== 'undefined' ? global : window);

/*global navigator:true */
var navigator = window.navigator;

if (typeof navigator !== 'undefined') {
Expand All @@ -29,7 +76,7 @@
} else {
navigator = {
getUserMedia: function() {},
userAgent: 'Fake/5.0 (FakeOS) AppleWebKit/123 (KHTML, like Gecko) Fake/12.3.4567.89 Fake/123.45'
userAgent: browserFakeUserAgent
};
}

Expand Down Expand Up @@ -965,4 +1012,13 @@

window.DetectRTC = DetectRTC;

if (typeof module !== 'undefined' /* && !!module.exports*/ ) {
module.exports = DetectRTC;
}

if (typeof define === 'function' && define.amd) {
define('DetectRTC', [], function() {
return DetectRTC;
});
}
})();
4 changes: 2 additions & 2 deletions DetectRTC.min.js

Large diffs are not rendered by default.

30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ node server.js
http://localhost:9001
```

# Test on NPM

```javascript
var DetectRTC = require('detectrtc');

console.log(DetectRTC.browser);

DetectRTC.load(function() {
console.log(DetectRTC);
});
```

* Live NPM test: https://tonicdev.com/npm/detectrtc

Or try `npm-test.js`:

```
cd node_modules
cd detectrtc
node npm-test.js
```

# How to link?

```html
Expand All @@ -66,14 +88,20 @@ http://localhost:9001
You can even link specific versions:

```html
<script src="https://github.com/muaz-khan/DetectRTC/releases/download/1.2.9/DetectRTC.js"></script>
<script src="https://github.com/muaz-khan/DetectRTC/releases/download/1.3.0/DetectRTC.js"></script>
```

<img src="https://cdn.webrtc-experiment.com/images/DetectRTC.png" style="width:100%;" />

# How to use it?

```javascript
// for node.js users
var DetectRTC = require('detectrtc');

// non-nodejs users can skip above line
// below code will work for all users

DetectRTC.load(function() {
DetectRTC.hasWebcam (has webcam device!)
DetectRTC.hasMicrophone (has microphone device!)
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "detectrtc",
"version": "1.2.9",
"version": "1.3.0",
"authors": [
{
"name": "Muaz Khan",
Expand Down
48 changes: 47 additions & 1 deletion dev/common.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
var browserFakeUserAgent = 'Fake/5.0 (FakeOS) AppleWebKit/123 (KHTML, like Gecko) Fake/12.3.4567.89 Fake/123.45';

(function(that) {
if (typeof window !== 'undefined') {
return;
}

if (typeof window === 'undefined' && typeof global !== 'undefined') {
global.navigator = {
userAgent: browserFakeUserAgent,
getUserMedia: function() {}
};

/*global window:true */
that.window = global;
} else if (typeof window === 'undefined') {
// window = this;
}

if (typeof document === 'undefined') {
/*global document:true */
that.document = {};

document.createElement = document.captureStream = document.mozCaptureStream = function() {
return {};
};
}

if (typeof location === 'undefined') {
/*global location:true */
that.location = {
protocol: 'file:',
href: '',
hash: ''
};
}

if (typeof screen === 'undefined') {
/*global screen:true */
that.screen = {
width: 0,
height: 0
};
}
})(typeof global !== 'undefined' ? global : window);

/*global navigator:true */
var navigator = window.navigator;

Expand All @@ -12,6 +58,6 @@ if (typeof navigator !== 'undefined') {
} else {
navigator = {
getUserMedia: function() {},
userAgent: 'Fake/5.0 (FakeOS) AppleWebKit/123 (KHTML, like Gecko) Fake/12.3.4567.89 Fake/123.45'
userAgent: browserFakeUserAgent
};
}
9 changes: 9 additions & 0 deletions dev/tail.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
window.DetectRTC = DetectRTC;

if (typeof module !== 'undefined' /* && !!module.exports*/ ) {
module.exports = DetectRTC;
}

if (typeof define === 'function' && define.amd) {
define('DetectRTC', [], function() {
return DetectRTC;
});
}
})();
11 changes: 11 additions & 0 deletions npm-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// https://tonicdev.com/npm/detectrtc

var DetectRTC = require('detectrtc');

console.log(DetectRTC.browser);

console.log('\n\n-------\n\n');

DetectRTC.load(function() {
console.log(DetectRTC.browser);
});
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "detectrtc",
"preferGlobal": false,
"version": "1.2.9",
"version": "1.3.0",
"author": {
"name": "Muaz Khan",
"email": "muazkh@gmail.com",
Expand All @@ -12,6 +12,10 @@
"type": "git",
"url": "https://github.com/muaz-khan/DetectRTC.git"
},
"scripts": {
"start": "node server.js"
},
"main": "DetectRTC.js",
"keywords": [
"webrtc",
"detectrtc",
Expand All @@ -32,6 +36,7 @@
"email": "muazkh@gmail.com"
},
"homepage": "https://www.webrtc-experiment.com/DetectRTC/",
"tonicExampleFilename": "npm-test.js",
"_id": "detectrtc@",
"_from": "detectrtc@",
"devDependencies": {
Expand Down

0 comments on commit dfbd400

Please sign in to comment.