NAV
Unity (UniTask) Unity Unity (Legacy) Unreal Engine 5 Unreal Engine 4

GS2-Chat

GS2-SDK for Game Engine Reference

SDK for Game Engine

Models

EzRoom

Room

A room represents the area within which chat messages can be delivered.
GS2-Chat rooms do not have the concept of participation.
Therefore, you do not need to be a member of a room to receive messages, as long as you know the name of the room.

If you wish to limit the number of game players who can view the messages in a room, there are two options.
The first is to set a password for the room.
Second, you can whitelist the room and limit the game players by setting their user IDs in the whitelist.

Note that if you set a password, even the game administrator will not be able to retrieve messages without knowing the password.
This is because this may fall under the secret of communication stipulated in the Constitution of Japan.

If you subscribe to a room, you can receive GS2-Gateway push notifications when new messages are sent to the room.
By using this notification function, you will be able to know if there are any new messages without polling the room.

Type Description
name string Room Name
metadata string metadata

EzMessage

Message

Messages are data posted to a room.

It has a field called category, which allows classification of messages.
For example, a category of 0 is interpreted as a normal text message, while a category of
If 1, the client can be run to process it as a stamp (sticker).

Posted messages are automatically deleted one hour after submission.
This time cannot be changed.

Type Description
name string Message name
roomName string Room Name
userId string User Id
category int Type number when you want to classify message types.
metadata string metadata
createdAt long Datetime of creation

EzSubscribe

Subscribe

By subscribing to a room, you will be instantly informed of new messages for that room.
When subscribing, you can specify the category of the message.
This feature can be used to subscribe only to messages that are of high importance to you.

Type Description
userId string User Id
roomName string Room name to subscribe to
notificationTypes List<EzNotificationType> Category list to receive notifications of new messages

EzNotificationType

Type Description
category int Categories for which you receive new message notifications
enableTransferMobilePushNotification bool Transfer to mobile push notifications when you were offline?

Methods

createRoom

createRoom

///////////////////////////////////////////////////////////////
// New Experience (Enabled UniTask)
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;
#if GS2_ENABLE_UNITASK
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.Linq;
#endif

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
await profile.InitializeAsync();
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    );
    var result = await domain.CreateRoomAsync(
        name: "room-0001",
        metadata: null,
        password: null,
        whiteListUserIds: null
    );
    var item = await result.ModelAsync();
}
///////////////////////////////////////////////////////////////
// New Experience
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
var future = profile.Initialize();
yield return future;
if (future.Error != null)
{
    onError.Invoke(future.Error, null);
    yield break;
}
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    );
    var future = domain.CreateRoom(
        name: "room-0001",
        metadata: null,
        password: null,
        whiteListUserIds: null
    );
    yield return future;
    if (future.Error != null)
    {
        onError.Invoke(future.Error, null);
        yield break;
    }
    var future2 = future.Result.Model();
    yield return future2;
    if (future2.Error != null)
    {
        onError.Invoke(future2.Error, null);
        yield break;
    }
    var result = future2.Result;
}
///////////////////////////////////////////////////////////////
// Legacy Experience
///////////////////////////////////////////////////////////////

using Gs2.Core.AsyncResult;
using Gs2.Gs2Account.Unity.Result;
using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);

{
    AsyncResult<object> asyncResult = null;
    var current = profile.Initialize(
        r => { asyncResult = r; }
    );
    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }
}
var gs2 = new Gs2.Unity.Client(profile);

// Up to this line is the initialization process.

{
    AsyncResult<EzCreateRoomResult> asyncResult = null;
    var current = gs2.Chat.CreateRoom(
        callback: r => { asyncResult = r; },
        session: session,
        namespaceName: "namespace-0001",
        name: "room-0001",
        accessToken: "accessToken-0001",
        metadata: null,
        password: null,
        whiteListUserIds: null
    );

    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }

    var result = asyncResult.Result;
    var item = result.Item;
}

const auto Profile = MakeShared<Gs2::UE5::Util::FProfile>(
    "your client id",
    "your client secret",
    Gs2::Core::Model::ERegion::ApNorthEast1,
    MakeShareable<Gs2::UE5::Util::IReOpener>(new Gs2::UE5::Util::FGs2BasicReOpener())
);

Gs2::UE5::Core::Domain::FGs2DomainPtr Gs2;
{
    const auto Future = Profile->Initialize();
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;

    Gs2 = Future->GetTask().Result();
    Future->EnsureCompletion();
}

// Up to this line is the initialization process.

{
    const auto Domain = Gs2->Chat->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    );
    const auto Future = Domain->CreateRoom(
        "room-0001", // name
        nullptr, // metadata
        nullptr, // password
        nullptr // whiteListUserIds
    );
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;

    // obtain changed values / result values
    const auto Future2 = Future->GetTask().Result()->Model();
    Future2->StartSynchronousTask();
    if (!TestFalse(WHAT, Future2->GetTask().IsError())) return false;
    const auto Result = Future2->GetTask().Result();
}
ProfilePtr = std::make_shared<gs2::ez::Profile>(
    TCHAR_TO_ANSI(*ClientId),
    TCHAR_TO_ANSI(*ClientSecret),
    gs2::ez::Gs2BasicReopener()
);

