StartSessionAdvertisementAsync.StopSessionAdvertisementAsync.

StartSessionAdvertisementAsync and StopSessionAdvertisementAsync C++ API is accessed through the OculusXRColocation interface.StartSessionAdvertisementAsync function takes an array of bytes that acts as metadata as well as a delegate parameter as an argument which will be executed on success or failure. The return type of the API call is TSharedPtr<FStartSessionAdvertisementRequest>.StopSessionAdvertisementAsync function takes only the delegate parameter as an argument that will be executed on success or failure. The return type of the API call is TSharedPtr<FStopSessionAdvertisementRequest>.FStartSessionAdvertisementRequest and FStopSessionAdvertisementRequest types are classes that wrap an underlying AsyncRequest type and the function call will configure and execute the AsyncRequest for you. Completion, both failure and success, will occur on the game thread. Either immediately as the request is executed or after some number of frames.| Delegate | Parameters |
|---|---|
FStartSessionAdvertisementRequest::FCompleteDelegate | FStartSessionAdvertisementRequest::FResultType Result |
FStopSessionAdvertisementRequest::FCompleteDelegate | FStopSessionAdvertisementRequest::FResultType Result |
| Name | Type | Description |
|---|---|---|
TResultType | EColocationResult | The result enum value. |
TValueType | FOculusXRColocationSession | Structure containing the session UUID and Metadata. |
EColocationResult enum values. These values apply to both advertisement and discovery operations.| Value | Description |
|---|---|
Success | Operation succeeded. |
Success_AlreadyAdvertising | Already advertising. Not an error. |
Success_AlreadyDiscovering | Already discovering. Not an error. |
Failure | Generic failure. |
FailureInvalidParameter | Invalid parameter provided. |
FailureDataIsInvalid | Data validation failed. |
NetworkTimeout | Network operation timed out. |
NetworkRequestFailed | Network request failed. |
InsufficientPermissions | Missing required permissions. |
CloudStorageDisabled | Cloud storage is disabled. |
NoDiscoveryMethodAvailable | No discovery method available on device. |
You are not required to use a lambda as your delegate functor, that is only used to simplify this example.
void StartAdvertising(const TArray<uint8>& Metadata)
{
OculusXRColocation::FColocation::StartSessionAdvertisementAsync(
Metadata,
FStartSessionAdvertisementRequest::FCompleteDelegate::CreateLambda([](
const FStartSessionAdvertisementRequest::FResultType& Result)
{
if (Result.IsSuccess())
{
FOculusXRColocationSession session = Result.GetValue();
}
else
{
auto status = Result.GetStatus();
// Do something with the status code on error
}
})
);
}
void StopAdvertising()
{
OculusXRColocation::FColocation::StopSessionAdvertisementAsync(
FStopSessionAdvertisementRequest::FCompleteDelegate::CreateLambda([](
const FStopSessionAdvertisementRequest::FResultType& Result)
{
if (Result.IsSuccess())
{
// Stopped successfully
}
else
{
auto status = Result.GetStatus();
// Do something with the status code on error
}
})
);
}
DiscoverSessionsAsync.StopDiscoverSessions.

DiscoverSessionsAsync and StopDiscoverSessions C++ API is accessed through the OculusXRColocation interface.DiscoverSessionsAsync function takes a completion delegate parameter as an argument which will be executed on success or failure. It also takes an OnSessionFound parameter which will be executed every time a Colocation Session is found. The return type of the API call is TSharedPtr<FDiscoverSessionsRequest>. The FDiscoverSessionsRequest type is a class that wraps an underlying AsyncRequest type and the function call will configure and execute the AsyncRequest for you. Completion, both failure and success, will occur on the game thread. Either immediately as the request is executed or after some number of frames.StopDiscoverSessions function takes only a reference to the FDiscoverSessionsRequest. The return type of the API call is EColocationResult.| Delegate | Parameters |
|---|---|
FDiscoverSessionsRequest::FCompleteDelegate | FDiscoverSessionsRequest::FResultType Result |
FOculusXRColocationSessionFoundDelegate | const FOculusXRColocationSession& Session |
| Name | Type | Description |
|---|---|---|
TResultType | EColocationResult | The result enum value. |
TValueType | TArray<FOculusXRColocationSession> | Array of found colocation sessions. |
You are not required to use a lambda as your delegate functor, that is only used to simplify this example.
TSharedPtr<FDiscoverSessionsRequest> StartDiscovery()
{
auto request = OculusXRColocation::FColocation::DiscoverSessionsAsync(
FDiscoverSessionsRequest::FCompleteDelegate::CreateLambda([](
const FDiscoverSessionsRequest::FResultType& Result)
{
if (Result.IsSuccess())
{
TArray<FOculusXRColocationSession> sessions = Result.GetValue();
}
else
{
auto status = Result.GetStatus();
// Do something with the status code on error
}
}),
FOculusXRColocationSessionFoundDelegate::CreateLambda([](
const FOculusXRColocationSession& Session)
{
// Do something when a session is found
})
);
return request;
}
void StopDiscovery(TSharedPtr<FDiscoverSessionsRequest> Request)
{
auto result = OculusXRColocation::FColocation::StopDiscoverSessions(Request);
if(result != EColocationResult::Success)
{
switch(result)
{
// ... Do whatever you want based on the error code
}
}
}