0

I'm calling on a client, one-to-one, multiple times during a session and the streamCreated event gets called on the host. When I hang up, I unsubscribe and the client unpublishes. However, when I call on the client again, the streamCreated event gets called twice on the host's side. I call on the client 3, 4, 5, etc. more times and the streamCreated event fires the same number of times as I have called on the client. For example on the 7th time I call the client, streamCreated gets called 7 times! It seems like I'm not really destroying the streams although streamDestroyed gets called.

On the client side, I was desperate enough to try and unpublish with:

clientSession.unpublish(clientPublisher, handleError);
clientPublisher.stream.destroy();
clientPublisher.destroy();
clientPublisher = null;

On the host side, I've also tried to make sure the subscriber was destroyed:

clientSession.unsubscribe(clientSubscriber);
clientSubscriber.destroy();
clientSubscriber = null;

The problem with this is when I open a video monitor with multiple clients and have each client publish without audio. However, I can still hear the client I called on... like their original stream(s) still exists. What am I doing wrong?

Manik
  • 1,495
  • 11
  • 19
Velocedge
  • 1,222
  • 1
  • 11
  • 35
  • TokBox Developer Evangelist here. I understand that you found a solution, but I wanted to confirm that both streams are being destroyed when you "hang-up"? If you only unpublish one stream, the other stream may still be publishing unless you explicitly unpublish the other stream as well. – Manik Nov 23 '18 at 02:42
  • That is correct, I'm unpublishing both streams. Thanks for checking. – Velocedge Nov 26 '18 at 15:21

1 Answers1

2

Every time I called on the person, I was using:

clientSession.on('streamCreated', function (event) {
clientSubscriber = clientSession.subscribe(event.stream, vid, {
...   

So, each time I called on a client, it created a new event handler. To correct the issue, I added the following code when I disconnected from the client.

clientSession.unsubscribe(clientSubscriber);
clientSession.off();

That killed the event handler and everything works properly now.

Velocedge
  • 1,222
  • 1
  • 11
  • 35