Skip to content

Commit

Permalink
frontend: Refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
CSantosM committed Aug 19, 2024
1 parent 3d1c862 commit dc491dc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export class VideoRoomComponent implements OnInit {
async onRecordingStopRequested(event: RecordingStopRequestedEvent) {
try {
const { recordingId } = event;

if(!recordingId) throw new Error('Recording ID not found when stopping recording');

await this.restService.stopRecording(recordingId);
} catch (error) {
console.error(error);
Expand All @@ -78,6 +81,9 @@ export class VideoRoomComponent implements OnInit {
async onRecordingDeleteRequested(event: RecordingDeleteRequestedEvent) {
try {
const { recordingId } = event;

if(!recordingId) throw new Error('Recording ID not found when deleting recording');

await this.restService.deleteRecording(recordingId);
} catch (error) {
console.error(error);
Expand Down
18 changes: 15 additions & 3 deletions openvidu-call-front/src/app/services/rest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ export class RestService {
'Content-Type': 'application/json'
});
const userCredentials = this.storageService.getUserCredentials();

if (userCredentials?.username && userCredentials?.password) {
return headers.append('Authorization', `Basic ${btoa(`${userCredentials.username}:${userCredentials.password}`)}`);
return headers.append(
'Authorization',
`Basic ${btoa(`${userCredentials.username}:${userCredentials.password}`)}`
);
}

return headers;
Expand All @@ -35,8 +39,16 @@ export class RestService {
'Content-Type': 'application/json'
});
const adminCredentials = this.storageService.getAdminCredentials();
if (adminCredentials.username && adminCredentials.password) {
return headers.set('Authorization', `Basic ${btoa(`${adminCredentials.username}:${adminCredentials.password}`)}`);

if (!adminCredentials) {
console.error('Admin credentials not found');
return headers;
}

const { username, password } = adminCredentials;

if (username && password) {
return headers.set('Authorization', `Basic ${btoa(`${username}:${password}`)}`);
}

return headers;
Expand Down
4 changes: 2 additions & 2 deletions openvidu-call-front/src/app/services/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export class StorageService {
this.set(Storage.ADMIN_CREDENTIALS, encodedCredentials);
}

getAdminCredentials(): { username: string; password: string } {
getAdminCredentials(): { username: string; password: string } | undefined {
const encodedCredentials = this.get(Storage.ADMIN_CREDENTIALS);

if (encodedCredentials) {
const [username, password] = atob(encodedCredentials).split(':');
return { username, password };
}

return null;
return undefined;
}

clearAdminCredentials() {
Expand Down

0 comments on commit dc491dc

Please sign in to comment.