2018-04-18 14:29:07 +02:00
|
|
|
/*
|
2020-02-04 11:25:54 +01:00
|
|
|
* (C) Copyright 2017-2020 OpenVidu (https://openvidu.io)
|
2018-04-18 14:29:07 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-10-08 19:31:47 +02:00
|
|
|
import axios, { AxiosError } from 'axios';
|
2021-04-05 17:06:12 +02:00
|
|
|
import { VideoCodec } from './VideoCodec';
|
2018-07-22 22:13:45 +02:00
|
|
|
import { Connection } from './Connection';
|
2020-10-21 22:19:01 +02:00
|
|
|
import { ConnectionProperties } from './ConnectionProperties';
|
2018-04-23 11:06:16 +02:00
|
|
|
import { MediaMode } from './MediaMode';
|
2018-07-22 22:13:45 +02:00
|
|
|
import { OpenVidu } from './OpenVidu';
|
|
|
|
import { Publisher } from './Publisher';
|
2019-01-29 12:31:38 +01:00
|
|
|
import { Recording } from './Recording';
|
2018-04-23 11:06:16 +02:00
|
|
|
import { RecordingLayout } from './RecordingLayout';
|
|
|
|
import { RecordingMode } from './RecordingMode';
|
2018-01-27 19:39:49 +01:00
|
|
|
import { SessionProperties } from './SessionProperties';
|
2018-04-23 11:06:16 +02:00
|
|
|
import { TokenOptions } from './TokenOptions';
|
2021-04-14 15:21:27 +02:00
|
|
|
import { RecordingProperties } from 'RecordingProperties';
|
2022-02-16 17:36:41 +01:00
|
|
|
import { IceServerProperties } from 'IceServerProperties';
|
2017-06-10 01:44:31 +02:00
|
|
|
|
|
|
|
export class Session {
|
|
|
|
|
2018-07-22 22:13:45 +02:00
|
|
|
/**
|
|
|
|
* Unique identifier of the Session
|
|
|
|
*/
|
2018-04-24 15:42:23 +02:00
|
|
|
sessionId: string;
|
2018-07-22 22:13:45 +02:00
|
|
|
|
2018-09-06 12:02:07 +02:00
|
|
|
/**
|
|
|
|
* Timestamp when this session was created, in UTC milliseconds (ms since Jan 1, 1970, 00:00:00 UTC)
|
|
|
|
*/
|
|
|
|
createdAt: number;
|
|
|
|
|
2018-07-22 22:13:45 +02:00
|
|
|
/**
|
|
|
|
* Properties defining the session
|
|
|
|
*/
|
2018-04-24 15:42:23 +02:00
|
|
|
properties: SessionProperties;
|
2017-06-10 01:44:31 +02:00
|
|
|
|
2018-07-22 22:13:45 +02:00
|
|
|
/**
|
2020-10-15 13:16:29 +02:00
|
|
|
* Array of Connections to the Session. This property always initialize as an empty array and
|
|
|
|
* **will remain unchanged since the last time method [[Session.fetch]] or [[OpenVidu.fetch]] was called**.
|
|
|
|
* Exceptions to this rule are:
|
2018-07-22 22:13:45 +02:00
|
|
|
*
|
2020-10-22 20:42:54 +02:00
|
|
|
* - Calling [[Session.createConnection]] automatically adds the new Connection object to the local collection.
|
2020-10-08 19:31:47 +02:00
|
|
|
* - Calling [[Session.forceUnpublish]] automatically updates each affected local Connection object.
|
|
|
|
* - Calling [[Session.forceDisconnect]] automatically updates each affected local Connection object.
|
|
|
|
* - Calling [[Session.updateConnection]] automatically updates the attributes of the affected local Connection object.
|
2018-07-22 22:13:45 +02:00
|
|
|
*
|
2020-10-15 13:16:29 +02:00
|
|
|
* To get the array of Connections with their current actual value, you must call [[Session.fetch]] or [[OpenVidu.fetch]]
|
|
|
|
* before consulting property [[connections]]
|
|
|
|
*/
|
|
|
|
connections: Connection[] = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array containing the active Connections of the Session. It is a subset of [[Session.connections]] array containing only
|
|
|
|
* those Connections with property [[Connection.status]] to `active`.
|
|
|
|
*
|
|
|
|
* To get the array of active Connections with their current actual value, you must call [[Session.fetch]] or [[OpenVidu.fetch]]
|
|
|
|
* before consulting property [[activeConnections]]
|
2018-07-22 22:13:45 +02:00
|
|
|
*/
|
|
|
|
activeConnections: Connection[] = [];
|
2018-06-04 14:14:17 +02:00
|
|
|
|
2018-07-22 22:13:45 +02:00
|
|
|
/**
|
|
|
|
* Whether the session is being recorded or not
|
|
|
|
*/
|
|
|
|
recording = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
2019-05-22 17:01:30 +02:00
|
|
|
constructor(private ov: OpenVidu, propertiesOrJson?) {
|
2018-07-22 22:13:45 +02:00
|
|
|
if (!!propertiesOrJson) {
|
|
|
|
// Defined parameter
|
|
|
|
if (!!propertiesOrJson.sessionId) {
|
|
|
|
// Parameter is a JSON representation of Session ('sessionId' property always defined)
|
2020-10-16 13:45:15 +02:00
|
|
|
this.resetWithJson(propertiesOrJson);
|
2018-07-22 22:13:45 +02:00
|
|
|
} else {
|
|
|
|
// Parameter is a SessionProperties object
|
|
|
|
this.properties = propertiesOrJson;
|
|
|
|
}
|
2018-01-27 19:39:49 +01:00
|
|
|
} else {
|
2018-07-22 22:13:45 +02:00
|
|
|
// Empty parameter
|
|
|
|
this.properties = {};
|
2018-01-27 19:39:49 +01:00
|
|
|
}
|
2021-04-14 15:21:27 +02:00
|
|
|
this.sanitizeDefaultSessionProperties(this.properties);
|
2017-06-10 01:44:31 +02:00
|
|
|
}
|
|
|
|
|
2018-04-25 17:50:55 +02:00
|
|
|
/**
|
2020-10-20 22:09:06 +02:00
|
|
|
* @deprecated Use [[Session.createConnection]] instead to get a [[Connection]] object.
|
2020-10-08 19:31:47 +02:00
|
|
|
*
|
|
|
|
* @returns A Promise that is resolved to the generated _token_ string if success and rejected with an Error object if not
|
2018-04-24 15:42:23 +02:00
|
|
|
*/
|
2018-04-25 17:50:55 +02:00
|
|
|
public generateToken(tokenOptions?: TokenOptions): Promise<string> {
|
2018-04-18 10:56:28 +02:00
|
|
|
return new Promise<string>((resolve, reject) => {
|
2018-06-04 14:14:17 +02:00
|
|
|
const data = JSON.stringify({
|
2018-04-25 17:50:55 +02:00
|
|
|
session: this.sessionId,
|
2020-10-05 13:59:22 +02:00
|
|
|
role: (!!tokenOptions && !!tokenOptions.role) ? tokenOptions.role : null,
|
|
|
|
data: (!!tokenOptions && !!tokenOptions.data) ? tokenOptions.data : null,
|
|
|
|
kurentoOptions: (!!tokenOptions && !!tokenOptions.kurentoOptions) ? tokenOptions.kurentoOptions : null
|
2017-06-10 01:44:31 +02:00
|
|
|
});
|
2018-06-04 14:14:17 +02:00
|
|
|
axios.post(
|
2020-06-11 13:15:30 +02:00
|
|
|
this.ov.host + OpenVidu.API_TOKENS,
|
2018-06-04 14:14:17 +02:00
|
|
|
data,
|
|
|
|
{
|
|
|
|
headers: {
|
2019-05-22 17:01:30 +02:00
|
|
|
'Authorization': this.ov.basicAuth,
|
2018-06-04 14:14:17 +02:00
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
2018-03-14 18:48:29 +01:00
|
|
|
}
|
2018-06-04 14:14:17 +02:00
|
|
|
)
|
|
|
|
.then(res => {
|
|
|
|
if (res.status === 200) {
|
2018-04-25 17:50:55 +02:00
|
|
|
// SUCCESS response from openvidu-server. Resolve token
|
2020-10-20 22:09:06 +02:00
|
|
|
resolve(res.data.token);
|
|
|
|
} else {
|
|
|
|
// ERROR response from openvidu-server. Resolve HTTP status
|
|
|
|
reject(new Error(res.status.toString()));
|
|
|
|
}
|
|
|
|
}).catch(error => {
|
|
|
|
this.handleError(error, reject);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new Connection object associated to Session object and configured with
|
2020-10-21 22:19:01 +02:00
|
|
|
* `connectionProperties`. Each user connecting to the Session requires a Connection.
|
2020-10-20 22:09:06 +02:00
|
|
|
* The token string value to send to the client side is available at [[Connection.token]].
|
|
|
|
*
|
|
|
|
* @returns A Promise that is resolved to the generated [[Connection]] object if success and rejected with an Error object if not
|
|
|
|
*/
|
2020-10-21 22:19:01 +02:00
|
|
|
public createConnection(connectionProperties?: ConnectionProperties): Promise<Connection> {
|
2020-10-20 22:09:06 +02:00
|
|
|
return new Promise<Connection>((resolve, reject) => {
|
|
|
|
const data = JSON.stringify({
|
2021-01-25 10:51:19 +01:00
|
|
|
type: (!!connectionProperties && !!connectionProperties.type) ? connectionProperties.type : null,
|
2020-10-21 22:19:01 +02:00
|
|
|
data: (!!connectionProperties && !!connectionProperties.data) ? connectionProperties.data : null,
|
|
|
|
record: !!connectionProperties ? connectionProperties.record : null,
|
2021-01-25 10:51:19 +01:00
|
|
|
role: (!!connectionProperties && !!connectionProperties.role) ? connectionProperties.role : null,
|
|
|
|
kurentoOptions: (!!connectionProperties && !!connectionProperties.kurentoOptions) ? connectionProperties.kurentoOptions : null,
|
|
|
|
rtspUri: (!!connectionProperties && !!connectionProperties.rtspUri) ? connectionProperties.rtspUri : null,
|
|
|
|
adaptativeBitrate: !!connectionProperties ? connectionProperties.adaptativeBitrate : null,
|
|
|
|
onlyPlayWithSubscribers: !!connectionProperties ? connectionProperties.onlyPlayWithSubscribers : null,
|
2022-02-11 20:03:26 +01:00
|
|
|
networkCache: (!!connectionProperties && (connectionProperties.networkCache != null)) ? connectionProperties.networkCache : null,
|
|
|
|
customIceServers: (!!connectionProperties && (!!connectionProperties.customIceServers != null)) ? connectionProperties.customIceServers : null
|
2020-10-20 22:09:06 +02:00
|
|
|
});
|
|
|
|
axios.post(
|
|
|
|
this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection',
|
|
|
|
data,
|
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
'Authorization': this.ov.basicAuth,
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.then(res => {
|
|
|
|
if (res.status === 200) {
|
|
|
|
// SUCCESS response from openvidu-server. Store and resolve Connection
|
|
|
|
const connection = new Connection(res.data);
|
|
|
|
this.connections.push(connection);
|
|
|
|
if (connection.status === 'active') {
|
|
|
|
this.activeConnections.push(connection);
|
|
|
|
}
|
|
|
|
resolve(new Connection(res.data));
|
2018-04-18 10:56:28 +02:00
|
|
|
} else {
|
|
|
|
// ERROR response from openvidu-server. Resolve HTTP status
|
2018-06-04 14:14:17 +02:00
|
|
|
reject(new Error(res.status.toString()));
|
|
|
|
}
|
|
|
|
}).catch(error => {
|
2020-10-08 19:31:47 +02:00
|
|
|
this.handleError(error, reject);
|
2018-07-13 12:56:27 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gracefully closes the Session: unpublishes all streams and evicts every participant
|
|
|
|
*
|
2018-07-22 22:13:45 +02:00
|
|
|
* @returns A Promise that is resolved if the session has been closed successfully and rejected with an Error object if not
|
2018-07-13 12:56:27 +02:00
|
|
|
*/
|
2021-04-05 17:06:12 +02:00
|
|
|
public close(): Promise<void> {
|
|
|
|
return new Promise<void>((resolve, reject) => {
|
2018-07-22 22:13:45 +02:00
|
|
|
axios.delete(
|
2020-06-11 13:15:30 +02:00
|
|
|
this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId,
|
2018-07-22 22:13:45 +02:00
|
|
|
{
|
|
|
|
headers: {
|
2019-05-22 17:01:30 +02:00
|
|
|
'Authorization': this.ov.basicAuth,
|
2018-07-22 22:13:45 +02:00
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.then(res => {
|
|
|
|
if (res.status === 204) {
|
|
|
|
// SUCCESS response from openvidu-server
|
2019-05-22 17:01:30 +02:00
|
|
|
const indexToRemove: number = this.ov.activeSessions.findIndex(s => s.sessionId === this.sessionId);
|
|
|
|
this.ov.activeSessions.splice(indexToRemove, 1);
|
2018-07-22 22:13:45 +02:00
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
// ERROR response from openvidu-server. Resolve HTTP status
|
|
|
|
reject(new Error(res.status.toString()));
|
|
|
|
}
|
|
|
|
}).catch(error => {
|
2020-10-08 19:31:47 +02:00
|
|
|
this.handleError(error, reject);
|
2018-07-22 22:13:45 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-15 13:16:29 +02:00
|
|
|
* Updates every property of the Session with the current status it has in OpenVidu Server. This is especially useful for accessing the list of
|
|
|
|
* Connections of the Session ([[Session.connections]], [[Session.activeConnections]]) and use those values to call [[Session.forceDisconnect]],
|
|
|
|
* [[Session.forceUnpublish]] or [[Session.updateConnection]].
|
2018-09-28 10:29:14 +02:00
|
|
|
*
|
2020-10-08 19:31:47 +02:00
|
|
|
* To update all Session objects owned by OpenVidu object at once, call [[OpenVidu.fetch]]
|
2018-07-22 22:13:45 +02:00
|
|
|
*
|
|
|
|
* @returns A promise resolved to true if the Session status has changed with respect to the server, or to false if not.
|
|
|
|
* This applies to any property or sub-property of the Session object
|
|
|
|
*/
|
|
|
|
public fetch(): Promise<boolean> {
|
|
|
|
return new Promise<boolean>((resolve, reject) => {
|
2019-05-31 14:38:20 +02:00
|
|
|
const beforeJSON: string = JSON.stringify(this, this.removeCircularOpenViduReference);
|
2018-07-22 22:13:45 +02:00
|
|
|
axios.get(
|
2020-10-15 13:16:29 +02:00
|
|
|
this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '?pendingConnections=true',
|
2018-07-22 22:13:45 +02:00
|
|
|
{
|
|
|
|
headers: {
|
2019-05-22 17:01:30 +02:00
|
|
|
'Authorization': this.ov.basicAuth,
|
2018-07-22 22:13:45 +02:00
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.then(res => {
|
|
|
|
if (res.status === 200) {
|
|
|
|
// SUCCESS response from openvidu-server
|
2020-10-16 13:45:15 +02:00
|
|
|
this.resetWithJson(res.data);
|
2019-05-31 14:38:20 +02:00
|
|
|
const afterJSON: string = JSON.stringify(this, this.removeCircularOpenViduReference);
|
2018-07-22 22:13:45 +02:00
|
|
|
const hasChanged: boolean = !(beforeJSON === afterJSON);
|
|
|
|
console.log("Session info fetched for session '" + this.sessionId + "'. Any change: " + hasChanged);
|
|
|
|
resolve(hasChanged);
|
|
|
|
} else {
|
|
|
|
// ERROR response from openvidu-server. Resolve HTTP status
|
|
|
|
reject(new Error(res.status.toString()));
|
|
|
|
}
|
|
|
|
}).catch(error => {
|
2020-10-08 19:31:47 +02:00
|
|
|
this.handleError(error, reject);
|
2018-07-22 22:13:45 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-20 22:09:06 +02:00
|
|
|
* Removes the Connection from the Session. This can translate into a forced eviction of a user from the Session if the
|
|
|
|
* Connection had status `active` or into a token invalidation if no user had taken the Connection yet (status `pending`).
|
|
|
|
*
|
|
|
|
* In the first case, OpenVidu Browser will trigger the proper events in the client-side (`streamDestroyed`, `connectionDestroyed`,
|
|
|
|
* `sessionDisconnected`) with reason set to `"forceDisconnectByServer"`.
|
|
|
|
*
|
|
|
|
* In the second case, the token of the Connection will be invalidated and no user will be able to connect to the session with it.
|
2020-10-08 19:31:47 +02:00
|
|
|
*
|
|
|
|
* This method automatically updates the properties of the local affected objects. This means that there is no need to call
|
2020-10-20 22:09:06 +02:00
|
|
|
* [[Session.fetch]] or [[OpenVidu.fetch]]] to see the changes consequence of the execution of this method applied in the local objects.
|
2018-07-22 22:13:45 +02:00
|
|
|
*
|
2020-10-20 22:09:06 +02:00
|
|
|
* @param connection The Connection object to remove from the session, or its `connectionId` property
|
2020-10-08 19:31:47 +02:00
|
|
|
*
|
2020-10-15 13:16:29 +02:00
|
|
|
* @returns A Promise that is resolved if the Connection was successfully removed from the Session and rejected with an Error object if not
|
2018-07-22 22:13:45 +02:00
|
|
|
*/
|
2021-04-05 17:06:12 +02:00
|
|
|
public forceDisconnect(connection: string | Connection): Promise<void> {
|
|
|
|
return new Promise<void>((resolve, reject) => {
|
2018-07-22 22:13:45 +02:00
|
|
|
const connectionId: string = typeof connection === 'string' ? connection : (<Connection>connection).connectionId;
|
|
|
|
axios.delete(
|
2020-06-11 13:15:30 +02:00
|
|
|
this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection/' + connectionId,
|
2018-07-22 22:13:45 +02:00
|
|
|
{
|
|
|
|
headers: {
|
2019-05-22 17:01:30 +02:00
|
|
|
'Authorization': this.ov.basicAuth,
|
2018-07-22 22:13:45 +02:00
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(res => {
|
|
|
|
if (res.status === 204) {
|
|
|
|
// SUCCESS response from openvidu-server
|
2020-10-15 13:16:29 +02:00
|
|
|
// Remove connection from connections array
|
2018-07-22 22:13:45 +02:00
|
|
|
let connectionClosed;
|
2020-10-15 13:16:29 +02:00
|
|
|
this.connections = this.connections.filter(con => {
|
2018-07-22 22:13:45 +02:00
|
|
|
if (con.connectionId !== connectionId) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
connectionClosed = con;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Remove every Publisher of the closed connection from every subscriber list of other connections
|
|
|
|
if (!!connectionClosed) {
|
|
|
|
connectionClosed.publishers.forEach(publisher => {
|
2020-10-15 13:16:29 +02:00
|
|
|
this.connections.forEach(con => {
|
2018-09-24 11:04:54 +02:00
|
|
|
con.subscribers = con.subscribers.filter(subscriber => {
|
|
|
|
// tslint:disable:no-string-literal
|
|
|
|
if (!!subscriber['streamId']) {
|
|
|
|
// Subscriber with advanced webRtc configuration properties
|
|
|
|
return (subscriber['streamId'] !== publisher.streamId);
|
|
|
|
// tslint:enable:no-string-literal
|
|
|
|
} else {
|
|
|
|
// Regular string subscribers
|
|
|
|
return subscriber !== publisher.streamId;
|
|
|
|
}
|
|
|
|
});
|
2018-07-22 22:13:45 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
2020-10-15 13:16:29 +02:00
|
|
|
console.warn("The closed connection wasn't fetched in OpenVidu Node Client. No changes in the collection of active connections of the Session");
|
2018-07-22 22:13:45 +02:00
|
|
|
}
|
2020-10-15 13:16:29 +02:00
|
|
|
this.updateActiveConnectionsArray();
|
2018-07-22 22:13:45 +02:00
|
|
|
console.log("Connection '" + connectionId + "' closed");
|
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
// ERROR response from openvidu-server. Resolve HTTP status
|
|
|
|
reject(new Error(res.status.toString()));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
2020-10-08 19:31:47 +02:00
|
|
|
this.handleError(error, reject);
|
2018-07-22 22:13:45 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-20 22:09:06 +02:00
|
|
|
* Forces some Connection to unpublish a Stream (identified by its `streamId` or the corresponding [[Publisher]] object owning it).
|
2018-07-22 22:13:45 +02:00
|
|
|
* OpenVidu Browser will trigger the proper events on the client-side (`streamDestroyed`) with reason set to `"forceUnpublishByServer"`.
|
|
|
|
*
|
|
|
|
* You can get `publisher` parameter from [[Connection.publishers]] array ([[Publisher.streamId]] for getting each `streamId` property).
|
2020-10-15 13:16:29 +02:00
|
|
|
* Remember to call [[Session.fetch]] or [[OpenVidu.fetch]] before to fetch the current actual properties of the Session from OpenVidu Server
|
2018-07-22 22:13:45 +02:00
|
|
|
*
|
2020-10-08 19:31:47 +02:00
|
|
|
* This method automatically updates the properties of the local affected objects. This means that there is no need to call
|
2020-10-15 13:16:29 +02:00
|
|
|
* [[Session.fetch]] or [[OpenVidu.fetch]] to see the changes consequence of the execution of this method applied in the local objects.
|
2020-10-08 19:31:47 +02:00
|
|
|
*
|
2020-10-20 22:09:06 +02:00
|
|
|
* @param publisher The Publisher object to unpublish, or its `streamId` property
|
|
|
|
*
|
2018-07-22 22:13:45 +02:00
|
|
|
* @returns A Promise that is resolved if the stream was successfully unpublished and rejected with an Error object if not
|
|
|
|
*/
|
2021-04-05 17:06:12 +02:00
|
|
|
public forceUnpublish(publisher: string | Publisher): Promise<void> {
|
|
|
|
return new Promise<void>((resolve, reject) => {
|
2018-07-22 22:13:45 +02:00
|
|
|
const streamId: string = typeof publisher === 'string' ? publisher : (<Publisher>publisher).streamId;
|
2018-07-13 12:56:27 +02:00
|
|
|
axios.delete(
|
2020-06-11 13:15:30 +02:00
|
|
|
this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/stream/' + streamId,
|
2018-07-13 12:56:27 +02:00
|
|
|
{
|
|
|
|
headers: {
|
2019-05-22 17:01:30 +02:00
|
|
|
'Authorization': this.ov.basicAuth,
|
2018-07-13 12:56:27 +02:00
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.then(res => {
|
|
|
|
if (res.status === 204) {
|
|
|
|
// SUCCESS response from openvidu-server
|
2020-10-15 13:16:29 +02:00
|
|
|
this.connections.forEach(connection => {
|
2018-07-22 22:13:45 +02:00
|
|
|
// Try to remove the Publisher from the Connection publishers collection
|
|
|
|
connection.publishers = connection.publishers.filter(pub => pub.streamId !== streamId);
|
|
|
|
// Try to remove the Publisher from the Connection subscribers collection
|
2018-09-24 11:04:54 +02:00
|
|
|
if (!!connection.subscribers && connection.subscribers.length > 0) {
|
|
|
|
// tslint:disable:no-string-literal
|
|
|
|
if (!!connection.subscribers[0]['streamId']) {
|
|
|
|
// Subscriber with advanced webRtc configuration properties
|
|
|
|
connection.subscribers = connection.subscribers.filter(sub => sub['streamId'] !== streamId);
|
|
|
|
// tslint:enable:no-string-literal
|
|
|
|
} else {
|
|
|
|
// Regular string subscribers
|
|
|
|
connection.subscribers = connection.subscribers.filter(sub => sub !== streamId);
|
|
|
|
}
|
|
|
|
}
|
2018-07-22 22:13:45 +02:00
|
|
|
});
|
2020-10-15 13:16:29 +02:00
|
|
|
this.updateActiveConnectionsArray();
|
2018-07-22 22:13:45 +02:00
|
|
|
console.log("Stream '" + streamId + "' unpublished");
|
2018-07-13 12:56:27 +02:00
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
// ERROR response from openvidu-server. Resolve HTTP status
|
|
|
|
reject(new Error(res.status.toString()));
|
|
|
|
}
|
|
|
|
}).catch(error => {
|
2020-10-08 19:31:47 +02:00
|
|
|
this.handleError(error, reject);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-22 20:42:54 +02:00
|
|
|
* **This feature is part of OpenVidu Pro tier** <a href="https://docs.openvidu.io/en/stable/openvidu-pro/" target="_blank" style="display: inline-block; background-color: rgb(0, 136, 170); color: white; font-weight: bold; padding: 0px 5px; margin-right: 5px; border-radius: 3px; font-size: 13px; line-height:21px; font-family: Montserrat, sans-serif">PRO</a>
|
|
|
|
*
|
2020-10-21 22:19:01 +02:00
|
|
|
* Updates the properties of a Connection with a [[ConnectionProperties]] object.
|
2020-10-13 12:28:06 +02:00
|
|
|
* Only these properties can be updated:
|
2020-10-08 19:31:47 +02:00
|
|
|
*
|
2020-10-21 22:19:01 +02:00
|
|
|
* - [[ConnectionProperties.role]]
|
|
|
|
* - [[ConnectionProperties.record]]
|
2020-10-08 19:31:47 +02:00
|
|
|
*
|
|
|
|
* This method automatically updates the properties of the local affected objects. This means that there is no need to call
|
2020-10-15 13:16:29 +02:00
|
|
|
* [[Session.fetch]] or [[OpenVidu.fetch]] to see the changes consequence of the execution of this method applied in the local objects.
|
2020-10-08 19:31:47 +02:00
|
|
|
*
|
2022-01-14 13:31:26 +01:00
|
|
|
* The affected client will trigger one [ConnectionPropertyChangedEvent](/en/stable/api/openvidu-browser/classes/ConnectionPropertyChangedEvent.html)
|
2020-10-25 16:42:40 +01:00
|
|
|
* for each modified property.
|
2020-10-23 11:26:58 +02:00
|
|
|
*
|
2020-10-15 13:16:29 +02:00
|
|
|
* @param connectionId The [[Connection.connectionId]] of the Connection object to modify
|
2020-10-21 22:19:01 +02:00
|
|
|
* @param connectionProperties A new [[ConnectionProperties]] object with the updated values to apply
|
2020-10-08 19:31:47 +02:00
|
|
|
*
|
|
|
|
* @returns A Promise that is resolved to the updated [[Connection]] object if the operation was
|
2020-10-13 12:28:06 +02:00
|
|
|
* successful and rejected with an Error object if not
|
2020-10-08 19:31:47 +02:00
|
|
|
*/
|
2020-10-21 22:19:01 +02:00
|
|
|
public updateConnection(connectionId: string, connectionProperties: ConnectionProperties): Promise<Connection | undefined> {
|
2020-10-08 19:31:47 +02:00
|
|
|
return new Promise<any>((resolve, reject) => {
|
|
|
|
axios.patch(
|
|
|
|
this.ov.host + OpenVidu.API_SESSIONS + "/" + this.sessionId + "/connection/" + connectionId,
|
2020-10-21 22:19:01 +02:00
|
|
|
connectionProperties,
|
2020-10-08 19:31:47 +02:00
|
|
|
{
|
|
|
|
headers: {
|
|
|
|
'Authorization': this.ov.basicAuth,
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.then(res => {
|
|
|
|
if (res.status === 200) {
|
|
|
|
console.log('Connection ' + connectionId + ' updated');
|
2018-07-13 12:56:27 +02:00
|
|
|
} else {
|
2020-10-08 19:31:47 +02:00
|
|
|
// ERROR response from openvidu-server. Resolve HTTP status
|
|
|
|
reject(new Error(res.status.toString()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Update the actual Connection object with the new options
|
2020-10-15 13:16:29 +02:00
|
|
|
const existingConnection: Connection = this.connections.find(con => con.connectionId === connectionId);
|
2020-10-08 19:31:47 +02:00
|
|
|
if (!existingConnection) {
|
|
|
|
// The updated Connection is not available in local map
|
|
|
|
const newConnection: Connection = new Connection(res.data);
|
2020-10-15 13:16:29 +02:00
|
|
|
this.connections.push(newConnection);
|
|
|
|
this.updateActiveConnectionsArray();
|
2020-10-08 19:31:47 +02:00
|
|
|
resolve(newConnection);
|
|
|
|
} else {
|
|
|
|
// The updated Connection was available in local map
|
2020-10-21 22:19:01 +02:00
|
|
|
existingConnection.overrideConnectionProperties(connectionProperties);
|
2020-10-15 13:16:29 +02:00
|
|
|
this.updateActiveConnectionsArray();
|
2020-10-08 19:31:47 +02:00
|
|
|
resolve(existingConnection);
|
2018-04-18 10:56:28 +02:00
|
|
|
}
|
2020-10-08 19:31:47 +02:00
|
|
|
}).catch(error => {
|
|
|
|
this.handleError(error, reject);
|
2018-04-18 10:56:28 +02:00
|
|
|
});
|
2017-06-10 01:44:31 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-25 16:42:40 +01:00
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
public getSessionId(): string {
|
|
|
|
return this.sessionId;
|
|
|
|
}
|
|
|
|
|
2018-04-24 15:42:23 +02:00
|
|
|
/**
|
2018-04-25 17:50:55 +02:00
|
|
|
* @hidden
|
2018-04-24 15:42:23 +02:00
|
|
|
*/
|
2020-11-19 17:06:50 +01:00
|
|
|
public getSessionHttp(): Promise<string> {
|
2018-04-18 10:56:28 +02:00
|
|
|
return new Promise<string>((resolve, reject) => {
|
|
|
|
|
2018-04-25 17:50:55 +02:00
|
|
|
if (!!this.sessionId) {
|
|
|
|
resolve(this.sessionId);
|
|
|
|
}
|
|
|
|
|
2021-04-14 15:21:27 +02:00
|
|
|
this.sanitizeDefaultSessionProperties(this.properties);
|
2020-11-19 17:06:50 +01:00
|
|
|
|
2021-04-05 17:06:12 +02:00
|
|
|
const data = JSON.stringify(
|
|
|
|
this.properties
|
|
|
|
);
|
2018-04-18 10:56:28 +02:00
|
|
|
|
2018-06-04 14:14:17 +02:00
|
|
|
axios.post(
|
2020-06-11 13:15:30 +02:00
|
|
|
this.ov.host + OpenVidu.API_SESSIONS,
|
2018-06-04 14:14:17 +02:00
|
|
|
data,
|
|
|
|
{
|
|
|
|
headers: {
|
2019-05-22 17:01:30 +02:00
|
|
|
'Authorization': this.ov.basicAuth,
|
2018-06-04 14:14:17 +02:00
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
2018-03-14 18:48:29 +01:00
|
|
|
}
|
2018-06-04 14:14:17 +02:00
|
|
|
)
|
|
|
|
.then(res => {
|
|
|
|
if (res.status === 200) {
|
|
|
|
// SUCCESS response from openvidu-server. Resolve token
|
|
|
|
this.sessionId = res.data.id;
|
2018-09-06 12:02:07 +02:00
|
|
|
this.createdAt = res.data.createdAt;
|
2021-04-05 17:06:12 +02:00
|
|
|
this.properties.mediaMode = res.data.mediaMode;
|
|
|
|
this.properties.recordingMode = res.data.recordingMode;
|
|
|
|
this.properties.customSessionId = res.data.customSessionId;
|
2021-04-14 15:21:27 +02:00
|
|
|
this.properties.defaultRecordingProperties = res.data.defaultRecordingProperties;
|
2021-04-05 17:06:12 +02:00
|
|
|
this.properties.mediaNode = res.data.mediaNode;
|
2020-11-19 17:06:50 +01:00
|
|
|
this.properties.forcedVideoCodec = res.data.forcedVideoCodec;
|
2021-11-26 15:25:25 +01:00
|
|
|
this.properties.forcedVideoCodecResolved = res.data.forcedVideoCodecResolved;
|
2020-11-19 17:06:50 +01:00
|
|
|
this.properties.allowTranscoding = res.data.allowTranscoding;
|
2021-04-14 15:21:27 +02:00
|
|
|
this.sanitizeDefaultSessionProperties(this.properties);
|
2018-05-08 14:49:42 +02:00
|
|
|
resolve(this.sessionId);
|
2018-04-18 10:56:28 +02:00
|
|
|
} else {
|
|
|
|
// ERROR response from openvidu-server. Resolve HTTP status
|
2018-06-04 14:14:17 +02:00
|
|
|
reject(new Error(res.status.toString()));
|
|
|
|
}
|
|
|
|
}).catch(error => {
|
|
|
|
if (error.response) {
|
|
|
|
// The request was made and the server responded with a status code (not 2xx)
|
|
|
|
if (error.response.status === 409) {
|
|
|
|
// 'customSessionId' already existed
|
|
|
|
this.sessionId = this.properties.customSessionId;
|
|
|
|
resolve(this.sessionId);
|
|
|
|
} else {
|
|
|
|
reject(new Error(error.response.status.toString()));
|
|
|
|
}
|
|
|
|
} else if (error.request) {
|
|
|
|
// The request was made but no response was received
|
|
|
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
|
|
|
// http.ClientRequest in node.js
|
2018-09-03 09:54:21 +02:00
|
|
|
reject(new Error(error.request));
|
2018-06-04 14:14:17 +02:00
|
|
|
} else {
|
|
|
|
// Something happened in setting up the request that triggered an Error
|
2018-09-03 09:54:21 +02:00
|
|
|
reject(new Error(error.message));
|
2018-04-18 10:56:28 +02:00
|
|
|
}
|
|
|
|
});
|
2017-06-10 01:44:31 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-22 22:13:45 +02:00
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
2020-10-16 13:45:15 +02:00
|
|
|
public resetWithJson(json): Session {
|
2018-07-22 22:13:45 +02:00
|
|
|
this.sessionId = json.sessionId;
|
2018-09-19 15:36:26 +02:00
|
|
|
this.createdAt = json.createdAt;
|
2018-07-22 22:13:45 +02:00
|
|
|
this.recording = json.recording;
|
|
|
|
this.properties = {
|
2020-10-16 13:45:15 +02:00
|
|
|
customSessionId: json.customSessionId,
|
2018-07-22 22:13:45 +02:00
|
|
|
mediaMode: json.mediaMode,
|
|
|
|
recordingMode: json.recordingMode,
|
2021-04-05 17:06:12 +02:00
|
|
|
defaultRecordingProperties: json.defaultRecordingProperties,
|
2020-11-19 17:06:50 +01:00
|
|
|
forcedVideoCodec: json.forcedVideoCodec,
|
2021-11-26 15:25:25 +01:00
|
|
|
forcedVideoCodecResolved: json.forcedVideoCodecResolved,
|
2020-11-19 17:06:50 +01:00
|
|
|
allowTranscoding: json.allowTranscoding
|
2018-07-22 22:13:45 +02:00
|
|
|
};
|
2021-04-14 15:21:27 +02:00
|
|
|
this.sanitizeDefaultSessionProperties(this.properties);
|
2021-04-05 17:06:12 +02:00
|
|
|
if (json.defaultRecordingProperties == null) {
|
|
|
|
delete this.properties.defaultRecordingProperties;
|
2020-10-16 13:45:15 +02:00
|
|
|
}
|
|
|
|
if (json.customSessionId == null) {
|
|
|
|
delete this.properties.customSessionId;
|
2018-07-22 22:13:45 +02:00
|
|
|
}
|
2020-11-19 17:06:50 +01:00
|
|
|
if (json.mediaNode == null) {
|
|
|
|
delete this.properties.mediaNode;
|
|
|
|
}
|
|
|
|
if (json.forcedVideoCodec == null) {
|
|
|
|
delete this.properties.forcedVideoCodec;
|
|
|
|
}
|
2021-11-26 15:25:25 +01:00
|
|
|
if (json.forcedVideoCodecResolved == null) {
|
|
|
|
delete this.properties.forcedVideoCodecResolved;
|
|
|
|
}
|
2020-11-19 17:06:50 +01:00
|
|
|
if (json.allowTranscoding == null) {
|
|
|
|
delete this.properties.allowTranscoding;
|
|
|
|
}
|
2018-07-22 22:13:45 +02:00
|
|
|
|
2020-10-16 13:45:15 +02:00
|
|
|
// 1. Array to store fetched connections and later remove closed ones
|
|
|
|
const fetchedConnectionIds: string[] = [];
|
2020-10-15 13:16:29 +02:00
|
|
|
json.connections.content.forEach(jsonConnection => {
|
2020-10-16 13:45:15 +02:00
|
|
|
const connectionObj: Connection = new Connection(jsonConnection);
|
|
|
|
fetchedConnectionIds.push(connectionObj.connectionId);
|
|
|
|
let storedConnection = this.connections.find(c => c.connectionId === connectionObj.connectionId);
|
|
|
|
|
|
|
|
if (!!storedConnection) {
|
|
|
|
// 2. Update existing Connection
|
|
|
|
storedConnection.resetWithJson(jsonConnection);
|
|
|
|
} else {
|
|
|
|
// 3. Add new Connection
|
|
|
|
this.connections.push(connectionObj);
|
|
|
|
}
|
2020-10-15 13:16:29 +02:00
|
|
|
});
|
2020-10-08 19:31:47 +02:00
|
|
|
|
2020-10-16 13:45:15 +02:00
|
|
|
// 4. Remove closed sessions from local collection
|
|
|
|
for (var i = this.connections.length - 1; i >= 0; --i) {
|
|
|
|
if (!fetchedConnectionIds.includes(this.connections[i].connectionId)) {
|
|
|
|
this.connections.splice(i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-20 12:24:07 +02:00
|
|
|
// Order connections by time of creation
|
2020-10-15 13:16:29 +02:00
|
|
|
this.connections.sort((c1, c2) => (c1.createdAt > c2.createdAt) ? 1 : ((c2.createdAt > c1.createdAt) ? -1 : 0));
|
2022-02-16 17:36:41 +01:00
|
|
|
|
|
|
|
// Order Ice candidates in connection properties
|
|
|
|
this.connections.forEach(connection => {
|
|
|
|
if (connection.connectionProperties.customIceServers != null &&
|
|
|
|
connection.connectionProperties.customIceServers.length > 0) {
|
|
|
|
// Order alphabetically Ice servers using url just to keep the same list order.
|
|
|
|
const simpleIceComparator = (a: IceServerProperties, b: IceServerProperties) => (a.url > b.url) ? 1 : -1
|
|
|
|
connection.connectionProperties.customIceServers.sort(simpleIceComparator);
|
|
|
|
}
|
|
|
|
});
|
2020-10-15 13:16:29 +02:00
|
|
|
// Populate activeConnections array
|
|
|
|
this.updateActiveConnectionsArray();
|
2018-07-22 22:13:45 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-09-19 15:36:26 +02:00
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
equalTo(other: Session): boolean {
|
|
|
|
let equals: boolean = (
|
|
|
|
this.sessionId === other.sessionId &&
|
|
|
|
this.createdAt === other.createdAt &&
|
|
|
|
this.recording === other.recording &&
|
2020-10-15 13:16:29 +02:00
|
|
|
this.connections.length === other.connections.length &&
|
2018-09-19 15:36:26 +02:00
|
|
|
JSON.stringify(this.properties) === JSON.stringify(other.properties)
|
|
|
|
);
|
|
|
|
if (equals) {
|
|
|
|
let i = 0;
|
2020-10-15 13:16:29 +02:00
|
|
|
while (equals && i < this.connections.length) {
|
|
|
|
equals = this.connections[i].equalTo(other.connections[i]);
|
2018-09-19 15:36:26 +02:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return equals;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 14:38:20 +02:00
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
private removeCircularOpenViduReference(key: string, value: any) {
|
|
|
|
if (key === 'ov' && value instanceof OpenVidu) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-15 13:16:29 +02:00
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
private updateActiveConnectionsArray() {
|
|
|
|
this.activeConnections = [];
|
|
|
|
this.connections.forEach(con => {
|
|
|
|
if (con.status === 'active') {
|
|
|
|
this.activeConnections.push(con);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-08 19:31:47 +02:00
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
private handleError(error: AxiosError, reject: (reason?: any) => void) {
|
|
|
|
if (error.response) {
|
|
|
|
// The request was made and the server responded with a status code (not 2xx)
|
|
|
|
reject(new Error(error.response.status.toString()));
|
|
|
|
} else if (error.request) {
|
|
|
|
// The request was made but no response was received
|
|
|
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
|
|
|
// http.ClientRequest in node.js
|
|
|
|
reject(new Error(error.request));
|
|
|
|
} else {
|
|
|
|
// Something happened in setting up the request that triggered an Error
|
|
|
|
reject(new Error(error.message));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-05 17:06:12 +02:00
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
2021-04-14 15:21:27 +02:00
|
|
|
private sanitizeDefaultSessionProperties(props: SessionProperties) {
|
|
|
|
|
|
|
|
props.mediaMode = (props.mediaMode != null) ? props.mediaMode : MediaMode.ROUTED;
|
|
|
|
props.recordingMode = (props.recordingMode != null) ? props.recordingMode : RecordingMode.MANUAL;
|
|
|
|
props.customSessionId = (props.customSessionId != null) ? props.customSessionId : '';
|
2021-11-26 15:25:25 +01:00
|
|
|
|
|
|
|
// Remove null values: either set, or undefined
|
|
|
|
props.mediaNode = props.mediaNode ?? undefined;
|
|
|
|
props.forcedVideoCodec = props.forcedVideoCodec ?? undefined;
|
|
|
|
props.forcedVideoCodecResolved = props.forcedVideoCodecResolved ?? undefined;
|
|
|
|
props.allowTranscoding = props.allowTranscoding ?? undefined;
|
2021-04-12 13:44:12 +02:00
|
|
|
|
2021-04-14 15:21:27 +02:00
|
|
|
if (!props.defaultRecordingProperties) {
|
|
|
|
props.defaultRecordingProperties = {};
|
|
|
|
}
|
|
|
|
props.defaultRecordingProperties.name = (props.defaultRecordingProperties?.name != null) ? props.defaultRecordingProperties.name : '';
|
2021-05-11 13:00:08 +02:00
|
|
|
props.defaultRecordingProperties.hasAudio = (props.defaultRecordingProperties?.hasAudio != null) ? props.defaultRecordingProperties.hasAudio : Recording.DefaultRecordingPropertiesValues.hasAudio;
|
|
|
|
props.defaultRecordingProperties.hasVideo = (props.defaultRecordingProperties?.hasVideo != null) ? props.defaultRecordingProperties.hasVideo : Recording.DefaultRecordingPropertiesValues.hasVideo;
|
|
|
|
props.defaultRecordingProperties.outputMode = (props.defaultRecordingProperties?.outputMode != null) ? props.defaultRecordingProperties.outputMode : Recording.DefaultRecordingPropertiesValues.outputMode;
|
2021-04-14 15:21:27 +02:00
|
|
|
props.defaultRecordingProperties.mediaNode = props.defaultRecordingProperties?.mediaNode;
|
|
|
|
if ((props.defaultRecordingProperties.outputMode === Recording.OutputMode.COMPOSED || props.defaultRecordingProperties.outputMode == Recording.OutputMode.COMPOSED_QUICK_START) && props.defaultRecordingProperties.hasVideo) {
|
2021-05-11 13:00:08 +02:00
|
|
|
props.defaultRecordingProperties.recordingLayout = (props.defaultRecordingProperties.recordingLayout != null) ? props.defaultRecordingProperties.recordingLayout : Recording.DefaultRecordingPropertiesValues.recordingLayout;
|
|
|
|
props.defaultRecordingProperties.resolution = (props.defaultRecordingProperties.resolution != null) ? props.defaultRecordingProperties.resolution : Recording.DefaultRecordingPropertiesValues.resolution;
|
|
|
|
props.defaultRecordingProperties.frameRate = (props.defaultRecordingProperties.frameRate != null) ? props.defaultRecordingProperties.frameRate : Recording.DefaultRecordingPropertiesValues.frameRate;
|
|
|
|
props.defaultRecordingProperties.shmSize = (props.defaultRecordingProperties.shmSize != null) ? props.defaultRecordingProperties.shmSize : Recording.DefaultRecordingPropertiesValues.shmSize;
|
2021-04-14 15:21:27 +02:00
|
|
|
if (props.defaultRecordingProperties.recordingLayout === RecordingLayout.CUSTOM) {
|
|
|
|
props.defaultRecordingProperties.customLayout = (props.defaultRecordingProperties.customLayout != null) ? props.defaultRecordingProperties.customLayout : '';
|
|
|
|
}
|
2021-04-12 13:44:12 +02:00
|
|
|
}
|
2021-05-11 13:00:08 +02:00
|
|
|
if (props.defaultRecordingProperties.outputMode === Recording.OutputMode.INDIVIDUAL) {
|
|
|
|
props.defaultRecordingProperties.ignoreFailedStreams = (props.defaultRecordingProperties?.ignoreFailedStreams != null) ? props.defaultRecordingProperties.ignoreFailedStreams : Recording.DefaultRecordingPropertiesValues.ignoreFailedStreams;
|
|
|
|
}
|
2021-04-12 13:44:12 +02:00
|
|
|
|
2021-04-14 15:21:27 +02:00
|
|
|
this.formatMediaNodeObjectIfNecessary(props.defaultRecordingProperties);
|
|
|
|
this.formatMediaNodeObjectIfNecessary(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
private formatMediaNodeObjectIfNecessary(properties: RecordingProperties | SessionProperties) {
|
|
|
|
if (properties.mediaNode != null) {
|
|
|
|
if (typeof properties.mediaNode === 'string') {
|
|
|
|
properties.mediaNode = { id: properties.mediaNode };
|
2021-04-09 17:32:33 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-05 17:06:12 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 19:58:56 +02:00
|
|
|
}
|