Skip to content

Commit

Permalink
attach rtc options to the stream so you can reconstruct the implement…
Browse files Browse the repository at this point in the history
…ation as needed
  • Loading branch information
Contra committed Dec 16, 2015
1 parent 87d7f53 commit bad6814
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 15 deletions.
3 changes: 2 additions & 1 deletion platforms/chrome/gum.js
@@ -1,6 +1,6 @@
'use strict';

module.exports = function() {
module.exports = function(opt) {
var getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia;

Expand All @@ -15,6 +15,7 @@ module.exports = function() {
}

function success(stream) {
stream._rtcOpt = opt;
cb(null, stream);
}

Expand Down
3 changes: 2 additions & 1 deletion platforms/cordova-ios/gum.js
Expand Up @@ -4,7 +4,7 @@ function needPlatform(){
throw new Error('Missing iosrtc plugin for getUserMedia');
}

module.exports = function() {
module.exports = function(opt) {
return function(constraints, cb) {
if (typeof cordova === 'undefined') return needPlatform();
if (typeof cordova.plugins === 'undefined') return needPlatform();
Expand All @@ -20,6 +20,7 @@ module.exports = function() {
}

function success(stream) {
stream._rtcOpt = opt;
cb(null, stream);
}

Expand Down
9 changes: 5 additions & 4 deletions platforms/edge/gum.js
@@ -1,10 +1,10 @@
'use strict';

module.exports = function() {
var getUserMedia = navigator.getUserMedia ||
navigator.msGetUserMedia;

module.exports = function(opt) {
return function(constraints, cb) {
var getUserMedia = navigator.getUserMedia ||
navigator.msGetUserMedia;

// make constraints optional
if (arguments.length !== 2) {
cb = constraints;
Expand All @@ -15,6 +15,7 @@ module.exports = function() {
}

function success(stream) {
stream._rtcOpt = opt;
cb(null, stream);
}

Expand Down
9 changes: 5 additions & 4 deletions platforms/firefox/gum.js
@@ -1,10 +1,10 @@
'use strict';

module.exports = function() {
var getUserMedia = navigator.getUserMedia ||
navigator.mozGetUserMedia;

module.exports = function(opt) {
return function(constraints, cb) {
var getUserMedia = navigator.getUserMedia ||
navigator.mozGetUserMedia;

// make constraints optional
if (arguments.length !== 2) {
cb = constraints;
Expand All @@ -15,6 +15,7 @@ module.exports = function() {
}

function success(stream) {
stream._rtcOpt = opt;
cb(null, stream);
}

Expand Down
3 changes: 2 additions & 1 deletion platforms/ie/gum.js
@@ -1,6 +1,6 @@
'use strict';

module.exports = function() {
module.exports = function(opt) {
var temasys = require('../../lib/temasys');
temasys(); // start loading ahead of time

Expand All @@ -15,6 +15,7 @@ module.exports = function() {
}

function success(stream) {
stream._rtcOpt = opt;
cb(null, stream);
}

Expand Down
4 changes: 2 additions & 2 deletions platforms/react-native/gum.js
@@ -1,14 +1,13 @@
'use strict';

module.exports = function() {
module.exports = function(opt) {
var rtc;
try {
rtc = require('react-native-webrtc');
} catch (err) {
return;
}
var getUserMedia = navigator.getUserMedia;
if (typeof getUserMedia === 'undefined') return;

return function(constraints, cb) {
// make constraints optional
Expand All @@ -21,6 +20,7 @@ module.exports = function() {
}

function success(stream) {
stream._rtcOpt = opt;
cb(null, stream);
}

Expand Down
3 changes: 2 additions & 1 deletion platforms/safari/gum.js
@@ -1,6 +1,6 @@
'use strict';

module.exports = function() {
module.exports = function(opt) {
var temasys = require('../../lib/temasys');
temasys(); // start loading ahead of time

Expand All @@ -15,6 +15,7 @@ module.exports = function() {
}

function success(stream) {
stream._rtcOpt = opt;
cb(null, stream);
}

Expand Down
5 changes: 4 additions & 1 deletion util/onStreamLoaded/isVideoWorking.js
Expand Up @@ -2,6 +2,7 @@

var hasValidTrack = require('./hasValidTrack');
var crel = require('crel');
var rtc = require('../../');
var timeoutTime = 20000;

// basic premise:
Expand All @@ -13,6 +14,8 @@ function isVideoWorking(stream, cb){
if (!hasValidTrack(stream, 'video')) return cb('dead video');
if (stream._videoMeta) return cb(null, stream._videoMeta);

var rtcInst = rtc(stream._rtcOpt);

var vidEl, actualEl;
var finished = false;
var timeout = setTimeout(finishIt.bind(null, 'no video data'), timeoutTime);
Expand Down Expand Up @@ -40,7 +43,7 @@ function isVideoWorking(stream, cb){
style: 'display: none;'
});

actualEl = attach(stream, vidEl);
actualEl = rtcInst.attachStream(stream, vidEl);
actualEl.addEventListener('canplay', canPlay, false);
actualEl.addEventListener('playing', canPlay, false);
}
Expand Down

0 comments on commit bad6814

Please sign in to comment.