Quantum 3 3.1.0

Static Public Member Functions | List of all members
Photon.Realtime.AsyncExtensions Class Reference

Extensions methods to wrap Photon Realtime API calls into System.Threading.Tasks. More...

Static Public Member Functions

static Task< RegionHandler > ConnectToNameserverAndWaitForRegionsAsync (this RealtimeClient client, AppSettings appSettings, bool pingRegions=true, AsyncConfig config=null)
 Connect to the name server and wait until ping results are available. Will work when client is already connected or connecting to nameserver. Will fail when connected to another server type. The client connection will be disconnected AFTER returning the result. It's not supposed to be useable. More...
 
static Task ConnectUsingSettingsAsync (this RealtimeClient client, AppSettings appSettings, AsyncConfig config=null)
 Connect to master server. More...
 
static Task< short > CreateAndJoinRoomAsync (this RealtimeClient client, EnterRoomArgs enterRoomArgs, bool throwOnError=true, AsyncConfig config=null)
 Create and join a room. More...
 
static AsyncOperationHandler CreateConnectionHandler (this RealtimeClient client, bool throwOnErrors=true, AsyncConfig config=null)
 Create a AsyncOperationHandler instance, sets up the Photon callbacks, schedules removing them, create a connection service task. The handler will monitor the Photon callbacks and complete, fault accordingly. AsyncOperationHandler.Task can complete with ErrorCode.Ok, exception on errors and a timeout OperationTimeoutException. More...
 
static void CreateServiceTask (this RealtimeClient client, CancellationToken token, TaskCompletionSource< short > completionSource=null, IDisposable disposable=null, AsyncConfig config=null)
 Starts a task that calls RealtimeClient.Service() every updateIntervalMs milliseconds. The task is stopped by the cancellation token from AsyncOperationHandler.Token. It will set an exception on the AsyncOperationHandler TaskCompletionSource if after the timeout it is still not completed. More...
 
static Task DisconnectAsync (this RealtimeClient client, AsyncConfig config=null)
 Disconnects the client. More...
 
static Task< short > JoinLobbyAsync (this RealtimeClient client, TypedLobby lobby=null, bool throwOnError=true, AsyncConfig config=null)
 Join a Lobby More...
 
static Task< short > JoinOrCreateRoomAsync (this RealtimeClient client, EnterRoomArgs enterRoomArgs, bool throwOnError=true, AsyncConfig config=null)
 Join or create room. More...
 
static Task< short > JoinRandomOrCreateRoomAsync (this RealtimeClient client, JoinRandomRoomArgs joinRandomRoomParams=null, EnterRoomArgs enterRoomArgs=null, bool throwOnError=true, AsyncConfig config=null)
 Join random or create room More...
 
static Task< short > JoinRandomRoomAsync (this RealtimeClient client, JoinRandomRoomArgs joinRandomRoomParams=null, bool throwOnError=true, AsyncConfig config=null)
 Join random room More...
 
static Task< short > JoinRoomAsync (this RealtimeClient client, EnterRoomArgs enterRoomArgs, bool throwOnError=true, AsyncConfig config=null)
 Join room. More...
 
static Task< short > LeaveLobbyAsync (this RealtimeClient client, bool throwOnError=true, AsyncConfig config=null)
 Leave a Lobby More...
 
static Task LeaveRoomAsync (this RealtimeClient client, bool becomeInactive=false, bool throwOnError=true, AsyncConfig config=null)
 Leave room More...
 
static Task< short > ReconnectAndRejoinAsync (this RealtimeClient client, bool throwOnError=true, AsyncConfig config=null)
 
static Task< short > ReconnectAndRejoinAsync (this RealtimeClient client, object ticket=null, bool throwOnError=true, AsyncConfig config=null)
 Runs reconnect and rejoin. More...
 
static Task ReconnectToMasterAsync (this RealtimeClient client, AsyncConfig config=null)
 Reconnect to master server, re-using the existing authentication token (RealtimeClient.AuthValues). More...
 
static Task< short > RejoinRoomAsync (this RealtimeClient client, string roomName, object ticket=null, bool throwOnError=true, AsyncConfig config=null)
 Rejoin room. More...
 
static Task WaitForDisconnect (this RealtimeClient client, AsyncConfig config=null)
 Returns a task that is completed when the connection disconnects. This does not create a service handler not does the task timeout. More...
 

Detailed Description

Extensions methods to wrap Photon Realtime API calls into System.Threading.Tasks.