ClientPtr = std::make_shared<gs2::ez::Client>(
    *ProfilePtr
);

ProfilePtr->initialize(
    [this](gs2::ez::Profile::AsyncInitializeResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "profile.initialize failed.");
        }
        else
        {
            AccountCreate();
        }
    }
);

// Up to this line is the initialization process.

ClientPtr->chat.createRoom(
    [](gs2::ez::account::AsyncEzCreateRoomResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "chat.createRoom failed.");
        }
        else
        {
            Item = r.getResult()->getItem();
        }
    },
    ProfilePtr->getGs2Session(),
    TCHAR_TO_ANSI("namespace-0001") // namespaceName,
    TCHAR_TO_ANSI("room-0001"), // name
    TCHAR_TO_ANSI("accessToken-0001"), // accessToken
    TCHAR_TO_ANSI(null), // metadata
    TCHAR_TO_ANSI(null), // password
    null // whiteListUserIds
);

Creating a Room

Fails if the namespace settings do not allow game players to create rooms.
If a password is set for a room, the player will not be able to speak unless the password matches when he/she speaks.



Request

Type Require Default Limitation Description
namespaceName string ~ 32 chars Namespace name
name string UUID ~ 128 chars Room Name
accessToken string ~ 128 chars Owner User ID
metadata string ~ 1024 chars metadata
password string ~ 128 chars Password required to access the room
whiteListUserIds List<string> [] List of user IDs with access to the room

Result

Type Description
item EzRoom Room created

deleteRoom

deleteRoom

///////////////////////////////////////////////////////////////
// New Experience (Enabled UniTask)
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;
#if GS2_ENABLE_UNITASK
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.Linq;
#endif

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
await profile.InitializeAsync();
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Room(
        roomName: "room-0001",
        password: null
    );
    var result = await domain.DeleteRoomAsync(
    );
}
///////////////////////////////////////////////////////////////
// New Experience
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
var future = profile.Initialize();
yield return future;
if (future.Error != null)
{
    onError.Invoke(future.Error, null);
    yield break;
}
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Room(
        roomName: "room-0001",
        password: null
    );
    var future = domain.DeleteRoom(
    );
    yield return future;
    if (future.Error != null)
    {
        onError.Invoke(future.Error, null);
        yield break;
    }
}
///////////////////////////////////////////////////////////////
// Legacy Experience
///////////////////////////////////////////////////////////////

using Gs2.Core.AsyncResult;
using Gs2.Gs2Account.Unity.Result;
using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);

{
    AsyncResult<object> asyncResult = null;
    var current = profile.Initialize(
        r => { asyncResult = r; }
    );
    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }
}
var gs2 = new Gs2.Unity.Client(profile);

// Up to this line is the initialization process.

{
    AsyncResult<EzDeleteRoomResult> asyncResult = null;
    var current = gs2.Chat.DeleteRoom(
        callback: r => { asyncResult = r; },
        session: session,
        namespaceName: "namespace-0001",
        roomName: "room-0001",
        accessToken: "accessToken-0001"
    );

    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }

    var result = asyncResult.Result;
    var item = result.Item;
}

const auto Profile = MakeShared<Gs2::UE5::Util::FProfile>(
    "your client id",
    "your client secret",
    Gs2::Core::Model::ERegion::ApNorthEast1,
    MakeShareable<Gs2::UE5::Util::IReOpener>(new Gs2::UE5::Util::FGs2BasicReOpener())
);

Gs2::UE5::Core::Domain::FGs2DomainPtr Gs2;
{
    const auto Future = Profile->Initialize();
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;

    Gs2 = Future->GetTask().Result();
    Future->EnsureCompletion();
}

// Up to this line is the initialization process.

{
    const auto Domain = Gs2->Chat->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    )->Room(
        "room-0001", // roomName
        nullptr // password
    );
    const auto Future = Domain->DeleteRoom(
    );
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;
}
ProfilePtr = std::make_shared<gs2::ez::Profile>(
    TCHAR_TO_ANSI(*ClientId),
    TCHAR_TO_ANSI(*ClientSecret),
    gs2::ez::Gs2BasicReopener()
);

ClientPtr = std::make_shared<gs2::ez::Client>(
    *ProfilePtr
);

ProfilePtr->initialize(
    [this](gs2::ez::Profile::AsyncInitializeResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "profile.initialize failed.");
        }
        else
        {
            AccountCreate();
        }
    }
);

// Up to this line is the initialization process.

ClientPtr->chat.deleteRoom(
    [](gs2::ez::account::AsyncEzDeleteRoomResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "chat.deleteRoom failed.");
        }
        else
        {
            Item = r.getResult()->getItem();
        }
    },
    ProfilePtr->getGs2Session(),
    TCHAR_TO_ANSI("namespace-0001"), // namespaceName
    TCHAR_TO_ANSI("room-0001") // roomName,
    TCHAR_TO_ANSI("accessToken-0001") // accessToken
);

Deleting a Room

This can only be performed on rooms that player has created.



Request

Type Require Default Limitation Description
namespaceName string ~ 32 chars Namespace name
roomName string UUID ~ 128 chars Room Name
accessToken string ~ 128 chars Owner User ID

