diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6c5424e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +# editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d9db9a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +.DS_Store +build +lib-cov +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.gz + +pids +logs +results + +npm-debug.log +node_modules +*.sublime* +*.node +coverage +*.orig +.idea +sandbox diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..727d54a --- /dev/null +++ b/.jshintrc @@ -0,0 +1,19 @@ +{ + "camelcase": true, + "curly": true, + "eqeqeq": true, + "freeze": true, + "indent": 2, + "newcap": false, + "quotmark": "single", + "maxdepth": 3, + "maxstatements": 50, + "maxlen": 80, + "eqnull": true, + "funcscope": true, + "strict": true, + "undef": true, + "unused": true, + "node": true, + "mocha": true +} diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..d9db9a3 --- /dev/null +++ b/.npmignore @@ -0,0 +1,23 @@ +.DS_Store +build +lib-cov +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.gz + +pids +logs +results + +npm-debug.log +node_modules +*.sublime* +*.node +coverage +*.orig +.idea +sandbox diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9e3cf9a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +sudo: false +language: node_js +node_js: + - 'iojs' + - '0.12' + - '0.10' + - '4.0.0' +after_script: + - npm run coveralls diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..900e6a4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2015 Contra + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..040e5ca --- /dev/null +++ b/README.md @@ -0,0 +1,76 @@ +# rtc-everywhere [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Support us][gittip-image]][gittip-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] + + +## Information + + + + + + + + + + + + + + +
Packagertc-everywhere
DescriptionCross-everything WebRTC Adapter/Polyfill
Node Version>= 0.10
+ +## Usage + +## Install + +``` +npm install rtc-everywhere --save +``` +## Example + +```js +EXAMPLEHERE +``` + +## LICENSE + +(MIT License) + +Copyright (c) 2015 Contra + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +[gittip-url]: https://www.gittip.com/contra/ +[gittip-image]: http://img.shields.io/gittip/contra.svg + +[downloads-image]: http://img.shields.io/npm/dm/rtc-everywhere.svg +[npm-url]: https://npmjs.org/package/rtc-everywhere +[npm-image]: http://img.shields.io/npm/v/rtc-everywhere.svg + +[travis-url]: https://travis-ci.org/contra/rtc-everywhere +[travis-image]: https://travis-ci.org/contra/rtc-everywhere.png?branch=master + +[coveralls-url]: https://coveralls.io/r/contra/rtc-everywhere +[coveralls-image]: https://coveralls.io/repos/contra/rtc-everywhere/badge.png + +[depstat-url]: https://david-dm.org/contra/rtc-everywhere +[depstat-image]: https://david-dm.org/contra/rtc-everywhere.png + +[david-url]: https://david-dm.org/contra/rtc-everywhere +[david-image]: https://david-dm.org/contra/rtc-everywhere.png?theme=shields.io diff --git a/index.js b/index.js new file mode 100644 index 0000000..41952db --- /dev/null +++ b/index.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = {}; \ No newline at end of file diff --git a/lib/getUserMedia/browser.js b/lib/getUserMedia/browser.js new file mode 100644 index 0000000..0d07e0d --- /dev/null +++ b/lib/getUserMedia/browser.js @@ -0,0 +1,31 @@ +'use strict'; + +module.exports = function() { + if (typeof navigator === 'undefined') return; + var getUserMedia = navigator.getUserMedia + || navigator.webkitGetUserMedia + || navigator.mozGetUserMedia + || navigator.msGetUserMedia; + if (typeof getUserMedia === 'undefined') return; + + return function(constraints, cb) { + // make constraints optional + if (arguments.length !== 2) { + cb = constraints; + constraints = { + video: true, + audio: true + }; + } + + function success(stream) { + cb(null, stream); + } + + function error(err) { + cb(err); + } + + getUserMedia.call(navigator, constraints, success, error); + }; +}; diff --git a/lib/getUserMedia/ios.js b/lib/getUserMedia/ios.js new file mode 100644 index 0000000..cf8e802 --- /dev/null +++ b/lib/getUserMedia/ios.js @@ -0,0 +1,28 @@ +'use strict'; + +module.exports = function() { + return function(constraints, cb) { + if (typeof cordova === 'undefined') return; + if (typeof cordova.plugins === 'undefined') return; + if (typeof cordova.plugins.iosrtc === 'undefined') return; + + // make constraints optional + if (arguments.length !== 2) { + cb = constraints; + constraints = { + video: true, + audio: true + }; + } + + function success(stream) { + cb(null, stream); + } + + function error(err) { + cb(err); + } + + cordova.plugins.iosrtc.getUserMedia(constraints, success, error); + }; +}; diff --git a/lib/getUserMedia/node.js b/lib/getUserMedia/node.js new file mode 100644 index 0000000..eb68907 --- /dev/null +++ b/lib/getUserMedia/node.js @@ -0,0 +1,15 @@ +'use strict'; + +module.exports = function() { + return function(constraints, cb) { + + // make constraints optional + if (arguments.length !== 2) { + cb = constraints; + } + + var err = new Error('MediaStreamError'); + err.name = 'NotSupportedError'; + return cb(err); + }; +}; diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..3af469f --- /dev/null +++ b/lib/index.js @@ -0,0 +1,41 @@ +'use strict'; + +var browser = require('detect-browser'); + +var getUserMedia, rtc; +switch (browser.name) { + case 'node': + getUserMedia = require('./getUserMedia/node'); + rtc = require('./rtc/node'); + break; + case 'ios': + getUserMedia = require('./getUserMedia/ios'); + rtc = require('./rtc/ios'); + break; + case 'chrome': + getUserMedia = require('./getUserMedia/browser'); + rtc = require('./rtc/chrome'); + break; + case 'firefox': + getUserMedia = require('./getUserMedia/browser'); + rtc = require('./rtc/firefox'); + break; + case 'edge': + getUserMedia = require('./getUserMedia/browser'); + rtc = require('./rtc/edge'); + break; + default: + getUserMedia = require('./getUserMedia/browser'); + rtc = require('./rtc/unsupported'); + break; +} + +module.exports = function() { + var ctors = rtc(); + return { + getUserMedia: getUserMedia(), + RTCPeerConnection: ctors.RTCPeerConnection, + RTCSessionDescription: ctors.RTCSessionDescription, + RTCIceCandidate: ctors.RTCIceCandidate + }; +}; diff --git a/lib/rtc/chrome.js b/lib/rtc/chrome.js new file mode 100644 index 0000000..fdd1980 --- /dev/null +++ b/lib/rtc/chrome.js @@ -0,0 +1,10 @@ +'use strict'; + +module.exports = function() { + if (typeof window === 'undefined') return; + return { + RTCPeerConnection: window.RTCPeerConnection || window.webkitRTCPeerConnection, + RTCSessionDescription: window.RTCSessionDescription || window.webkitRTCSessionDescription, + RTCIceCandidate: window.RTCIceCandidate || window.webkitRTCIceCandidate + }; +}; diff --git a/lib/rtc/edge.js b/lib/rtc/edge.js new file mode 100644 index 0000000..e74ed6c --- /dev/null +++ b/lib/rtc/edge.js @@ -0,0 +1,10 @@ +'use strict'; + +module.exports = function() { + var ortc = require('ortc-adapter'); + return { + RTCPeerConnection: ortc.RTCPeerConnection, + RTCSessionDescription: ortc.RTCSessionDescription, + RTCIceCandidate: ortc.RTCIceCandidate + }; +}; diff --git a/lib/rtc/firefox.js b/lib/rtc/firefox.js new file mode 100644 index 0000000..fbeb305 --- /dev/null +++ b/lib/rtc/firefox.js @@ -0,0 +1,10 @@ +'use strict'; + +module.exports = function() { + if (typeof window === 'undefined') return; + return { + RTCPeerConnection: window.RTCPeerConnection || window.mozRTCPeerConnection, + RTCSessionDescription: window.RTCSessionDescription || window.mozRTCSessionDescription, + RTCIceCandidate: window.RTCIceCandidate || window.mozRTCIceCandidate + }; +}; diff --git a/lib/rtc/ios.js b/lib/rtc/ios.js new file mode 100644 index 0000000..9e8a4b1 --- /dev/null +++ b/lib/rtc/ios.js @@ -0,0 +1,13 @@ +'use strict'; + +module.exports = function() { + if (typeof cordova === 'undefined') return; + if (typeof cordova.plugins === 'undefined') return; + if (typeof cordova.plugins.iosrtc === 'undefined') return; + + return { + RTCPeerConnection: cordova.plugins.iosrtc.RTCPeerConnection, + RTCSessionDescription: cordova.plugins.iosrtc.RTCSessionDescription, + RTCIceCandidate: cordova.plugins.iosrtc.RTCIceCandidate + }; +}; diff --git a/lib/rtc/node.js b/lib/rtc/node.js new file mode 100644 index 0000000..214e180 --- /dev/null +++ b/lib/rtc/node.js @@ -0,0 +1,10 @@ +'use strict'; + +module.exports = function() { + var wrtc = require('wrtc'); + return { + RTCPeerConnection: wrtc.RTCPeerConnection, + RTCSessionDescription: wrtc.RTCSessionDescription, + RTCIceCandidate: wrtc.RTCIceCandidate + }; +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..b24ff72 --- /dev/null +++ b/package.json @@ -0,0 +1,38 @@ +{ + "name": "rtc-everywhere", + "description": "Cross-everything WebRTC Adapter/Polyfill", + "version": "0.0.1", + "homepage": "http://github.com/contra/rtc-everywhere", + "repository": "git://github.com/contra/rtc-everywhere.git", + "author": "Contra (http://contra.io)", + "dependencies": { + "detect-browser": "^1.2.0", + "ortc-adapter": "^0.1.6" + }, + "devDependencies": { + "istanbul-coveralls": "^1.0.1", + "jshint": "^2.5.11", + "jshint-stylish": "^2.0.0", + "mochify": "dylanfm/mochify.js", + "mochify-istanbul": "^2.1.1", + "should": "^7.0.0" + }, + "optionalDependencies": { + "wrtc": "^0.0.59" + }, + "main": "./index.js", + "scripts": { + "lint": "jshint index.js lib --exclude node_modules --config .jshintrc --reporter node_modules/jshint-stylish/index.js", + "test": "npm run-script lint && mochify --recursive --reporter spec", + "coveralls": "mochify --recursive --plugin [ mochify-istanbul --exclude '**/+(test|node_modules)/**/*' --report lcov --dir ./coverage ] && istanbul-coveralls" + }, + "engines": { + "node": ">= 0.10" + }, + "licenses": [ + { + "type": "MIT", + "url": "http://github.com/contra/rtc-everywhere/raw/master/LICENSE" + } + ] +} diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..7b8f731 --- /dev/null +++ b/test/index.js @@ -0,0 +1,11 @@ +'use strict'; + +var should = require('should'); +var rtc-everywhere = require('../'); + +describe('FUNCTIONNAME()', function() { + it('should TASKNAME', function(done) { + should.exist(rtc-everywhere); + done(); + }); +});