SEBSERV-255

This commit is contained in:
anhefti 2022-01-04 11:04:22 +01:00
parent c863fd0f03
commit 3d7a09b462
2 changed files with 36 additions and 25 deletions

View file

@ -12,6 +12,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.rap.rwt.RWT; import org.eclipse.rap.rwt.RWT;
@ -24,6 +25,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
@ -80,32 +82,14 @@ public class MonitoringProctoringService {
private static final LocTextKey EXAM_ROOM_NAME = private static final LocTextKey EXAM_ROOM_NAME =
new LocTextKey("sebserver.monitoring.exam.proctoring.room.all.name"); new LocTextKey("sebserver.monitoring.exam.proctoring.room.all.name");
// @formatter:off private static final String OPEN_ROOM_SCRIPT_RES =
static final String OPEN_ROOM_SCRIPT = "classpath:ch/ethz/seb/sebserver/gui/service/session/proctoring/openRoomScript.js";
"try {\n" +
"var existingWin = window.open('', '%s', 'height=%s,width=%s,location=no,scrollbars=yes,status=no,menubar=0,toolbar=no,titlebar=no,dialog=no');\n" +
"try {\n" +
"if(existingWin.location.href === 'about:blank'){\n" +
" existingWin.document.title = '%s';\n" +
" existingWin.location.href = '%s%s';\n" +
" existingWin.focus();\n" +
"} else {\n" +
" existingWin.focus();\n" +
"}" +
"} catch(secErr) {\n" +
" alert(\"Unexpected Javascript Error happened: \" + secErr);\n"+
" existingWin.focus();\n" +
"}" +
"}" +
"catch(err) {\n" +
" alert(\"Unexpected Javascript Error happened: \" + err);\n"+
"}";
// @formatter:on
private final PageService pageService; private final PageService pageService;
private final GuiServiceInfo guiServiceInfo; private final GuiServiceInfo guiServiceInfo;
private final ProctorRoomConnectionsPopup proctorRoomConnectionsPopup; private final ProctorRoomConnectionsPopup proctorRoomConnectionsPopup;
private final JSONMapper jsonMapper; private final JSONMapper jsonMapper;
private final Resource openRoomScriptRes;
private final String remoteProctoringEndpoint; private final String remoteProctoringEndpoint;
public MonitoringProctoringService( public MonitoringProctoringService(
@ -113,12 +97,14 @@ public class MonitoringProctoringService {
final GuiServiceInfo guiServiceInfo, final GuiServiceInfo guiServiceInfo,
final ProctorRoomConnectionsPopup proctorRoomConnectionsPopup, final ProctorRoomConnectionsPopup proctorRoomConnectionsPopup,
final JSONMapper jsonMapper, final JSONMapper jsonMapper,
@Value(OPEN_ROOM_SCRIPT_RES) final Resource openRoomScript,
@Value("${sebserver.gui.remote.proctoring.entrypoint:/remote-proctoring}") final String remoteProctoringEndpoint) { @Value("${sebserver.gui.remote.proctoring.entrypoint:/remote-proctoring}") final String remoteProctoringEndpoint) {
this.pageService = pageService; this.pageService = pageService;
this.guiServiceInfo = guiServiceInfo; this.guiServiceInfo = guiServiceInfo;
this.proctorRoomConnectionsPopup = proctorRoomConnectionsPopup; this.proctorRoomConnectionsPopup = proctorRoomConnectionsPopup;
this.jsonMapper = jsonMapper; this.jsonMapper = jsonMapper;
this.openRoomScriptRes = openRoomScript;
this.remoteProctoringEndpoint = remoteProctoringEndpoint; this.remoteProctoringEndpoint = remoteProctoringEndpoint;
} }
@ -299,7 +285,7 @@ public class MonitoringProctoringService {
final String startLink = extractZoomStartLink(room); final String startLink = extractZoomStartLink(room);
final String script = String.format( final String script = String.format(
OPEN_ROOM_SCRIPT, getOpenRoomScriptTemplate(),
room.name, room.name,
800, 800,
1200, 1200,
@ -314,7 +300,7 @@ public class MonitoringProctoringService {
} else { } else {
final String script = String.format( final String script = String.format(
OPEN_ROOM_SCRIPT, getOpenRoomScriptTemplate(),
room.name, room.name,
800, 800,
1200, 1200,
@ -387,7 +373,7 @@ public class MonitoringProctoringService {
final JavaScriptExecutor javaScriptExecutor = RWT.getClient().getService(JavaScriptExecutor.class); final JavaScriptExecutor javaScriptExecutor = RWT.getClient().getService(JavaScriptExecutor.class);
final String script = String.format( final String script = String.format(
MonitoringProctoringService.OPEN_ROOM_SCRIPT, getOpenRoomScriptTemplate(),
connectionData.clientConnection.userSessionId, connectionData.clientConnection.userSessionId,
800, 800,
1200, 1200,
@ -429,7 +415,7 @@ public class MonitoringProctoringService {
final String windowName = proctoringGUIService.getTownhallWindowName(examId.modelId); final String windowName = proctoringGUIService.getTownhallWindowName(examId.modelId);
final JavaScriptExecutor javaScriptExecutor = RWT.getClient().getService(JavaScriptExecutor.class); final JavaScriptExecutor javaScriptExecutor = RWT.getClient().getService(JavaScriptExecutor.class);
final String script = String.format( final String script = String.format(
OPEN_ROOM_SCRIPT, getOpenRoomScriptTemplate(),
windowName, windowName,
800, 800,
1200, 1200,
@ -523,4 +509,13 @@ public class MonitoringProctoringService {
} }
} }
private String getOpenRoomScriptTemplate() {
try {
return IOUtils.toString(this.openRoomScriptRes.getInputStream());
} catch (final Exception e) {
log.error("Failed to load open proctoring room script template", e);
return "ERROR: " + e.getLocalizedMessage();
}
}
} }

View file

@ -0,0 +1,16 @@
try {
var existingWin = window.open('', '%s', 'height=%s,width=%s,location=no,scrollbars=yes,status=no,menubar=0,toolbar=no,titlebar=no,dialog=no');
if (existingWin == null || typeof(existingWin)=='undefined') {
alert('Please disable your pop-up blocker and try again.');
} else {
if(existingWin.location.href === 'about:blank') {
existingWin.document.title = '%s';
existingWin.location.href = '%s%s';
existingWin.focus();
} else {
existingWin.focus();
}
}
} catch(err) {
alert("Unexpected Javascript Error happened: " + err);
}