Result

Type Description
item EzRoom Deleted Rooms

getRoom

getRoom

///////////////////////////////////////////////////////////////
// New Experience (Enabled UniTask)
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;
#if GS2_ENABLE_UNITASK
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.Linq;
#endif

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
await profile.InitializeAsync();
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).User(
        userId: null
    ).Room(
        roomName: "room-0001",
        password: null
    );
    var item = await domain.ModelAsync();
}
///////////////////////////////////////////////////////////////
// New Experience
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
var future = profile.Initialize();
yield return future;
if (future.Error != null)
{
    onError.Invoke(future.Error, null);
    yield break;
}
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).User(
        userId: null
    ).Room(
        roomName: "room-0001",
        password: null
    );
    var future = domain.Model();
    yield return future;
    var item = future.Result;
}
///////////////////////////////////////////////////////////////
// Legacy Experience
///////////////////////////////////////////////////////////////

using Gs2.Core.AsyncResult;
using Gs2.Gs2Account.Unity.Result;
using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);

{
    AsyncResult<object> asyncResult = null;
    var current = profile.Initialize(
        r => { asyncResult = r; }
    );
    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }
}
var gs2 = new Gs2.Unity.Client(profile);

// Up to this line is the initialization process.

{
    AsyncResult<EzGetRoomResult> asyncResult = null;
    var current = gs2.Chat.GetRoom(
        callback: r => { asyncResult = r; },
        namespaceName: "namespace-0001",
        roomName: "room-0001"
    );

    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }

    var result = asyncResult.Result;
    var item = result.Item;
}

const auto Profile = MakeShared<Gs2::UE5::Util::FProfile>(
    "your client id",
    "your client secret",
    Gs2::Core::Model::ERegion::ApNorthEast1,
    MakeShareable<Gs2::UE5::Util::IReOpener>(new Gs2::UE5::Util::FGs2BasicReOpener())
);

Gs2::UE5::Core::Domain::FGs2DomainPtr Gs2;
{
    const auto Future = Profile->Initialize();
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;

    Gs2 = Future->GetTask().Result();
    Future->EnsureCompletion();
}

// Up to this line is the initialization process.

{
    const auto Domain = Gs2->Chat->Namespace(
        "namespace-0001" // namespaceName
    )->User(
        nullptr // userId
    )->Room(
        "room-0001", // roomName
        nullptr // password
    );
    const auto item = Domain.Model();
}
ProfilePtr = std::make_shared<gs2::ez::Profile>(
    TCHAR_TO_ANSI(*ClientId),
    TCHAR_TO_ANSI(*ClientSecret),
    gs2::ez::Gs2BasicReopener()
);

ClientPtr = std::make_shared<gs2::ez::Client>(
    *ProfilePtr
);

ProfilePtr->initialize(
    [this](gs2::ez::Profile::AsyncInitializeResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "profile.initialize failed.");
        }
        else
        {
            AccountCreate();
        }
    }
);

// Up to this line is the initialization process.

ClientPtr->chat.getRoom(
    [](gs2::ez::account::AsyncEzGetRoomResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "chat.getRoom failed.");
        }
        else
        {
            Item = r.getResult()->getItem();
        }
    },
    TCHAR_TO_ANSI("namespace-0001"), // namespaceName
    TCHAR_TO_ANSI("room-0001") // roomName
);

Get Room



Request

Type Require Default Limitation Description
namespaceName string ~ 32 chars Namespace name
roomName string UUID ~ 128 chars Room Name

Result

Type Description
item EzRoom Room

listMessages

listMessages

///////////////////////////////////////////////////////////////
// New Experience (Enabled UniTask)
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;
#if GS2_ENABLE_UNITASK
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.Linq;
#endif

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
await profile.InitializeAsync();
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Room(
        roomName: "room-0001",
        password: null
    );
    var items = await domain.MessagesAsync(
    ).ToListAsync();
}
///////////////////////////////////////////////////////////////
// New Experience
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
var future = profile.Initialize();
yield return future;
if (future.Error != null)
{
    onError.Invoke(future.Error, null);
    yield break;
}
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Room(
        roomName: "room-0001",
        password: null
    );
    var it = domain.Messages(
    );
    List<EzMessage> items = new List<EzMessage>();
    while (it.HasNext())
    {
        yield return it.Next();
        if (it.Error != null)
        {
            onError.Invoke(it.Error, null);
            break;
        }
        if (it.Current != null)
        {
            items.Add(it.Current);
        }
        else
        {
            break;
        }
    }
}
///////////////////////////////////////////////////////////////
// Legacy Experience
///////////////////////////////////////////////////////////////

using Gs2.Core.AsyncResult;
using Gs2.Gs2Account.Unity.Result;
using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);

{
    AsyncResult<object> asyncResult = null;
    var current = profile.Initialize(
        r => { asyncResult = r; }
    );
    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }
}
var gs2 = new Gs2.Unity.Client(profile);

// Up to this line is the initialization process.

{
    AsyncResult<EzListMessagesResult> asyncResult = null;
    var current = gs2.Chat.ListMessages(
        callback: r => { asyncResult = r; },
        session: session,
        namespaceName: "namespace-0001",
        roomName: "room-0001",
        startAt: null,
        limit: null,
        password: null
    );

    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }

    var result = asyncResult.Result;
    var items = result.Items;
}

