openvidu-node-client: Added .prettierrc file and formated the code

pull/780/head
csantosm 2023-02-22 23:23:43 +01:00
parent e10198f501
commit 027e85052a
18 changed files with 897 additions and 900 deletions

View File

@ -0,0 +1,10 @@
{
"singleQuote": true,
"printWidth": 140,
"trailingComma": "none",
"semi": true,
"bracketSpacing": true,
"useTabs": false,
"jsxSingleQuote": true,
"tabWidth": 4
}

View File

@ -24,7 +24,6 @@ import { IceServerProperties } from './IceServerProperties';
* See {@link Session.connections}
*/
export class Connection {
/**
* Identifier of the Connection. You can call methods {@link Session.forceDisconnect}
* or {@link Session.updateConnection} passing this property as parameter
@ -119,7 +118,6 @@ export class Connection {
* @hidden
*/
resetWithJson(json): Connection {
this.connectionId = json.connectionId;
this.status = json.status;
this.createdAt = json.createdAt;
@ -139,7 +137,7 @@ export class Connection {
this.connectionProperties.adaptativeBitrate = json.adaptativeBitrate;
this.connectionProperties.onlyPlayWithSubscribers = json.onlyPlayWithSubscribers;
this.connectionProperties.networkCache = json.networkCache;
this.connectionProperties.customIceServers = json.customIceServers ?? []
this.connectionProperties.customIceServers = json.customIceServers ?? [];
} else {
this.connectionProperties = {
type: json.type,
@ -152,21 +150,19 @@ export class Connection {
onlyPlayWithSubscribers: json.onlyPlayWithSubscribers,
networkCache: json.networkCache,
customIceServers: json.customIceServers ?? []
}
};
}
this.role = json.role;
this.serverData = json.serverData;
// publishers may be null
if (json.publishers != null) {
// 1. Array to store fetched Publishers and later remove closed ones
const fetchedPublisherIds: string[] = [];
json.publishers.forEach(jsonPublisher => {
json.publishers.forEach((jsonPublisher) => {
const publisherObj: Publisher = new Publisher(jsonPublisher);
fetchedPublisherIds.push(publisherObj.streamId);
let storedPublisher = this.publishers.find(c => c.streamId === publisherObj.streamId);
let storedPublisher = this.publishers.find((c) => c.streamId === publisherObj.streamId);
if (!!storedPublisher) {
// 2. Update existing Publisher
@ -183,16 +179,14 @@ export class Connection {
this.publishers.splice(i, 1);
}
}
}
// subscribers may be null
if (json.subscribers != null) {
// 1. Array to store fetched Subscribers and later remove closed ones
const fetchedSubscriberIds: string[] = [];
json.subscribers.forEach(jsonSubscriber => {
fetchedSubscriberIds.push(jsonSubscriber.streamId)
json.subscribers.forEach((jsonSubscriber) => {
fetchedSubscriberIds.push(jsonSubscriber.streamId);
if (this.subscribers.indexOf(jsonSubscriber.streamId) === -1) {
// 2. Add new Subscriber
this.subscribers.push(jsonSubscriber.streamId);
@ -214,7 +208,7 @@ export class Connection {
* @hidden
*/
equalTo(other: Connection): boolean {
let equals: boolean = (
let equals: boolean =
this.connectionId === other.connectionId &&
this.status === other.status &&
this.createdAt === other.createdAt &&
@ -234,18 +228,19 @@ export class Connection {
this.platform === other.platform &&
this.clientData === other.clientData &&
this.subscribers.length === other.subscribers.length &&
this.publishers.length === other.publishers.length);
this.publishers.length === other.publishers.length;
if (equals) {
if (this.connectionProperties.kurentoOptions != null) {
equals = JSON.stringify(this.connectionProperties.kurentoOptions) === JSON.stringify(other.connectionProperties.kurentoOptions);
equals =
JSON.stringify(this.connectionProperties.kurentoOptions) === JSON.stringify(other.connectionProperties.kurentoOptions);
} else {
equals = (this.connectionProperties.kurentoOptions === other.connectionProperties.kurentoOptions);
equals = this.connectionProperties.kurentoOptions === other.connectionProperties.kurentoOptions;
}
}
if (equals) {
if (this.connectionProperties.customIceServers != null) {
// 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
const simpleIceComparator = (a: IceServerProperties, b: IceServerProperties) => (a.url > b.url ? 1 : -1);
const sortedIceServers = this.connectionProperties.customIceServers.sort(simpleIceComparator);
const sortedOtherIceServers = other.connectionProperties.customIceServers.sort(simpleIceComparator);
equals = JSON.stringify(sortedIceServers) === JSON.stringify(sortedOtherIceServers);
@ -280,5 +275,4 @@ export class Connection {
this.connectionProperties.role = newConnectionProperties.role;
}
}
}

View File

@ -20,7 +20,6 @@ import { ConnectionType } from './ConnectionType';
import { OpenViduRole } from './OpenViduRole';
export interface ConnectionProperties {
/**
* Type of Connection. The {@link ConnectionType} dictates what properties will have effect:
*
@ -85,11 +84,11 @@ export interface ConnectionProperties {
* **Only for {@link ConnectionType.WEBRTC}**
*/
kurentoOptions?: {
videoMaxRecvBandwidth?: number,
videoMinRecvBandwidth?: number,
videoMaxSendBandwidth?: number,
videoMinSendBandwidth?: number,
allowedFilters?: string[]
videoMaxRecvBandwidth?: number;
videoMinRecvBandwidth?: number;
videoMaxSendBandwidth?: number;
videoMinSendBandwidth?: number;
allowedFilters?: string[];
};
/**

View File

@ -19,7 +19,6 @@
* See {@link Session.createConnection}
*/
export enum ConnectionType {
/**
* WebRTC connection. This is the normal type of Connection for a regular user
* connecting to a session from an application.
@ -31,4 +30,4 @@ export enum ConnectionType {
* connect to a session.
*/
IPCAM = 'IPCAM'
}
}

View File

@ -16,7 +16,6 @@
*/
export interface IceServerProperties {
/**
* Set the url for the ICE Server you want to use.
* It should follow a valid format:
@ -46,5 +45,4 @@ export interface IceServerProperties {
* This parameter should be defined only for TURN, not for STUN ICE Servers.
*/
credential?: string;
}
}

View File

@ -19,7 +19,6 @@
* See {@link SessionProperties.mediaMode}
*/
export enum MediaMode {
/**
* _(not available yet)_ The session will attempt to transmit streams directly between clients
*/

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,6 @@
* See {@link TokenOptions.role}
*/
export enum OpenViduRole {
/**
* Can subscribe to published Streams of other users
*/
@ -35,4 +34,4 @@ export enum OpenViduRole {
* (call `Session.forceUnpublish()` and `Session.forceDisconnect()`)
*/
MODERATOR = 'MODERATOR'
}
}

View File

@ -15,14 +15,12 @@
*
*/
/**
* See {@link Connection.publishers}
*
* This is a backend representation of a published media stream (see [OpenVidu Browser Stream class](/en/stable/api/openvidu-browser/classes/Stream.html))
*/
export class Publisher {
/**
* Unique identifier of the [Stream](/en/stable/api/openvidu-browser/classes/Stream.html) associated to this Publisher.
* Each Publisher is paired with only one Stream, so you can identify each Publisher by its
@ -109,5 +107,4 @@ export class Publisher {
this.videoDimensions === other.videoDimensions
);
}
}
}

View File

@ -22,7 +22,6 @@ import { RecordingLayout } from './RecordingLayout';
* See {@link OpenVidu.startRecording}
*/
export class Recording {
/**
* Recording unique identifier
*/
@ -63,7 +62,6 @@ export class Recording {
*/
properties: RecordingProperties;
/* tslint:disable:no-string-literal */
/**
* @hidden
@ -77,37 +75,44 @@ export class Recording {
this.url = json['url'];
this.status = json['status'];
this.properties = {
name: (json['name'] != null) ? json['name'] : this.id,
hasAudio: (json['hasAudio'] != null) ? !!json['hasAudio'] : Recording.DefaultRecordingPropertiesValues.hasAudio,
hasVideo: (json['hasVideo'] != null) ? !!json['hasVideo'] : Recording.DefaultRecordingPropertiesValues.hasVideo,
outputMode: (json['outputMode'] != null) ? json['outputMode'] : Recording.DefaultRecordingPropertiesValues.outputMode,
name: json['name'] != null ? json['name'] : this.id,
hasAudio: json['hasAudio'] != null ? !!json['hasAudio'] : Recording.DefaultRecordingPropertiesValues.hasAudio,
hasVideo: json['hasVideo'] != null ? !!json['hasVideo'] : Recording.DefaultRecordingPropertiesValues.hasVideo,
outputMode: json['outputMode'] != null ? json['outputMode'] : Recording.DefaultRecordingPropertiesValues.outputMode,
mediaNode: json['mediaNode']
};
if ((this.properties.outputMode.toString() === Recording.OutputMode[Recording.OutputMode.COMPOSED]
|| this.properties.outputMode.toString() === Recording.OutputMode[Recording.OutputMode.COMPOSED_QUICK_START])
&& this.properties.hasVideo) {
this.properties.recordingLayout = (json['recordingLayout'] != null) ? json['recordingLayout'] : Recording.DefaultRecordingPropertiesValues.recordingLayout;
this.properties.resolution = (json['resolution'] != null) ? json['resolution'] : Recording.DefaultRecordingPropertiesValues.resolution;
this.properties.frameRate = (json['frameRate'] != null) ? Number(json['frameRate']) : Recording.DefaultRecordingPropertiesValues.frameRate;
this.properties.shmSize = (json['shmSize'] != null) ? Number(json['shmSize']) : Recording.DefaultRecordingPropertiesValues.shmSize;
if (
(this.properties.outputMode.toString() === Recording.OutputMode[Recording.OutputMode.COMPOSED] ||
this.properties.outputMode.toString() === Recording.OutputMode[Recording.OutputMode.COMPOSED_QUICK_START]) &&
this.properties.hasVideo
) {
this.properties.recordingLayout =
json['recordingLayout'] != null ? json['recordingLayout'] : Recording.DefaultRecordingPropertiesValues.recordingLayout;
this.properties.resolution =
json['resolution'] != null ? json['resolution'] : Recording.DefaultRecordingPropertiesValues.resolution;
this.properties.frameRate =
json['frameRate'] != null ? Number(json['frameRate']) : Recording.DefaultRecordingPropertiesValues.frameRate;
this.properties.shmSize =
json['shmSize'] != null ? Number(json['shmSize']) : Recording.DefaultRecordingPropertiesValues.shmSize;
if (this.properties.recordingLayout.toString() === RecordingLayout[RecordingLayout.CUSTOM]) {
this.properties.customLayout = (json['customLayout'] != null) ? json['customLayout'] : '';
this.properties.customLayout = json['customLayout'] != null ? json['customLayout'] : '';
}
}
if (this.properties.outputMode.toString() === Recording.OutputMode[Recording.OutputMode.INDIVIDUAL]) {
this.properties.ignoreFailedStreams = (json['ignoreFailedStreams'] != null) ? !!json['ignoreFailedStreams'] : Recording.DefaultRecordingPropertiesValues.ignoreFailedStreams;
this.properties.ignoreFailedStreams =
json['ignoreFailedStreams'] != null
? !!json['ignoreFailedStreams']
: Recording.DefaultRecordingPropertiesValues.ignoreFailedStreams;
}
}
/* tslint:enable:no-string-literal */
}
export namespace Recording {
/**
* See {@link Recording.status}
*/
export enum Status {
/**
* The recording is starting (cannot be stopped). Some recording may not go
* through this status and directly reach "started" status
@ -142,7 +147,6 @@ export namespace Recording {
* See {@link RecordingProperties.outputMode}
*/
export enum OutputMode {
/**
* Record all streams in a grid layout in a single archive
*/
@ -153,7 +157,7 @@ export namespace Recording {
* service module will start some time in advance and won't be terminated
* once a specific session recording has ended. This module will remain
* up and running as long as the session remains active.
*
*
* - **Pros vs COMPOSED**: the process of starting the recording will be noticeably
* faster. This can be very useful in use cases where a session needs to be
* recorded multiple times over time, when a better response time is usually
@ -181,10 +185,9 @@ export namespace Recording {
static readonly hasVideo: boolean = true;
static readonly outputMode: Recording.OutputMode = Recording.OutputMode.COMPOSED;
static readonly recordingLayout: RecordingLayout = RecordingLayout.BEST_FIT;
static readonly resolution: string = "1280x720";
static readonly resolution: string = '1280x720';
static readonly frameRate: number = 25;
static readonly shmSize: number = 536870912;
static readonly ignoreFailedStreams: boolean = false;
}
}
}

View File

@ -19,7 +19,6 @@
* See {@link RecordingProperties.recordingLayout}
*/
export enum RecordingLayout {
/**
* All the videos are evenly distributed, taking up as much space as possible
*/

View File

@ -19,7 +19,6 @@
* See {@link SessionProperties.recordingMode}
*/
export enum RecordingMode {
/**
* The session is recorded automatically as soon as the first client publishes a stream to the session. It is automatically stopped
* after last user leaves the session (or until you call {@link OpenVidu.stopRecording}).

View File

@ -22,7 +22,6 @@ import { RecordingLayout } from './RecordingLayout';
* See {@link OpenVidu.startRecording}
*/
export interface RecordingProperties {
/**
* Name of the Recording. The video file will be named after this property.
* You can access this same value in your clients on recording events
@ -122,6 +121,5 @@ export interface RecordingProperties {
*/
mediaNode?: {
id: string;
}
};
}

View File

@ -30,7 +30,6 @@ import { RecordingProperties } from './RecordingProperties';
import { IceServerProperties } from './IceServerProperties';
export class Session {
/**
* Unique identifier of the Session
*/
@ -110,21 +109,18 @@ export class Session {
return new Promise<string>((resolve, reject) => {
const data = JSON.stringify({
session: this.sessionId,
role: (!!tokenOptions && !!tokenOptions.role) ? tokenOptions.role : null,
data: (!!tokenOptions && !!tokenOptions.data) ? tokenOptions.data : null,
kurentoOptions: (!!tokenOptions && !!tokenOptions.kurentoOptions) ? tokenOptions.kurentoOptions : null
role: !!tokenOptions && !!tokenOptions.role ? tokenOptions.role : null,
data: !!tokenOptions && !!tokenOptions.data ? tokenOptions.data : null,
kurentoOptions: !!tokenOptions && !!tokenOptions.kurentoOptions ? tokenOptions.kurentoOptions : null
});
axios.post(
this.ov.host + OpenVidu.API_TOKENS,
data,
{
axios
.post(this.ov.host + OpenVidu.API_TOKENS, data, {
headers: {
'Authorization': this.ov.basicAuth,
Authorization: this.ov.basicAuth,
'Content-Type': 'application/json'
}
}
)
.then(res => {
})
.then((res) => {
if (res.status === 200) {
// SUCCESS response from openvidu-server. Resolve token
resolve(res.data.token);
@ -132,7 +128,8 @@ export class Session {
// ERROR response from openvidu-server. Resolve HTTP status
reject(new Error(res.status.toString()));
}
}).catch(error => {
})
.catch((error) => {
this.ov.handleError(error, reject);
});
});
@ -149,28 +146,28 @@ export class Session {
public createConnection(connectionProperties?: ConnectionProperties): Promise<Connection> {
return new Promise<Connection>((resolve, reject) => {
const data = JSON.stringify({
type: (!!connectionProperties && !!connectionProperties.type) ? connectionProperties.type : null,
data: (!!connectionProperties && !!connectionProperties.data) ? connectionProperties.data : null,
type: !!connectionProperties && !!connectionProperties.type ? connectionProperties.type : null,
data: !!connectionProperties && !!connectionProperties.data ? connectionProperties.data : null,
record: !!connectionProperties ? connectionProperties.record : null,
role: (!!connectionProperties && !!connectionProperties.role) ? connectionProperties.role : null,
kurentoOptions: (!!connectionProperties && !!connectionProperties.kurentoOptions) ? connectionProperties.kurentoOptions : null,
rtspUri: (!!connectionProperties && !!connectionProperties.rtspUri) ? connectionProperties.rtspUri : null,
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,
networkCache: (!!connectionProperties && (connectionProperties.networkCache != null)) ? connectionProperties.networkCache : null,
customIceServers: (!!connectionProperties && (!!connectionProperties.customIceServers != null)) ? connectionProperties.customIceServers : null
networkCache:
!!connectionProperties && connectionProperties.networkCache != null ? connectionProperties.networkCache : null,
customIceServers:
!!connectionProperties && !!connectionProperties.customIceServers != null ? connectionProperties.customIceServers : null
});
axios.post(
this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection',
data,
{
axios
.post(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection', data, {
headers: {
'Authorization': this.ov.basicAuth,
Authorization: this.ov.basicAuth,
'Content-Type': 'application/json'
}
}
)
.then(res => {
})
.then((res) => {
if (res.status === 200) {
// SUCCESS response from openvidu-server. Store and resolve Connection
const connection = new Connection(res.data);
@ -183,7 +180,8 @@ export class Session {
// ERROR response from openvidu-server. Resolve HTTP status
reject(new Error(res.status.toString()));
}
}).catch(error => {
})
.catch((error) => {
this.ov.handleError(error, reject);
});
});
@ -197,26 +195,25 @@ export class Session {
*/
public close(): Promise<void> {
return new Promise<void>((resolve, reject) => {
axios.delete(
this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId,
{
axios
.delete(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId, {
headers: {
'Authorization': this.ov.basicAuth,
Authorization: this.ov.basicAuth,
'Content-Type': 'application/x-www-form-urlencoded'
}
}
)
.then(res => {
})
.then((res) => {
if (res.status === 204) {
// SUCCESS response from openvidu-server
const indexToRemove: number = this.ov.activeSessions.findIndex(s => s.sessionId === this.sessionId);
const indexToRemove: number = this.ov.activeSessions.findIndex((s) => s.sessionId === this.sessionId);
this.ov.activeSessions.splice(indexToRemove, 1);
resolve();
} else {
// ERROR response from openvidu-server. Resolve HTTP status
reject(new Error(res.status.toString()));
}
}).catch(error => {
})
.catch((error) => {
this.ov.handleError(error, reject);
});
});
@ -235,16 +232,14 @@ export class Session {
public fetch(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
const beforeJSON: string = JSON.stringify(this, this.removeCircularOpenViduReference);
axios.get(
this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '?pendingConnections=true',
{
axios
.get(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '?pendingConnections=true', {
headers: {
'Authorization': this.ov.basicAuth,
Authorization: this.ov.basicAuth,
'Content-Type': 'application/x-www-form-urlencoded'
}
}
)
.then(res => {
})
.then((res) => {
if (res.status === 200) {
// SUCCESS response from openvidu-server
this.resetWithJson(res.data);
@ -256,7 +251,8 @@ export class Session {
// ERROR response from openvidu-server. Resolve HTTP status
reject(new Error(res.status.toString()));
}
}).catch(error => {
})
.catch((error) => {
this.ov.handleError(error, reject);
});
});
@ -282,20 +278,19 @@ export class Session {
public forceDisconnect(connection: string | Connection): Promise<void> {
return new Promise<void>((resolve, reject) => {
const connectionId: string = typeof connection === 'string' ? connection : (<Connection>connection).connectionId;
axios.delete(
this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection/' + connectionId,
{
axios
.delete(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection/' + connectionId, {
headers: {
'Authorization': this.ov.basicAuth,
Authorization: this.ov.basicAuth,
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then(res => {
.then((res) => {
if (res.status === 204) {
// SUCCESS response from openvidu-server
// Remove connection from connections array
let connectionClosed;
this.connections = this.connections.filter(con => {
this.connections = this.connections.filter((con) => {
if (con.connectionId !== connectionId) {
return true;
} else {
@ -305,13 +300,13 @@ export class Session {
});
// Remove every Publisher of the closed connection from every subscriber list of other connections
if (!!connectionClosed) {
connectionClosed.publishers.forEach(publisher => {
this.connections.forEach(con => {
con.subscribers = con.subscribers.filter(subscriber => {
connectionClosed.publishers.forEach((publisher) => {
this.connections.forEach((con) => {
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);
return subscriber['streamId'] !== publisher.streamId;
// tslint:enable:no-string-literal
} else {
// Regular string subscribers
@ -321,7 +316,9 @@ export class Session {
});
});
} else {
console.warn("The closed connection wasn't fetched in OpenVidu Node Client. No changes in the collection of active connections of the Session");
console.warn(
"The closed connection wasn't fetched in OpenVidu Node Client. No changes in the collection of active connections of the Session"
);
}
this.updateActiveConnectionsArray();
console.log("Connection '" + connectionId + "' closed");
@ -331,7 +328,7 @@ export class Session {
reject(new Error(res.status.toString()));
}
})
.catch(error => {
.catch((error) => {
this.ov.handleError(error, reject);
});
});
@ -355,31 +352,29 @@ export class Session {
public forceUnpublish(publisher: string | Publisher): Promise<void> {
return new Promise<void>((resolve, reject) => {
const streamId: string = typeof publisher === 'string' ? publisher : (<Publisher>publisher).streamId;
axios.delete(
this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/stream/' + streamId,
{
axios
.delete(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/stream/' + streamId, {
headers: {
'Authorization': this.ov.basicAuth,
Authorization: this.ov.basicAuth,
'Content-Type': 'application/x-www-form-urlencoded'
}
}
)
.then(res => {
})
.then((res) => {
if (res.status === 204) {
// SUCCESS response from openvidu-server
this.connections.forEach(connection => {
this.connections.forEach((connection) => {
// Try to remove the Publisher from the Connection publishers collection
connection.publishers = connection.publishers.filter(pub => pub.streamId !== streamId);
connection.publishers = connection.publishers.filter((pub) => pub.streamId !== streamId);
// Try to remove the Publisher from the Connection subscribers collection
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);
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);
connection.subscribers = connection.subscribers.filter((sub) => sub !== streamId);
}
}
});
@ -390,7 +385,8 @@ export class Session {
// ERROR response from openvidu-server. Resolve HTTP status
reject(new Error(res.status.toString()));
}
}).catch(error => {
})
.catch((error) => {
this.ov.handleError(error, reject);
});
});
@ -423,17 +419,14 @@ export class Session {
*/
public updateConnection(connectionId: string, connectionProperties: ConnectionProperties): Promise<Connection | undefined> {
return new Promise<any>((resolve, reject) => {
axios.patch(
this.ov.host + OpenVidu.API_SESSIONS + "/" + this.sessionId + "/connection/" + connectionId,
connectionProperties,
{
axios
.patch(this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection/' + connectionId, connectionProperties, {
headers: {
'Authorization': this.ov.basicAuth,
Authorization: this.ov.basicAuth,
'Content-Type': 'application/json'
}
}
)
.then(res => {
})
.then((res) => {
if (res.status === 200) {
console.log('Connection ' + connectionId + ' updated');
} else {
@ -442,7 +435,7 @@ export class Session {
return;
}
// Update the actual Connection object with the new options
const existingConnection: Connection = this.connections.find(con => con.connectionId === connectionId);
const existingConnection: Connection = this.connections.find((con) => con.connectionId === connectionId);
if (!existingConnection) {
// The updated Connection is not available in local map
const newConnection: Connection = new Connection(res.data);
@ -455,7 +448,8 @@ export class Session {
this.updateActiveConnectionsArray();
resolve(existingConnection);
}
}).catch(error => {
})
.catch((error) => {
this.ov.handleError(error, reject);
});
});
@ -473,28 +467,22 @@ export class Session {
*/
public getSessionHttp(): Promise<string> {
return new Promise<string>((resolve, reject) => {
if (!!this.sessionId) {
resolve(this.sessionId);
}
this.sanitizeDefaultSessionProperties(this.properties);
const data = JSON.stringify(
this.properties
);
const data = JSON.stringify(this.properties);
axios.post(
this.ov.host + OpenVidu.API_SESSIONS,
data,
{
axios
.post(this.ov.host + OpenVidu.API_SESSIONS, data, {
headers: {
'Authorization': this.ov.basicAuth,
Authorization: this.ov.basicAuth,
'Content-Type': 'application/json'
}
}
)
.then(res => {
})
.then((res) => {
if (res.status === 200) {
// SUCCESS response from openvidu-server. Resolve token
this.sessionId = res.data.id;
@ -512,7 +500,8 @@ export class Session {
// ERROR response from openvidu-server. Resolve HTTP status
reject(new Error(res.status.toString()));
}
}).catch(error => {
})
.catch((error) => {
if (!!error.response && error.response.status === 409) {
// 'customSessionId' already existed
this.sessionId = this.properties.customSessionId;
@ -559,10 +548,10 @@ export class Session {
// 1. Array to store fetched connections and later remove closed ones
const fetchedConnectionIds: string[] = [];
json.connections.content.forEach(jsonConnection => {
json.connections.content.forEach((jsonConnection) => {
const connectionObj: Connection = new Connection(jsonConnection);
fetchedConnectionIds.push(connectionObj.connectionId);
let storedConnection = this.connections.find(c => c.connectionId === connectionObj.connectionId);
let storedConnection = this.connections.find((c) => c.connectionId === connectionObj.connectionId);
if (!!storedConnection) {
// 2. Update existing Connection
@ -581,14 +570,13 @@ export class Session {
}
// Order connections by time of creation
this.connections.sort((c1, c2) => (c1.createdAt > c2.createdAt) ? 1 : ((c2.createdAt > c1.createdAt) ? -1 : 0));
this.connections.sort((c1, c2) => (c1.createdAt > c2.createdAt ? 1 : c2.createdAt > c1.createdAt ? -1 : 0));
// Order Ice candidates in connection properties
this.connections.forEach(connection => {
if (connection.connectionProperties.customIceServers != null &&
connection.connectionProperties.customIceServers.length > 0) {
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
const simpleIceComparator = (a: IceServerProperties, b: IceServerProperties) => (a.url > b.url ? 1 : -1);
connection.connectionProperties.customIceServers.sort(simpleIceComparator);
}
});
@ -601,14 +589,13 @@ export class Session {
* @hidden
*/
equalTo(other: Session): boolean {
let equals: boolean = (
let equals: boolean =
this.sessionId === other.sessionId &&
this.createdAt === other.createdAt &&
this.recording === other.recording &&
this.broadcasting === other.broadcasting &&
this.connections.length === other.connections.length &&
JSON.stringify(this.properties) === JSON.stringify(other.properties)
);
JSON.stringify(this.properties) === JSON.stringify(other.properties);
if (equals) {
let i = 0;
while (equals && i < this.connections.length) {
@ -637,7 +624,7 @@ export class Session {
*/
private updateActiveConnectionsArray() {
this.activeConnections = [];
this.connections.forEach(con => {
this.connections.forEach((con) => {
if (con.status === 'active') {
this.activeConnections.push(con);
}
@ -648,10 +635,9 @@ export class Session {
* @hidden
*/
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 : '';
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 : '';
// Remove null values: either set, or undefined
props.mediaNode = props.mediaNode ?? undefined;
@ -661,22 +647,51 @@ export class Session {
if (!props.defaultRecordingProperties) {
props.defaultRecordingProperties = {};
}
props.defaultRecordingProperties.name = (props.defaultRecordingProperties?.name != null) ? props.defaultRecordingProperties.name : '';
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;
props.defaultRecordingProperties.name = props.defaultRecordingProperties?.name != null ? props.defaultRecordingProperties.name : '';
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;
props.defaultRecordingProperties.mediaNode = props.defaultRecordingProperties?.mediaNode;
if ((props.defaultRecordingProperties.outputMode === Recording.OutputMode.COMPOSED || props.defaultRecordingProperties.outputMode == Recording.OutputMode.COMPOSED_QUICK_START) && props.defaultRecordingProperties.hasVideo) {
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;
if (
(props.defaultRecordingProperties.outputMode === Recording.OutputMode.COMPOSED ||
props.defaultRecordingProperties.outputMode == Recording.OutputMode.COMPOSED_QUICK_START) &&
props.defaultRecordingProperties.hasVideo
) {
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;
if (props.defaultRecordingProperties.recordingLayout === RecordingLayout.CUSTOM) {
props.defaultRecordingProperties.customLayout = (props.defaultRecordingProperties.customLayout != null) ? props.defaultRecordingProperties.customLayout : '';
props.defaultRecordingProperties.customLayout =
props.defaultRecordingProperties.customLayout != null ? props.defaultRecordingProperties.customLayout : '';
}
}
if (props.defaultRecordingProperties.outputMode === Recording.OutputMode.INDIVIDUAL) {
props.defaultRecordingProperties.ignoreFailedStreams = (props.defaultRecordingProperties?.ignoreFailedStreams != null) ? props.defaultRecordingProperties.ignoreFailedStreams : Recording.DefaultRecordingPropertiesValues.ignoreFailedStreams;
props.defaultRecordingProperties.ignoreFailedStreams =
props.defaultRecordingProperties?.ignoreFailedStreams != null
? props.defaultRecordingProperties.ignoreFailedStreams
: Recording.DefaultRecordingPropertiesValues.ignoreFailedStreams;
}
this.formatMediaNodeObjectIfNecessary(props.defaultRecordingProperties);
@ -693,5 +708,4 @@ export class Session {
}
}
}
}

View File

@ -24,7 +24,6 @@ import { VideoCodec } from './VideoCodec';
* See {@link OpenVidu.createSession}
*/
export interface SessionProperties {
/**
* How the media streams will be sent and received by your clients: routed through OpenVidu Media Node
* (`MediaMode.ROUTED`) or attempting direct p2p connections (`MediaMode.RELAYED`, _not available yet_)
@ -68,7 +67,7 @@ export interface SessionProperties {
*/
mediaNode?: {
id: string;
}
};
/**
* Define which video codec will be forcibly used for this session.

View File

@ -21,10 +21,9 @@ import { OpenViduRole } from './OpenViduRole';
* @deprecated Use {@link ConnectionProperties} instead
*/
export interface TokenOptions {
/**
* The role assigned to this token
*
*
* @default PUBLISHER
*/
role?: OpenViduRole;
@ -59,10 +58,10 @@ export interface TokenOptions {
* - `allowedFilters`: names of the filters the user owning the token will be able to apply. See [Voice and video filters](/en/stable/advanced-features/filters/)
*/
kurentoOptions?: {
videoMaxRecvBandwidth?: number,
videoMinRecvBandwidth?: number,
videoMaxSendBandwidth?: number,
videoMinSendBandwidth?: number,
allowedFilters?: string[]
videoMaxRecvBandwidth?: number;
videoMinRecvBandwidth?: number;
videoMaxSendBandwidth?: number;
videoMinSendBandwidth?: number;
allowedFilters?: string[];
};
}
}

View File

@ -6,5 +6,5 @@ export enum VideoCodec {
NONE = 'NONE',
VP8 = 'VP8',
VP9 = 'VP9',
H264 = 'H264',
H264 = 'H264'
}

View File

@ -13,4 +13,4 @@ export * from './RecordingProperties';
export * from './Connection';
export * from './Publisher';
export * from './VideoCodec';
export * from './IceServerProperties';
export * from './IceServerProperties';