- Renamed `setParticipantToken` to `setParticipantTokenAndUpdateContext` in ContextService to clarify its functionality. - Introduced ParticipantTokenService to encapsulate token generation logic and manage role/permissions extraction. - Updated VideoRoomComponent to utilize the new ParticipantTokenService for generating participant tokens. - Refactored access room method to improve form validation and participant name initialization. - Added unit tests for ParticipantTokenService to ensure proper functionality. - Updated sidenav model comments for clarity.
34 lines
957 B
TypeScript
34 lines
957 B
TypeScript
import { Injectable } from '@angular/core';
|
|
import { TokenGenerationResult } from '@lib/models/auth.model';
|
|
import { HttpService, ContextService, SessionStorageService } from 'shared-meet-components';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class ParticipantTokenService {
|
|
constructor(
|
|
private httpService: HttpService,
|
|
private ctxService: ContextService,
|
|
private sessionStorageService: SessionStorageService
|
|
) {}
|
|
|
|
/**
|
|
* Generates a participant token and extracts role/permissions
|
|
*/
|
|
async generateToken(roomId: string, participantName: string, secret: string): Promise<TokenGenerationResult> {
|
|
const response = await this.httpService.generateParticipantToken({
|
|
roomId,
|
|
participantName,
|
|
secret
|
|
});
|
|
|
|
this.ctxService.setParticipantTokenAndUpdateContext(response.token);
|
|
|
|
return {
|
|
token: response.token,
|
|
role: this.ctxService.getParticipantRole(),
|
|
permissions: this.ctxService.getParticipantPermissions()
|
|
};
|
|
}
|
|
}
|