OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 var SessionInfo = {}; | |
asargent_no_longer_on_chrome
2016/03/17 19:24:28
nit: variable names should use camelCase.
https:
| |
6 | |
7 /** | |
8 * When extension icon clicked, get device list | |
9 * Then return the list to popup page | |
10 */ | |
11 chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { | |
12 if (message.browserActionClicked) { | |
13 getDeviceList(function(deviceList) { | |
14 sendResponse({ returnDeviceList: deviceList }); | |
15 }); | |
16 } | |
17 return true; | |
18 }); | |
19 | |
20 function getDeviceList(callback) { | |
21 chrome.displaySource.getAvailableSinks(callback); | |
22 } | |
23 | |
24 chrome.displaySource.onSessionTerminated.addListener(function(terminatedSink) { | |
25 chrome.runtime.sendMessage({ sessionTerminated: true, | |
26 currentSinkId: terminatedSink }); | |
27 | |
28 if (SessionInfo.Stream) { | |
29 SessionInfo.Stream.getTracks().forEach(function (track) { track.stop(); }); | |
30 delete SessionInfo.Stream; | |
31 } | |
32 delete SessionInfo.SinkId; | |
33 }); | |
34 | |
35 chrome.displaySource.onSinksUpdated.addListener(function(updatedSinks) { | |
36 console.log('Sinks updated'); | |
37 chrome.runtime.sendMessage({ sinksUpdated: true, | |
38 currentSinkId: SessionInfo.SinkId, | |
39 sinksList: updatedSinks}); | |
40 }); | |
41 | |
42 function Start(sinkId) { | |
asargent_no_longer_on_chrome
2016/03/17 19:24:29
nit: function names should use camelCase
https://
| |
43 // If no session, proceed. | |
44 if (!SessionInfo.SinkId) { | |
45 SessionInfo.SinkId = parseInt(sinkId); | |
asargent_no_longer_on_chrome
2016/03/17 19:24:28
nit: variable names should use camelCase
| |
46 captureTabAndStartSession(SessionInfo.SinkId); | |
47 } | |
48 } | |
49 | |
50 function captureTabAndStartSession(sink_id) { | |
51 chrome.tabs.getCurrent(function(tab) { | |
52 var video_constraints = { | |
53 mandatory: { | |
54 chromeMediaSource: 'tab', | |
55 minWidth: 1920, | |
56 minHeight: 1080, | |
57 maxWidth: 1920, | |
58 maxHeight: 1080, | |
59 minFrameRate: 60, | |
60 maxFrameRate: 60 | |
61 } | |
62 }; | |
63 | |
64 var constraints = { | |
65 audio: true, | |
66 video: true, | |
67 videoConstraints: video_constraints | |
68 }; | |
69 | |
70 function onStream(stream) { | |
71 SessionInfo.Stream = stream; | |
asargent_no_longer_on_chrome
2016/03/17 19:24:29
nit: variable names should use camelCase
| |
72 var session_info = { | |
73 sinkId: sink_id, | |
74 videoTrack: SessionInfo.Stream.getVideoTracks()[0], | |
75 audioTrack: SessionInfo.Stream.getAudioTracks()[0] | |
76 }; | |
77 | |
78 function onStarted() { | |
79 if (chrome.runtime.error) { | |
80 console.log('The Session to sink ' + SessionInfo.SinkId | |
81 + 'could not start, error: ' | |
82 + chrome.runtime.lastError.message); | |
83 } else { | |
84 console.log('The Session to sink ' + SessionInfo.SinkId | |
85 + ' has started.'); | |
86 } | |
87 } | |
88 console.log('Starting session to sink: ' + sink_id); | |
89 chrome.displaySource.startSession(session_info, onStarted); | |
90 } | |
91 | |
92 chrome.tabCapture.capture(constraints, onStream); | |
93 }); | |
94 } | |
95 | |
96 function Stop() { | |
asargent_no_longer_on_chrome
2016/03/17 19:24:29
nit: function names should use camelCase
| |
97 function onTerminated() { | |
98 if (chrome.runtime.lastError) { | |
99 console.log('The Session to sink ' + SessionInfo.SinkId | |
100 + 'could not terminate, error: ' | |
101 + chrome.runtime.lastError.message); | |
102 } else { | |
103 console.log('The Session to sink ' + SessionInfo.SinkId | |
104 + ' has terminated.'); | |
105 } | |
106 } | |
107 console.log('Terminating session to sink: ' + SessionInfo.SinkId); | |
108 chrome.displaySource.terminateSession(SessionInfo.SinkId, onTerminated); | |
109 } | |
OLD | NEW |