When using Vivox SDK v16+ in Unity, exceptions may occur if you interact with a channel immediately after calling and awaiting JoinGroupChannelAsync or JoinPositionalChannelAsync. This is because the channel's media (audio or text) is not connected yet—awaiting the join method only dispatches the request to the server. To safely perform channel operations, subscribe to the VivoxService.Instance.ChannelJoined event, which signals when the channel media is fully connected.
Issue:
Exceptions are sometimes encountered when attempting to perform operations on a channel immediately after the await task completes.
// Start the join process await VivoxService.Instance.JoinGroupChannelAsync(LobbyChannelName, ChatCapability.VoiceOnly); // But don't try to do something with that channel just yet!
Cause:
This is caused by trying to perform actions on a channel before the media (either audio or text) has actually been connected. The call to the join method (i.e., JoinEchoChannelAsync, JoinGroupChannelAsync, JoinPositionalChannelAsync) is only a request to perform the join action to the Vivox server. Upon the completion of the await task, the request has been dispatched to the server, but the channel's media is not actually connected.
Resolution:
To determine when the channel media is joined, the VivoxService.Instance.ChannelJoined event must be bound to. The event itself will fire with the name of the channel, which should be used to trigger the specific events required for that channel.
To find more information on this topic, including an example of subscribing to the ChannelJoined and ChannelLeft events, please see: Initiate a channel join.