Skip to content

Commit

Permalink
Added support for "Screen Capturing on Android"
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Nov 7, 2016
1 parent 67bb09a commit b856c9c
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 22 deletions.
4 changes: 2 additions & 2 deletions demos/file-sharing.html
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@
connection.fileReceived = {};

// by default, socket.io server is assumed to be deployed on your own URL
// connection.socketURL = '/';
connection.socketURL = '/';

// comment-out below line if you do not have your own socket.io server
connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';
// connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';

connection.socketMessageEvent = 'file-sharing-demo';

Expand Down
4 changes: 3 additions & 1 deletion dev/MultiPeersHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ function MultiPeers(connection) {
self.onDataChannelClosed(event, remoteUserId);
},
onRemoteStream: function(stream) {
connection.peers[remoteUserId].streams.push(stream);
if (connection.peers[remoteUserId]) {
connection.peers[remoteUserId].streams.push(stream);
}

if (isPluginRTC && window.PluginRTC) {
var mediaElement = document.createElement('video');
Expand Down
1 change: 1 addition & 0 deletions dev/RTCPeerConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ function PeerInitiator(config) {

var streamObject;
peer.addEventListener(remoteStreamAddEvent, function(event) {
if (!event) return;
if (event.streams && event.streams.length && !event.stream) {
if (!streamObject) {
streamObject = new MediaStream();
Expand Down
29 changes: 28 additions & 1 deletion dev/Screen-Capturing.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated at Sep 01, 2016, 08:32:23
// Last time updated at Nov 07, 2016, 08:32:23

// Latest file can be found here: https://cdn.webrtc-experiment.com/Screen-Capturing.js

Expand All @@ -21,6 +21,15 @@ window.addEventListener('message', function(event) {
onMessageCallback(event.data);
});

// via: https://bugs.chromium.org/p/chromium/issues/detail?id=487935#c17
// you can capture screen on Android Chrome >= 55 with flag: "Experimental ScreenCapture android"
window.IsAndroidChrome = false;
try {
if (navigator.userAgent.toLowerCase().indexOf("android") > -1 && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor)) {
window.IsAndroidChrome = true;
}
} catch (e) {}

// and the function that handles received messages

function onMessageCallback(data) {
Expand Down Expand Up @@ -56,6 +65,12 @@ function isChromeExtensionAvailable(callback) {

if (isFirefox) return isFirefoxExtensionAvailable(callback);

if (window.IsAndroidChrome) {
chromeMediaSource = 'screen';
callback(true);
return;
}

if (chromeMediaSource == 'desktop') return callback(true);

// ask extension if it is available
Expand Down Expand Up @@ -124,6 +139,12 @@ function getSourceId(callback, audioPlusTab) {
}

function getChromeExtensionStatus(extensionid, callback) {
if (window.IsAndroidChrome) {
chromeMediaSource = 'screen';
callback('installed-enabled');
return;
}

if (arguments.length != 2) {
callback = extensionid;
extensionid = window.RMCExtensionID || 'ajhifddimkapgcifgcodmmfdlknahffk'; // default extension-id
Expand Down Expand Up @@ -173,6 +194,12 @@ function getScreenConstraints(callback, audioPlusTab) {
optional: []
};

if (window.IsAndroidChrome) {
// now invoking native getUserMedia API
callback(null, screen_constraints);
return;
}

// this statement verifies chrome extension availability
// if installed and available then it will invoke extension API
// otherwise it will fallback to command-line based screen capturing API
Expand Down
7 changes: 3 additions & 4 deletions dev/StreamsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ var StreamsHandler = (function() {
mediaElement.volume = 0;
afterEach(200, 5, function() {
try {
mediaElement.volume += .20;
}
catch(e) {
mediaElement.volume = 1;
mediaElement.volume += .20;
} catch (e) {
mediaElement.volume = 1;
}
});
}
Expand Down
61 changes: 60 additions & 1 deletion dev/getScreenId.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated at Sep 01, 2016, 08:32:23
// Last time updated at Nov 07, 2016, 08:32:23

// Latest file can be found here: https://cdn.webrtc-experiment.com/getScreenId.js

Expand All @@ -21,8 +21,35 @@ getScreenId(function (error, sourceId, screen_constraints) {
});
*/

// via: https://bugs.chromium.org/p/chromium/issues/detail?id=487935#c17
// you can capture screen on Android Chrome >= 55 with flag: "Experimental ScreenCapture android"
window.IsAndroidChrome = false;
try {
if (navigator.userAgent.toLowerCase().indexOf("android") > -1 && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor)) {
window.IsAndroidChrome = true;
}
} catch (e) {}

(function() {
window.getScreenId = function(callback) {
if (window.IsAndroidChrome) {
var screen_constraints = {
mandatory: {
chromeMediaSource: 'screen',
maxWidth: 29999,
maxHeight: 8640,
minFrameRate: 30,
maxFrameRate: 128,
minAspectRatio: 1.77 // 2.39
},
optional: []
};
callback(null, null, {
video: screen_constraints
});
return;
}

// for Firefox:
// sourceId == 'firefox'
// screen_constraints = {...}
Expand Down Expand Up @@ -115,6 +142,22 @@ getScreenId(function (error, sourceId, screen_constraints) {

// this function is used in v3.0
window.getScreenConstraints = function(callback) {
if (window.IsAndroidChrome) {
var screen_constraints = {
mandatory: {
chromeMediaSource: 'screen',
maxWidth: 29999,
maxHeight: 8640,
minFrameRate: 30,
maxFrameRate: 128,
minAspectRatio: 1.77 // 2.39
},
optional: []
};
callback(null, screen_constraints);
return;
}

loadIFrame(function() {
getScreenId(function(error, sourceId, screen_constraints) {
callback(error, (screen_constraints || {}).video);
Expand Down Expand Up @@ -221,6 +264,22 @@ getScreenId(function (error, sourceId, screen_constraints) {

// this function is used in v3.0
window.getScreenConstraints = function(callback) {
if (window.IsAndroidChrome) {
var screen_constraints = {
mandatory: {
chromeMediaSource: 'screen',
maxWidth: 29999,
maxHeight: 8640,
minFrameRate: 30,
maxFrameRate: 128,
minAspectRatio: 1.77 // 2.39
},
optional: []
};
callback(null, screen_constraints);
return;
}

loadIFrame(function() {
getScreenId(function(error, sourceId, screen_constraints) {
callback(error, (screen_constraints || {}).video);
Expand Down
2 changes: 1 addition & 1 deletion dev/getUserMedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function getUserMediaHandler(options) {
}
currentUserMediaRequest.mutex = true;

// easy way to match
// easy way to match
var idInstance = JSON.stringify(options.localMediaConstraints);

function streaming(stream, returnBack) {
Expand Down
48 changes: 41 additions & 7 deletions dist/RTCMultiConnection.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Last time updated: 2016-11-04 9:09:57 AM UTC
// Last time updated: 2016-11-07 3:00:06 PM UTC

// _________________________
// RTCMultiConnection v3.4.1
// RTCMultiConnection v3.4.2

// Open-Sourced: https://github.com/muaz-khan/RTCMultiConnection

Expand Down Expand Up @@ -1582,7 +1582,7 @@
};

connection.trickleIce = true;
connection.version = '3.4.1';
connection.version = '3.4.2';
}

function SocketConnection(connection, connectCallback) {
Expand Down Expand Up @@ -2077,7 +2077,9 @@
self.onDataChannelClosed(event, remoteUserId);
},
onRemoteStream: function(stream) {
connection.peers[remoteUserId].streams.push(stream);
if (connection.peers[remoteUserId]) {
connection.peers[remoteUserId].streams.push(stream);
}

if (isPluginRTC && window.PluginRTC) {
var mediaElement = document.createElement('video');
Expand Down Expand Up @@ -4022,6 +4024,7 @@

var streamObject;
peer.addEventListener(remoteStreamAddEvent, function(event) {
if (!event) return;
if (event.streams && event.streams.length && !event.stream) {
if (!streamObject) {
streamObject = new MediaStream();
Expand Down Expand Up @@ -4753,7 +4756,7 @@
}
currentUserMediaRequest.mutex = true;

// easy way to match
// easy way to match
var idInstance = JSON.stringify(options.localMediaConstraints);

function streaming(stream, returnBack) {
Expand Down Expand Up @@ -4954,7 +4957,11 @@
var mediaElement = connection.streamEvents[stream.streamid].mediaElement;
mediaElement.volume = 0;
afterEach(200, 5, function() {
mediaElement.volume += .20;
try {
mediaElement.volume += .20;
} catch (e) {
mediaElement.volume = 1;
}
});
}
}
Expand All @@ -4975,7 +4982,7 @@
};
})();

// Last time updated at Sep 01, 2016, 08:32:23
// Last time updated at Nov 07, 2016, 08:32:23

// Latest file can be found here: https://cdn.webrtc-experiment.com/Screen-Capturing.js

Expand All @@ -4998,6 +5005,15 @@
onMessageCallback(event.data);
});

// via: https://bugs.chromium.org/p/chromium/issues/detail?id=487935#c17
// you can capture screen on Android Chrome >= 55 with flag: "Experimental ScreenCapture android"
window.IsAndroidChrome = false;
try {
if (navigator.userAgent.toLowerCase().indexOf("android") > -1 && /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor)) {
window.IsAndroidChrome = true;
}
} catch (e) {}

// and the function that handles received messages

function onMessageCallback(data) {
Expand Down Expand Up @@ -5033,6 +5049,12 @@

if (isFirefox) return isFirefoxExtensionAvailable(callback);

if (window.IsAndroidChrome) {
chromeMediaSource = 'screen';
callback(true);
return;
}

if (chromeMediaSource == 'desktop') return callback(true);

// ask extension if it is available
Expand Down Expand Up @@ -5101,6 +5123,12 @@
}

function getChromeExtensionStatus(extensionid, callback) {
if (window.IsAndroidChrome) {
chromeMediaSource = 'screen';
callback('installed-enabled');
return;
}

if (arguments.length != 2) {
callback = extensionid;
extensionid = window.RMCExtensionID || 'ajhifddimkapgcifgcodmmfdlknahffk'; // default extension-id
Expand Down Expand Up @@ -5150,6 +5178,12 @@
optional: []
};

if (window.IsAndroidChrome) {
// now invoking native getUserMedia API
callback(null, screen_constraints);
return;
}

// this statement verifies chrome extension availability
// if installed and available then it will invoke extension API
// otherwise it will fallback to command-line based screen capturing API
Expand Down
10 changes: 5 additions & 5 deletions dist/RTCMultiConnection.min.js

Large diffs are not rendered by default.

0 comments on commit b856c9c

Please sign in to comment.