Submitting Messages

Using the submitMessage Function

The RACE JS SDK provides the submitMessage function in both the AppClient and SubClient classes to allow players to send chat messages or other communications to the Transactor server. This function takes a single argument, content, which is a string representing the message content.

Here's an example of using the submitMessage function to send a chat message:

// Assuming client is an initialized AppClient or SubClient instance

const messageContent = 'Hello, everyone!';

client.submitMessage(messageContent);

When the client calls this function, the SDK performs the following actions:

  1. Serialization: The message content is serialized into a Message object, which includes the sender's address and the content string.

  2. Encryption: The Message object is encrypted using the Transactor's public key. This ensures that only the Transactor can decrypt and read the message.

  3. Transmission: The encrypted Message object is sent to the Transactor server.

Upon receiving the message, the Transactor decrypts it and then broadcasts it to all connected clients. The clients can then display the message in their chat interfaces or handle it according to the game logic.

By utilizing the submitMessage function, developers can implement chat features or other communication mechanisms within their Race games, allowing players to interact with each other and with the game server in a secure and efficient manner.

Last updated