Skip to content

Commit

Permalink
fix a bunch of problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Dec 15, 2015
1 parent 96b803e commit c8849c3
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"browser": true,
"mocha": true,
"globals": {
"cordova": true
"cordova": true,
"ActiveXObject": true
}
}
6 changes: 4 additions & 2 deletions lib/temasys/MockRTC.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var RTCPeerConnectionMock = mock({
]
});

/*
var RTCSessionDescriptionMock = mock({
properties: [
'type',
Expand All @@ -50,6 +51,7 @@ var RTCIceCandidateMock = mock({
'sdpMLineIndex'
]
});
*/

if (!isInstalled()) {
module.exports = {};
Expand All @@ -68,7 +70,7 @@ if (!isInstalled()) {
ctor = rtc.RTCSessionDescription;
});
if (!ctor) {
throw new Error('Tried to use RTCSessionDescription before plugin loaded!');
throw new Error('Tried RTCSessionDescription before RTCPeerConnection');
}
return nu.apply(ctor, arguments);
},
Expand All @@ -78,7 +80,7 @@ if (!isInstalled()) {
ctor = rtc.RTCIceCandidate;
});
if (!ctor) {
throw new Error('Tried to use RTCIceCandidate before plugin loaded!');
throw new Error('Tried RTCIceCandidate before RTCPeerConnection');
}
return nu.apply(ctor, arguments);
}
Expand Down
2 changes: 0 additions & 2 deletions platforms/chrome/gum.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
'use strict';

module.exports = function() {
if (typeof navigator === 'undefined') return;
var getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia;
if (typeof getUserMedia === 'undefined') return;

return function(constraints, cb) {
// make constraints optional
Expand Down
2 changes: 1 addition & 1 deletion platforms/chrome/match.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports = function(){
return typeof window!== 'undefined' &&
return typeof window !== 'undefined' &&
typeof window.chrome !== 'undefined';
};
1 change: 0 additions & 1 deletion platforms/chrome/rtc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

module.exports = function() {
if (typeof window === 'undefined') return;
return {
RTCPeerConnection: window.RTCPeerConnection ||
window.webkitRTCPeerConnection,
Expand Down
10 changes: 7 additions & 3 deletions platforms/cordova-ios/attachStream.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
'use strict';

function needPlatform(){
throw new Error('Missing iosrtc plugin for attachStream');
}

module.exports = function(){
var URL = window.URL || window.webkitURL;

return function(el, stream) {
if (typeof cordova === 'undefined') return;
if (typeof cordova.plugins === 'undefined') return;
if (typeof cordova.plugins.iosrtc === 'undefined') return;
if (typeof cordova === 'undefined') return needPlatform();
if (typeof cordova.plugins === 'undefined') return needPlatform();
if (typeof cordova.plugins.iosrtc === 'undefined') return needPlatform();

el.src = URL.createObjectURL(stream);
el.setAttribute('webkit-playsinline', 'true');
Expand Down
10 changes: 7 additions & 3 deletions platforms/cordova-ios/gum.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
'use strict';

function needPlatform(){
throw new Error('Missing iosrtc plugin for getUserMedia');
}

module.exports = function() {
return function(constraints, cb) {
if (typeof cordova === 'undefined') return;
if (typeof cordova.plugins === 'undefined') return;
if (typeof cordova.plugins.iosrtc === 'undefined') return;
if (typeof cordova === 'undefined') return needPlatform();
if (typeof cordova.plugins === 'undefined') return needPlatform();
if (typeof cordova.plugins.iosrtc === 'undefined') return needPlatform();

// make constraints optional
if (arguments.length !== 2) {
Expand Down
10 changes: 7 additions & 3 deletions platforms/cordova-ios/rtc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
'use strict';

function needPlatform(){
throw new Error('Missing iosrtc plugin for RTCPeerConnection');
}

module.exports = function() {
if (typeof cordova === 'undefined') return;
if (typeof cordova.plugins === 'undefined') return;
if (typeof cordova.plugins.iosrtc === 'undefined') return;
if (typeof cordova === 'undefined') return needPlatform();
if (typeof cordova.plugins === 'undefined') return needPlatform();
if (typeof cordova.plugins.iosrtc === 'undefined') return needPlatform();

return {
RTCPeerConnection: cordova.plugins.iosrtc.RTCPeerConnection,
Expand Down
2 changes: 0 additions & 2 deletions platforms/edge/gum.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
'use strict';

module.exports = function() {
if (typeof navigator === 'undefined') return;
var getUserMedia = navigator.getUserMedia ||
navigator.msGetUserMedia;
if (typeof getUserMedia === 'undefined') return;

return function(constraints, cb) {
// make constraints optional
Expand Down
3 changes: 1 addition & 2 deletions platforms/edge/match.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var browser = require('detect-browser');

module.exports = function(){
var browser = require('detect-browser');
return browser.name === 'edge';
};
2 changes: 0 additions & 2 deletions platforms/firefox/gum.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
'use strict';

module.exports = function() {
if (typeof navigator === 'undefined') return;
var getUserMedia = navigator.getUserMedia ||
navigator.mozGetUserMedia;
if (typeof getUserMedia === 'undefined') return;

return function(constraints, cb) {
// make constraints optional
Expand Down
1 change: 0 additions & 1 deletion platforms/firefox/rtc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

module.exports = function() {
if (typeof window === 'undefined') return;
return {
RTCPeerConnection: window.RTCPeerConnection ||
window.mozRTCPeerConnection,
Expand Down
2 changes: 1 addition & 1 deletion platforms/ie/attachStream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports = module.exports = function(){
module.exports = function(){
return function(el, stream) {
// TODO
};
Expand Down
3 changes: 1 addition & 2 deletions platforms/ie/match.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var browser = require('detect-browser');

module.exports = function(){
var browser = require('detect-browser');
return browser.name === 'ie';
};
1 change: 0 additions & 1 deletion platforms/react-native/gum.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module.exports = function() {
var rtc;
if (typeof navigator === 'undefined') return;
try {
rtc = require('react-native-webrtc');
} catch (err) {
Expand Down
7 changes: 6 additions & 1 deletion platforms/react-native/rtc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
'use strict';

module.exports = function() {
var rtc = require('react-native-webrtc');
var rtc;
try {
rtc = require('react-native-webrtc');
} catch (err) {
return;
}
return {
RTCPeerConnection: rtc.RTCPeerConnection,
RTCSessionDescription: rtc.RTCSessionDescription,
Expand Down
2 changes: 1 addition & 1 deletion platforms/safari/attachStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module.exports = function(){
return function(el, stream) {
// TODO
// TODO
};
};
3 changes: 2 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe('rtc()', function(){
'getUserMedia',
'RTCPeerConnection',
'RTCSessionDescription',
'RTCIceCandidate'
'RTCIceCandidate',
'attachStream'
]);
done();
});
Expand Down

0 comments on commit c8849c3

Please sign in to comment.