Member Function Documentation

◆ ConnectUsingSettingsAsync()

static Task Photon.Realtime.AsyncExtensions.ConnectUsingSettingsAsync ( this RealtimeClient  client,
AppSettings  appSettings,
AsyncConfig  config = null 
)
inlinestatic

Connect to master server.

Parameters
clientClient.
appSettingsApp settings.
configOptional AsyncConfig, otherwise AsyncConfig.Global is used.
Returns
When connected to master server callback was called. Continues immediately if the client is connected to the Master Server (then no AppSettings are changed).
Exceptions
DisconnectExceptionIs thrown when the connection is terminated.
AuthenticationFailedExceptionIs thrown when the authentication failed.
OperationStartExceptionIs thrown when the operation could not be started.
OperationExceptionIs thrown when the operation completed unsuccessfully.
OperationTimeoutExceptionIs thrown when the operation timed out.
OperationCanceledExceptionIs thrown when the operation have been canceled (AsyncConfig.CancellationSource).

◆ ReconnectAndRejoinAsync()

static Task<short> Photon.Realtime.AsyncExtensions.ReconnectAndRejoinAsync ( this RealtimeClient  client,
object  ticket = null,
bool  throwOnError = true,
AsyncConfig  config = null 
)
inlinestatic

Runs reconnect and rejoin.

Parameters
clientClient object should be in Disconnected state.
ticketOptional Matchmaking Ticket.
throwOnErrorSet ErrorCode as result on RoomJoinFailed.
configOptional AsyncConfig, otherwise AsyncConfig.Global is used.
Returns
Returns when inside the room or error
Exceptions
DisconnectExceptionIs thrown when the connection terminated.
OperationStartExceptionIs thrown when the operation could not be started.
OperationExceptionIs thrown when the operation completed unsuccessfully.
OperationTimeoutExceptionIs thrown when the operation timed out.
OperationCanceledExceptionIs thrown when the operation have been canceled (AsyncConfig.CancellationSource).

◆ ReconnectToMasterAsync()

static Task Photon.Realtime.AsyncExtensions.ReconnectToMasterAsync ( this RealtimeClient  client,
AsyncConfig  config = null 
)
inlinestatic

Reconnect to master server, re-using the existing authentication token (RealtimeClient.AuthValues).

Authentication errors are not signalled as AuthenticationFailedException here (unlike ConnectUsingSettingsAsync). The server rejects the token with an error response and the client disconnects, so an expired or invalid token arrives as a DisconnectException. Check its DisconnectException.Cause for DisconnectCause.AuthenticationTicketExpired, DisconnectCause.InvalidAuthentication or DisconnectCause.CustomAuthenticationFailed to tell an auth failure apart from a network drop. Recovering from those means setting fresh RealtimeClient.AuthValues and running a full ConnectUsingSettingsAsync.

RealtimeClient.ReconnectToMaster only checks that a token is present, not whether it expired.

Parameters
clientClient object should be in Disconnected state.
configOptional AsyncConfig, otherwise AsyncConfig.Global is used.
Returns
Returns when connected to the Master Server (OnConnectedToMaster was called).
Exceptions
DisconnectExceptionIs thrown when the connection terminated, including when the token was rejected (see remarks).
OperationStartExceptionIs thrown when the operation could not be started (client still connected, no known Master Server address or no token).
OperationTimeoutExceptionIs thrown when the operation timed out.
OperationCanceledExceptionIs thrown when the operation have been canceled (AsyncConfig.CancellationSource).

◆ DisconnectAsync()

static Task Photon.Realtime.AsyncExtensions.DisconnectAsync ( this RealtimeClient  client,
AsyncConfig  config = null 
)
inlinestatic

Disconnects the client.

Parameters
clientClient.
configOptional AsyncConfig, otherwise AsyncConfig.Global is used.
Returns
Returns when the client has successfully disconnected
Exceptions
DisconnectExceptionIs thrown when the connection terminated.
OperationStartExceptionIs thrown when the operation could not be started.
OperationExceptionIs thrown when the operation completed unsuccessfully.
OperationTimeoutExceptionIs thrown when the operation timed out.
OperationCanceledExceptionIs thrown when the operation have been canceled (AsyncConfig.CancellationSource).

◆ ConnectToNameserverAndWaitForRegionsAsync()

