Skip to content
Permalink
Browse files

options to override platform and platforms list

  • Loading branch information
contra committed Jan 2, 2016
1 parent 6235e0b commit f68c72bcfd5ec4a6777078e795c63a08e43a02c0
Showing with 31 additions and 5 deletions.
  1. +3 −1 examples/loopback/index.js
  2. +3 −1 index.js
  3. +25 −3 lib/findPlatform.js
@@ -1,11 +1,13 @@
//require('es5-shim-sham');

var rtc = require('../../')();
var ctor = require('../../');
var rtc = ctor();
var Peer = require('simple-peer');
var crel = require('crel');
var browser = require('detect-browser');
var onStreamLoaded = require('../../util/onStreamLoaded');

window.ctor = ctor;
window.rtc = rtc;
bootstrap();

@@ -4,7 +4,7 @@ var findPlatform = require('./lib/findPlatform');

module.exports = function(opt) {
if (!opt) opt = {};
var match = findPlatform();
var match = findPlatform(opt);
var ctors = match.platform.rtc(opt);
var gum = match.platform.gum(opt);
var attachStream = match.platform.attachStream(opt);
@@ -20,3 +20,5 @@ module.exports = function(opt) {
attachStream: attachStream
};
};

module.exports.platforms = findPlatform.platforms;
@@ -2,14 +2,35 @@

var requireDir = require('bulk-require');
var platforms = requireDir(__dirname + '/../platforms', ['**/*.js']);
var platformKeys = Object.keys(platforms);

function matches(k){
var platform = platforms[k];
return platform.match && platform.match();
return platform && platform.match && platform.match();
}

function findPlatform() {
var foundKey = Object.keys(platforms).filter(matches)[0];
// valid options: platforms, platform
function findPlatform(opt) {
var availPlatforms = platformKeys;
var foundKey;

if (opt && opt.platforms) {
if (!Array.isArray(opt.platforms)) {
throw new Error('Invalid platforms option');
}
availPlatforms = availPlatforms.filter(function(p){
return opt.platforms.indexOf(p) !== -1;
});
}

if (opt && opt.platform) {
if (availPlatforms.indexOf(opt.platform) === -1) {
throw new Error('Invalid platform option');
}
foundKey = opt.platform;
} else {
foundKey = availPlatforms.filter(matches)[0];
}

return {
name: foundKey || 'unsupported',
@@ -18,3 +39,4 @@ function findPlatform() {
}

module.exports = findPlatform;
module.exports.platforms = platformKeys;

0 comments on commit f68c72b

Please sign in to comment.
You can’t perform that action at this time.