1// Copyright 2013 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 5function gotStream(stream) { 6 console.log("Received local stream"); 7 var video = document.querySelector("video"); 8 video.src = webkitURL.createObjectURL(stream); 9 localstream = stream; 10 stream.onended = function() { console.log("Ended"); }; 11} 12 13function getUserMediaError() { 14 console.log("getUserMedia() failed."); 15} 16 17function onAccessApproved(id) { 18 if (!id) { 19 console.log("Access rejected."); 20 return; 21 } 22 navigator.webkitGetUserMedia({ 23 audio:false, 24 video: { mandatory: { chromeMediaSource: "desktop", 25 chromeMediaSourceId: id } } 26 }, gotStream, getUserMediaError); 27} 28 29var pending_request_id = null; 30 31document.querySelector('#start').addEventListener('click', function(e) { 32 pending_request_id = chrome.desktopCapture.chooseDesktopMedia( 33 ["screen", "window"], onAccessApproved); 34}); 35 36document.querySelector('#cancel').addEventListener('click', function(e) { 37 if (pending_request_id != null) { 38 chrome.desktopCapture.cancelChooseDesktopMedia(pending_request_id); 39 } 40}); 41