mirror of https://github.com/OpenVidu/openvidu.git
openvidu-browser: fix VB edition checks
parent
5d354f1f0e
commit
1f1b54f111
|
@ -1344,6 +1344,46 @@ export class Session extends EventDispatcher {
|
|||
return listenersInStreamManager > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
getTokenParams(token: string) {
|
||||
const match = token.match(/^(wss?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
|
||||
if (!!match) {
|
||||
const url = {
|
||||
protocol: match[1],
|
||||
host: match[2],
|
||||
hostname: match[3],
|
||||
port: match[4],
|
||||
pathname: match[5],
|
||||
search: match[6],
|
||||
hash: match[7]
|
||||
};
|
||||
|
||||
const params = token.split('?');
|
||||
const queryParams = decodeURI(params[1])
|
||||
.split('&')
|
||||
.map(param => param.split('='))
|
||||
.reduce((values, [key, value]) => {
|
||||
values[key] = value
|
||||
return values
|
||||
}, {});
|
||||
|
||||
return {
|
||||
url,
|
||||
sessionId: queryParams['sessionId'],
|
||||
secret: queryParams['secret'],
|
||||
recorder: queryParams['recorder'],
|
||||
webrtcStatsInterval: queryParams['webrtcStatsInterval'],
|
||||
sendBrowserLogs: queryParams['sendBrowserLogs'],
|
||||
edition: queryParams['edition']
|
||||
};
|
||||
|
||||
} else {
|
||||
throw new Error(`Token not valid: "${token}"`);
|
||||
}
|
||||
}
|
||||
|
||||
/* Private methods */
|
||||
|
||||
private connectAux(token: string): Promise<void> {
|
||||
|
@ -1461,54 +1501,26 @@ export class Session extends EventDispatcher {
|
|||
}
|
||||
|
||||
private processToken(token: string): void {
|
||||
const match = token.match(/^(wss?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
|
||||
if (!!match) {
|
||||
const url = {
|
||||
protocol: match[1],
|
||||
host: match[2],
|
||||
hostname: match[3],
|
||||
port: match[4],
|
||||
pathname: match[5],
|
||||
search: match[6],
|
||||
hash: match[7]
|
||||
};
|
||||
const tokenParams = this.getTokenParams(token;
|
||||
this.sessionId = tokenParams.sessionId;
|
||||
|
||||
const params = token.split('?');
|
||||
const queryParams = decodeURI(params[1])
|
||||
.split('&')
|
||||
.map(param => param.split('='))
|
||||
.reduce((values, [key, value]) => {
|
||||
values[key] = value
|
||||
return values
|
||||
}, {});
|
||||
|
||||
this.sessionId = <string>queryParams['sessionId'];
|
||||
const secret = queryParams['secret'];
|
||||
const recorder = queryParams['recorder'];
|
||||
const webrtcStatsInterval = queryParams['webrtcStatsInterval'];
|
||||
const sendBrowserLogs = queryParams['sendBrowserLogs'];
|
||||
const edition = queryParams['edition'];
|
||||
|
||||
if (!!secret) {
|
||||
this.openvidu.secret = secret;
|
||||
if (!!tokenParams.secret) {
|
||||
this.openvidu.secret = tokenParams.secret;
|
||||
}
|
||||
if (!!recorder) {
|
||||
if (!!tokenParams.recorder) {
|
||||
this.openvidu.recorder = true;
|
||||
}
|
||||
if (!!webrtcStatsInterval) {
|
||||
this.openvidu.webrtcStatsInterval = +webrtcStatsInterval;
|
||||
if (!!tokenParams.webrtcStatsInterval) {
|
||||
this.openvidu.webrtcStatsInterval = tokenParams.webrtcStatsInterval;
|
||||
}
|
||||
if (!!sendBrowserLogs) {
|
||||
this.openvidu.sendBrowserLogs = sendBrowserLogs;
|
||||
if (!!tokenParams.sendBrowserLogs) {
|
||||
this.openvidu.sendBrowserLogs = tokenParams.sendBrowserLogs;
|
||||
}
|
||||
this.openvidu.isAtLeastPro = !!webrtcStatsInterval && !!sendBrowserLogs;
|
||||
this.openvidu.isEnterprise = edition === 'enterprise';
|
||||
this.openvidu.isAtLeastPro = tokenParams.edition === 'pro' || tokenParams.edition === 'enterprise';
|
||||
this.openvidu.isEnterprise = tokenParams.edition === 'enterprise';
|
||||
|
||||
this.openvidu.wsUri = 'wss://' + url.host + '/openvidu';
|
||||
this.openvidu.httpUri = 'https://' + url.host;
|
||||
} else {
|
||||
logger.error('Token "' + token + '" is not valid')
|
||||
}
|
||||
this.openvidu.wsUri = 'wss://' + tokenParams.url.host + '/openvidu';
|
||||
this.openvidu.httpUri = 'https://' + tokenParams.url.host;
|
||||
}
|
||||
|
||||
private processJoinRoomResponse(opts: LocalConnectionOptions, token: string) {
|
||||
|
|
|
@ -348,9 +348,6 @@ export class Stream {
|
|||
|
||||
// Client filters
|
||||
|
||||
if (!this.session.openvidu.isAtLeastPro) {
|
||||
return reject(new OpenViduError(OpenViduErrorName.VIRTUAL_BACKGROUND_ERROR, 'OpenVidu Virtual Background API is available from OpenVidu Pro edition onwards'));
|
||||
}
|
||||
if (!this.hasVideo) {
|
||||
return reject(new OpenViduError(OpenViduErrorName.VIRTUAL_BACKGROUND_ERROR, 'The Virtual Background filter requires a video track to be applied'));
|
||||
}
|
||||
|
@ -358,8 +355,6 @@ export class Stream {
|
|||
return reject(new OpenViduError(OpenViduErrorName.VIRTUAL_BACKGROUND_ERROR, 'The StreamManager requires some video element to be attached to it in order to apply a Virtual Background filter'));
|
||||
}
|
||||
|
||||
logger.info('Applying Virtual Background to stream ' + this.streamId);
|
||||
|
||||
let openviduToken: string;
|
||||
if (!!this.session.token) {
|
||||
openviduToken = this.session.token;
|
||||
|
@ -369,8 +364,22 @@ export class Stream {
|
|||
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'));
|
||||
}
|
||||
|
||||
if (!!this.session.token && !this.session.openvidu.isAtLeastPro) {
|
||||
// Check OpenVidu edition after connection to the Session
|
||||
return reject(new OpenViduError(OpenViduErrorName.VIRTUAL_BACKGROUND_ERROR, 'OpenVidu Virtual Background API is available from OpenVidu Pro edition onwards'));
|
||||
} else {
|
||||
// Check OpenVidu edition with the token
|
||||
const tokenParams = this.session.getTokenParams(openviduToken);
|
||||
if (tokenParams.edition !== 'pro' && tokenParams.edition !== 'enterprise') {
|
||||
return reject(new OpenViduError(OpenViduErrorName.VIRTUAL_BACKGROUND_ERROR, 'OpenVidu Virtual Background API is available from OpenVidu Pro edition onwards'));
|
||||
}
|
||||
}
|
||||
|
||||
openviduToken = encodeURIComponent(btoa(openviduToken));
|
||||
|
||||
logger.info('Applying Virtual Background to stream ' + this.streamId);
|
||||
|
||||
const afterScriptLoaded = async () => {
|
||||
try {
|
||||
const id = this.streamId + '_' + uuidv4();
|
||||
|
|
Loading…
Reference in New Issue