Socket
Socket
Sign inDemoInstall

getscreenmedia

Package Overview
Dependencies
Maintainers
4
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

getscreenmedia - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

new.js

25

chrome-extension-sample/background.js
/* background page, responsible for actually choosing media */
chrome.runtime.onConnect.addListener(function (channel) {
channel.onMessage.addListener(function (message) {
switch(message.type) {
chrome.runtime.onMessageExternal.addListener(function (message, sender, callback) {
switch(message.type) {
case 'getScreen':
var pending = chrome.desktopCapture.chooseDesktopMedia(message.options || ['screen', 'window'],
channel.sender.tab, function (streamid) {
var pending = chrome.desktopCapture.chooseDesktopMedia(message.options || ['screen', 'window'],
sender.tab, function (streamid) {
// communicate this string to the app so it can call getUserMedia with it
message.type = 'gotScreen';
message.sourceId = streamid;
channel.postMessage(message);
callback(message);
return false;
});
// let the app know that it can cancel the timeout
message.type = 'getScreenPending';
message.request = pending;
channel.postMessage(message);
break;
return true; // retain callback for chooseDesktopMedia result
case 'cancelGetScreen':
chrome.desktopCapture.cancelChooseDesktopMedia(message.request);
message.type = 'canceledGetScreen';
channel.postMessage(message);
break;
}
});
callback(message);
return false; //dispose callback
}
});

15

chrome-extension-sample/content.js

@@ -1,14 +0,1 @@

/* the chrome content script which can listen to the page dom events */
var channel = chrome.runtime.connect();
channel.onMessage.addListener(function (message) {
console.log('channel message', message);
window.postMessage(message, '*');
});
window.addEventListener('message', function (event) {
if (event.source != window)
return;
if (!event.data && (event.data.type == 'getScreen' || event.data.type == 'cancelGetScreen'))
return;
channel.postMessage(event.data);
});
sessionStorage.getScreenMediaJSExtensionId = chrome.runtime.id;

@@ -18,3 +18,8 @@ {

"matches": [ "https://simplewebrtc.com/*" ]
}]
}],
"externally_connectable": {
"matches": [
"https://simplewebrtc.com/*"
]
}
}
This is an example app which implements the extension-side of [getscreenmedia](https://github.com/henrikjoreteg/getscreenmedia).
It basically uses window event messages to communicate between the website javascript and the content script (content.js).
The content script in turn uses channel messaging to talk to the backend script which calls [chooseDesktopMedia](https://developer.chrome.com/extensions/desktopCapture)
and returns the sourceId of the chosen window. This sourceId has to be passed back to getUserMedia.
The browser useѕ [chrome.runtime.sendMessage](https://developer.chrome.com/extensions/runtime#method-sendMessage) to talk to the backend script which calls [chooseDesktopMedia](https://developer.chrome.com/extensions/desktopCapture) and returns the sourceId of the chosen window. This sourceId has to be passed back to getUserMedia.

@@ -7,0 +5,0 @@ See also [the tutorial for using inline installation](https://developer.chrome.com/webstore/inline_installation).

@@ -25,3 +25,34 @@ !function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.getScreenMedia=e():"undefined"!=typeof global?global.getScreenMedia=e():"undefined"!=typeof self&&(self.getScreenMedia=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

if (window.navigator.userAgent.match('Linux')) maxver = 35;
if (isCef || (chromever >= 26 && chromever <= maxver)) {
// check that the extension is installed by looking for a
// sessionStorage variable that contains the extension id
// this has to be set after installation unless the contest
// script does that
if (sessionStorage.getScreenMediaJSExtensionId) {
chrome.runtime.sendMessage(sessionStorage.getScreenMediaJSExtensionId,
{type:'getScreen', id: 1}, null,
function (data) {
if (data.sourceId === '') { // user canceled
var error = new Error('NavigatorUserMediaError');
error.name = 'PERMISSION_DENIED';
callback(error);
} else {
var constraints = constraints || {audio: false, video: {
mandatory: {
chromeMediaSource: 'desktop',
maxWidth: window.screen.width,
maxHeight: window.screen.height,
maxFrameRate: 3
},
optional: [
{googLeakyBucket: true},
{googTemporalLayeredScreencast: true}
]
}};
constraints.video.mandatory.chromeMediaSourceId = data.sourceId;
getUserMedia(constraints, callback);
}
}
);
} else if (isCef || (chromever >= 26 && chromever <= maxver)) {
// chrome 26 - chrome 33 way to do it -- requires bad chrome://flags

@@ -28,0 +59,0 @@ // note: this is basically in maintenance mode and will go away soon

@@ -24,3 +24,34 @@ // getScreenMedia helper by @HenrikJoreteg

if (window.navigator.userAgent.match('Linux')) maxver = 35;
if (isCef || (chromever >= 26 && chromever <= maxver)) {
// check that the extension is installed by looking for a
// sessionStorage variable that contains the extension id
// this has to be set after installation unless the contest
// script does that
if (sessionStorage.getScreenMediaJSExtensionId) {
chrome.runtime.sendMessage(sessionStorage.getScreenMediaJSExtensionId,
{type:'getScreen', id: 1}, null,
function (data) {
if (data.sourceId === '') { // user canceled
var error = new Error('NavigatorUserMediaError');
error.name = 'PERMISSION_DENIED';
callback(error);
} else {
var constraints = constraints || {audio: false, video: {
mandatory: {
chromeMediaSource: 'desktop',
maxWidth: window.screen.width,
maxHeight: window.screen.height,
maxFrameRate: 3
},
optional: [
{googLeakyBucket: true},
{googTemporalLayeredScreencast: true}
]
}};
constraints.video.mandatory.chromeMediaSourceId = data.sourceId;
getUserMedia(constraints, callback);
}
}
);
} else if (isCef || (chromever >= 26 && chromever <= maxver)) {
// chrome 26 - chrome 33 way to do it -- requires bad chrome://flags

@@ -27,0 +58,0 @@ // note: this is basically in maintenance mode and will go away soon

{
"name": "getscreenmedia",
"version": "1.3.0",
"version": "1.4.0",
"description": "A browser module for attempting to get access to a MediaStream of a user's screen. With a nice node-like API.",

@@ -5,0 +5,0 @@ "main": "getscreenmedia.js",

@@ -51,3 +51,3 @@ # getScreenMedia

Because that's a current requirement of Chrome, the only browser that currently supports screensharing.
Because that's a current requirement of Chrome.

@@ -54,0 +54,0 @@ See the [handling errors section of the getUserMedia lib](https://github.com/HenrikJoreteg/getUserMedia#handling-errors-summary) for details about how errors are handled.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc