Created
December 3, 2020 17:46
-
-
Save ckerr/d77e6880e34fb7a5b15c7febc9ce9359 to your computer and use it in GitHub Desktop.
@msach22's repro testcase for https://github.com/electron/electron/issues/23529
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> | |
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'"> | |
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'"> | |
<title>Hello World!</title> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
We are using Node.js <span id="node-version"></span>, | |
Chromium <span id="chrome-version"></span>, | |
and Electron <span id="electron-version"></span>. | |
<!-- You can also require other files to run in this process --> | |
<script src="./renderer.js"></script> | |
</body> | |
</html> | |
// Modules to control application life and create native browser window | |
const {app, BrowserWindow} = require('electron') | |
const path = require('path') | |
function createWindow () { | |
// Create the browser window. | |
const mainWindow = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
webPreferences: { | |
preload: path.join(__dirname, 'preload.js') | |
} | |
}) | |
// and load the index.html of the app. | |
mainWindow.loadFile('index.html') | |
// Open the DevTools. | |
// mainWindow.webContents.openDevTools() | |
} | |
// This method will be called when Electron has finished | |
// initialization and is ready to create browser windows. | |
// Some APIs can only be used after this event occurs. | |
app.whenReady().then(() => { | |
createWindow() | |
app.on('activate', function () { | |
// On macOS it's common to re-create a window in the app when the | |
// dock icon is clicked and there are no other windows open. | |
if (BrowserWindow.getAllWindows().length === 0) createWindow() | |
}) | |
}) | |
// Quit when all windows are closed, except on macOS. There, it's common | |
// for applications and their menu bar to stay active until the user quits | |
// explicitly with Cmd + Q. | |
app.on('window-all-closed', function () { | |
if (process.platform !== 'darwin') app.quit() | |
}) | |
// In this file you can include the rest of your app's specific main process | |
// code. You can also put them in separate files and require them here. | |
{ | |
"name": "electron-quick-start", | |
"version": "1.0.0", | |
"description": "A minimal Electron application", | |
"main": "main.js", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"repository": "https://github.com/electron/electron-quick-start", | |
"keywords": [ | |
"Electron", | |
"quick", | |
"start", | |
"tutorial", | |
"demo" | |
], | |
"author": "GitHub", | |
"license": "CC0-1.0", | |
"devDependencies": { | |
"electron": "^11.0.3" | |
} | |
} | |
// All of the Node.js APIs are available in the preload process. | |
// It has the same sandbox as a Chrome extension. | |
window.addEventListener('DOMContentLoaded', () => { | |
const replaceText = (selector, text) => { | |
const element = document.getElementById(selector) | |
if (element) element.innerText = text | |
} | |
for (const type of ['chrome', 'node', 'electron']) { | |
replaceText(`${type}-version`, process.versions[type]) | |
} | |
}) | |
// This file is required by the index.html file and will | |
// be executed in the renderer process for that window. | |
// No Node.js APIs are available in this process because | |
// `nodeIntegration` is turned off. Use `preload.js` to | |
// selectively enable features needed in the rendering | |
// process. | |
const pc1 = new RTCPeerConnection(); | |
const pc2 = new RTCPeerConnection(); | |
let desc = null; | |
let incomingStream = new MediaStream(); | |
const incomingVideoElement = document.createElement('video'); | |
incomingVideoElement.srcObject = incomingStream; | |
let isAdded = false; | |
pc2.ontrack = (event) => { | |
incomingStream.addTrack(event.track); | |
if (event.track.kind === 'video') { | |
document.body.appendChild(incomingVideoElement); | |
incomingVideoElement.play() | |
isAdded = true; | |
} | |
} | |
const noAction = () => { | |
}; | |
const errorHandler = (e) => { | |
console.log(e); | |
} | |
const start = async () => { | |
pc1.onicecandidate = (event) => { | |
if (event.candidate) { | |
pc2.addIceCandidate(new RTCIceCandidate(event.candidate, noAction, (error) => { | |
errorHandler(`PC2 adding ice candidate erorr ${error}`); | |
})); | |
} | |
}; | |
pc2.onicecandidate = (event) => { | |
if (event.candidate) { | |
pc1.addIceCandidate(new RTCIceCandidate(event.candidate, noAction, (error) => { | |
errorHandler(`PC1 adding ice candidate erorr ${error}`); | |
})); | |
} | |
}; | |
try { | |
let description = await pc1.createOffer(); | |
desc = description; | |
pc1.setLocalDescription(description); | |
pc2.setRemoteDescription(description); | |
let description2 = await pc2.createAnswer(); | |
pc2.setLocalDescription(description2); | |
pc1.setRemoteDescription(description2); | |
} catch (e) { | |
errorHandler(e); | |
} | |
}; | |
(async () => { | |
stream = null; | |
try { | |
stream = await navigator.mediaDevices.getUserMedia({ | |
audio: true, | |
video: true | |
}); | |
const videoElement = document.createElement('video'); | |
videoElement.srcObject = stream; | |
document.body.appendChild(videoElement); | |
await videoElement.play() | |
for (let track of stream.getTracks()) { | |
pc1.addTrack(track); | |
} | |
await start(); | |
} catch (error) { | |
console.log('error getting media', error); | |
} | |
return stream; | |
})() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> | |
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'"> | |
<meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'"> | |
<title>Hello World!</title> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
We are using Node.js <span id="node-version"></span>, | |
Chromium <span id="chrome-version"></span>, | |
and Electron <span id="electron-version"></span>. | |
<!-- You can also require other files to run in this process --> | |
<script src="./renderer.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Modules to control application life and create native browser window | |
const {app, BrowserWindow} = require('electron') | |
const path = require('path') | |
function createWindow () { | |
// Create the browser window. | |
const mainWindow = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
webPreferences: { | |
preload: path.join(__dirname, 'preload.js') | |
} | |
}) | |
// and load the index.html of the app. | |
mainWindow.loadFile('index.html') | |
// Open the DevTools. | |
// mainWindow.webContents.openDevTools() | |
} | |
// This method will be called when Electron has finished | |
// initialization and is ready to create browser windows. | |
// Some APIs can only be used after this event occurs. | |
app.whenReady().then(() => { | |
createWindow() | |
app.on('activate', function () { | |
// On macOS it's common to re-create a window in the app when the | |
// dock icon is clicked and there are no other windows open. | |
if (BrowserWindow.getAllWindows().length === 0) createWindow() | |
}) | |
}) | |
// Quit when all windows are closed, except on macOS. There, it's common | |
// for applications and their menu bar to stay active until the user quits | |
// explicitly with Cmd + Q. | |
app.on('window-all-closed', function () { | |
if (process.platform !== 'darwin') app.quit() | |
}) | |
// In this file you can include the rest of your app's specific main process | |
// code. You can also put them in separate files and require them here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "electron-quick-start", | |
"version": "1.0.0", | |
"description": "A minimal Electron application", | |
"main": "main.js", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"repository": "https://github.com/electron/electron-quick-start", | |
"keywords": [ | |
"Electron", | |
"quick", | |
"start", | |
"tutorial", | |
"demo" | |
], | |
"author": "GitHub", | |
"license": "CC0-1.0", | |
"devDependencies": { | |
"electron": "^11.0.3" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// All of the Node.js APIs are available in the preload process. | |
// It has the same sandbox as a Chrome extension. | |
window.addEventListener('DOMContentLoaded', () => { | |
const replaceText = (selector, text) => { | |
const element = document.getElementById(selector) | |
if (element) element.innerText = text | |
} | |
for (const type of ['chrome', 'node', 'electron']) { | |
replaceText(`${type}-version`, process.versions[type]) | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This file is required by the index.html file and will | |
// be executed in the renderer process for that window. | |
// No Node.js APIs are available in this process because | |
// `nodeIntegration` is turned off. Use `preload.js` to | |
// selectively enable features needed in the rendering | |
// process. | |
const pc1 = new RTCPeerConnection(); | |
const pc2 = new RTCPeerConnection(); | |
let desc = null; | |
let incomingStream = new MediaStream(); | |
const incomingVideoElement = document.createElement('video'); | |
incomingVideoElement.srcObject = incomingStream; | |
let isAdded = false; | |
pc2.ontrack = (event) => { | |
incomingStream.addTrack(event.track); | |
if (event.track.kind === 'video') { | |
document.body.appendChild(incomingVideoElement); | |
incomingVideoElement.play() | |
isAdded = true; | |
} | |
} | |
const noAction = () => { | |
}; | |
const errorHandler = (e) => { | |
console.log(e); | |
} | |
const start = async () => { | |
pc1.onicecandidate = (event) => { | |
if (event.candidate) { | |
pc2.addIceCandidate(new RTCIceCandidate(event.candidate, noAction, (error) => { | |
errorHandler(`PC2 adding ice candidate erorr ${error}`); | |
})); | |
} | |
}; | |
pc2.onicecandidate = (event) => { | |
if (event.candidate) { | |
pc1.addIceCandidate(new RTCIceCandidate(event.candidate, noAction, (error) => { | |
errorHandler(`PC1 adding ice candidate erorr ${error}`); | |
})); | |
} | |
}; | |
try { | |
let description = await pc1.createOffer(); | |
desc = description; | |
pc1.setLocalDescription(description); | |
pc2.setRemoteDescription(description); | |
let description2 = await pc2.createAnswer(); | |
pc2.setLocalDescription(description2); | |
pc1.setRemoteDescription(description2); | |
} catch (e) { | |
errorHandler(e); | |
} | |
}; | |
(async () => { | |
stream = null; | |
try { | |
stream = await navigator.mediaDevices.getUserMedia({ | |
audio: true, | |
video: true | |
}); | |
const videoElement = document.createElement('video'); | |
videoElement.srcObject = stream; | |
document.body.appendChild(videoElement); | |
await videoElement.play() | |
for (let track of stream.getTracks()) { | |
pc1.addTrack(track); | |
} | |
await start(); | |
} catch (error) { | |
console.log('error getting media', error); | |
} | |
return stream; | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment