Tokbox streamCreated being called same number of times client is called

空扰寡人 提交于 2019-12-11 16:58:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!