Skip to content

Commit

Permalink
openvidu-testapp: when changing Publisher dynamically do not unpublis…
Browse files Browse the repository at this point in the history
…h until new Publisher receives 'accessAllowed' event
  • Loading branch information
pabloFuente committed Apr 18, 2018
1 parent 870600d commit ab13435
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down

0 comments on commit ab13435

Please sign in to comment.