Skip to content

Commit

Permalink
streamSelector improvements (#1479)
Browse files Browse the repository at this point in the history
* removing the need of contentIsolation in the streamSelector part and other improvements
  • Loading branch information
IsmaelMartinez authored Nov 15, 2024
1 parent 05f734a commit e430d4b
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 79 deletions.
35 changes: 34 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,39 @@
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"args" : ["--disable-http-cache","./app"]
}
},
{
"type": "node",
"request": "launch",
"name": "Electron: Main",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
"runtimeArgs": [
"--remote-debugging-port=9223",
"."
],
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
}
},
{
"name": "Electron: Renderer",
"type": "chrome",
"request": "attach",
"port": 9223,
"webRoot": "${workspaceFolder}",
"timeout": 30000,
"resolveSourceMapLocations": [
"${workspaceFolder}"
],
}
],
"compounds": [
{
"name": "Electron: All",
"configurations": [
"Electron: Main",
"Electron: Renderer"
]
}
]
}
7 changes: 6 additions & 1 deletion app/login/formSender.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ function sendForm(event) { // eslint-disable-line no-unused-vars
{
username: document.getElementById('username').value,
password: document.getElementById('password').value,
});
}
);
// window.api.submitForm({
// username: document.getElementById('username').value,
// password: document.getElementById('password').value,
// });
}
2 changes: 2 additions & 0 deletions app/login/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { app, ipcMain, BrowserWindow } = require('electron');
const { execSync } = require('child_process');
// const path = require('path');

let isFirstLoginTry = true;

