openvidu-components: Allowed one single string token in webcomponent

pull/732/head
csantosm 2022-06-02 18:00:14 +02:00
parent 2fd764ce7c
commit 5d574fb3d2
3 changed files with 17 additions and 7 deletions

View File

@ -39,6 +39,7 @@ import { PanelType } from '../../models/panel.model';
import { PanelService } from '../../services/panel/panel.service'; import { PanelService } from '../../services/panel/panel.service';
import { RecordingService } from '../../services/recording/recording.service'; import { RecordingService } from '../../services/recording/recording.service';
import { TranslateService } from '../../services/translate/translate.service'; import { TranslateService } from '../../services/translate/translate.service';
import { OpenViduAngularConfigService } from '../../services/config/openvidu-angular.config.service';
/** /**
* @internal * @internal
@ -80,6 +81,7 @@ export class SessionComponent implements OnInit {
protected loggerSrv: LoggerService, protected loggerSrv: LoggerService,
protected chatService: ChatService, protected chatService: ChatService,
protected tokenService: TokenService, protected tokenService: TokenService,
private libService: OpenViduAngularConfigService,
protected layoutService: LayoutService, protected layoutService: LayoutService,
protected panelService: PanelService, protected panelService: PanelService,
private recordingService: RecordingService, private recordingService: RecordingService,
@ -121,6 +123,10 @@ export class SessionComponent implements OnInit {
async ngOnInit() { async ngOnInit() {
if (!this.usedInPrejoinPage) { if (!this.usedInPrejoinPage) {
if(!this.tokenService.getScreenToken()){
// Hide screenshare button if screen token does not exist
this.libService.screenshareButton.next(false);
}
this.session = this.openviduService.getWebcamSession(); this.session = this.openviduService.getWebcamSession();
this.sessionScreen = this.openviduService.getScreenSession(); this.sessionScreen = this.openviduService.getScreenSession();
this.subscribeToConnectionCreatedAndDestroyed(); this.subscribeToConnectionCreatedAndDestroyed();

View File

@ -279,8 +279,6 @@ export class VideoconferenceComponent implements OnInit, OnDestroy, AfterViewIni
if (tokens.screen) { if (tokens.screen) {
this.tokenService.setScreenToken(tokens.screen); this.tokenService.setScreenToken(tokens.screen);
} else { } else {
// Hide screenshare button if screen token does not exist
this.libService.screenshareButton.next(false);
this.log.w('No screen token found. Screenshare feature will be disabled'); this.log.w('No screen token found. Screenshare feature will be disabled');
} }
this.tokensReceived = true; this.tokensReceived = true;

View File

@ -514,7 +514,10 @@ export class OpenviduWebComponentComponent implements OnInit {
/** /**
* @example * @example
* <openvidu-webcomponent tokens='{"webcam":"TOKEN1", "screen":"TOKEN2"}'></openvidu-webcomponent> * <openvidu-webcomponent tokens='{"webcam":"TOKEN1", "screen":"TOKEN2"}'></openvidu-webcomponent>
* * <openvidu-webcomponent tokens='TOKEN'></openvidu-webcomponent> *
* or
*
* <openvidu-webcomponent tokens='TOKEN1'></openvidu-webcomponent>
*/ */
@Input('tokens') @Input('tokens')
set tokens(value: TokenModel | string) { set tokens(value: TokenModel | string) {
@ -523,8 +526,12 @@ export class OpenviduWebComponentComponent implements OnInit {
this._tokens = this.castToJson(value); this._tokens = this.castToJson(value);
this.success = !!this._tokens?.webcam && !!this._tokens?.screen; this.success = !!this._tokens?.webcam && !!this._tokens?.screen;
} catch (error) { } catch (error) {
if (typeof value === 'string' && value !== '') {
this.log.d('Sigle token received.');
this._tokens = { webcam: value };
this.success = true;
} else {
this.log.e(error); this.log.e(error);
if (!this.success) {
this.log.e('Parameters received are incorrect: ', value); this.log.e('Parameters received are incorrect: ', value);
this.log.e('Session cannot start'); this.log.e('Session cannot start');
} }
@ -663,8 +670,7 @@ export class OpenviduWebComponentComponent implements OnInit {
try { try {
return JSON.parse(value); return JSON.parse(value);
} catch (error) { } catch (error) {
this.log.e('Unexpected JSON', error); throw 'Unexpected JSON' + error;
throw 'Unexpected JSON';
} }
} else if (typeof value === 'object') { } else if (typeof value === 'object') {
return value; return value;