Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Dec 17, 2015
1 parent dcb7802 commit 925d434
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 18 deletions.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -44,6 +44,7 @@ var rtc = require('rtc-everywhere')();
// rtc.RTCIceCandidate
// rtc.RTCSessionDescription
// rtc.getUserMedia
// rtc.attachStream(stream, videoElement)
```

### API
Expand Down Expand Up @@ -71,6 +72,14 @@ rtc.getUserMedia(function(err, stream){});
rtc.getUserMedia({video: true, audio: true}, function(err, stream){});
```

#### attachStream(stream, element)

- Attaches a stream to a given video element
- Returns the element the video was attached to
- In IE and Safari, the video element will be replaced by an `object` element
- Elements will not be replaced or modified unless they exist on the DOM
- Regardless of replacement, the new `object` element will be returned

### Related Libraries
- [simple-peer](https://github.com/feross/simple-peer)
- [blob-util](https://github.com/nolanlawson/blob-util)
Expand Down
8 changes: 4 additions & 4 deletions examples/loopback/index.js
@@ -1,10 +1,10 @@
require('es5-shim-sham');
//require('es5-shim-sham');

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

window.rtc = rtc;

Expand All @@ -17,7 +17,7 @@ function makeVideo(stream) {
var el = crel('video', {
muted: true,
autoplay: true,
className: 'video-stream'
className: 'video-stream',
style: 'height:100px; width:100px; display:inline-block; background-color:black;'
});
return rtc.attachStream(el, stream);
Expand All @@ -27,7 +27,7 @@ rtc.getUserMedia(function(err, stream){
if (err) {
return console.error(err);
}
isStreamWorking(stream, function(err, res){
onStreamLoaded(stream, function(err, res){
console.log(err, res);
});

Expand Down
1 change: 1 addition & 0 deletions lib/temasys/index.js
Expand Up @@ -15,6 +15,7 @@ var pluginId = uuid.v4();
var pageId = uuid.v4();
var onLoadFn = '___$' + pluginId;

// TODO: handle not installed
// this takes about 272ms to load the plugin
module.exports = function(cb){
if (!isInstalled()) {
Expand Down
2 changes: 1 addition & 1 deletion platforms/chrome/attachStream.js
Expand Up @@ -2,7 +2,7 @@

module.exports = function(){
var URL = window.URL || window.webkitURL;
return function(el, stream) {
return function(stream, el) {
el.src = URL.createObjectURL(stream);
return el;
};
Expand Down
10 changes: 7 additions & 3 deletions platforms/chrome/gum.js
@@ -1,10 +1,14 @@
'use strict';

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

return function(constraints, cb) {
var getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia;

if (!getUserMedia) {
throw new Error('Failed to find getUserMedia');
}

// make constraints optional
if (arguments.length !== 2) {
cb = constraints;
Expand Down
2 changes: 1 addition & 1 deletion platforms/cordova-ios/attachStream.js
Expand Up @@ -7,7 +7,7 @@ function needPlatform(){
module.exports = function(){
var URL = window.URL || window.webkitURL;

return function(el, stream) {
return function(stream, el) {
if (typeof cordova === 'undefined') return needPlatform();
if (typeof cordova.plugins === 'undefined') return needPlatform();
if (typeof cordova.plugins.iosrtc === 'undefined') return needPlatform();
Expand Down
2 changes: 1 addition & 1 deletion platforms/edge/attachStream.js
@@ -1,7 +1,7 @@
'use strict';

module.exports = function(){
return function(el, stream) {
return function(stream, el) {
el.srcObject = stream;
return el;
};
Expand Down
3 changes: 3 additions & 0 deletions platforms/edge/gum.js
Expand Up @@ -5,6 +5,9 @@ module.exports = function(opt) {
var getUserMedia = navigator.getUserMedia ||
navigator.msGetUserMedia;

if (!getUserMedia) {
throw new Error('Failed to find getUserMedia');
}
// make constraints optional
if (arguments.length !== 2) {
cb = constraints;
Expand Down
2 changes: 1 addition & 1 deletion platforms/firefox/attachStream.js
@@ -1,7 +1,7 @@
'use strict';

module.exports = function(){
return function(el, stream) {
return function(stream, el) {
el.srcObject = stream;
return el;
};
Expand Down
4 changes: 4 additions & 0 deletions platforms/firefox/gum.js
Expand Up @@ -5,6 +5,10 @@ module.exports = function(opt) {
var getUserMedia = navigator.getUserMedia ||
navigator.mozGetUserMedia;

if (!getUserMedia) {
throw new Error('Failed to find getUserMedia');
}

// make constraints optional
if (arguments.length !== 2) {
cb = constraints;
Expand Down
2 changes: 1 addition & 1 deletion platforms/ie/attachStream.js
Expand Up @@ -3,7 +3,7 @@
module.exports = function(){
var copyStyle = require('../../lib/copyStyle');
var temasys = require('../../lib/temasys');
return function(el, stream) {
return function(stream, el) {
var newVideo = temasys.createVideo(stream);
copyStyle(el, newVideo);

Expand Down
6 changes: 6 additions & 0 deletions platforms/ie/gum.js
@@ -1,5 +1,7 @@
'use strict';

// TODO: handle not installed

module.exports = function(opt) {
var temasys = require('../../lib/temasys');
temasys(); // start loading ahead of time
Expand All @@ -24,6 +26,10 @@ module.exports = function(opt) {
}

temasys(function(rtc){
if (!rtc || !rtc.getUserMedia) {
throw new Error('Failed to find getUserMedia');
}

rtc.getUserMedia(constraints, success, error);
});
};
Expand Down
2 changes: 2 additions & 0 deletions platforms/ie/rtc.js
@@ -1,5 +1,7 @@
'use strict';

// TODO: handle not installed

module.exports = function() {
var MockRTC = require('../../lib/temasys/MockRTC');
return MockRTC;
Expand Down
2 changes: 1 addition & 1 deletion platforms/react-native/attachStream.js
@@ -1,7 +1,7 @@
'use strict';

module.exports = function(){
return function(el, stream) {
return function(stream, el) {
// TODO
};
};
4 changes: 4 additions & 0 deletions platforms/react-native/gum.js
Expand Up @@ -10,6 +10,10 @@ module.exports = function(opt) {
return function(constraints, cb) {
var getUserMedia = navigator.getUserMedia;

if (!getUserMedia) {
throw new Error('Failed to find getUserMedia');
}

// make constraints optional
if (arguments.length !== 2) {
cb = constraints;
Expand Down
2 changes: 1 addition & 1 deletion platforms/safari/attachStream.js
Expand Up @@ -3,7 +3,7 @@
module.exports = function(){
var copyStyle = require('../../lib/copyStyle');
var temasys = require('../../lib/temasys');
return function(el, stream) {
return function(stream, el) {
var newVideo = temasys.createVideo(stream);
copyStyle(el, newVideo);

Expand Down
5 changes: 5 additions & 0 deletions platforms/safari/gum.js
@@ -1,5 +1,7 @@
'use strict';

// TODO: handle not installed

module.exports = function(opt) {
var temasys = require('../../lib/temasys');
temasys(); // start loading ahead of time
Expand All @@ -24,6 +26,9 @@ module.exports = function(opt) {
}

temasys(function(rtc){
if (!rtc || !rtc.getUserMedia) {
throw new Error('Failed to find getUserMedia');
}
rtc.getUserMedia(constraints, success, error);
});
};
Expand Down
2 changes: 2 additions & 0 deletions platforms/safari/rtc.js
@@ -1,5 +1,7 @@
'use strict';

// TODO: handle not installed

module.exports = function() {
var MockRTC = require('../../lib/temasys/MockRTC');
return MockRTC;
Expand Down
2 changes: 1 addition & 1 deletion platforms/unsupported/attachStream.js
@@ -1,7 +1,7 @@
'use strict';

module.exports = function(){
return function(el, stream) {
return function(stream, el) {
throw new Error('No DOM, what are you doing?');
};
};
2 changes: 1 addition & 1 deletion util/onStreamLoaded/index.js
Expand Up @@ -6,8 +6,8 @@ var isVideoWorking = require('./isVideoWorking');

function isStreamWorking(opt, stream, cb) {
if (arguments.length !== 3) {
stream = opt;
cb = stream;
stream = opt;
opt = null;
}
if (!opt) {
Expand Down
4 changes: 2 additions & 2 deletions util/onStreamLoaded/isVideoWorking.js
Expand Up @@ -44,8 +44,8 @@ function isVideoWorking(stream, cb){
});

actualEl = rtcInst.attachStream(stream, vidEl);
actualEl.addEventListener('canplay', canPlay, false);
actualEl.addEventListener('playing', canPlay, false);
actualEl.addEventListener('canplay', finishIt.bind(null, null), false);
actualEl.addEventListener('playing', finishIt.bind(null, null), false);
}

module.exports = isVideoWorking;

0 comments on commit 925d434

Please sign in to comment.