Expand All @@ -16,6 +17,7 @@ exports.loginService = function loginService(parentWindow, callback) {
webPreferences: {
contextIsolation: false,
nodeIntegration: true
//preload: path.join(__dirname, 'preload.js')
}
});
win.once('ready-to-show', () => {
Expand Down
12 changes: 12 additions & 0 deletions app/login/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const {
contextBridge,
ipcRenderer
} = require("electron");

contextBridge.exposeInMainWorld(
"api", {
submitForm: (args) => {
ipcRenderer.send('submitForm', args);
},
},
);
75 changes: 47 additions & 28 deletions app/streamSelector/browser.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,51 @@
const { ipcRenderer } = require('electron');
window.addEventListener('DOMContentLoaded', init());

function init() {
return () => {
ipcRenderer.once('get-screensizes-response', (event, screens) => {
createPreviewScreen(screens);
});
ipcRenderer.send('get-screensizes-request');
};
}

function createPreviewScreen(screens) {
window.addEventListener('DOMContentLoaded', () => {
const screens = [
{
width: 1280,
height: 720,
name: 'HD',
alt_name: '720p',
default: false
},
{
width: 1920,
height: 1080,
name: 'FHD',
alt_name: '1080p',
default: true
},
{
width: 2048,
height: 1080,
name: '2K',
alt_name: 'QHD',
default: false
},
{
width: 3840,
height: 2160,
name: '4K',
alt_name: 'UHD',
default: false
}
];
let windowsIndex = 0;
const sscontainer = document.getElementById('screen-size');
createEventHandlers({ screens, sscontainer });
ipcRenderer.invoke('desktop-capturer-get-sources', { types: ['window', 'screen'] }).then(async (sources) => {
const rowElement = document.querySelector('.container-fluid .row');
for (const source of sources) {
await createPreview({
source,
title: source.id.startsWith('screen:') ? source.name : `Window ${++windowsIndex}`,
rowElement,
screens,
sscontainer
});
}
});
}
window.api.desktopCapturerGetSources({ types: ['window', 'screen'] })
.then(async (sources) => {
const rowElement = document.querySelector('.container-fluid .row');
for (const source of sources) {
await createPreview({
source,
title: source.id.startsWith('screen:') ? source.name : `Window ${++windowsIndex}`,
rowElement,
screens,
sscontainer
});
}
});
});

async function createPreview(properties) {
let columnElement = document.createElement('div');
Expand Down Expand Up @@ -75,7 +94,7 @@ async function createPreviewStream(properties, videoElement) {
function playPreview(properties) {
properties.videoElement.onclick = () => {
closePreviews();
ipcRenderer.send('selected-source', {
window.api.selectedSource({
id: properties.source.id,
screen: properties.screens[properties.sscontainer.value]
});
Expand All @@ -89,7 +108,7 @@ function createEventHandlers(properties) {
document.querySelector('#btn-windows').addEventListener('click', toggleSources);
document.querySelector('#btn-close').addEventListener('click', () => {
closePreviews();
ipcRenderer.send('close-view');
window.api.closeView();
});
}

Expand Down
53 changes: 8 additions & 45 deletions app/streamSelector/index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,5 @@
const { ipcMain, BrowserView } = require('electron');
const { ipcMain, WebContentsView } = require('electron');
const path = require('path');
const resolutions = [
{
width: 1280,
height: 720,
name: 'HD',
alt_name: '720p',
default: false
},
{
width: 1920,
height: 1080,
name: 'FHD',
alt_name: '1080p',
default: true
},
{
width: 2048,
height: 1080,
name: '2K',
alt_name: 'QHD',
default: false
},
{
width: 3840,
height: 2160,
name: '4K',
alt_name: 'UHD',
default: false
}
];

let _StreamSelector_parent = new WeakMap();
let _StreamSelector_window = new WeakMap();
Expand All @@ -54,7 +24,7 @@ class StreamSelector {
}

/**
* @type {BrowserView}
* @type {WebContentsView}
*/
get view() {
return _StreamSelector_window.get(this);
Expand Down Expand Up @@ -85,23 +55,24 @@ class StreamSelector {
show(callback) {
let self = this;
self.callback = callback;
self.view = new BrowserView({
self.view = new WebContentsView({
webPreferences: {
nodeIntegration: true,
contextIsolation: false
preload: path.join(__dirname, 'preload.js')
}
});

createScreenRequestHandler();
self.view.webContents.loadFile(path.join(__dirname, 'index.html'));
self.parent.addBrowserView(self.view);
self.parent.contentView.addChildView(self.view);

let _resize = () => {
resizeView(self);
};
resizeView(self);

let _close = (_event, source) => {
//'screen:x:0' -> whole screen
//'window:x:0' -> small window
// show captured source in a new view? Maybe reuse the same view, but make it smaller? probably best a new "file"/view
closeView({ view: self, _resize, _close, source });
};

Expand Down Expand Up @@ -135,12 +106,4 @@ function resizeView(view) {
}, 0);
}

function createScreenRequestHandler() {
ipcMain.once('get-screensizes-request', event => {
event.reply('get-screensizes-response', resolutions.map(resolution => {
return Object.assign({}, resolution);
}));
});
}

module.exports = { StreamSelector };
20 changes: 20 additions & 0 deletions app/streamSelector/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const {
contextBridge,
ipcRenderer
} = require("electron");

// Expose protected methods that allow the renderer process to use
// the ipcRenderer without exposing the entire object
contextBridge.exposeInMainWorld(
"api", {
selectedSource: (args) => {
return ipcRenderer.send('selected-source', args);
},
closeView: () => {
return ipcRenderer.send('close-view');
},
desktopCapturerGetSources: (args) => {
return ipcRenderer.invoke('desktop-capturer-get-sources', args);
},
}
);
12 changes: 11 additions & 1 deletion com.github.IsmaelMartinez.teams_for_linux.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@
<url type="bugtracker">https://github.com/IsmaelMartinez/teams-for-linux/issues</url>
<launchable type="desktop-id">com.github.IsmaelMartinez.teams_for_linux.desktop</launchable>
<releases>
<release version="1.12.0" date="2024-11-15">
<description>
<ul>
<li>Improving security on the streamSelector to work without the need of contentIsolation</li>
<li>Move from BaseView (deprecated), to WebContentsView in the streamSelector</li>
<li>Updating vsconfig to allow for electron and chrome debugging</li>
</ul>
</description>
</release>
<release version="1.11.5" date="2024-11-11">
<description>
<ul>
<li>Change the default value of frame to true</li>
<li>Package updates including moving to electron 33.2.0</li>
</ul>
</description>
</release><release version="1.11.4" date="2024-11-09">
</release>
<release version="1.11.4" date="2024-11-09">
<description>
<ul>
<li>Allow frameless window by using the config 'frame' option</li>
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "teams-for-linux",
"version": "1.11.5",
"version": "1.12.0",
"main": "app/index.js",
"description": "Unofficial client for Microsoft Teams for Linux",
"homepage": "https://github.com/IsmaelMartinez/teams-for-linux",
Expand Down

0 comments on commit e430d4b

Please sign in to comment.