const auto Profile = MakeShared<Gs2::UE5::Util::FProfile>(
    "your client id",
    "your client secret",
    Gs2::Core::Model::ERegion::ApNorthEast1,
    MakeShareable<Gs2::UE5::Util::IReOpener>(new Gs2::UE5::Util::FGs2BasicReOpener())
);

Gs2::UE5::Core::Domain::FGs2DomainPtr Gs2;
{
    const auto Future = Profile->Initialize();
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;

    Gs2 = Future->GetTask().Result();
    Future->EnsureCompletion();
}

// Up to this line is the initialization process.

{
    const auto Domain = Gs2->Chat->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    )->Room(
        "room-0001", // roomName
        nullptr // password
    );
    const auto It = Domain->Messages(
    );
    for (auto Item : *It)
    {

    }
}
ProfilePtr = std::make_shared<gs2::ez::Profile>(
    TCHAR_TO_ANSI(*ClientId),
    TCHAR_TO_ANSI(*ClientSecret),
    gs2::ez::Gs2BasicReopener()
);

ClientPtr = std::make_shared<gs2::ez::Client>(
    *ProfilePtr
);

ProfilePtr->initialize(
    [this](gs2::ez::Profile::AsyncInitializeResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "profile.initialize failed.");
        }
        else
        {
            AccountCreate();
        }
    }
);

// Up to this line is the initialization process.

ClientPtr->chat.describeMessages(
    [](gs2::ez::account::AsyncEzDescribeMessagesResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "chat.describeMessages failed.");
        }
        else
        {
            Items = r.getResult()->getItems();
        }
    },
    ProfilePtr->getGs2Session(),
    TCHAR_TO_ANSI("namespace-0001"), // namespaceName
    TCHAR_TO_ANSI("room-0001"), // roomName
    null, // startAt
    null // limit,
    TCHAR_TO_ANSI(null) // password
);

Get list of messages in a room

Messages posted after the time of startAt can be retrieved.
Messages matching startAt exactly are also included.

Messages are retrieved in order of oldest to newest post.

Messages can be traced back up to the past hour.



Request

Type Require Default Limitation Description
namespaceName string ~ 32 chars Namespace name
roomName string ~ 128 chars Room Name
startAt long Difference from current time(-1 hours) Time to start retrieving messages
limit int 30 1 ~ 1000 Number of data acquired
password string ~ 128 chars Password required to receive messages

Result

Type Description
items List<EzMessage> List of Message

post

post

///////////////////////////////////////////////////////////////
// New Experience (Enabled UniTask)
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;
#if GS2_ENABLE_UNITASK
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.Linq;
#endif

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
await profile.InitializeAsync();
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Room(
        roomName: "room-0001",
        password: null
    );
    var result = await domain.PostAsync(
        metadata: "MESSAGE_0001",
        category: null
    );
    var item = await result.ModelAsync();
}
///////////////////////////////////////////////////////////////
// New Experience
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
var future = profile.Initialize();
yield return future;
if (future.Error != null)
{
    onError.Invoke(future.Error, null);
    yield break;
}
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Room(
        roomName: "room-0001",
        password: null
    );
    var future = domain.Post(
        metadata: "MESSAGE_0001",
        category: null
    );
    yield return future;
    if (future.Error != null)
    {
        onError.Invoke(future.Error, null);
        yield break;
    }
    var future2 = future.Result.Model();
    yield return future2;
    if (future2.Error != null)
    {
        onError.Invoke(future2.Error, null);
        yield break;
    }
    var result = future2.Result;
}
///////////////////////////////////////////////////////////////
// Legacy Experience
///////////////////////////////////////////////////////////////

using Gs2.Core.AsyncResult;
using Gs2.Gs2Account.Unity.Result;
using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);

{
    AsyncResult<object> asyncResult = null;
    var current = profile.Initialize(
        r => { asyncResult = r; }
    );
    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }
}
var gs2 = new Gs2.Unity.Client(profile);

// Up to this line is the initialization process.

{
    AsyncResult<EzPostResult> asyncResult = null;
    var current = gs2.Chat.Post(
        callback: r => { asyncResult = r; },
        session: session,
        namespaceName: "namespace-0001",
        roomName: "room-0001",
        category: null,
        metadata: "MESSAGE_0001",
        password: null
    );

    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }

    var result = asyncResult.Result;
    var item = result.Item;
}

const auto Profile = MakeShared<Gs2::UE5::Util::FProfile>(
    "your client id",
    "your client secret",
    Gs2::Core::Model::ERegion::ApNorthEast1,
    MakeShareable<Gs2::UE5::Util::IReOpener>(new Gs2::UE5::Util::FGs2BasicReOpener())
);

Gs2::UE5::Core::Domain::FGs2DomainPtr Gs2;
{
    const auto Future = Profile->Initialize();
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;

    Gs2 = Future->GetTask().Result();
    Future->EnsureCompletion();
}

// Up to this line is the initialization process.

