From ab13435af878688c8bb57d851c956927a97b1f34 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Wed, 18 Apr 2018 15:49:38 +0200 Subject: [PATCH] openvidu-testapp: when changing Publisher dynamically do not unpublish until new Publisher receives 'accessAllowed' event --- .../openvidu-instance.component.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) 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 1b1252f2d6..f09d32df23 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 @@ -522,13 +522,6 @@ export class OpenviduInstanceComponent implements OnInit, OnChanges, OnDestroy { } changePublisher() { - - if (!this.unpublished) { - this.session.unpublish(this.publisher); - this.removeUserData(this.session.connection.connectionId); - this.restartPublisherRecord(); - } - let screenChange; if (!this.publisherChanged) { if (this.sendAudio && !this.sendVideo) { @@ -560,7 +553,7 @@ export class OpenviduInstanceComponent implements OnInit, OnChanges, OnDestroy { this.updateVideoIcon(); this.updatePublishIcon(); - this.publisher = this.OV.initPublisher( + const otherPublisher = this.OV.initPublisher( 'local-vid-' + this.session.connection.connectionId, { audioSource: this.sendAudioChange ? undefined : false, @@ -584,8 +577,17 @@ export class OpenviduInstanceComponent implements OnInit, OnChanges, OnDestroy { } } }); - this.addPublisherEvents(this.publisher); - this.session.publish(this.publisher); + this.addPublisherEvents(otherPublisher); + + otherPublisher.once('accessAllowed', () => { + if (!this.unpublished) { + this.session.unpublish(this.publisher); + this.publisher = otherPublisher; + this.removeUserData(this.session.connection.connectionId); + this.restartPublisherRecord(); + } + this.session.publish(otherPublisher); + }); this.publisherChanged = !this.publisherChanged; }