1 | !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){
|
2 |
|
3 | var getUserMedia = require('getusermedia');
|
4 |
|
5 |
|
6 | var cache = {};
|
7 |
|
8 | module.exports = function (constraints, cb) {
|
9 | var hasConstraints = arguments.length === 2;
|
10 | var callback = hasConstraints ? cb : constraints;
|
11 | var error;
|
12 |
|
13 | if (typeof window === 'undefined' || window.location.protocol === 'http:') {
|
14 | error = new Error('NavigatorUserMediaError');
|
15 | error.name = 'HTTPS_REQUIRED';
|
16 | return callback(error);
|
17 | }
|
18 |
|
19 | if (window.navigator.userAgent.match('Chrome')) {
|
20 | var chromever = parseInt(window.navigator.userAgent.match(/Chrome\/(.*) /)[1], 10);
|
21 | var maxver = 33;
|
22 |
|
23 | if (window.navigator.userAgent.match('Linux')) maxver = 35;
|
24 | if (chromever >= 26 && chromever <= maxver) {
|
25 |
|
26 |
|
27 | constraints = (hasConstraints && constraints) || {
|
28 | video: {
|
29 | mandatory: {
|
30 | googLeakyBucket: true,
|
31 | maxWidth: window.screen.width,
|
32 | maxHeight: window.screen.height,
|
33 | maxFrameRate: 3,
|
34 | chromeMediaSource: 'screen'
|
35 | }
|
36 | }
|
37 | };
|
38 | getUserMedia(constraints, callback);
|
39 | } else {
|
40 |
|
41 | var pending = window.setTimeout(function () {
|
42 | error = new Error('NavigatorUserMediaError');
|
43 | error.name = 'EXTENSION_UNAVAILABLE';
|
44 | return callback(error);
|
45 | }, 1000);
|
46 | cache[pending] = [callback, hasConstraints ? constraint : null];
|
47 | window.postMessage({ type: 'getScreen', id: pending }, '*');
|
48 | }
|
49 | } else if (window.navigator.userAgent.match('Firefox')) {
|
50 | var ffver = parseInt(window.navigator.userAgent.match(/Firefox\/(.*)/)[1], 10);
|
51 | if (ffver >= 33) {
|
52 | constraints = (hasConstraints && constraints) || {
|
53 | video: {
|
54 | mozMediaSource: 'window',
|
55 | mediaSource: 'window'
|
56 | }
|
57 | }
|
58 | getUserMedia(constraints, function (err, stream) {
|
59 | callback(err, stream);
|
60 |
|
61 | if (!err) {
|
62 | var lastTime = stream.currentTime;
|
63 | var polly = window.setInterval(function () {
|
64 | if (!stream) window.clearInterval(polly);
|
65 | if (stream.currentTime == lastTime) {
|
66 | window.clearInterval(polly);
|
67 | if (stream.onended) {
|
68 | stream.onended();
|
69 | }
|
70 | }
|
71 | lastTime = stream.currentTime;
|
72 | }, 500);
|
73 | }
|
74 | });
|
75 | } else {
|
76 | error = new Error('NavigatorUserMediaError');
|
77 | error.name = 'EXTENSION_UNAVAILABLE';
|
78 | }
|
79 | }
|
80 | };
|
81 |
|
82 | window.addEventListener('message', function (event) {
|
83 | if (event.origin != window.location.origin) {
|
84 | return;
|
85 | }
|
86 | if (event.data.type == 'gotScreen' && cache[event.data.id]) {
|
87 | var data = cache[event.data.id];
|
88 | var constraints = data[1];
|
89 | var callback = data[0];
|
90 | delete cache[event.data.id];
|
91 |
|
92 | if (event.data.sourceId === '') {
|
93 | var error = new Error('NavigatorUserMediaError');
|
94 | error.name = 'PERMISSION_DENIED';
|
95 | callback(error);
|
96 | } else {
|
97 | constraints = constraints || {audio: false, video: {
|
98 | mandatory: {
|
99 | chromeMediaSource: 'desktop',
|
100 | maxWidth: window.screen.width,
|
101 | maxHeight: window.screen.height,
|
102 | maxFrameRate: 3
|
103 | },
|
104 | optional: [
|
105 | {googLeakyBucket: true},
|
106 | {googTemporalLayeredScreencast: true}
|
107 | ]
|
108 | }};
|
109 | constraints.video.mandatory.chromeMediaSourceId = event.data.sourceId;
|
110 | getUserMedia(constraints, callback);
|
111 | }
|
112 | } else if (event.data.type == 'getScreenPending') {
|
113 | window.clearTimeout(event.data.id);
|
114 | }
|
115 | });
|
116 |
|
117 | },{"getusermedia":2}],2:[function(require,module,exports){
|
118 |
|
119 | var func = (window.navigator.getUserMedia ||
|
120 | window.navigator.webkitGetUserMedia ||
|
121 | window.navigator.mozGetUserMedia ||
|
122 | window.navigator.msGetUserMedia);
|
123 |
|
124 |
|
125 | module.exports = function (constraints, cb) {
|
126 | var options;
|
127 | var haveOpts = arguments.length === 2;
|
128 | var defaultOpts = {video: true, audio: true};
|
129 | var error;
|
130 | var denied = 'PermissionDeniedError';
|
131 | var notSatified = 'ConstraintNotSatisfiedError';
|
132 |
|
133 |
|
134 | if (!haveOpts) {
|
135 | cb = constraints;
|
136 | constraints = defaultOpts;
|
137 | }
|
138 |
|
139 |
|
140 | if (!func) {
|
141 |
|
142 | error = new Error('MediaStreamError');
|
143 | error.name = 'NotSupportedError';
|
144 | return cb(error);
|
145 | }
|
146 |
|
147 | func.call(window.navigator, constraints, function (stream) {
|
148 | cb(null, stream);
|
149 | }, function (err) {
|
150 | var error;
|
151 |
|
152 |
|
153 |
|
154 | if (typeof err === 'string') {
|
155 | error = new Error('MediaStreamError');
|
156 | if (err === denied) {
|
157 | error.name = denied;
|
158 | } else {
|
159 | error.name = notSatified;
|
160 | }
|
161 | } else {
|
162 |
|
163 |
|
164 | error = err;
|
165 | if (!error.name) {
|
166 |
|
167 |
|
168 |
|
169 | if (error[denied]) {
|
170 | err.name = denied;
|
171 | } else {
|
172 | err.name = notSatified;
|
173 | }
|
174 | }
|
175 | }
|
176 |
|
177 | cb(error);
|
178 | });
|
179 | };
|
180 |
|
181 | },{}]},{},[1])
|
182 | (1)
|
183 | });
|
184 | ; |
\ | No newline at end of file |