var chromeMediaSource = 'screen'; var screenCallback; var isFirefox = typeof window.InstallTrigger !== 'undefined'; var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; var isChrome = !!window.chrome && !isOpera; window.addEventListener('message', function (event) { if (event.origin != window.location.origin) { return; } onMessageCallback(event.data); }); function onMessageCallback(data) { if (data == 'PermissionDeniedError') { chromeMediaSource = 'PermissionDeniedError'; if (screenCallback) return screenCallback('PermissionDeniedError'); else throw new Error('PermissionDeniedError'); } if (data == 'rtcmulticonnection-extension-loaded') { chromeMediaSource = 'desktop'; } if (data.sourceId && screenCallback) { screenCallback(sourceId = data.sourceId); } } function isChromeExtensionAvailable(callback) { if (isFirefox) return callback(false); if (chromeMediaSource == 'desktop') return callback('isFirefox'); window.postMessage('are-you-there', '*'); setTimeout(function () { if (chromeMediaSource == 'screen') { callback('unavailable'); } else callback('available'); }, 2000); } function getSourceId(callback) { if (!callback) throw '"callback" parameter is mandatory.'; if (sourceId) return callback(sourceId); screenCallback = callback; window.postMessage('get-sourceId', '*'); } function getChromeExtensionStatus(extensionid, callback) { if (isFirefox) return callback('not-chrome'); if (arguments.length != 2) { callback = extensionid; extensionid = 'ajhifddimkapgcifgcodmmfdlknahffk'; } var image = document.createElement('img'); image.src = 'chrome-extension://' + extensionid + '/icon.png'; image.onload = function () { chromeMediaSource = 'screen'; window.postMessage('are-you-there', '*'); setTimeout(function () { if (chromeMediaSource == 'screen') { callback(extensionid == extensionid ? 'installed-enabled' : 'installed-disabled'); } else callback('installed-enabled'); }, 2000); }; image.onerror = function () { callback('not-installed'); }; } function getScreenConstraints(callback) { sourceId = ''; var firefoxScreenConstraints = { mozMediaSource: 'window', mediaSource: 'window' }; if (isFirefox) return callback(null, firefoxScreenConstraints); var screen_constraints = { mandatory: { chromeMediaSource: chromeMediaSource, maxWidth: screen.width > 1920 ? screen.width : 1920, maxHeight: screen.height > 1080 ? screen.height : 1080 }, optional: [] }; if (chromeMediaSource == 'desktop' && !sourceId) { getSourceId(function () { screen_constraints.mandatory.chromeMediaSourceId = sourceId; callback(sourceId == 'PermissionDeniedError' ? sourceId : null, screen_constraints); }); return; } if (chromeMediaSource == 'desktop') { screen_constraints.mandatory.chromeMediaSourceId = sourceId; } callback(null, screen_constraints); } exports.getScreenConstraints = getScreenConstraints; exports.isChromeExtensionAvailable = isChromeExtensionAvailable; exports.getChromeExtensionStatus = getChromeExtensionStatus; exports.getSourceId = getSourceId; //# sourceMappingURL=Screen-Capturing.js.map