From 6e7e7696d3348135561bd331030a0c40c5d5bfb4 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Thu, 8 Jul 2021 10:15:56 +0200 Subject: [PATCH] Removed the product user mapping stuff, as it falls well out of the scope of this class. That should be taken care of by the platform-specific use cases. --- Assets/Scripts/EOSVoiceChat.cs | 40 ++++++++++---------------- Assets/Scripts/MagnificentVoiceChat.cs | 13 +-------- 2 files changed, 16 insertions(+), 37 deletions(-) diff --git a/Assets/Scripts/EOSVoiceChat.cs b/Assets/Scripts/EOSVoiceChat.cs index 79f408d..f330a45 100644 --- a/Assets/Scripts/EOSVoiceChat.cs +++ b/Assets/Scripts/EOSVoiceChat.cs @@ -8,7 +8,7 @@ using Epic.OnlineServices.RTCAudio; using UnityEngine; /// -/// Generic re-usable cross-platform class to provide common voice chat functionality based on the EOS Voice Chat service. +/// Generic reusable cross-platform class to provide common voice chat functionality based on the EOS Voice Chat service. /// This class does not know anything about EOS platform initialization or authentication; it just takes the required /// EOS interfaces and exposes a number of game-related voice functions. /// @@ -20,7 +20,6 @@ public class EOSVoiceChat private readonly RTCInterface rtcInterface; private readonly RTCAudioInterface audioInterface; private readonly Func localUserProvider; - private readonly IProductUserMapper productUserMapper; private readonly Dictionary chatUsers = new Dictionary(); @@ -36,13 +35,12 @@ public class EOSVoiceChat /// public EOSVoiceChat( LobbyInterface lobbyInterface, RTCInterface rtcInterface, RTCAudioInterface audioInterface, - Func localUserProvider, IProductUserMapper productUserMapper) + Func localUserProvider) { this.lobbyInterface = lobbyInterface; this.rtcInterface = rtcInterface; this.audioInterface = audioInterface; this.localUserProvider = localUserProvider; - this.productUserMapper = productUserMapper; } /// @@ -115,7 +113,7 @@ public class EOSVoiceChat chatUsers.Clear(); SubscribeToRoomNotifications(); - connectArgs.onCompleted?.Invoke(true); + connectArgs.onCompleted?.Invoke(true); // NOTE: this callback may come too soon, we probably don't have the list of participants populated yet... break; case Result.LobbyLobbyAlreadyExists: // This can happen if two clients try to create the same lobby at the same time, a classic race condition. @@ -146,7 +144,7 @@ public class EOSVoiceChat chatUsers.Clear(); SubscribeToRoomNotifications(); - connectArgs.onCompleted?.Invoke(true); + connectArgs.onCompleted?.Invoke(true); // NOTE: this callback may come too soon, we probably don't have the list of participants populated yet... break; default: connectedLobbyId = null; @@ -218,21 +216,18 @@ public class EOSVoiceChat /// Mute or unmute a specific remove player. This can be used to filter out specific players in the chat lobby, /// or for manually muting toxic players. /// - public void SetRemoteMuted(string remotePlayerId, bool muted) + public void SetRemoteMuted(ProductUserId remoteUser, bool muted) { if (!IsConnected) return; - productUserMapper.MapPlatformIdToProductUser(remotePlayerId, remoteProductUser => + audioInterface.UpdateReceiving(new UpdateReceivingOptions { - audioInterface.UpdateReceiving(new UpdateReceivingOptions - { - LocalUserId = localUserProvider.Invoke(), - ParticipantId = remoteProductUser, - RoomName = rtcRoomName, - AudioEnabled = !muted, - }, null, data => { }); - }); + LocalUserId = localUserProvider.Invoke(), + ParticipantId = remoteUser, + RoomName = rtcRoomName, + AudioEnabled = !muted, + }, null, data => { }); } /// @@ -272,16 +267,13 @@ public class EOSVoiceChat } /// - /// Whether the requested player is currently talking or not. - /// This can be either the local player or a remote player. + /// Whether the requested user is currently talking or not. + /// This can be either the local player or a remote user. /// - public bool IsPlayerTalking(string playerId) + public bool IsUserTalking(ProductUserId user) { - foreach (var chatUser in chatUsers.Values) + if (chatUsers.TryGetValue(user, out var chatUser)) { - if (chatUser.platformPlayerId != playerId) - continue; - return chatUser.audioStatus == RTCAudioStatus.Enabled && chatUser.isSpeaking; } @@ -382,7 +374,6 @@ public class EOSVoiceChat return; var chatUser = new ChatUser(data.ParticipantId); - productUserMapper.MapProductUserToPlatformId(data.ParticipantId, pid => chatUser.platformPlayerId = pid); chatUsers.Add(data.ParticipantId, chatUser); break; case RTCParticipantStatus.Left: @@ -420,7 +411,6 @@ public class EOSVoiceChat { public readonly ProductUserId productUserId; - public string platformPlayerId; public RTCAudioStatus audioStatus; public bool isSpeaking; diff --git a/Assets/Scripts/MagnificentVoiceChat.cs b/Assets/Scripts/MagnificentVoiceChat.cs index 6c08daa..74d9ff8 100644 --- a/Assets/Scripts/MagnificentVoiceChat.cs +++ b/Assets/Scripts/MagnificentVoiceChat.cs @@ -126,7 +126,7 @@ public class MagnificentVoiceChat : MonoBehaviour ScopeFlags = AuthScopeFlags.BasicProfile, }, null, HandleLoginResult); - voiceChat = new EOSVoiceChat(lobbyInterface, rtcInterface, audioInterface, () => localProductUserId, new NilProductUserMapper()); + voiceChat = new EOSVoiceChat(lobbyInterface, rtcInterface, audioInterface, () => localProductUserId); } private Credentials GetEpicCredentials() // This is platform-specific @@ -305,15 +305,4 @@ public class MagnificentVoiceChat : MonoBehaviour GUILayout.Label(status.ToString()); } - - private class NilProductUserMapper : IProductUserMapper - { - public void MapProductUserToPlatformId(ProductUserId productUserId, Action platformIdCallback) - { - } - - public void MapPlatformIdToProductUser(string platformId, Action productUserCallback) - { - } - } }