CotC C# SDK for Unity  v1.4.0.1
Making social games is easy !
Properties | Public Member Functions | Public Attributes | List of all members
CotcSdk.DomainEventLoop Class Reference

Description

This class is responsible for polling the server waiting for new events. You should instantiate one and manage its lifecycle as the state of the application changes.

A loop is typically managed through the Gamer.StartEventLoop method (loops are always running as an authenticated gamer) and should be started once the gamer is logged in, and stopped at logout. The loop is automatically paused by the system when the user leaves the application, and automatically restarted as well.

void Login() {
Cloud.LoginAnonymous()
.Then(gamer => {
loop = gamer.StartEventLoop();
loop.ReceivedEvent += ReceivedEvent;
});
}
void Logout() {
loop.Stop();
}
void ReceivedEvent(DomainEventLoop sender, EventLoopArgs e) {
Debug.Log("Received event of type " + e.Message.Type + ": " + e.Message.ToJson());
}

Properties

String Domain [get]
 The domain on which this loop is listening. More...
 
Gamer Gamer [get]
 
EventLoopHandler ReceivedEvent
 This event is raised when an event is received. More...
 

Public Member Functions

 DomainEventLoop (Gamer gamer, String domain=Common.PrivateDomain, int iterationDuration=590)
 You need valid credentials in order to instantiate this class. Use Cloud.Login* methods for that purpose. Once the object is created, you need to start the coroutine, please look at the other methods available. More...
 
DomainEventLoop Start ()
 Starts the coroutine. Call this upon initialization. More...
 
DomainEventLoop Stop ()
 Will stop the event coroutine. Might take some time until the current request finishes. You should not use this object for other purposes later on. In particular, do not start it again. More...
 
DomainEventLoop Suspend ()
 Suspends the event coroutine. More...
 
DomainEventLoop Resume ()
 Resumes a suspended event coroutine. More...
 

Public Attributes

bool Stopped = false
 
int LoopIterationDuration
 
const float PopEventDelayCoroutineHold = 3f
 

Constructor & Destructor Documentation

◆ DomainEventLoop()

CotcSdk.DomainEventLoop.DomainEventLoop ( Gamer  gamer,
String  domain = Common.PrivateDomain,
int  iterationDuration = 590 
)

You need valid credentials in order to instantiate this class. Use Cloud.Login* methods for that purpose. Once the object is created, you need to start the coroutine, please look at the other methods available.

Parameters
gamerThe gamer object received from a login or similar function. Used to authenticate (receive events related to the said gamer).
domainThe domain on which to listen for events. Note that you may create multiple event loops, especially if you are using multiple domains. The default domain, that you should use unless you are explicitly using multiple domains, is the private domain.
iterationDurationSets a custom timeout in seconds for the long polling event loop. Should be used with care and set to a high value (at least 60). Defaults to 590 (~10 min).

Property Documentation

◆ Domain

String CotcSdk.DomainEventLoop.Domain
get

The domain on which this loop is listening.

◆ ReceivedEvent

EventLoopHandler CotcSdk.DomainEventLoop.ReceivedEvent
addremove

This event is raised when an event is received.

Member Function Documentation

◆ Resume()

DomainEventLoop CotcSdk.DomainEventLoop.Resume ( )

Resumes a suspended event coroutine.

◆ Start()

DomainEventLoop CotcSdk.DomainEventLoop.Start ( )

Starts the coroutine. Call this upon initialization.

◆ Stop()

DomainEventLoop CotcSdk.DomainEventLoop.Stop ( )

Will stop the event coroutine. Might take some time until the current request finishes. You should not use this object for other purposes later on. In particular, do not start it again.

◆ Suspend()

DomainEventLoop CotcSdk.DomainEventLoop.Suspend ( )

Suspends the event coroutine.