{
    const auto Domain = Gs2->Chat->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    )->Room(
        "room-0001", // roomName
        nullptr // password
    );
    const auto Future = Domain->Post(
        "MESSAGE_0001",
        nullptr // category
    );
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;

    // obtain changed values / result values
    const auto Future2 = Future->GetTask().Result()->Model();
    Future2->StartSynchronousTask();
    if (!TestFalse(WHAT, Future2->GetTask().IsError())) return false;
    const auto Result = Future2->GetTask().Result();
}
ProfilePtr = std::make_shared<gs2::ez::Profile>(
    TCHAR_TO_ANSI(*ClientId),
    TCHAR_TO_ANSI(*ClientSecret),
    gs2::ez::Gs2BasicReopener()
);

ClientPtr = std::make_shared<gs2::ez::Client>(
    *ProfilePtr
);

ProfilePtr->initialize(
    [this](gs2::ez::Profile::AsyncInitializeResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "profile.initialize failed.");
        }
        else
        {
            AccountCreate();
        }
    }
);

// Up to this line is the initialization process.

ClientPtr->chat.post(
    [](gs2::ez::account::AsyncEzPostResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "chat.post failed.");
        }
        else
        {
            Item = r.getResult()->getItem();
        }
    },
    ProfilePtr->getGs2Session(),
    TCHAR_TO_ANSI("namespace-0001"), // namespaceName
    TCHAR_TO_ANSI("room-0001"), // roomName
    null, // category
    TCHAR_TO_ANSI("MESSAGE_0001") // metadata,
    TCHAR_TO_ANSI(null) // password
);

Post a message.



Request

Type Require Default Limitation Description
namespaceName string ~ 32 chars Namespace name
roomName string ~ 128 chars Room Name
accessToken string ~ 128 chars User Id
category int 0 ~ 2147483646 Type number when you want to classify message types.
metadata string ~ 1024 chars metadata
password string ~ 128 chars Password

Result

Type Description
item EzMessage Posted message

listSubscribeRooms

listSubscribeRooms

///////////////////////////////////////////////////////////////
// New Experience (Enabled UniTask)
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;
#if GS2_ENABLE_UNITASK
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.Linq;
#endif

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
await profile.InitializeAsync();
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    );
    var items = await domain.SubscribesAsync(
    ).ToListAsync();
}
///////////////////////////////////////////////////////////////
// New Experience
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
var future = profile.Initialize();
yield return future;
if (future.Error != null)
{
    onError.Invoke(future.Error, null);
    yield break;
}
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    );
    var it = domain.Subscribes(
    );
    List<EzSubscribe> items = new List<EzSubscribe>();
    while (it.HasNext())
    {
        yield return it.Next();
        if (it.Error != null)
        {
            onError.Invoke(it.Error, null);
            break;
        }
        if (it.Current != null)
        {
            items.Add(it.Current);
        }
        else
        {
            break;
        }
    }
}
///////////////////////////////////////////////////////////////
// Legacy Experience
///////////////////////////////////////////////////////////////

using Gs2.Core.AsyncResult;
using Gs2.Gs2Account.Unity.Result;
using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);

{
    AsyncResult<object> asyncResult = null;
    var current = profile.Initialize(
        r => { asyncResult = r; }
    );
    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }
}
var gs2 = new Gs2.Unity.Client(profile);

// Up to this line is the initialization process.

{
    AsyncResult<EzListSubscribeRoomsResult> asyncResult = null;
    var current = gs2.Chat.ListSubscribeRooms(
        callback: r => { asyncResult = r; },
        session: session,
        namespaceName: "namespace-0001",
        limit: null,
        pageToken: null
    );

    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }

    var result = asyncResult.Result;
    var items = result.Items;
    var nextPageToken = result.NextPageToken;
}

const auto Profile = MakeShared<Gs2::UE5::Util::FProfile>(
    "your client id",
    "your client secret",
    Gs2::Core::Model::ERegion::ApNorthEast1,
    MakeShareable<Gs2::UE5::Util::IReOpener>(new Gs2::UE5::Util::FGs2BasicReOpener())
);

Gs2::UE5::Core::Domain::FGs2DomainPtr Gs2;
{
    const auto Future = Profile->Initialize();
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;

    Gs2 = Future->GetTask().Result();
    Future->EnsureCompletion();
}

// Up to this line is the initialization process.

{
    const auto Domain = Gs2->Chat->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    );
    const auto It = Domain->Subscribes(
    );
    for (auto Item : *It)
    {

    }
}
ProfilePtr = std::make_shared<gs2::ez::Profile>(
    TCHAR_TO_ANSI(*ClientId),
    TCHAR_TO_ANSI(*ClientSecret),
    gs2::ez::Gs2BasicReopener()
);

ClientPtr = std::make_shared<gs2::ez::Client>(
    *ProfilePtr
);

ProfilePtr->initialize(
    [this](gs2::ez::Profile::AsyncInitializeResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "profile.initialize failed.");
        }
        else
        {
            AccountCreate();
        }
    }
);

// Up to this line is the initialization process.

