Commit f7885d9 1 parent 9345414 commit f7885d9 Copy full SHA for f7885d9
File tree 4 files changed +76
-22
lines changed
4 files changed +76
-22
lines changed Original file line number Diff line number Diff line change 1
1
<!DOCTYPE html>
2
- < html lang =" en " >
2
+ < html >
3
3
< head >
4
4
< meta charset ="UTF-8 ">
5
5
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
6
- < meta http-equiv ="Content-Security-Policy " content ="default-src 'self'; script-src 'self' ">
7
- < title > Hello World!</ title >
6
+ < meta http-equiv ="Content-Security-Policy "
7
+ content ="img-src 'self' data: filesystem:; default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; script-src-elem 'self' 'unsafe-eval' https://unpkg.com ">
8
+ < title > Live Desktop Translator</ title >
8
9
</ head >
10
+
9
11
< body >
10
- < h1 > Hello World!</ h1 >
11
- We are using Node.js < span id ="node-version "> </ span > ,
12
- Chromium < span id ="chrome-version "> </ span > ,
13
- and Electron < span id ="electron-version "> </ span > .
12
+ < div style ="text-align: center; ">
13
+ < button id ="startButton " class ="button "> Start</ button >
14
+ < button id ="stopButton " class ="button "> Stop</ button >
15
+
16
+ < br />
17
+ < br />
18
+
19
+ < video width ="800 " height ="450 " autoplay > </ video >
20
+
21
+ < hr />
22
+
23
+ < button id ="videoSelectButton " class ="button "> Choose a Video Source</ button >
24
+
25
+ < script src ="renderer.js "> </ script >
26
+ </ div >
14
27
</ body >
15
- </ html >
28
+ </ html >
Original file line number Diff line number Diff line change 1
- const { app, BrowserWindow } = require ( 'electron' )
1
+ const { app, BrowserWindow, desktopCapturer , session } = require ( 'electron' )
2
2
3
3
const path = require ( 'node:path' )
4
4
5
5
const createWindow = ( ) => {
6
6
const win = new BrowserWindow ( {
7
- width : 800 ,
8
- height : 600 ,
7
+ width : 850 ,
8
+ height : 700 ,
9
9
webPreferences : {
10
- preload : path . join ( __dirname , 'preload.js' )
10
+ preload : path . join ( __dirname , 'preload.js' ) ,
11
+ nodeIntegration : true ,
12
+ contextIsolation : false
11
13
}
12
14
} )
13
15
16
+ session . defaultSession . setDisplayMediaRequestHandler ( ( request , callback ) => {
17
+ desktopCapturer . getSources ( { types : [ 'screen' ] } ) . then ( ( sources ) => {
18
+ // Grant access to the first screen found.
19
+ callback ( { video : sources [ 0 ] } )
20
+ } )
21
+ // If true, use the system picker if available.
22
+ // Note: this is currently experimental. If the system picker
23
+ // is available, it will be used and the media request handler
24
+ // will not be invoked.
25
+ } , { useSystemPicker : true } )
26
+
14
27
win . loadFile ( 'electron_app/control_menu.html' )
15
28
}
16
29
Original file line number Diff line number Diff line change 1
- window . addEventListener ( 'DOMContentLoaded' , ( ) => {
2
- const replaceText = ( selector , text ) => {
3
- const element = document . getElementById ( selector )
4
- if ( element ) element . innerText = text
5
- }
6
-
7
- for ( const dependency of [ 'chrome' , 'node' , 'electron' ] ) {
8
- replaceText ( `${ dependency } -version` , process . versions [ dependency ] )
9
- }
10
- } )
Original file line number Diff line number Diff line change
1
+ const startButton = document . getElementById ( 'startButton' )
2
+ const stopButton = document . getElementById ( 'stopButton' )
3
+ const videoSelectButton = document . getElementById ( 'videoSelectButton' )
4
+
5
+ const video = document . querySelector ( 'video' )
6
+
7
+ startButton . addEventListener ( 'click' , ( ) => {
8
+ console . log ( "startButton" )
9
+ navigator . mediaDevices . getDisplayMedia ( {
10
+ audio : true ,
11
+ video : {
12
+ width : 800 ,
13
+ height : 450 ,
14
+ frameRate : 30
15
+ }
16
+ } ) . then ( stream => {
17
+ video . srcObject = stream
18
+ video . onloadedmetadata = ( e ) => video . play ( )
19
+ } ) . catch ( e => console . log ( e ) )
20
+ } )
21
+
22
+ stopButton . addEventListener ( 'click' , ( ) => {
23
+ console . log ( "stopButton" )
24
+ video . pause ( )
25
+ } )
26
+
27
+ // Get the available video sources
28
+ const { desktopCapturer } = require ( 'electron' )
29
+ videoSelectButton . addEventListener ( 'click' , ( ) => {
30
+ console . log ( "videoSelectButton" )
31
+
32
+ const inputSources = desktopCapturer . getSources ( {
33
+ types : [ 'window' , 'screen' ]
34
+ } ) ;
35
+
36
+ console . log ( inputSources )
37
+
38
+ } )
You can’t perform that action at this time.
0 commit comments