static Task<RegionHandler> Photon.Realtime.AsyncExtensions.ConnectToNameserverAndWaitForRegionsAsync ( this RealtimeClient  client,
AppSettings  appSettings,
bool  pingRegions = true,
AsyncConfig  config = null 
)
inlinestatic

Connect to the name server and wait until ping results are available. Will work when client is already connected or connecting to nameserver. Will fail when connected to another server type. The client connection will be disconnected AFTER returning the result. It's not supposed to be useable.

A client that is already connected to the Name Server gets sent an OpGetRegions by this method. A client that is still connecting to it sends that operation by itself, unless its AppSettings.FixedRegion is set. That case can not produce a region list, so it fails with an OperationStartException right away (disconnect the client first).

Parameters
clientClient object.
appSettingsPhoton AppSettings, only uses AppId.
pingRegionsPing each region, takes longer to complete.
configAsync config.
Returns
RegionHandler with filled out EnabledRegions
Exceptions
DisconnectExceptionIs thrown when the connection terminated.
OperationStartExceptionIs thrown when the operation could not be started.
OperationExceptionIs thrown when the operation completed unsuccessfully.
OperationTimeoutExceptionIs thrown when the operation timed out.
OperationCanceledExceptionIs thrown when the operation have been canceled (AsyncConfig.CancellationSource).

◆ CreateAndJoinRoomAsync()

static Task<short> Photon.Realtime.AsyncExtensions.CreateAndJoinRoomAsync ( this RealtimeClient  client,
EnterRoomArgs  enterRoomArgs,
bool  throwOnError = true,
AsyncConfig  config = null 
)
inlinestatic

Create and join a room.

The lobby is only left when the client leaves the Master Server to enter a room on a Game Server (InLobby becomes false). A failure on the Master Server keeps the client in the lobby. The lobby is never re-joined automatically. When the entry fails on the Game Server, the client returns to the Master Server before this task completes, so JoinLobbyAsync can be called right after it.

Parameters
clientClient object.
enterRoomArgsEnter room params.
throwOnErrorSet ErrorCode as result on RoomCreateFailed or RoomJoinFailed.
configOptional AsyncConfig, otherwise AsyncConfig.Global is used.
Returns
When the room has been entered
Exceptions
DisconnectExceptionIs thrown when the connection terminated.
OperationStartExceptionIs thrown when the operation could not be started.
OperationExceptionIs thrown when the operation completed unsuccessfully.
OperationTimeoutExceptionIs thrown when the operation timed out.
OperationCanceledExceptionIs thrown when the operation have been canceled (AsyncConfig.CancellationSource).

◆ JoinRoomAsync()

static Task<short> Photon.Realtime.AsyncExtensions.JoinRoomAsync ( this RealtimeClient  client,
EnterRoomArgs  enterRoomArgs,
bool  throwOnError = true,
AsyncConfig  config = null 
)
inlinestatic

Join room.

The lobby is only left when the client leaves the Master Server to enter a room on a Game Server (InLobby becomes false). A failure on the Master Server keeps the client in the lobby. The lobby is never re-joined automatically. When the entry fails on the Game Server, the client returns to the Master Server before this task completes, so JoinLobbyAsync can be called right after it.

Parameters
clientClient object.
enterRoomArgsEnter room params.
throwOnErrorSet ErrorCode as result when JoinRoomFailed.
configOptional AsyncConfig, otherwise AsyncConfig.Global is used.
Returns
When room has been entered
Exceptions
DisconnectExceptionIs thrown when the connection terminated.
OperationStartExceptionIs thrown when the operation could not be started.
OperationExceptionIs thrown when the operation completed unsuccessfully.
OperationTimeoutExceptionIs thrown when the operation timed out.
OperationCanceledExceptionIs thrown when the operation have been canceled (AsyncConfig.CancellationSource).

◆ RejoinRoomAsync()

static Task<short> Photon.Realtime.AsyncExtensions.RejoinRoomAsync ( this RealtimeClient  client,
string  roomName,
object  ticket = null,
bool  throwOnError = true,
AsyncConfig  config = null 
)
inlinestatic

Rejoin room.

The lobby is only left when the client leaves the Master Server to enter a room on a Game Server (InLobby becomes false). A failure on the Master Server keeps the client in the lobby. The lobby is never re-joined automatically. When the entry fails on the Game Server, the client returns to the Master Server before this task completes, so JoinLobbyAsync can be called right after it.

