2018-05-18 12:46:41 +02:00
|
|
|
import { Component, Inject } from '@angular/core';
|
2018-06-15 14:45:47 +02:00
|
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
|
2018-05-18 12:46:41 +02:00
|
|
|
|
2021-04-13 13:04:49 +02:00
|
|
|
import { OpenVidu as OpenViduAPI, Session as SessionAPI, RecordingProperties, ConnectionProperties, OpenViduRole } from 'openvidu-node-client';
|
2018-05-18 12:46:41 +02:00
|
|
|
|
|
|
|
@Component({
|
2018-05-29 18:32:49 +02:00
|
|
|
selector: 'app-session-api-dialog',
|
2019-01-21 18:46:40 +01:00
|
|
|
templateUrl: './session-api-dialog.component.html',
|
|
|
|
styleUrls: ['./session-api-dialog.component.css']
|
2018-05-18 12:46:41 +02:00
|
|
|
})
|
|
|
|
export class SessionApiDialogComponent {
|
|
|
|
|
|
|
|
OV: OpenViduAPI;
|
2018-07-13 13:47:06 +02:00
|
|
|
session: SessionAPI;
|
2018-05-18 12:46:41 +02:00
|
|
|
sessionId: string;
|
|
|
|
recordingId: string;
|
2020-10-08 17:37:17 +02:00
|
|
|
connectionId: string;
|
|
|
|
streamId: string;
|
2018-05-18 12:46:41 +02:00
|
|
|
response: string;
|
|
|
|
|
2019-01-21 18:46:40 +01:00
|
|
|
recordingProperties: RecordingProperties;
|
2020-10-08 17:37:17 +02:00
|
|
|
openviduRoles = OpenViduRole;
|
2019-01-21 18:46:40 +01:00
|
|
|
customLayout = '';
|
|
|
|
recPropertiesIcon = 'add_circle';
|
|
|
|
showRecProperties = false;
|
|
|
|
|
2020-10-21 22:19:01 +02:00
|
|
|
connectionProperties: ConnectionProperties = {
|
2020-10-08 17:37:17 +02:00
|
|
|
record: true,
|
2020-11-19 14:44:52 +01:00
|
|
|
role: OpenViduRole.PUBLISHER,
|
|
|
|
data: ''
|
2020-10-08 17:37:17 +02:00
|
|
|
};
|
|
|
|
|
2018-05-18 12:46:41 +02:00
|
|
|
constructor(public dialogRef: MatDialogRef<SessionApiDialogComponent>,
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data) {
|
|
|
|
this.OV = data.openVidu;
|
2018-07-13 13:47:06 +02:00
|
|
|
this.session = data.session;
|
2018-05-18 12:46:41 +02:00
|
|
|
this.sessionId = data.sessionId;
|
2019-01-21 18:46:40 +01:00
|
|
|
this.recordingProperties = data.recordingProperties;
|
2018-05-18 12:46:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-13 13:47:06 +02:00
|
|
|
closeSession() {
|
|
|
|
console.log('Closing session');
|
|
|
|
if (!this.session) {
|
|
|
|
this.response = 'Error [Session undefined]';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.session.close()
|
|
|
|
.then(() => {
|
|
|
|
this.response = 'Session closed';
|
|
|
|
delete this.session;
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.response = 'Error [' + error.message + ']';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-18 12:46:41 +02:00
|
|
|
startRecording() {
|
|
|
|
console.log('Starting recording');
|
2020-12-03 17:21:22 +01:00
|
|
|
const finalRecordingProperties = {
|
|
|
|
name: this.recordingProperties.name,
|
|
|
|
outputMode: this.recordingProperties.outputMode,
|
|
|
|
recordingLayout: this.recordingProperties.recordingLayout,
|
|
|
|
customLayout: this.recordingProperties.customLayout,
|
|
|
|
resolution: this.recordingProperties.resolution,
|
2021-04-05 20:50:29 +02:00
|
|
|
frameRate: this.recordingProperties.frameRate,
|
2020-12-03 17:21:22 +01:00
|
|
|
hasAudio: this.recordingProperties.hasAudio,
|
|
|
|
hasVideo: this.recordingProperties.hasVideo,
|
|
|
|
shmSize: this.recordingProperties.shmSize,
|
|
|
|
mediaNode: !this.recordingProperties.mediaNode.id ? undefined : this.recordingProperties.mediaNode
|
|
|
|
}
|
|
|
|
this.OV.startRecording(this.sessionId, finalRecordingProperties)
|
2018-05-18 12:46:41 +02:00
|
|
|
.then(recording => {
|
|
|
|
this.response = 'Recording started [' + recording.id + ']';
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.response = 'Error [' + error.message + ']';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
stopRecording() {
|
|
|
|
console.log('Stopping recording');
|
|
|
|
this.OV.stopRecording(this.recordingId)
|
|
|
|
.then(recording => {
|
|
|
|
this.response = 'Recording stopped [' + recording.id + ']';
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.response = 'Error [' + error.message + ']';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getRecording() {
|
|
|
|
console.log('Getting recording');
|
|
|
|
this.OV.getRecording(this.recordingId)
|
|
|
|
.then(recording => {
|
|
|
|
this.response = 'Recording got [' + recording.id + ']';
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.response = 'Error [' + error.message + ']';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
listRecordings() {
|
|
|
|
console.log('Listing recordings');
|
|
|
|
this.OV.listRecordings()
|
|
|
|
.then(recordingList => {
|
|
|
|
let recordingIds = '';
|
|
|
|
recordingList.forEach((rec, index) => {
|
|
|
|
recordingIds += rec.id;
|
|
|
|
if (index !== recordingList.length - 1) {
|
|
|
|
recordingIds += ', ';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.response = 'Recording list [' + recordingIds + ']';
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.response = 'Error [' + error.message + ']';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteRecording() {
|
|
|
|
console.log('Deleting recording');
|
|
|
|
this.OV.deleteRecording(this.recordingId)
|
|
|
|
.then(() => {
|
|
|
|
this.response = 'Recording deleted';
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.response = 'Error [' + error.message + ']';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-22 22:54:36 +02:00
|
|
|
fetchActiveConnections() {
|
|
|
|
console.log('Fetching session info');
|
|
|
|
if (!this.session) {
|
|
|
|
this.response = 'Error [Session undefined]';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.session.fetch()
|
|
|
|
.then(anyChange => {
|
|
|
|
const resp = {};
|
|
|
|
this.session.activeConnections.forEach(con => {
|
|
|
|
resp[con.connectionId] = [];
|
|
|
|
con.publishers.forEach(pub => {
|
|
|
|
resp[con.connectionId].push(pub);
|
|
|
|
});
|
|
|
|
});
|
2018-07-23 10:53:24 +02:00
|
|
|
this.response = 'Session info fetched %[' + JSON.stringify(resp) + ']%. Changes: ' + anyChange;
|
2018-07-22 22:54:36 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.response = 'Error [' + error.message + ']';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchActiveSessions() {
|
|
|
|
console.log('Fetching all sessions info');
|
|
|
|
this.OV.fetch()
|
|
|
|
.then(anyChange => {
|
2018-07-23 10:53:24 +02:00
|
|
|
this.response = 'All sessions info fetched. Number: ' + this.OV.activeSessions.length + '. Changes: ' + anyChange;
|
2018-07-22 22:54:36 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.response = 'Error [' + error.message + ']';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
forceDisconnect() {
|
|
|
|
console.log('Forcing disconnect');
|
2020-10-08 17:37:17 +02:00
|
|
|
this.session.forceDisconnect(this.connectionId)
|
2018-07-22 22:54:36 +02:00
|
|
|
.then(() => {
|
|
|
|
this.response = 'User disconnected';
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.response = 'Error [' + error.message + ']';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
forceUnpublish() {
|
|
|
|
console.log('Forcing unpublish');
|
2020-10-08 17:37:17 +02:00
|
|
|
this.session.forceUnpublish(this.streamId)
|
2018-07-22 22:54:36 +02:00
|
|
|
.then(() => {
|
|
|
|
this.response = 'Stream unpublished';
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.response = 'Error [' + error.message + ']';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-21 11:48:38 +02:00
|
|
|
createConnection() {
|
|
|
|
console.log('Creating connection');
|
2020-10-21 22:19:01 +02:00
|
|
|
this.session.createConnection(this.connectionProperties)
|
2020-10-21 11:48:38 +02:00
|
|
|
.then(connection => {
|
2020-11-19 14:44:52 +01:00
|
|
|
this.response = 'Connection created: ' + JSON.stringify(connection);
|
2020-10-21 11:48:38 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.response = 'Error [' + error.message + ']';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-08 17:37:17 +02:00
|
|
|
updateConnection() {
|
|
|
|
console.log('Updating connection');
|
2020-10-21 22:19:01 +02:00
|
|
|
this.session.updateConnection(this.connectionId, this.connectionProperties)
|
2020-10-08 17:37:17 +02:00
|
|
|
.then(modifiedConnection => {
|
2020-11-19 14:44:52 +01:00
|
|
|
this.response = 'Connection updated: ' + JSON.stringify({
|
|
|
|
role: modifiedConnection.connectionProperties.role,
|
|
|
|
record: modifiedConnection.connectionProperties.record,
|
|
|
|
data: modifiedConnection.connectionProperties.data
|
|
|
|
});
|
2020-10-08 17:37:17 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.response = 'Error [' + error.message + ']';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-21 18:46:40 +01:00
|
|
|
enumToArray(enumerator: any) {
|
|
|
|
return Object.keys(enumerator);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleRecProperties() {
|
|
|
|
this.showRecProperties = !this.showRecProperties;
|
|
|
|
this.recPropertiesIcon = this.showRecProperties ? 'remove_circle' : 'add_circle';
|
|
|
|
}
|
|
|
|
|
2018-05-18 12:46:41 +02:00
|
|
|
}
|