openvidu-browser: manage token on VB

pull/715/head
pabloFuente 2022-04-22 16:54:10 +02:00
parent 707ad3d673
commit 1ee4a9be10
1 changed files with 13 additions and 2 deletions

View File

@ -364,6 +364,17 @@ export class Stream {
logger.info('Applying Virtual Background to stream ' + this.streamId); logger.info('Applying Virtual Background to stream ' + this.streamId);
let openviduToken: string;
if (!!this.session.token) {
openviduToken = this.session.token;
} else {
openviduToken = options['token'];
}
if (!openviduToken) {
return reject(new OpenViduError(OpenViduErrorName.VIRTUAL_BACKGROUND_ERROR, 'Virtual Background requires the client to be connected to a Session or to have a "token" property available in "options" parameter with a valid OpenVidu token'));
}
openviduToken = encodeURIComponent(btoa(openviduToken));
const afterScriptLoaded = async () => { const afterScriptLoaded = async () => {
try { try {
const id = this.streamId + '_' + uuidv4(); const id = this.streamId + '_' + uuidv4();
@ -385,7 +396,7 @@ export class Stream {
const VB = new VirtualBackground.VirtualBackground({ const VB = new VirtualBackground.VirtualBackground({
id, id,
openviduServerUrl: new URL(this.session.openvidu.httpUri), openviduServerUrl: new URL(this.session.openvidu.httpUri),
openviduToken: this.session.token, openviduToken,
inputVideo: videoClone, inputVideo: videoClone,
inputResolution: '160x96', inputResolution: '160x96',
outputFramerate: 24 outputFramerate: 24
@ -430,7 +441,7 @@ export class Stream {
if (typeof VirtualBackground === "undefined") { if (typeof VirtualBackground === "undefined") {
let script: HTMLScriptElement = document.createElement("script"); let script: HTMLScriptElement = document.createElement("script");
script.type = "text/javascript"; script.type = "text/javascript";
script.src = this.session.openvidu.httpUri + '/openvidu/virtual-background/openvidu-virtual-background.js?token=' + encodeURIComponent(this.session.token); script.src = this.session.openvidu.httpUri + '/openvidu/virtual-background/openvidu-virtual-background.js?token=' + openviduToken;
script.onload = async () => { script.onload = async () => {
try { try {
await afterScriptLoaded(); await afterScriptLoaded();