Room Chat
Room Chat is a real-time, room-based chat system. You can join a room, send/receive messages, and query message history.
roomChat.join
Joins a chat room and returns a RoomChatHandle.
roomName is optional:
- If provided: The host automatically prefixes it with the miniApp ID (e.g.,
"lobby"→"com.example.game_lobby"). This ensures rooms with the same name from different games don't collide. - If omitted: Automatically derived from the active match (e.g.,
"match_abc123"). In this case,persistenceis automatically set tofalsesince match chats are temporary.
// Optional: with roomName (lobby, waiting-room, etc.)
const chat = await gameTegra.roomChat.join('lobby')
// Optional: with additional parameters
const chat = await gameTegra.roomChat.join('match-room', {
persistence: true, // Should messages be persisted
hidden: false // Should user appear in presence
})
// Without roomName — auto-derived from active match
const chat = await gameTegra.roomChat.join()var chat = await gameTegra.RoomChat.Join("lobby");
// or with additional parameters
var chat = await gameTegra.RoomChat.Join("match-room",
persistence: true,
hidden: false
);
// Without roomName
var chat = await gameTegra.RoomChat.Join();var chat = await gameTegra.roomChat.join("lobby")
# or with additional parameters
var chat = await gameTegra.roomChat.join("match-room", true, false)
# Without roomName
var chat = await gameTegra.roomChat.join()Parameters:
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| roomName | string | No | - | Room name. If omitted, derived from active match. Automatically prefixed with miniAppId by the host. |
| persistence | boolean | No | true | Whether messages should be persisted. Automatically false for match-based rooms. |
| hidden | boolean | No | false | Whether user is hidden in the presence list |
Return Type: RoomChatHandle
Room Name Isolation
Room names are automatically prefixed with the miniApp ID by the host. So just writing "lobby" is enough — different games' lobbies won't collide.
Match Chats
When you call roomChat.join() without a roomName, the active match is automatically detected and a temporary chat room is created (persistence: false). Messages are lost when the match ends.
openMatchChat
Opens a group chat screen for players in the current match. This method shows a native chat UI on the Flutter side.
room_name is optional:
- If provided: Prefixed with miniApp ID,
persistence: true. - If omitted: Auto-derived from active match,
persistence: false.
// Without roomName — auto-derived from active match
await gameTegra.openMatchChat()
// With roomName (e.g., lobby)
await gameTegra.openMatchChat({ room_name: 'lobby' })await gameTegra.OpenMatchChat();
// With roomName
await gameTegra.OpenMatchChat(roomName: "lobby");await gameTegra.open_match_chat()
# With roomName
await gameTegra.open_match_chat({ "room_name": "lobby" })Parameters:
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| room_name | string | No | - | Room name. If omitted, derived from active match ID. |
Return Type: { success: boolean, room_name: string, player_count: number }
RoomChatHandle
The object returned from roomChat.join(). Used for interacting with the room.
Properties
| Property | Type | Description |
|---|---|---|
| roomName | string | Room name (resolved, may be empty) |
| channelId | string | Channel ID |
| streamKey | string | Stream key |
send
Sends a message to the room.
// String message
await chat.send('Hello!')
// Object message
await chat.send({
type: 'game_action',
action: 'attack',
target: 'player2'
})await chat.SendAsync("Hello!");
// or object
await chat.SendAsync(new Dictionary<string, object> {
{ "type", "game_action" },
{ "action", "attack" }
});await chat.send("Hello!")
# or object
await chat.send({
"type": "game_action",
"action": "attack"
})Parameters:
| Field | Type | Required | Description |
|---|---|---|---|
| content | any | Yes | Message content to send |
getHistory
Gets message history.
const history = await chat.getHistory(50)
// With pagination
const history = await chat.getHistory(20, 'cursor-token', true)var history = await chat.GetHistoryAsync(limit: 50);
// With pagination
var history = await chat.GetHistoryAsync(
limit: 20,
cursor: "cursor-token",
forward: true
);var history = await chat.get_history(50)
# With pagination
var history = await chat.get_history(20, "cursor-token", true)Parameters:
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| limit | number | No | 50 | Number of messages to retrieve |
| cursor | string | No | "" | Pagination cursor |
| forward | boolean | No | false | Whether to paginate forward |
Event Listening
message
Triggered when a new message arrives in the room.
const unsub = chat.on('message', (data) => {
console.log('New message:', data)
})
// Stop listening
unsub()Action unsub = chat.On("message", (data) => {
Debug.Log($"New message: {data}");
});
// Stop listening
unsub();var unsub = chat.on("message", func(data):
print("New message: ", data)
)
# Stop listening: unsub.call()presence
User join/leave events.
chat.on('presence', (data) => {
console.log('Presence change:', data)
})chat.On("presence", (data) => {
Debug.Log($"Presence: {data}");
});chat.on("presence", func(data):
print("Presence: ", data)
)leave
Leaves the chat room and cleans up all listeners.
await chat.leave()await chat.LeaveAsync();await chat.leave()Full Example
// Join a room (roomName is optional)
const chat = await gameTegra.roomChat.join('game-lobby')
// Listen for messages
chat.on('message', (msg) => {
console.log(`[${msg.sender}]: ${msg.content}`)
})
// Listen for presence changes
chat.on('presence', (event) => {
console.log('Player join/leave:', event)
})
// Get past messages
const history = await chat.getHistory(20)
console.log('Last 20 messages:', history)
// Send a message
await chat.send({ text: 'Let the game begin!' })
// Leave the room
await chat.leave()Match Chat (Automatic)
// Without roomName — active match is auto-detected
const chat = await gameTegra.roomChat.join()
chat.on('message', (msg) => {
console.log(`[${msg.sender}]: ${msg.content}`)
})
await chat.send({ text: 'GG!' })
// or with native UI
await gameTegra.openMatchChat()