ClientPtr->chat.describeSubscribes(
    [](gs2::ez::account::AsyncEzDescribeSubscribesResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "chat.describeSubscribes failed.");
        }
        else
        {
            Items = r.getResult()->getItems();
            NextPageToken = r.getResult()->getNextPageToken();
        }
    },
    ProfilePtr->getGs2Session(),
    TCHAR_TO_ANSI("namespace-0001"), // namespaceName
    null // limit,
    TCHAR_TO_ANSI(null) // pageToken
);

Get list of rooms to which you are subscribed



Request

Type Require Default Limitation Description
namespaceName string ~ 32 chars Namespace name
accessToken string ~ 128 chars User Id
pageToken string ~ 1024 chars Token specifying the position from which to start acquiring data
limit int 30 1 ~ 1000 Number of data acquired

Result

Type Description
items List<EzSubscribe> List of Subscribe
nextPageToken string Page token to retrieve the rest of the listing

subscribe

subscribe

///////////////////////////////////////////////////////////////
// New Experience (Enabled UniTask)
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;
#if GS2_ENABLE_UNITASK
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.Linq;
#endif

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
await profile.InitializeAsync();
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Subscribe(
        roomName: "room-0001"
    );
    var result = await domain.SubscribeAsync(
        notificationTypes: new Gs2.Unity.Gs2Chat.Model.EzNotificationType[] {
            new Gs2.Unity.Gs2Chat.Model.EzNotificationType {
            },
        }
    );
    var item = await result.ModelAsync();
}
///////////////////////////////////////////////////////////////
// New Experience
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
var future = profile.Initialize();
yield return future;
if (future.Error != null)
{
    onError.Invoke(future.Error, null);
    yield break;
}
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Subscribe(
        roomName: "room-0001"
    );
    var future = domain.Subscribe(
        notificationTypes: new Gs2.Unity.Gs2Chat.Model.EzNotificationType[] {
            new Gs2.Unity.Gs2Chat.Model.EzNotificationType {
            },
        }
    );
    yield return future;
    if (future.Error != null)
    {
        onError.Invoke(future.Error, null);
        yield break;
    }
    var future2 = future.Result.Model();
    yield return future2;
    if (future2.Error != null)
    {
        onError.Invoke(future2.Error, null);
        yield break;
    }
    var result = future2.Result;
}
///////////////////////////////////////////////////////////////
// Legacy Experience
///////////////////////////////////////////////////////////////

using Gs2.Core.AsyncResult;
using Gs2.Gs2Account.Unity.Result;
using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);

{
    AsyncResult<object> asyncResult = null;
    var current = profile.Initialize(
        r => { asyncResult = r; }
    );
    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }
}
var gs2 = new Gs2.Unity.Client(profile);

// Up to this line is the initialization process.

{
    AsyncResult<EzSubscribeResult> asyncResult = null;
    var current = gs2.Chat.Subscribe(
        callback: r => { asyncResult = r; },
        session: session,
        namespaceName: "namespace-0001",
        roomName: "room-0001",
        notificationTypes: new List<Gs2.Unity.Gs2Chat.Model.EzNotificationType> {
            new Gs2.Unity.Gs2Chat.Model.EzNotificationType() {
            }
        }
    );

    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }

    var result = asyncResult.Result;
    var item = result.Item;
}

const auto Profile = MakeShared<Gs2::UE5::Util::FProfile>(
    "your client id",
    "your client secret",
    Gs2::Core::Model::ERegion::ApNorthEast1,
    MakeShareable<Gs2::UE5::Util::IReOpener>(new Gs2::UE5::Util::FGs2BasicReOpener())
);

Gs2::UE5::Core::Domain::FGs2DomainPtr Gs2;
{
    const auto Future = Profile->Initialize();
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;

    Gs2 = Future->GetTask().Result();
    Future->EnsureCompletion();
}

// Up to this line is the initialization process.

{
    const auto Domain = Gs2->Chat->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    )->Subscribe(
        "room-0001" // roomName
    );
    const auto Future = Domain->Subscribe(
        new Gs2.Unity.Gs2Chat.Model.EzNotificationType[] {
            new Gs2.Unity.Gs2Chat.Model.EzNotificationType {
            },
        } // notificationTypes
    );
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;

    // obtain changed values / result values
    const auto Future2 = Future->GetTask().Result()->Model();
    Future2->StartSynchronousTask();
    if (!TestFalse(WHAT, Future2->GetTask().IsError())) return false;
    const auto Result = Future2->GetTask().Result();
}
ProfilePtr = std::make_shared<gs2::ez::Profile>(
    TCHAR_TO_ANSI(*ClientId),
    TCHAR_TO_ANSI(*ClientSecret),
    gs2::ez::Gs2BasicReopener()
);

ClientPtr = std::make_shared<gs2::ez::Client>(
    *ProfilePtr
);

ProfilePtr->initialize(
    [this](gs2::ez::Profile::AsyncInitializeResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "profile.initialize failed.");
        }
        else
        {
            AccountCreate();
        }
    }
);

// Up to this line is the initialization process.

ClientPtr->chat.subscribe(
    [](gs2::ez::account::AsyncEzSubscribeResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "chat.subscribe failed.");
        }
        else
        {
            Item = r.getResult()->getItem();
        }
    },
    ProfilePtr->getGs2Session(),
    TCHAR_TO_ANSI("namespace-0001"), // namespaceName
    TCHAR_TO_ANSI("room-0001") // roomName,
    new Gs2.Gs2Chat.Model.NotificationType[] {
            new Gs2.Gs2Chat.Model.NotificationType()
        } // notificationTypes
);

