SEBWIN-449: Implemented workaround due to webcam and microphone access issue when using data URI for proctoring content.

This commit is contained in:
Damian Büchel 2021-03-17 00:05:29 +01:00
parent 52217fa477
commit f92c717e32
10 changed files with 44 additions and 9 deletions

View file

@ -249,7 +249,7 @@ namespace SafeExamBrowser.Client
private IOperation BuildProctoringOperation()
{
var controller = new ProctoringController(ModuleLogger(nameof(ProctoringController)), uiFactory);
var controller = new ProctoringController(context.AppConfig, new FileSystem(), ModuleLogger(nameof(ProctoringController)), uiFactory);
var operation = new ProctoringOperation(context, logger, controller);
context.ProctoringController = controller;

View file

@ -30,9 +30,6 @@ namespace SafeExamBrowser.Client.Operations
public override OperationResult Perform()
{
// TODO
Context.Settings.Proctoring.Enabled = true;
if (Context.Settings.Proctoring.Enabled)
{
logger.Info("Initializing proctoring...");

View file

@ -2,12 +2,18 @@
<head>
<meta charset="utf-8" />
</head>
<body>
<body style="margin: 0">
<div id="placeholder" />
<script src='https://meet.jit.si/external_api.js'></script>
<script type="text/javascript">
var domain = "%%_DOMAIN_%%";
var options = {
configOverwrite: {
startAudioOnly: false,
startWithAudioMuted: true,
startWithVideoMuted: false,
disable1On1Mode: true
},
height: "100%",
jwt: "%%_TOKEN_%%",
parentNode: document.querySelector('#placeholder'),

View file

@ -27,6 +27,7 @@ namespace SafeExamBrowser.Proctoring
{
if (e.PermissionKind == CoreWebView2PermissionKind.Camera || e.PermissionKind == CoreWebView2PermissionKind.Microphone)
{
e.State = CoreWebView2PermissionState.Allow;
logger.Info($"Granted access to {e.PermissionKind}.");
}
else

View file

@ -9,9 +9,11 @@
using System;
using System.IO;
using System.Reflection;
using SafeExamBrowser.Configuration.Contracts;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Proctoring.Contracts;
using SafeExamBrowser.Settings.Proctoring;
using SafeExamBrowser.SystemComponents.Contracts;
using SafeExamBrowser.UserInterface.Contracts;
using SafeExamBrowser.UserInterface.Contracts.Proctoring;
@ -19,13 +21,18 @@ namespace SafeExamBrowser.Proctoring
{
public class ProctoringController : IProctoringController
{
private readonly AppConfig appConfig;
private readonly IFileSystem fileSystem;
private readonly IModuleLogger logger;
private readonly IUserInterfaceFactory uiFactory;
private string filePath;
private IProctoringWindow window;
public ProctoringController(IModuleLogger logger, IUserInterfaceFactory uiFactory)
public ProctoringController(AppConfig appConfig, IFileSystem fileSystem, IModuleLogger logger, IUserInterfaceFactory uiFactory)
{
this.appConfig = appConfig;
this.fileSystem = fileSystem;
this.logger = logger;
this.uiFactory = uiFactory;
}
@ -34,11 +41,15 @@ namespace SafeExamBrowser.Proctoring
{
if (settings.JitsiMeet.Enabled || settings.Zoom.Enabled)
{
var content = LoadContent(settings);
var control = new ProctoringControl(logger.CloneFor(nameof(ProctoringControl)));
filePath = Path.Combine(appConfig.TemporaryDirectory, $"{Path.GetRandomFileName()}_index.html");
fileSystem.Save(content, filePath);
control.EnsureCoreWebView2Async().ContinueWith(_ =>
{
control.Dispatcher.Invoke(() => control.NavigateToString(LoadContent(settings)));
control.Dispatcher.Invoke(() => control.CoreWebView2.Navigate(filePath));
});
window = uiFactory.CreateProctoringWindow(control);
@ -55,6 +66,7 @@ namespace SafeExamBrowser.Proctoring
public void Terminate()
{
window?.Close();
fileSystem.Delete(filePath);
}
private string LoadContent(ProctoringSettings settings)

View file

@ -74,6 +74,10 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SafeExamBrowser.Configuration.Contracts\SafeExamBrowser.Configuration.Contracts.csproj">
<Project>{7d74555e-63e1-4c46-bd0a-8580552368c8}</Project>
<Name>SafeExamBrowser.Configuration.Contracts</Name>
</ProjectReference>
<ProjectReference Include="..\SafeExamBrowser.Logging.Contracts\SafeExamBrowser.Logging.Contracts.csproj">
<Project>{64ea30fb-11d4-436a-9c2b-88566285363e}</Project>
<Name>SafeExamBrowser.Logging.Contracts</Name>
@ -86,6 +90,10 @@
<Project>{30b2d907-5861-4f39-abad-c4abf1b3470e}</Project>
<Name>SafeExamBrowser.Settings</Name>
</ProjectReference>
<ProjectReference Include="..\SafeExamBrowser.SystemComponents.Contracts\SafeExamBrowser.SystemComponents.Contracts.csproj">
<Project>{903129c6-e236-493b-9ad6-c6a57f647a3a}</Project>
<Name>SafeExamBrowser.SystemComponents.Contracts</Name>
</ProjectReference>
<ProjectReference Include="..\SafeExamBrowser.UserInterface.Contracts\SafeExamBrowser.UserInterface.Contracts.csproj">
<Project>{c7889e97-6ff6-4a58-b7cb-521ed276b316}</Project>
<Name>SafeExamBrowser.UserInterface.Contracts</Name>

View file

@ -22,5 +22,10 @@ namespace SafeExamBrowser.SystemComponents.Contracts
/// Deletes the item at the given path, if it exists. Directories will be completely deleted, including all subdirectories and files.
/// </summary>
void Delete(string path);
/// <summary>
/// Saves the given content as a file under the specified path. If the file doesn't yet exist, it will be created, otherwise overwritten.
/// </summary>
void Save(string content, string path);
}
}

View file

@ -30,5 +30,10 @@ namespace SafeExamBrowser.SystemComponents
Directory.Delete(path, true);
}
}
public void Save(string content, string path)
{
File.WriteAllText(path, content);
}
}
}

View file

@ -4,7 +4,6 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SafeExamBrowser.UserInterface.Desktop.Windows"
mc:Ignorable="d"
Title="ProctoringWindow" Height="450" Width="800">
mc:Ignorable="d" Height="250" Width="350" Topmost="True" WindowStyle="None">
<DockPanel Name="ControlContainer" />
</Window>

View file

@ -75,6 +75,8 @@ namespace SafeExamBrowser.UserInterface.Desktop.Windows
}
Closing += ProctoringWindow_Closing;
Top = SystemParameters.WorkArea.Height - Height;
Left = SystemParameters.WorkArea.Width - Width;
}
}
}