Chat | Unity Realtime

The Gamedonia Realtime API provides special operations and events to deal with user chat communication. User chat rooms are especially suited for real time communication between users and a must for building a growing community of players.

Sending

The Gamedonia Realtime SDK offers two ways of sending chat meesasges: private and public. Private messages are addressed to specific users and public messages to a specific room. The related operations are the following:

Send public message

This operation will send a message to a room and the receival will be notified to all users in the room.

Parameters

  • roomId. Type long. Identifier of the room to send the message to. The user must already be in the room.
  • message. Type string. Text message to send.

Events

  • ON_SEND_PUBLIC_MESSAGE_SUCCESS

    Event received when the message is sent successfully.

  • ON_SEND_PUBLIC_MESSAGE_ERROR

    Event received when the message could not be sent.

Send private message

This operation will send a message only to a specific user. It doesn't matter if they share a room or not.

Parameters

  • userId. Type long. Identifier of the user to send the message to.
  • message. Type string. Text message to send.

Events

  • ON_SEND_PRIVATE_MESSAGE_SUCCESS

    Event received when the message is sent successfully.

  • ON_SEND_PRIVATE_MESSAGE_ERROR

    Event received when the message could not be sent.

Receiving

To receive messages with the Realtime chat API, you will need to subscribe to the following events:

ON_PUBLIC_MESSAGES_RECEIVED

This event will trigger every time a message comes to a specific room where the current is in. This will also trigger when the user joins a room, with some messages from the message log buffer. That's why you get an array of messages and not a single message.

Content

  • room: Type Room. Room where the message was published.
  • messages[]: Array of messages received.
    • u:. Type string. Name of the user who sent the message.
    • m: Type string. Message sent.

ON_PRIVATE_MESSAGE_RECEIVED

This event will trigger every time a message comes directly to the user. No other users will be able to see this message.

  • u:. Type string. Name of the user who sent the message.
  • m: Type string. Message sent.