Subscribe to a Room

Subscribing to a room allows you to receive notifications of new messages posted for that room.
You can choose to be notified only when a message has a specific category value, or only when a message has a specific category value.
If you are offline when you receive a notification, you can set up a mobile push notification to be forwarded to you.



Request

Type Require Default Limitation Description
namespaceName string ~ 32 chars Namespace name
roomName string ~ 128 chars Room name to subscribe to
accessToken string ~ 128 chars User Id
notificationTypes List<EzNotificationType> [] Category list to receive notifications of new messages

Result

Type Description
item EzSubscribe Subscribed Subscriptions

unsubscribe

unsubscribe

///////////////////////////////////////////////////////////////
// New Experience (Enabled UniTask)
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;
#if GS2_ENABLE_UNITASK
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.Linq;
#endif

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
await profile.InitializeAsync();
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Subscribe(
        roomName: "room-0001"
    );
    var result = await domain.UnsubscribeAsync(
    );
}
///////////////////////////////////////////////////////////////
// New Experience
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
var future = profile.Initialize();
yield return future;
if (future.Error != null)
{
    onError.Invoke(future.Error, null);
    yield break;
}
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Subscribe(
        roomName: "room-0001"
    );
    var future = domain.Unsubscribe(
    );
    yield return future;
    if (future.Error != null)
    {
        onError.Invoke(future.Error, null);
        yield break;
    }
}
///////////////////////////////////////////////////////////////
// Legacy Experience
///////////////////////////////////////////////////////////////

using Gs2.Core.AsyncResult;
using Gs2.Gs2Account.Unity.Result;
using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);

{
    AsyncResult<object> asyncResult = null;
    var current = profile.Initialize(
        r => { asyncResult = r; }
    );
    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }
}
var gs2 = new Gs2.Unity.Client(profile);

// Up to this line is the initialization process.

{
    AsyncResult<EzUnsubscribeResult> asyncResult = null;
    var current = gs2.Chat.Unsubscribe(
        callback: r => { asyncResult = r; },
        session: session,
        namespaceName: "namespace-0001",
        roomName: "room-0001"
    );

    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }

    var result = asyncResult.Result;
    var item = result.Item;
}

const auto Profile = MakeShared<Gs2::UE5::Util::FProfile>(
    "your client id",
    "your client secret",
    Gs2::Core::Model::ERegion::ApNorthEast1,
    MakeShareable<Gs2::UE5::Util::IReOpener>(new Gs2::UE5::Util::FGs2BasicReOpener())
);

Gs2::UE5::Core::Domain::FGs2DomainPtr Gs2;
{
    const auto Future = Profile->Initialize();
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;

    Gs2 = Future->GetTask().Result();
    Future->EnsureCompletion();
}

// Up to this line is the initialization process.

{
    const auto Domain = Gs2->Chat->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    )->Subscribe(
        "room-0001" // roomName
    );
    const auto Future = Domain->Unsubscribe(
    );
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;
}
ProfilePtr = std::make_shared<gs2::ez::Profile>(
    TCHAR_TO_ANSI(*ClientId),
    TCHAR_TO_ANSI(*ClientSecret),
    gs2::ez::Gs2BasicReopener()
);

ClientPtr = std::make_shared<gs2::ez::Client>(
    *ProfilePtr
);

ProfilePtr->initialize(
    [this](gs2::ez::Profile::AsyncInitializeResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "profile.initialize failed.");
        }
        else
        {
            AccountCreate();
        }
    }
);

// Up to this line is the initialization process.

ClientPtr->chat.unsubscribe(
    [](gs2::ez::account::AsyncEzUnsubscribeResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "chat.unsubscribe failed.");
        }
        else
        {
            Item = r.getResult()->getItem();
        }
    },
    ProfilePtr->getGs2Session(),
    TCHAR_TO_ANSI("namespace-0001"), // namespaceName
    TCHAR_TO_ANSI("room-0001") // roomName
);

Unsubscribe



Request

Type Require Default Limitation Description
namespaceName string ~ 32 chars Namespace name
roomName string ~ 128 chars Room name to subscribe to
accessToken string ~ 128 chars User Id

Result

Type Description
item EzSubscribe Unsubscribed subscriptions

updateSubscribeSetting

updateSubscribeSetting

///////////////////////////////////////////////////////////////
// New Experience (Enabled UniTask)
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;
#if GS2_ENABLE_UNITASK
using Cysharp.Threading.Tasks;
using Cysharp.Threading.Tasks.Linq;
#endif

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
await profile.InitializeAsync();
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Subscribe(
        roomName: "room-0001"
    );
    var result = await domain.UpdateSubscribeSettingAsync(
        notificationTypes: new Gs2.Unity.Gs2Chat.Model.EzNotificationType[] {
            new Gs2.Unity.Gs2Chat.Model.EzNotificationType
            {},
        }
    );
    var item = await result.ModelAsync();
}
///////////////////////////////////////////////////////////////
// New Experience
///////////////////////////////////////////////////////////////

