From 925d434473d66ac9051768960452ae97390b2b8f Mon Sep 17 00:00:00 2001 From: Contra Date: Thu, 17 Dec 2015 12:23:05 -0800 Subject: [PATCH] fixes --- README.md | 9 +++++++++ examples/loopback/index.js | 8 ++++---- lib/temasys/index.js | 1 + platforms/chrome/attachStream.js | 2 +- platforms/chrome/gum.js | 10 +++++++--- platforms/cordova-ios/attachStream.js | 2 +- platforms/edge/attachStream.js | 2 +- platforms/edge/gum.js | 3 +++ platforms/firefox/attachStream.js | 2 +- platforms/firefox/gum.js | 4 ++++ platforms/ie/attachStream.js | 2 +- platforms/ie/gum.js | 6 ++++++ platforms/ie/rtc.js | 2 ++ platforms/react-native/attachStream.js | 2 +- platforms/react-native/gum.js | 4 ++++ platforms/safari/attachStream.js | 2 +- platforms/safari/gum.js | 5 +++++ platforms/safari/rtc.js | 2 ++ platforms/unsupported/attachStream.js | 2 +- util/onStreamLoaded/index.js | 2 +- util/onStreamLoaded/isVideoWorking.js | 4 ++-- 21 files changed, 58 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5c7d40c..a4d2e64 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ var rtc = require('rtc-everywhere')(); // rtc.RTCIceCandidate // rtc.RTCSessionDescription // rtc.getUserMedia +// rtc.attachStream(stream, videoElement) ``` ### API @@ -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) diff --git a/examples/loopback/index.js b/examples/loopback/index.js index c36eae0..1019e7c 100644 --- a/examples/loopback/index.js +++ b/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; @@ -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); @@ -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); }); diff --git a/lib/temasys/index.js b/lib/temasys/index.js index 8074dfa..7195bac 100644 --- a/lib/temasys/index.js +++ b/lib/temasys/index.js @@ -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()) { diff --git a/platforms/chrome/attachStream.js b/platforms/chrome/attachStream.js index 2a98d02..530a67c 100644 --- a/platforms/chrome/attachStream.js +++ b/platforms/chrome/attachStream.js @@ -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; }; diff --git a/platforms/chrome/gum.js b/platforms/chrome/gum.js index d340be1..fe4c2c7 100644 --- a/platforms/chrome/gum.js +++ b/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; diff --git a/platforms/cordova-ios/attachStream.js b/platforms/cordova-ios/attachStream.js index 4a8e63c..d1a8397 100644 --- a/platforms/cordova-ios/attachStream.js +++ b/platforms/cordova-ios/attachStream.js @@ -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(); diff --git a/platforms/edge/attachStream.js b/platforms/edge/attachStream.js index fbdee54..ccee148 100644 --- a/platforms/edge/attachStream.js +++ b/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; }; diff --git a/platforms/edge/gum.js b/platforms/edge/gum.js index 5d8b273..0a2f4b2 100644 --- a/platforms/edge/gum.js +++ b/platforms/edge/gum.js @@ -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; diff --git a/platforms/firefox/attachStream.js b/platforms/firefox/attachStream.js index fbdee54..ccee148 100644 --- a/platforms/firefox/attachStream.js +++ b/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; }; diff --git a/platforms/firefox/gum.js b/platforms/firefox/gum.js index ab35ba3..82f918c 100644 --- a/platforms/firefox/gum.js +++ b/platforms/firefox/gum.js @@ -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; diff --git a/platforms/ie/attachStream.js b/platforms/ie/attachStream.js index deab5ad..e6c7dfb 100644 --- a/platforms/ie/attachStream.js +++ b/platforms/ie/attachStream.js @@ -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); diff --git a/platforms/ie/gum.js b/platforms/ie/gum.js index fd82519..eebfefb 100644 --- a/platforms/ie/gum.js +++ b/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 @@ -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); }); }; diff --git a/platforms/ie/rtc.js b/platforms/ie/rtc.js index 19c0911..307c985 100644 --- a/platforms/ie/rtc.js +++ b/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; diff --git a/platforms/react-native/attachStream.js b/platforms/react-native/attachStream.js index 662bb44..ae894d6 100644 --- a/platforms/react-native/attachStream.js +++ b/platforms/react-native/attachStream.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function(){ - return function(el, stream) { + return function(stream, el) { // TODO }; }; diff --git a/platforms/react-native/gum.js b/platforms/react-native/gum.js index d3a3e80..977a009 100644 --- a/platforms/react-native/gum.js +++ b/platforms/react-native/gum.js @@ -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; diff --git a/platforms/safari/attachStream.js b/platforms/safari/attachStream.js index deab5ad..e6c7dfb 100644 --- a/platforms/safari/attachStream.js +++ b/platforms/safari/attachStream.js @@ -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); diff --git a/platforms/safari/gum.js b/platforms/safari/gum.js index fd82519..41a9427 100644 --- a/platforms/safari/gum.js +++ b/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 @@ -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); }); }; diff --git a/platforms/safari/rtc.js b/platforms/safari/rtc.js index 19c0911..307c985 100644 --- a/platforms/safari/rtc.js +++ b/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; diff --git a/platforms/unsupported/attachStream.js b/platforms/unsupported/attachStream.js index eb99b89..c771b63 100644 --- a/platforms/unsupported/attachStream.js +++ b/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?'); }; }; diff --git a/util/onStreamLoaded/index.js b/util/onStreamLoaded/index.js index 9c7edd1..8f3f4f4 100644 --- a/util/onStreamLoaded/index.js +++ b/util/onStreamLoaded/index.js @@ -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) { diff --git a/util/onStreamLoaded/isVideoWorking.js b/util/onStreamLoaded/isVideoWorking.js index 1294353..4668fd1 100644 --- a/util/onStreamLoaded/isVideoWorking.js +++ b/util/onStreamLoaded/isVideoWorking.js @@ -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;