Parameters
clientClient object.
roomNameRoom name to rejoin.
ticketMatchmaking Ticket for this user and room. Can be null if not used.
throwOnErrorSet ErrorCode as result when JoinRoomFailed.
configOptional AsyncConfig, otherwise AsyncConfig.Global is used.
Returns
When room has been entered
Exceptions
DisconnectExceptionIs thrown when the connection terminated.
OperationStartExceptionIs thrown when the operation could not be started.
OperationExceptionIs thrown when the operation completed unsuccessfully.
OperationTimeoutExceptionIs thrown when the operation timed out.
OperationCanceledExceptionIs thrown when the operation have been canceled (AsyncConfig.CancellationSource).

◆ JoinOrCreateRoomAsync()

static Task<short> Photon.Realtime.AsyncExtensions.JoinOrCreateRoomAsync ( this RealtimeClient  client,
EnterRoomArgs  enterRoomArgs,
bool  throwOnError = true,
AsyncConfig  config = null 
)
inlinestatic

Join or create room.

The lobby is only left when the client leaves the Master Server to enter a room on a Game Server (InLobby becomes false). A failure on the Master Server keeps the client in the lobby. The lobby is never re-joined automatically. When the entry fails on the Game Server, the client returns to the Master Server before this task completes, so JoinLobbyAsync can be called right after it.

Parameters
clientClient object.
enterRoomArgsEnter room params.
throwOnErrorSet ErrorCode as result when JoinRoomFailed.
configOptional AsyncConfig, otherwise AsyncConfig.Global is used.
Returns
When room has been entered
Exceptions
DisconnectExceptionIs thrown when the connection terminated.
OperationStartExceptionIs thrown when the operation could not be started.
OperationExceptionIs thrown when the operation completed unsuccessfully.
OperationTimeoutExceptionIs thrown when the operation timed out.
OperationCanceledExceptionIs thrown when the operation have been canceled (AsyncConfig.CancellationSource).

◆ JoinRandomOrCreateRoomAsync()

static Task<short> Photon.Realtime.AsyncExtensions.JoinRandomOrCreateRoomAsync ( this RealtimeClient  client,
JoinRandomRoomArgs  joinRandomRoomParams = null,
EnterRoomArgs  enterRoomArgs = null,
bool  throwOnError = true,
AsyncConfig  config = null 
)
inlinestatic

Join random or create room

The lobby is only left when the client leaves the Master Server to enter a room on a Game Server (InLobby becomes false). A failure on the Master Server keeps the client in the lobby. The lobby is never re-joined automatically. When the entry fails on the Game Server, the client returns to the Master Server before this task completes, so JoinLobbyAsync can be called right after it.

Parameters
clientClient object.
joinRandomRoomParamsJoin random room params.
enterRoomArgsEnter room params.
throwOnErrorSet ErrorCode as result when operation fails with ErrorCode.
configOptional AsyncConfig, otherwise AsyncConfig.Global is used.
Returns
When inside a room
Exceptions
DisconnectExceptionIs thrown when the connection terminated.
OperationStartExceptionIs thrown when the operation could not be started.
OperationExceptionIs thrown when the operation completed unsuccessfully.
OperationTimeoutExceptionIs thrown when the operation timed out.
OperationCanceledExceptionIs thrown when the operation have been canceled (AsyncConfig.CancellationSource).

◆ JoinRandomRoomAsync()

static Task<short> Photon.Realtime.AsyncExtensions.JoinRandomRoomAsync ( this RealtimeClient  client,
JoinRandomRoomArgs  joinRandomRoomParams = null,
bool  throwOnError = true,
AsyncConfig  config = null 
)
inlinestatic

Join random room

The lobby is only left when the client leaves the Master Server to enter a room on a Game Server (InLobby becomes false). A failure on the Master Server keeps the client in the lobby. The lobby is never re-joined automatically. When the entry fails on the Game Server, the client returns to the Master Server before this task completes, so JoinLobbyAsync can be called right after it.

Parameters
clientClient object.
joinRandomRoomParamsJoin random room params.
throwOnErrorSet ErrorCode as result when operation fails with ErrorCode.
configOptional AsyncConfig, otherwise AsyncConfig.Global is used.
Returns
When inside a room
Exceptions
DisconnectExceptionIs thrown when the connection terminated.
OperationStartExceptionIs thrown when the operation could not be started.
OperationExceptionIs thrown when the operation completed unsuccessfully.
OperationTimeoutExceptionIs thrown when the operation timed out.
OperationCanceledExceptionIs thrown when the operation have been canceled (AsyncConfig.CancellationSource).