using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);
var future = profile.Initialize();
yield return future;
if (future.Error != null)
{
    onError.Invoke(future.Error, null);
    yield break;
}
var gs2 = new Gs2.Unity.Core.Gs2Domain(profile);

// Up to this line is the initialization process.

{
    var domain = gs2.Chat.Namespace(
        namespaceName: "namespace-0001"
    ).Me(
        gameSession: GameSession
    ).Subscribe(
        roomName: "room-0001"
    );
    var future = domain.UpdateSubscribeSetting(
        notificationTypes: new Gs2.Unity.Gs2Chat.Model.EzNotificationType[] {
            new Gs2.Unity.Gs2Chat.Model.EzNotificationType
            {},
        }
    );
    yield return future;
    if (future.Error != null)
    {
        onError.Invoke(future.Error, null);
        yield break;
    }
    var future2 = future.Result.Model();
    yield return future2;
    if (future2.Error != null)
    {
        onError.Invoke(future2.Error, null);
        yield break;
    }
    var result = future2.Result;
}
///////////////////////////////////////////////////////////////
// Legacy Experience
///////////////////////////////////////////////////////////////

using Gs2.Core.AsyncResult;
using Gs2.Gs2Account.Unity.Result;
using Gs2.Unity.Util;

var profile = new Profile(
    clientId: "your client id",
    clientSecret: "your client secret",
    reopener: new Gs2BasicReopener()
);

{
    AsyncResult<object> asyncResult = null;
    var current = profile.Initialize(
        r => { asyncResult = r; }
    );
    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }
}
var gs2 = new Gs2.Unity.Client(profile);

// Up to this line is the initialization process.

{
    AsyncResult<EzUpdateSubscribeSettingResult> asyncResult = null;
    var current = gs2.Chat.UpdateSubscribeSetting(
        callback: r => { asyncResult = r; },
        session: session,
        namespaceName: "namespace-0001",
        roomName: "room-0001",
        notificationTypes: new List<Gs2.Unity.Gs2Chat.Model.EzNotificationType> {
            {}
        }
    );

    yield return current;
    if (asyncResult.Error != null)
    {
        OnError(asyncResult.Error);
        yield break;
    }

    var result = asyncResult.Result;
    var item = result.Item;
}

const auto Profile = MakeShared<Gs2::UE5::Util::FProfile>(
    "your client id",
    "your client secret",
    Gs2::Core::Model::ERegion::ApNorthEast1,
    MakeShareable<Gs2::UE5::Util::IReOpener>(new Gs2::UE5::Util::FGs2BasicReOpener())
);

Gs2::UE5::Core::Domain::FGs2DomainPtr Gs2;
{
    const auto Future = Profile->Initialize();
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;

    Gs2 = Future->GetTask().Result();
    Future->EnsureCompletion();
}

// Up to this line is the initialization process.

{
    const auto Domain = Gs2->Chat->Namespace(
        "namespace-0001" // namespaceName
    )->Me(
        AccessToken
    )->Subscribe(
        "room-0001" // roomName
    );
    const auto Future = Domain->UpdateSubscribeSetting(
        new Gs2.Unity.Gs2Chat.Model.EzNotificationType[] {
            new Gs2.Unity.Gs2Chat.Model.EzNotificationType
            {},
        } // notificationTypes
    );
    Future->StartSynchronousTask();
    if (!TestFalse(WHAT, Future->GetTask().IsError())) return false;

    // obtain changed values / result values
    const auto Future2 = Future->GetTask().Result()->Model();
    Future2->StartSynchronousTask();
    if (!TestFalse(WHAT, Future2->GetTask().IsError())) return false;
    const auto Result = Future2->GetTask().Result();
}
ProfilePtr = std::make_shared<gs2::ez::Profile>(
    TCHAR_TO_ANSI(*ClientId),
    TCHAR_TO_ANSI(*ClientSecret),
    gs2::ez::Gs2BasicReopener()
);

ClientPtr = std::make_shared<gs2::ez::Client>(
    *ProfilePtr
);

ProfilePtr->initialize(
    [this](gs2::ez::Profile::AsyncInitializeResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "profile.initialize failed.");
        }
        else
        {
            AccountCreate();
        }
    }
);

// Up to this line is the initialization process.

ClientPtr->chat.updateNotificationType(
    [](gs2::ez::account::AsyncEzUpdateNotificationTypeResult r)
    {
        if (r.getError())
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "chat.updateNotificationType failed.");
        }
        else
        {
            Item = r.getResult()->getItem();
        }
    },
    ProfilePtr->getGs2Session(),
    TCHAR_TO_ANSI("namespace-0001"), // namespaceName
    TCHAR_TO_ANSI("room-0001") // roomName,
    new Gs2.Gs2Chat.Model.NotificationType[] {
            {}
        } // notificationTypes
);

Updating Subscription Preferences



Request

Type Require Default Limitation Description
namespaceName string ~ 32 chars Namespace name
roomName string ~ 128 chars Room name to subscribe to
accessToken string ~ 128 chars User Id
notificationTypes List<EzNotificationType> [] Category list to receive notifications of new messages

Result

Type Description
item EzSubscribe Renewed Subscriptions