Skip to content

Commit

Permalink
Merge pull request #6 from rtc-io/specify-mandatory
Browse files Browse the repository at this point in the history
Allow generation of mandatory constraints
  • Loading branch information
nathanoehlman committed Jun 22, 2015
2 parents bc1ffef + bf6e912 commit 9cc54a2
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .zuul.yml
@@ -1,7 +1,7 @@
ui: tape
browsers:
- name: chrome
version: [35,36,beta]
version: [41,42,beta]

- name: firefox
version: 30..latest
version: [36,37,beta]
20 changes: 15 additions & 5 deletions index.js
Expand Up @@ -2,6 +2,7 @@
'use strict';

var detect = require('rtc-core/detect');
var extend = require('cog/extend');
var reSeparator = /[\,\s]\s*/;
var offFlags = ['false', 'none', 'off'];
var reFPS = /(\d+)fps/i;
Expand Down Expand Up @@ -357,6 +358,15 @@ prot.toConstraints = function(opts) {
return info && info.kind === 'audio';
});
var selectedSource;
var useMandatory = !!(opts || {}).useMandatory;

function addConstraints(section, constraints) {
if (useMandatory) {
return extend.apply(null, [m[section]].concat(constraints));
}

o[section] = o[section].concat(constraints);
}

function complexConstraints(target) {
if (constraints[target] && typeof constraints[target] != 'object') {
Expand All @@ -381,19 +391,19 @@ prot.toConstraints = function(opts) {
// fps
if (cfg.fps) {
complexConstraints('video');
o.video = o.video.concat(buildConstraints('frameRate', cfg.fps));
addConstraints('video', buildConstraints('frameRate', cfg.fps));
}

// min res specified
if (cfg.res) {
complexConstraints('video');

o.video = o.video.concat(buildConstraints('width', {
addConstraints('video', buildConstraints('width', {
min: cfg.res.min && cfg.res.min.w,
max: cfg.res.max && cfg.res.max.w
}));

o.video = o.video.concat(buildConstraints('height', {
addConstraints('video', buildConstraints('height', {
min: cfg.res.min && cfg.res.min.h,
max: cfg.res.max && cfg.res.max.h
}));
Expand All @@ -405,7 +415,7 @@ prot.toConstraints = function(opts) {

if (selectedSource) {
complexConstraints('video');
o.video.push({ sourceId: selectedSource.id });
addConstraints('video', { sourceId: selectedSource.id });
}
}

Expand All @@ -415,7 +425,7 @@ prot.toConstraints = function(opts) {

if (selectedSource) {
complexConstraints('audio');
o.audio.push({ sourceId: selectedSource.id });
addConstraints('audio', { sourceId: selectedSource.id });
}
}

Expand Down
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -22,15 +22,15 @@
"url": "https://github.com/rtc-io/rtc-captureconfig/issues"
},
"devDependencies": {
"async": "^0.9.0",
"async": "^1.0.0",
"crel": "^2.1.5",
"getusermedia": "^1.1.0",
"rtc-media": "^1.5.5",
"tape": "^3.0.1",
"zuul": "^1.10.0"
"tape": "^4.0.0",
"zuul": "^3.0.0"
},
"dependencies": {
"cog": "^1.0.0",
"cog": "^1.1.0",
"rtc-core": "^4.0.0"
}
}
}
1 change: 1 addition & 0 deletions test/all.js
Expand Up @@ -9,6 +9,7 @@ require('./camera-targets');
require('./camera-resolution-constraints');
require('./camera-fps-constraints');
require('./camera-combo-constraints');
require('./camera-combo-constraints-mandatory');
require('./camera-noaudio-constraints');
require('./camera-targets-constraints');

Expand Down
36 changes: 36 additions & 0 deletions test/camera-combo-constraints-mandatory.js
@@ -0,0 +1,36 @@
var test = require('tape');
var expect = require('./helpers/expect-constraints-mandatory');

test('camera min:1280x720 15fps', expect({
audio: true,
video: {
mandatory: {
minFrameRate: 15,
maxFrameRate: 15,
frameRate: 15,
minWidth: 1280,
width: { min: 1280 },
minHeight: 720,
height: { min: 720 }
},
optional: []
}
}));

test('camera min:1280x720 max:1280x720 min:15fps max:25fps', expect({
audio: true,
video: {
mandatory: {
minFrameRate: 15,
maxFrameRate: 25,
frameRate: { min: 15, max: 25 },
minWidth: 1280,
maxWidth: 1280,
width: 1280,
minHeight: 720,
maxHeight: 720,
height: 720
},
optional: []
}
}));
12 changes: 12 additions & 0 deletions test/helpers/expect-constraints-mandatory.js
@@ -0,0 +1,12 @@
var captureconfig = require('../../');

module.exports = function(expected) {
return function(t) {
t.plan(1);
t.deepEqual(
captureconfig(t.name).toConstraints({ useMandatory: true }),
expected,
JSON.stringify(expected)
);
};
};

0 comments on commit 9cc54a2

Please sign in to comment.