Forum Discussion
eXifreXi
7 years agoExplorer
How to react to an incoming Session Invite by a Friend?
Hello there, I've looked into adding basic support for "Invite Friend to Session", "Accept Invite", "Reject Invite" and "React to Invite". Now I did things like these with Steam already, but it se...
eXifreXi
7 years agoExplorer
Alright, think I got it to work. For anyone being interested, here are parts of my code for this:
GameInstance.cpp
GameInstance.h
When receiving the Invite via "OnRoomInviteReceived", you can grab the RoomID like this:
And then perform the GetRoom request, to get more information about the room, such as the Owner (so the one who probably send you the invite):
And finall in the "OnRoomReceived" function, you can grab the OwnerID and more like this:
Hope this helps other users who want to display Invites ingame.
You can probably also listen to the Accept Message of the Oculus Interface Invite.
That would probably just be binding to the default SessionInterface delegate "OnSessionUserInviteAccepted".
At least as far as I can tell. Haven't tested it yet.
Cheers
GameInstance.cpp
void UMRGameInstance::Init()
{
Super::Init();
IOnlineSubsystem* OnlineSub = Online::GetSubsystem(GetWorld(), OCULUS_SUBSYSTEM);
if (OnlineSub)
{
// This is not safe, but even Epic advises us to do so.
// And sadly we need the OculusSubsystem, not just the Interface
OculusSubsystem = static_cast<FOnlineSubsystemOculus*>(OnlineSub);
// Listen to the RoomGet and RoomInviteReceived delegates.
// Oculus pops messages already on tick, so we have to register to their queue.
if (OculusSubsystem)
{
OnRoomReceivedDelegate_Handle = OculusSubsystem->GetNotifDelegate(ovrMessage_Room_Get).AddUObject(this, &UMRGameInstance::OnRoomReceived);
OnRoomInviteReceivedDelegate_Handle = OculusSubsystem->GetNotifDelegate(ovrMessage_Notification_Room_InviteReceived).AddUObject(this, &UMRGameInstance::OnRoomInviteReceived);
}
}
}
void UMRGameInstance::Shutdown()
{
// Make sure to clean these delegates up again!
if (OnRoomInviteReceivedDelegate_Handle.IsValid() && OculusSubsystem)
{
OculusSubsystem->RemoveNotifDelegate(ovrMessage_Notification_Room_InviteReceived, OnRoomInviteReceivedDelegate_Handle);
OnRoomInviteReceivedDelegate_Handle.Reset();
OculusSubsystem->RemoveNotifDelegate(ovrMessage_Room_Get, OnRoomReceivedDelegate_Handle);
OnRoomReceivedDelegate_Handle.Reset();
}
Super::Shutdown();
}
GameInstance.h
/** Pointer to the Oculus Subsystem. */
FOnlineSubsystemOculus* OculusSubsystem;
/** Delegate Handle. */
FDelegateHandle OnRoomInviteReceivedDelegate_Handle;
FDelegateHandle OnRoomReceivedDelegate_Handle;
/** Handles the Room Invite Message. */
void OnRoomInviteReceived(ovrMessageHandle Message, bool bIsError);
/** Handles receiving the room itself. */
void OnRoomReceived(ovrMessageHandle Message, bool bIsError);
virtual void Init() override;
virtual void Shutdown() override;
When receiving the Invite via "OnRoomInviteReceived", you can grab the RoomID like this:
// Retrieve RoomID
ovrRoomInviteNotificationHandle RoomInviteHandle = ovr_Message_GetRoomInviteNotification(Message);
ovrID RoomID = ovr_RoomInviteNotification_GetRoomID(RoomInviteHandle);And then perform the GetRoom request, to get more information about the room, such as the Owner (so the one who probably send you the invite):
// This returns an "ovrRequest" which you can save in an array of pending request.
// When receiving the response in "OnRoomReceived" you could use "ovr_Message_GetRequestID(Message)" to receive an "ovrRequest" again and simple compare them. They are just "uint64_t" variables.
ovr_Room_Get(RoomID)And finall in the "OnRoomReceived" function, you can grab the OwnerID and more like this:
// Retrieve OwnerID
ovrUserHandle Owner = ovr_Room_GetOwner(RoomHandle);
ovrID OwnerID = ovr_User_GetID(Owner);
// FUniqueNetIdOculus is a child of Epic UniqueNetId
// From here on I search for a FriendSession with this ID and then join that session via the normal JoinSession code
TSharedPtr<const FUniqueNetIdOculus> OculusOwnerID = MakeShareable(new FUniqueNetIdOculus(OwnerID));
Hope this helps other users who want to display Invites ingame.
You can probably also listen to the Accept Message of the Oculus Interface Invite.
That would probably just be binding to the default SessionInterface delegate "OnSessionUserInviteAccepted".
At least as far as I can tell. Haven't tested it yet.
Cheers
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device