Browse Source

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.

master
Nico de Poel 5 years ago
parent
commit
6e7e7696d3
  1. 30
      Assets/Scripts/EOSVoiceChat.cs
  2. 13
      Assets/Scripts/MagnificentVoiceChat.cs

30
Assets/Scripts/EOSVoiceChat.cs

@ -8,7 +8,7 @@ using Epic.OnlineServices.RTCAudio;
using UnityEngine;
/// <summary>
/// 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.
/// </summary>
@ -20,7 +20,6 @@ public class EOSVoiceChat
private readonly RTCInterface rtcInterface;
private readonly RTCAudioInterface audioInterface;
private readonly Func<ProductUserId> localUserProvider;
private readonly IProductUserMapper productUserMapper;
private readonly Dictionary<ProductUserId, ChatUser> chatUsers = new Dictionary<ProductUserId, ChatUser>();
@ -36,13 +35,12 @@ public class EOSVoiceChat
/// </summary>
public EOSVoiceChat(
LobbyInterface lobbyInterface, RTCInterface rtcInterface, RTCAudioInterface audioInterface,
Func<ProductUserId> localUserProvider, IProductUserMapper productUserMapper)
Func<ProductUserId> localUserProvider)
{
this.lobbyInterface = lobbyInterface;
this.rtcInterface = rtcInterface;
this.audioInterface = audioInterface;
this.localUserProvider = localUserProvider;
this.productUserMapper = productUserMapper;
}
/// <summary>
@ -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.
/// </summary>
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
{
LocalUserId = localUserProvider.Invoke(),
ParticipantId = remoteProductUser,
ParticipantId = remoteUser,
RoomName = rtcRoomName,
AudioEnabled = !muted,
}, null, data => { });
});
}
/// <summary>
@ -272,16 +267,13 @@ public class EOSVoiceChat
}
/// <summary>
/// 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.
/// </summary>
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;

13
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<string> platformIdCallback)
{
}
public void MapPlatformIdToProductUser(string platformId, Action<ProductUserId> productUserCallback)
{
}
}
}
Loading…
Cancel
Save