protected override void OnEventFired(object source, VoiceSessionAuthenticatedEventArgs args) { //Join the world channel with the session in the args. UnityAsyncHelper.UnityMainThreadContext.PostAsync(async() => { try { ResponseModel <VivoxChannelJoinResponse, VivoxLoginResponseCode> channelJoinResponse = await VivoxAutheAuthorizationService.JoinProximityChatAsync(); //TODO: Better handle failure. if (!channelJoinResponse.isSuccessful) { if (Logger.IsErrorEnabled) { Logger.Error($"Failed to join Proximity world channel. Reason: {channelJoinResponse.ResultCode}"); } return; } if (Logger.IsInfoEnabled) { Logger.Info($"Recieved Vivox Channel URI: {channelJoinResponse.Result.ChannelURI}"); } //TODO: We should share these inputs as shared constants. //IChannelSession testChannel = args.Session.GetChannelSession(new ChannelId("vrguardian-vrg-dev", "lobby", "vdx5.vivox.com", ChannelType.Positional)); IChannelSession testChannel = args.Session.GetChannelSession(new ChannelId(channelJoinResponse.Result.ChannelURI)); //Prevent mobile platform connecting to audio await testChannel.ConnectionAsync(true, true, TransmitPolicy.Yes, channelJoinResponse.Result.AuthToken) .ConfigureAwait(true); //Documentation says that it doesn't mean the channel has connected yet. if (Logger.IsInfoEnabled) { Logger.Info($"Vivox ChannelState: {testChannel.AudioState}"); } PositionalVoiceChannels.Add(testChannel); //Broadcast that we've joined proximity chat. ChannelJoinEventPublisher.PublishEvent(this, new ChatChannelJoinedEventArgs(ChatChannelType.Proximity, new DefaultVivoxTextChannelSubscribableAdapter(testChannel), new DefaultVivoxChatChannelSenderAdapter(testChannel))); } catch (Exception e) { Logger.Error($"Failed to Initialize Vivox Voice. Reason: {e.Message}\n\nStack: {e.StackTrace}"); throw; } }); }
protected override void OnGuildStatusChanged(GuildStatusChangedEventModel changeArgs) { //TODO: This needs to be authorative ProjectVersionStage.AssertBeta(); //If we're now guildless, we need to actually leave the guild chat channel //if we're in one. if (changeArgs.IsGuildless) { //TODO: Handle leaving guild channel return; } //We have a guild, let's join the guild channel now. UnityAsyncHelper.UnityMainThreadContext.PostAsync(async() => { try { ResponseModel <VivoxChannelJoinResponse, VivoxLoginResponseCode> channelJoinResponse = await VivoxAutheAuthorizationService.JoinGuildChatAsync(); //TODO: Better handle failure. if (!channelJoinResponse.isSuccessful) { if (Logger.IsErrorEnabled) { Logger.Error($"Failed to join Guild world channel. Reason: {channelJoinResponse.ResultCode}"); } return; } if (Logger.IsInfoEnabled) { Logger.Info($"Recieved Vivox Channel URI: {channelJoinResponse.Result.ChannelURI}"); } //TODO: Awaiting the ChatChannelSession may never complete. We should do a timeout. //TODO: We should share these inputs as shared constants. IChannelSession guildChannel = (await ChatChannelSession).GetChannelSession(new ChannelId(channelJoinResponse.Result.ChannelURI)); await guildChannel.ConnectionAsync(false, true, TransmitPolicy.Yes, channelJoinResponse.Result.AuthToken) .ConfigureAwait(true); if (Logger.IsInfoEnabled) { Logger.Info($"Joined Guild Chat"); } //Broadcast that we've joined proximity chat. ChannelJoinEventPublisher.PublishEvent(this, new ChatChannelJoinedEventArgs(ChatChannelType.Guild, new DefaultVivoxTextChannelSubscribableAdapter(guildChannel), new DefaultVivoxChatChannelSenderAdapter(guildChannel))); } catch (Exception e) { if (Logger.IsErrorEnabled) { Logger.Error($"Failed to Initialize Guild chat. Reason: {e.Message}\n\nStack: {e.StackTrace}"); } throw; } }); }