Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-3074] Fix issues with media permissions on Linux and Jitsi Meet in embedded mode on all platforms #3331

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/main/permissionsManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ jest.mock('main/windows/mainWindow', () => ({

describe('main/PermissionsManager', () => {
describe('setForServer', () => {
it('should ask for media permission when is not granted but the user explicitly granted it', () => {
systemPreferences.getMediaAccessStatus.mockReturnValue('denied');
const permissionsManager = new PermissionsManager('anyfile.json');
permissionsManager.setForServer({url: new URL('http://anyurl.com')}, {media: {allowed: true}});
expect(systemPreferences.askForMediaAccess).toHaveBeenNthCalledWith(1, 'microphone');
expect(systemPreferences.askForMediaAccess).toHaveBeenNthCalledWith(2, 'camera');
});
if (process.platform !== 'linux') {
it('should ask for media permission when is not granted but the user explicitly granted it', () => {
systemPreferences.getMediaAccessStatus.mockReturnValue('denied');
const permissionsManager = new PermissionsManager('anyfile.json');
permissionsManager.setForServer({url: new URL('http://anyurl.com')}, {media: {allowed: true}});
expect(systemPreferences.askForMediaAccess).toHaveBeenNthCalledWith(1, 'microphone');
expect(systemPreferences.askForMediaAccess).toHaveBeenNthCalledWith(2, 'camera');
});
}
});

describe('handlePermissionRequest', () => {
Expand Down
29 changes: 23 additions & 6 deletions src/main/permissionsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class PermissionsManager extends JsonFileManager<PermissionsByOrigin> {
};

setForServer = (server: MattermostServer, permissions: Permissions) => {
if (permissions.media?.allowed) {
if (permissions.media?.allowed && (process.platform === 'win32' || process.platform === 'darwin')) {
this.checkMediaAccess('microphone');
this.checkMediaAccess('camera');
}
Expand Down Expand Up @@ -137,11 +137,6 @@ export class PermissionsManager extends JsonFileManager<PermissionsByOrigin> {
url = details.securityOrigin;
}

const parsedURL = parseURL(url);
if (!parsedURL) {
return false;
}

let serverURL: URL | undefined;
if (CallsWidgetWindow.isCallsWidget(webContentsId)) {
serverURL = CallsWidgetWindow.getViewURL();
Expand All @@ -159,6 +154,28 @@ export class PermissionsManager extends JsonFileManager<PermissionsByOrigin> {
return true;
}

const preparsedURL = parseURL(url);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not meet ticket requirements


if (!preparsedURL) {
return false;
}

const preparsedHostChunks = preparsedURL.host.split('.').reverse();
const serverHostChunks = serverURL.host.split('.').reverse();

if (
preparsedHostChunks.length >= 3 && serverHostChunks.length >= 3 &&
preparsedHostChunks[0] === serverHostChunks[0] &&
preparsedHostChunks[1] === serverHostChunks[1]
) {
url = serverURL.href;
}

const parsedURL = parseURL(url);
if (!parsedURL) {
return false;
}

// Exception for embedded videos such as YouTube
// We still want to ask permission to do this though
const isExternalFullscreen = permission === 'fullscreen' && parsedURL.origin !== serverURL.origin;
Expand Down
Loading