forked from GoogleChrome/chrome-extensions-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventPage.js
82 lines (76 loc) · 2.36 KB
/
eventPage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// The window (tab) opened and navigated to receiver.html.
var receiver = null;
// Open a new window of receiver.html when browser action icon is clicked.
function playCapturedStream(stream) {
if (!stream) {
console.error('Error starting tab capture: ' +
(chrome.runtime.lastError.message || 'UNKNOWN'));
return;
}
if (receiver != null) {
receiver.close();
}
receiver = window.open('receiver.html');
receiver.currentStream = stream;
}
function testCapture() {
console.log('Test with method capture().');
chrome.tabCapture.capture({
video: true, audio: true,
videoConstraints: {
mandatory: {
// If minWidth/Height have the same aspect ratio (e.g., 16:9) as
// maxWidth/Height, the implementation will letterbox/pillarbox as
// needed. Otherwise, set minWidth/Height to 0 to allow output video
// to be of any arbitrary size.
minWidth: 16,
minHeight: 9,
maxWidth: 854,
maxHeight: 480,
maxFrameRate: 60, // Note: Frame rate is variable (0 <= x <= 60).
},
},
},
function(stream) {
playCapturedStream(stream);
});
}
function testGetMediaStreamId() {
console.log('Test with method getMediaStreamId().');
chrome.tabCapture.getMediaStreamId(function(streamId) {
if (typeof streamId !== 'string') {
console.error('Failed to get media stream id: ' +
(chrome.runtime.lastError.message || 'UNKNOWN'));
return;
}
navigator.webkitGetUserMedia({
audio:false,
video: {
mandatory:{
chromeMediaSource:'tab', // The media source must be 'tab' here.
chromeMediaSourceId:streamId
}
}
},
function(stream){
playCapturedStream(stream);
},
function(error){
console.error(error);
})
});
}
chrome.browserAction.onClicked.addListener(function(tab) {
// Retrieve the test option to test each method respectively.
// The captured stream will have different resolution for each test.
chrome.storage.local.get(['tabCaptureMethod'], function(result) {
if (result.tabCaptureMethod == 'streamId') {
testGetMediaStreamId();
} else {
testCapture();
}
});
});