I am working on some code for P2P audio chat. When two users wish to chat, I create a room (server-side) - all rooms are created using the same Room Template.
For each user entering the audio chat, I connect using the following steps:
For each user leaving the audio chat, I disconnect using the following steps:
Everything works perfect when I connect to my first room. Everyone gets subscribed and published and when I disconnect the users stop subscribing and publishing. However, when a user has left a room and then tries to connect to a new room (different audio chat), the user fails when publishing with the following error:
Error: AudioPublisher: The stream cannot be published because user does not have permission.
If I look at the room, the user is subscribed to the room - so the connect and subscribe worked!! It is just the publish that is failing.
The connection process is identical each time (other than the room). The instances of ConnectSession, AudioPublisher and AudioSubscriber are freshly created for each connection. I'm at a loss for why this is occurring - the only thing I can think of is that the user's session and/or publisher from the first call is not being cleaned up properly on the server causing the second publish to fail. But that's purely speculation.
I would greatly appreciate any help in resolving this issue!
One piece of additional information. I tried modifying the user's name by adding a sequential number to the end - hoping that because I was creating a new session based on a new user name that it would not have issues publishing. However, the same error still occurs.
I found a earlier post about ConnectSession garbage collection that pointed me in the right direction...
I've stopped recreating the session for each call - as I understand it the second time I create it there is a primarySession variable that gets out of sync. Now I just logout of the session and change the roomURL, which seems to correct the issue. Just wanted to provide the answer for others that might run into the same issue down the road.