Merge pull request #922 from johankwarnmarksymphony/sda-1826

feat: SDA-1826 Add new check-media-permission
This commit is contained in:
Johan Kwarnmark 2020-03-18 10:21:01 +01:00 committed by GitHub
commit cd8b7fe66a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 0 deletions

View File

@ -36,6 +36,7 @@ export enum apiCmds {
getConfigUrl = 'get-config-url',
registerRestartFloater = 'register-restart-floater',
setCloudConfig = 'set-cloud-config',
checkMediaPermission = 'check-media-permission',
}
export enum apiName {
@ -144,6 +145,12 @@ export interface IVersionInfo {
searchApiVer: string;
}
export interface IMediaPermission {
camera: string;
microphone: string;
screen: string;
}
export interface ILogMsg {
level: LogLevel;
details: any;

View File

@ -143,6 +143,22 @@
<button id='bring-to-front'>bring window to front</button>
<button id='bring-to-front-without-focus'>bring to front without focus</button>
<hr>
<p>Check Media Permission:</p>
<button id='check-media-permission'>Check media permission</button>
<br>
<table >
<tr>
<th>Camera permission</th>
<th>Microphone permission</th>
<th>Screen permission</th>
</tr>
<tr>
<td id="camera-permission"></td>
<td id="microphone-permission"></td>
<td id="screen-permission"></td>
</tr>
</table>
<hr>
<p>Get Media Sources:</p>
<button id='get-sources'>Open screen picker & screensharing indicator</button>
@ -210,6 +226,7 @@
notification: 'notification',
closeNotification: 'close-notification',
registerRestartFloater: 'register-restart-floater',
checkMediaPermission: 'check-media-permission',
};
let requestId = 0;
@ -508,6 +525,10 @@
case 'restart-floater-callback':
onRestartFloater(data);
break;
case 'check-media-permission-callback':
handleResponse(data);
console.log(event.data);
break;
default:
console.log(event.data);
}
@ -607,6 +628,40 @@
activityTimer = startActivityInterval();
};
/**
* Check media permission
*/
const mediaPermission = document.getElementById('check-media-permission');
mediaPermission.addEventListener('click', () => {
let cameraPermission = document.getElementById('camera-permission');
let microphonePermission = document.getElementById('microphone-permission');
let screenPermission = document.getElementById('screen-permission');
if (navigator.appVersion.indexOf("Mac") != -1) {
if (window.ssf) {
ssf.checkMediaPermission().then((mediaPermission) => {
console.log('check-media-permission, mediaPermission: ' + JSON.stringify(mediaPermission));
cameraPermission.innerText = mediaPermission.camera;
microphonePermission.innerText = mediaPermission.microphone;
screenPermission.innerText = mediaPermission.screen;
});
} else {
postRequest(apiCmds.checkMediaPermission, null, {
successCallback: (mediaPermission) => {
console.log('check-media-permission, mediaPermission: ' + JSON.stringify(mediaPermission));
cameraPermission.innerText = mediaPermission.camera;
microphonePermission.innerText = mediaPermission.microphone;
screenPermission.innerText = mediaPermission.screen;
}
});
}
} else {
const notImplementedText = 'Not implemented for windows';
cameraPermission.innerText = notImplementedText;
microphonePermission.innerText = notImplementedText;
screenPermission.innerText = notImplementedText;
}
});
/**
* Desktop capture
*/

View File

@ -174,6 +174,13 @@ export class AppBridge {
ssInstance.handleMessageEvents(data);
}
break;
case apiCmds.checkMediaPermission:
const mediaPermission = await ssf.checkMediaPermission();
this.broadcastMessage('check-media-permission-callback', {
requestId: data.requestId,
response: mediaPermission,
});
break;
}
}

View File

@ -9,6 +9,7 @@ import {
IBadgeCount,
IBoundsChange,
ILogMsg,
IMediaPermission,
IRestartFloaterData,
IScreenSharingIndicator,
IScreenSharingIndicatorOptions,
@ -486,6 +487,17 @@ export class SSFApi {
throttledSetCloudConfig(data);
}
/**
* Check media permission
*/
public async checkMediaPermission(): Promise<IMediaPermission> {
return Promise.resolve({
camera: remote.systemPreferences.getMediaAccessStatus('camera'),
microphone: remote.systemPreferences.getMediaAccessStatus('microphone'),
screen: remote.systemPreferences.getMediaAccessStatus('screen'),
});
}
}
/**