From 44302394814a185a471ac47bb75a1fb3d215b218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=99=93=E5=B3=B0?= Date: Fri, 1 Jun 2018 22:50:20 +0800 Subject: [PATCH 1/2] add source choose function --- main.js | 2 +- src/renderers/index/Index.js | 29 ++++++++++++++++++++++++++--- src/renderers/index/index.html | 6 ++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index bf903dc..94105d2 100755 --- a/main.js +++ b/main.js @@ -18,7 +18,7 @@ class Main { createWindow() { // Create the browser window. - this.mainWindow = new BrowserWindow({width: 380, height: 300}); + this.mainWindow = new BrowserWindow({width: 380, height: 720}); // and load the index.html of the app. this.mainWindow.loadURL("file://" + path.join(Config.getRenderersDir(), "index", "index.html")); diff --git a/src/renderers/index/Index.js b/src/renderers/index/Index.js index aeaa907..3ed0985 100755 --- a/src/renderers/index/Index.js +++ b/src/renderers/index/Index.js @@ -13,7 +13,7 @@ class Index { constructor() { this.initUI(); this.addListeners(); - this.tryToGetStream(); + this.getSources(); } initUI() { @@ -25,6 +25,8 @@ class Index { this._audioBpsInput = document.querySelector("#audioBpsInput"); this._audioBpsInput.value = LocalStorageManager.getAudioBps(48000); this._btnAbout = document.querySelector("#btn-about"); + this._sourcesContainer = document.getElementById('tagsContainer'); + this._video = document.getElementById('preview'); this._textInputDistDirPath = document.querySelector("#distDirPath"); //try to read the saved dist dir path @@ -128,13 +130,31 @@ class Index { }); } - tryToGetStream() { + getSources() { + electron.desktopCapturer.getSources({ + types: ['screen', 'window'] + }, (err, sources) => { + if (err) throw err + const tags = sources.map(source => `${source.name}
`) + this._sourcesContainer.innerHTML = tags.join('') + + const radios = document.getElementsByName('source') + radios.forEach(radio => { + radio.addEventListener('click', () => { + this.tryToGetStream(radio.value) + }) + }) + }) + } + + tryToGetStream(sourceId) { this.recordState = RecordStatus.RETRIEVING_SCREEN_STREAM; navigator.mediaDevices.getUserMedia({ audio: false, video: { mandatory: { - chromeMediaSource: 'screen', + chromeMediaSource: 'desktop', + chromeMediaSourceId: sourceId, minWidth: 1280, maxWidth: 1280, minHeight: 720, @@ -144,6 +164,9 @@ class Index { }).then(stream => { this._currentStream = stream; + this._video.srcObject = stream; + this._video.onloadedmetadata = e => video.play(); + this.recordState = RecordStatus.RETRIEVING_AUDIO_STREAM; return navigator.mediaDevices.getUserMedia({audio: true}); }).then(audioStream => { diff --git a/src/renderers/index/index.html b/src/renderers/index/index.html index 6d2c4bb..055d863 100755 --- a/src/renderers/index/index.html +++ b/src/renderers/index/index.html @@ -29,6 +29,12 @@
+
+
选择录制源
+
+
预览
+ +
全局热键说明

-
-
选择录制源
+
+
选择录制源
预览
- + +
全局热键说明