◆ LeaveRoomAsync()

static Task Photon.Realtime.AsyncExtensions.LeaveRoomAsync ( this RealtimeClient  client,
bool  becomeInactive = false,
bool  throwOnError = true,
AsyncConfig  config = null 
)
inlinestatic

Leave room

The task completes when the client is back on the Master Server. The lobby the client was in before it entered the room is not re-joined automatically (InLobby is false): call JoinLobbyAsync if needed.

Parameters
clientClient object.
becomeInactiveIf true, this player becomes inactive in the game and can return later (if PlayerTTL of the room is != 0).
throwOnErrorSet ErrorCode as result when operation fails with ErrorCode.
configOptional AsyncConfig, otherwise AsyncConfig.Global is used.
Returns
When the room has been left and the connection to the master server was resumed.
Exceptions
DisconnectExceptionIs thrown when the connection terminated.
OperationStartExceptionIs thrown when the operation could not be started.
OperationExceptionIs thrown when the operation completed unsuccessfully.
OperationTimeoutExceptionIs thrown when the operation timed out.
OperationCanceledExceptionIs thrown when the operation have been canceled (AsyncConfig.CancellationSource).

◆ JoinLobbyAsync()

static Task<short> Photon.Realtime.AsyncExtensions.JoinLobbyAsync ( this RealtimeClient  client,
TypedLobby  lobby = null,
bool  throwOnError = true,
AsyncConfig  config = null 
)
inlinestatic

Join a Lobby

Parameters
clientClient object.
lobbyLobby to Join.
throwOnErrorSet ErrorCode as result when operation fails with ErrorCode.
configOptional AsyncConfig, otherwise AsyncConfig.Global is used.
Returns
When inside a Lobby

◆ LeaveLobbyAsync()

static Task<short> Photon.Realtime.AsyncExtensions.LeaveLobbyAsync ( this RealtimeClient  client,
bool  throwOnError = true,
AsyncConfig  config = null 
)
inlinestatic

Leave a Lobby

Parameters
clientClient object.
throwOnErrorSet ErrorCode as result when operation fails with ErrorCode.
configOptional AsyncConfig, otherwise AsyncConfig.Global is used.
Returns
When inside a Lobby

◆ CreateConnectionHandler()

static AsyncOperationHandler Photon.Realtime.AsyncExtensions.CreateConnectionHandler ( this RealtimeClient  client,
bool  throwOnErrors = true,
AsyncConfig  config = null 
)
inlinestatic

Create a AsyncOperationHandler instance, sets up the Photon callbacks, schedules removing them, create a connection service task. The handler will monitor the Photon callbacks and complete, fault accordingly. AsyncOperationHandler.Task can complete with ErrorCode.Ok, exception on errors and a timeout OperationTimeoutException.

Parameters
clientClient.
throwOnErrorsThe default implementation will throw an exception on every unexpected result, set this to false to return a result ErrorCode instead.
configOptional AsyncConfig, otherwise AsyncConfig.Global is used.
Returns
Photon Connection Handler object

◆ CreateServiceTask()

static void Photon.Realtime.AsyncExtensions.CreateServiceTask ( this RealtimeClient  client,
CancellationToken  token,
TaskCompletionSource< short >  completionSource = null,
IDisposable  disposable = null,
AsyncConfig  config = null 
)
inlinestatic

Starts a task that calls RealtimeClient.Service() every updateIntervalMs milliseconds. The task is stopped by the cancellation token from AsyncOperationHandler.Token. It will set an exception on the AsyncOperationHandler TaskCompletionSource if after the timeout it is still not completed.

Parameters
clientClient.
tokenCancellation token to stop the update loop.
completionSourceCompletion source is notified on an exception in Service().
disposableOperationHandler requires disposing.
configOptional AsyncConfig, otherwise AsyncConfig.Global is used.

◆ WaitForDisconnect()

static Task Photon.Realtime.AsyncExtensions.WaitForDisconnect ( this RealtimeClient  client,
AsyncConfig  config = null 
)
inlinestatic

Returns a task that is completed when the connection disconnects. This does not create a service handler not does the task timeout.

Parameters
clientClient object.
configAsync config.
Returns
Task that completes upon disconnect
Exceptions
OperationCanceledExceptionIs thrown when the operation have been canceled (AsyncConfig.CancellationSource).