LEAP Documentation 40220
Documentation for the LEAP project
VivoxGameInstance.h
Go to the documentation of this file.
1#pragma once
2
3#include "SteamBeaconGameInstance.h"
4
5#if !PLATFORM_LINUX
6#include "VivoxCore.h"
7#endif
8
9#include "VivoxGameInstance.generated.h"
10
11#define VIVOX_ALLOW_EDITOR 0
12#define VIVOX_ALLOW_PROD 1
13
14//Turn the last flag off if you want to disable it entirely;
15#define VIVOX_ENABLED ((WITH_EDITOR && VIVOX_ALLOW_EDITOR) || (!WITH_EDITOR && VIVOX_ALLOW_PROD)) && 1
16
17DEFINE_LOG_CATEGORY_STATIC(LogVivoxGameInstance, Log, All);
18DEFINE_LOG_CATEGORY_STATIC(LogVivoxToken, Log, All);
19
20#if !PLATFORM_LINUX
22{
23 static void GenerateClientLoginToken(const ILoginSession& LoginSession, FString& OutToken);
24 static void GenerateClientJoinToken(const IChannelSession& ChannelSession, FString& OutToken);
25};
26
27template<class T>
29{
30public:
31 explicit CachedProperty(T value) {
32 m_dirty = false;
33 m_value = value;
34 }
35
36 const T &GetValue() const {
37 return m_value;
38 }
39
40 void SetValue(const T &value) {
41 if (m_value != value) {
42 m_value = value;
43 m_dirty = true;
44 }
45 }
46
47 void SetDirty(bool value) {
48 m_dirty = value;
49 }
50
51 bool IsDirty() const {
52 return m_dirty;
53 }
54protected:
55 bool m_dirty;
57};
58#endif
59
60DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FParticipantUpdated, bool, bIsSelf, const FString&, PlayerName, bool, bIsSpeaking);
61
63
64USTRUCT()
66{
67 GENERATED_BODY()
68public:
69 UPROPERTY()
70 FString SessionName = "Invalid";
71 UPROPERTY()
72 int32 SquadID = -1;
73
74 bool IsValid() {return !SessionName.Equals("Invalid"); }
75};
76
77UCLASS(config = Game)
78class PROJECTX_API UVivoxGameInstance : public USteamBeaconGameInstance
79{
80 GENERATED_BODY()
81
82public:
84
85 virtual void Init() override;
86 virtual void Shutdown() override;
87 void OnClientTravel(const FString& PendingURL, ETravelType TravelType, bool bIsSeamlessTravel);
88
89 virtual const FString GetPlatformAccountID();
90 //Parses BaseName into a safe id that can be exposed to the network that is safe to be used by Vivox
91 UFUNCTION(BlueprintPure)
92 static FString GetVivoxSafeName(const FString BaseName);
93 UFUNCTION(BlueprintPure)
94 static FString GetVivoxSafePlayerName(const FString BaseName);
95 UFUNCTION(BlueprintPure)
96 static APlayerState* GetPlayerStateByVivoxName(const UObject* WorldContextObject, UPARAM(ref) const FString& ID);
97 UFUNCTION(BlueprintPure, Category = "VOIP")
98 float GetParticipantVolume() const;
99 UFUNCTION(BlueprintPure)
100 bool IsUsingPushToTalk() const { return bUsingPushToTalk; };
101 UFUNCTION(BlueprintCallable, Category = "VOIP")
102 void UpdateParticipantVolume(const float Volume);
103 UFUNCTION(BlueprintCallable, Category = "VOIP")
104 void UpdatePushToTalk(const bool bNewPushToTalk);
105
106 UPROPERTY(BlueprintAssignable)
107 FParticipantUpdated OnParticipantUpdated;
108private:
109 bool bUsingPushToTalk = false;
110
111#if !PLATFORM_LINUX
112public:
114 virtual bool Exec(UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Out = *GLog) override;
115
116 //Steam Party Beacon overrides for party voice chat
117 virtual void InitBeaconHost() override;
118 virtual void InitBeaconClient(const FOnlineSessionSearchResult& DesiredHost) override;
119 virtual void InitBeaconClientForServerPlayer() override;
120
121 void BindLoginSessionHandlers(bool DoBind, ILoginSession& LoginSession);
122 void BindChannelSessionHandlers(bool DoBind, IChannelSession& ChannelSession);
123
124 VivoxCoreError Initialize(int logLevel);
125 void Uninitialize();
126
127 VivoxCoreError Login(const FString& PlayerName);
128 void ReLog();
129 void Logout();
130 void ReJoinVoiceChannels();
131 void ReJoinLastKnownSquadChannel();
132 void RejoinPartyVoiceChannel();
133 VivoxCoreError JoinVoiceChannels(FString OnlineSessionId, int32 TeamNum = -1);
134 VivoxCoreError JoinVoiceChannels(FString OnlineSessionId, int32 TeamNum, bool bUseOpenMic);
135 VivoxCoreError Join(ChannelType Type, bool IsOpenMic, FString ChannelName);
136 VivoxCoreError MultiChanPushToTalk(bool PTTKeyPressed);
137 void LeaveVoiceChannels(FVoiceChannelInfo Exception = FVoiceChannelInfo());
138 void LeaveVoiceChannel(FVoiceChannelInfo ChannelToLeave);
139 void Update3DPosition(APawn* Pawn);
140 void MutePlayerByPlayerState(const class AProjectXPlayerState* PlayerState, bool bToggle);
141
142 void OnLoginSessionStateChanged(LoginState State);
143 void OnChannelParticipantAdded(const IParticipant& Participant);
144 void OnChannelParticipantRemoved(const IParticipant& Participant);
145 void OnChannelParticipantUpdated(const IParticipant& Participant);
146 void OnChannelAudioStateChanged(const IChannelConnectionState& State);
147 void OnChannelTextStateChanged(const IChannelConnectionState& State);
148 void OnChannelTextMessageReceived(const IChannelTextMessage& Message);
149
150 virtual bool IsInitialized();
151 virtual bool IsLoggedIn();
152
153protected:
154 //Event: Login Complete Connected to Lobby/Party
155 virtual void OnPlayerStateEvent(ASteamBeaconPlayerState* InPlayerState) override;
156 //Event: Host Connection Failed
157 virtual void OnSteamBeaconHostConnectionFailureEvent() override;
158
159private:
160 bool ChangeSoundClassVolume(float Volume, const FSoftObjectPath& SoundClassPath);
161
162public:
170 TSharedPtr<IChannelSession> GetChannelSessionForRoster();
172
173private:
174 static bool bCleanedUp;
175 FTimerHandle DelayDummyHandle;
176 FTimerHandle RejoinSquadTimerHandle;
177 FVivoxCoreModule* VivoxModule;
178 FString LoggedInPlayerName;
179 ChannelId ConnectedPositionalChannel; // You can only be in one Positional channel at a time.
181 CachedProperty<FVector> CachedPosition = CachedProperty<FVector>(FVector());
182 CachedProperty<FVector> CachedForwardVector = CachedProperty<FVector>(FVector());
183 CachedProperty<FVector> CachedUpVector = CachedProperty<FVector>(FVector());
184 FVoiceChannelInfo LastKnownSquadVoiceChannel;
185 TMap<FString, FString> KnownParticipants = TMap<FString, FString>();
186
188 bool Get3DValuesAreDirty() const;
189 void Clear3DValuesAreDirty();
190#endif
191};
DEFINE_LOG_CATEGORY_STATIC(LogVivoxGameInstance, Log, All)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FParticipantUpdated, bool, bIsSelf, const FString &, PlayerName, bool, bIsSpeaking)
Definition: ProjectXPlayerState.h:238
Definition: VivoxGameInstance.h:29
const T & GetValue() const
Definition: VivoxGameInstance.h:36
CachedProperty(T value)
Definition: VivoxGameInstance.h:31
void SetValue(const T &value)
Definition: VivoxGameInstance.h:40
void SetDirty(bool value)
Definition: VivoxGameInstance.h:47
bool m_dirty
Definition: VivoxGameInstance.h:55
T m_value
Definition: VivoxGameInstance.h:56
bool IsDirty() const
Definition: VivoxGameInstance.h:51
Definition: VivoxGameInstance.h:79
bool bLoggedIn
Definition: VivoxGameInstance.h:167
bool bInitializing
Definition: VivoxGameInstance.h:166
FVoiceChannelInfo PartyVoiceChannel
Definition: VivoxGameInstance.h:171
bool bInitialized
Definition: VivoxGameInstance.h:165
bool bRelogging
Definition: VivoxGameInstance.h:169
bool bLoggingIn
Definition: VivoxGameInstance.h:168
IClient * VivoxVoiceClient
Definition: VivoxGameInstance.h:163
AccountId LoggedInAccountID
Definition: VivoxGameInstance.h:164
Definition: VivoxGameInstance.h:22
static void GenerateClientLoginToken(const ILoginSession &LoginSession, FString &OutToken)
Definition: VivoxGameInstance.cpp:32
static void GenerateClientJoinToken(const IChannelSession &ChannelSession, FString &OutToken)
Definition: VivoxGameInstance.cpp:41
Definition: VivoxGameInstance.h:66