问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/53394200/tokbox-streamcreated-being-called-same-number-of-times-client-is-called