openvidu-call: Improved backend responses

This commit is contained in:
csantosm 2022-08-17 12:54:18 +02:00
parent cfec726a44
commit 7a4a78cbfc
4 changed files with 53 additions and 32 deletions

View File

@ -36,9 +36,10 @@ public class AdminController {
private OpenViduService openviduService;
@PostMapping("/login")
public ResponseEntity<Map<String, Object>> login(@RequestBody(required = false) Map<String, String> params,
public ResponseEntity<?> login(@RequestBody(required = false) Map<String, String> params,
@CookieValue(name = OpenViduService.RECORDING_TOKEN_NAME, defaultValue = "") String recordingToken, HttpServletResponse res) {
String message = "";
Map<String, Object> response = new HashMap<String, Object>();
String password = params.get("password");
@ -69,13 +70,21 @@ public class AdminController {
return new ResponseEntity<>(response, HttpStatus.OK);
} catch (OpenViduJavaClientException | OpenViduHttpException error) {
if(Integer.parseInt(error.getMessage()) == 501) {
System.err.println(error.getMessage() + ". OpenVidu Server recording module is disabled.");
return new ResponseEntity<>(response, HttpStatus.OK);
} else {
message = error.getMessage() + " Unexpected error getting recordings";
error.printStackTrace();
System.err.println(message);
return new ResponseEntity<>(message, HttpStatus.INTERNAL_SERVER_ERROR);
}
error.printStackTrace();
System.err.println(error.getMessage() + "Unexpected error getting recordings");
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
} else {
System.err.println("Permissions denied");
message = "Permissions denied";
System.err.println(message);
return new ResponseEntity<>(null, HttpStatus.FORBIDDEN);
}

View File

@ -43,7 +43,7 @@ public class RecordingController {
private ProxyService proxyService;
@GetMapping("")
public ResponseEntity<List<Recording>> getRecordings(
public ResponseEntity<?> getRecordings(
@CookieValue(name = OpenViduService.RECORDING_TOKEN_NAME, defaultValue = "") String recordingToken) {
try {
List<Recording> recordings = new ArrayList<Recording>();
@ -64,7 +64,7 @@ public class RecordingController {
String message = IS_RECORDING_ENABLED ? "Permissions denied to drive recording"
: "Recording is disabled";
System.err.println(message);
return new ResponseEntity<>(null, HttpStatus.FORBIDDEN);
return new ResponseEntity<>(message, HttpStatus.FORBIDDEN);
}
} catch (OpenViduJavaClientException | OpenViduHttpException error) {
@ -75,13 +75,13 @@ public class RecordingController {
message = "No recording exist for the session";
}
System.err.println(message);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>(message, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@PostMapping("/start")
public ResponseEntity<Recording> startRecording(@RequestBody(required = false) Map<String, String> params,
public ResponseEntity<?> startRecording(@RequestBody(required = false) Map<String, String> params,
@CookieValue(name = OpenViduService.RECORDING_TOKEN_NAME, defaultValue = "") String recordingToken) {
try {
@ -93,9 +93,9 @@ public class RecordingController {
return new ResponseEntity<>(startingRecording, HttpStatus.OK);
} else {
System.out.println("Permissions denied for starting recording in session " + sessionId);
return new ResponseEntity<>(null, HttpStatus.FORBIDDEN);
String message = "Permissions denied for starting recording in session " + sessionId;
System.out.println(message);
return new ResponseEntity<>(message, HttpStatus.FORBIDDEN);
}
} catch (OpenViduJavaClientException | OpenViduHttpException error) {
error.printStackTrace();
@ -109,14 +109,14 @@ public class RecordingController {
message = "The session has no connected participants";
}
System.err.println(message);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>(message, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@PostMapping("/stop")
public ResponseEntity<List<Recording>> stopRecording(@RequestBody(required = false) Map<String, String> params,
public ResponseEntity<?> stopRecording(@RequestBody(required = false) Map<String, String> params,
@CookieValue(name = OpenViduService.RECORDING_TOKEN_NAME, defaultValue = "") String recordingToken) {
try {
String sessionId = params.get("sessionId");
@ -131,12 +131,14 @@ public class RecordingController {
openviduService.recordingMap.get(sessionId).setRecordingId("");
return new ResponseEntity<>(recordingList, HttpStatus.OK);
} else {
System.err.println("Session was not being recorded");
return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);
String message = "Session was not being recorded";
System.err.println(message);
return new ResponseEntity<>(message, HttpStatus.NOT_FOUND);
}
} else {
System.err.println("Permissions denied to drive recording");
return new ResponseEntity<>(null, HttpStatus.FORBIDDEN);
String message = "Permissions denied to drive recording";
System.err.println(message);
return new ResponseEntity<>(message, HttpStatus.FORBIDDEN);
}
} catch (OpenViduJavaClientException | OpenViduHttpException error) {
error.printStackTrace();
@ -148,12 +150,12 @@ public class RecordingController {
message = "Recording has STARTING status. Wait until STARTED status before stopping the recording";
}
System.err.println(message);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>(message, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@DeleteMapping("/delete/{recordingId}")
public ResponseEntity<List<Recording>> deleteRecording(@PathVariable String recordingId,
public ResponseEntity<?> deleteRecording(@PathVariable String recordingId,
@CookieValue(name = OpenViduService.RECORDING_TOKEN_NAME, defaultValue = "") String recordingToken,
@CookieValue(name = "session", defaultValue = "") String sessionToken) {
try {
@ -163,8 +165,9 @@ public class RecordingController {
if ((!sessionId.isEmpty() && openviduService.isValidToken(sessionId, recordingToken)) || isAdminDashboard) {
if (recordingId.isEmpty()) {
System.err.println("Missing recording id parameter.");
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
String message = "Missing recording id parameter.";
System.err.println(message);
return new ResponseEntity<>(message, HttpStatus.BAD_REQUEST);
}
System.out.println("Deleting recording " + recordingId);
@ -178,8 +181,9 @@ public class RecordingController {
return new ResponseEntity<>(recordings, HttpStatus.OK);
} else {
System.err.println("Permissions denied to drive recording");
return new ResponseEntity<>(recordings, HttpStatus.FORBIDDEN);
String message = "Permissions denied to drive recording";
System.err.println(message);
return new ResponseEntity<>(message, HttpStatus.FORBIDDEN);
}
} catch (OpenViduJavaClientException | OpenViduHttpException error) {
error.printStackTrace();
@ -193,7 +197,7 @@ public class RecordingController {
message = "No recording exists for the session";
}
System.err.println(message);
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
return new ResponseEntity<>(message, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@ -206,8 +210,9 @@ public class RecordingController {
String sessionId = this.openviduService.getSessionIdFromCookie(recordingToken);
if ((!sessionId.isEmpty() && openviduService.isValidToken(sessionId, recordingToken)) || isAdminDashboard) {
if (recordingId.isEmpty()) {
System.err.println("Missing recording id parameter.");
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
String message = "Missing recording id parameter.";
System.err.println(message);
return new ResponseEntity<>(message, HttpStatus.BAD_REQUEST);
} else {
try {
return proxyService.processProxyRequest(req, res);
@ -217,8 +222,9 @@ public class RecordingController {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
} else {
System.err.println("Permissions denied to drive recording");
return new ResponseEntity<>(null, HttpStatus.FORBIDDEN);
String message = "Permissions denied to drive recording";
System.err.println(message);
return new ResponseEntity<>(message, HttpStatus.FORBIDDEN);
}
}

View File

@ -1,7 +1,7 @@
server.port: 5000
server.ssl.enabled: false
OPENVIDU_URL: https://demos.openvidu.io
OPENVIDU_URL: https://localhost:4443
OPENVIDU_SECRET: MY_SECRET
RECORDING: ENABLED

View File

@ -28,8 +28,14 @@ app.post('/login', async (req: Request, res: Response) => {
console.log(`${recordings.length} recordings found`);
res.status(200).send(JSON.stringify({ recordings }));
} catch (error) {
console.error(error);
res.status(500).send('Unexpected error getting recordings');
const code = Number(error?.message);
if(code === 501){
console.log('501. OpenVidu Server recording module is disabled.');
res.status(200).send();
} else {
console.error(error);
res.status(500).send('Unexpected error getting recordings');
}
}
} else {
res.status(403).send('Permissions denied');