From 56e75a9b8162d6a1dfb9d75e2512964373b3bd86 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Sun, 22 Jul 2018 22:54:36 +0200 Subject: [PATCH] openvidu-testapp: Session API REST options extended --- .../session-api-dialog.component.ts | 75 ++++++++++++++++++- .../openvidu-instance.component.ts | 4 +- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/openvidu-testapp/src/app/components/dialogs/session-api-dialog/session-api-dialog.component.ts b/openvidu-testapp/src/app/components/dialogs/session-api-dialog/session-api-dialog.component.ts index 042ee911..38809990 100644 --- a/openvidu-testapp/src/app/components/dialogs/session-api-dialog/session-api-dialog.component.ts +++ b/openvidu-testapp/src/app/components/dialogs/session-api-dialog/session-api-dialog.component.ts @@ -9,18 +9,26 @@ import { OpenVidu as OpenViduAPI, Session as SessionAPI } from 'openvidu-node-cl

API REST

- + + + + + + + + + + - - + - + @@ -33,6 +41,9 @@ import { OpenVidu as OpenViduAPI, Session as SessionAPI } from 'openvidu-node-cl '#response-text-area { width: 100%; color: #808080; }', '#response-text-area textarea { resize: none; }', 'mat-dialog-content button, mat-divider { margin-bottom: 5px; }', + 'mat-dialog-content button { height: 30px; line-height: 30px; padding-left: 12px; padding-right: 12px; display: inline-flex;}', + '.label { display: block; font-size: 12px; color: rgba(0, 0, 0, 0.54); font-weight: 400; margin-bottom: 5px; margin-top: 13px}', + '.inner-text-input { margin-left: 16px; }' ] }) export class SessionApiDialogComponent { @@ -41,6 +52,7 @@ export class SessionApiDialogComponent { session: SessionAPI; sessionId: string; recordingId: string; + resourceId: string; response: string; constructor(public dialogRef: MatDialogRef, @@ -128,4 +140,59 @@ export class SessionApiDialogComponent { }); } + 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); + }); + }); + this.response = 'Session info fetched [' + JSON.stringify(resp) + ']. Changes: ' + anyChange; + }) + .catch(error => { + this.response = 'Error [' + error.message + ']'; + }); + } + + fetchActiveSessions() { + console.log('Fetching all sessions info'); + this.OV.fetch() + .then(anyChange => { + this.response = 'All sessions info fetched. Changes: ' + anyChange; + }) + .catch(error => { + this.response = 'Error [' + error.message + ']'; + }); + } + + forceDisconnect() { + console.log('Forcing disconnect'); + this.session.forceDisconnect(this.resourceId) + .then(() => { + this.response = 'User disconnected'; + }) + .catch(error => { + this.response = 'Error [' + error.message + ']'; + }); + } + + forceUnpublish() { + console.log('Forcing unpublish'); + this.session.forceUnpublish(this.resourceId) + .then(() => { + this.response = 'Stream unpublished'; + }) + .catch(error => { + this.response = 'Error [' + error.message + ']'; + }); + } + } diff --git a/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.ts b/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.ts index 5a56acc3..ae089da8 100644 --- a/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.ts +++ b/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.ts @@ -403,7 +403,9 @@ export class OpenviduInstanceComponent implements OnInit, OnChanges, OnDestroy { } if (this.sessionEvents.publisherStopSpeaking !== oldValues.publisherStopSpeaking || firstTime) { - this.session.off('publisherStopSpeaking'); + if (!this.sessionEvents.publisherStartSpeaking) { + this.session.off('publisherStopSpeaking'); + } if (this.sessionEvents.publisherStopSpeaking) { this.session.on('publisherStopSpeaking', (event: PublisherSpeakingEvent) => { this.updateEventList('publisherStopSpeaking', event.connection.connectionId);