ChatRoom

class ChatRoom @JvmOverloads constructor(    regionOrUrl: String,     tokenProvider: (ChatTokenCallback) -> Unit,     maxReconnectAttempts: Int = 3,     val id: String = UUID.randomUUID().toString())

Represents IVS chat room connection.

This is a high-level object representing connection to IVS Chat room. It is responsible for managing chat connection, it allows to send chat requests & receive chat events.

Parameters

regionOrUrl

AWS region name (e.g. "us-west-2") or web socket URL starting with "wss://" or "ws://"

tokenProvider

Callback method called when ChatRoom requires a fresh IVS chat token

maxReconnectAttempts

Number of times the room will automatically retry web socket connection in case of connection failures

Constructors

Link copied to clipboard
fun ChatRoom(    regionOrUrl: String,     tokenProvider: (ChatTokenCallback) -> Unit,     maxReconnectAttempts: Int = 3,     id: String = UUID.randomUUID().toString())

Constructs a new ChatRoom instance

Types

Link copied to clipboard
enum State : Enum<ChatRoom.State>

Represents chat room connection state.

Functions

Link copied to clipboard
fun connect()

Initiates the process of connecting to the socket, using user's token provider. In case of failure, the room will try to reconnect the number of times specified in maxReconnectAttempts, defaulting to 3 attempts.

Link copied to clipboard
fun deleteMessage(request: DeleteMessageRequest, callback: DeleteMessageCallback? = null)

Sends a delete message request through a socket connection.

Link copied to clipboard
fun disconnect()

Initiates a graceful disconnection of ChatRoom. Results in ChatRoomListener.onDisconnected event being called as well as DisconnectReason being set to DisconnectReason.CLIENT_DISCONNECT.

Link copied to clipboard
fun disconnectUser(request: DisconnectUserRequest, callback: DisconnectUserCallback? = null)

Sends a disconnect user request through a socket connection.

Link copied to clipboard
fun sendMessage(request: SendMessageRequest, callback: SendMessageCallback? = null)

Sends a message request to the room through a socket connection.

Properties

Link copied to clipboard
val id: String

Local room identifier, defaults to randomly generated UUID string. The parameter is useful at times when you have more than a single room connection at the same time, in order to differentiate between various room instances, e.g. in logs.

Link copied to clipboard
var listener: ChatRoomListener? = null

Property for attaching ChatRoomListener interface that will raise lifecycle events, e.g. ChatRoomListener.onConnected and receive events, e.g. ChatRoomListener.onMessageReceived.

Link copied to clipboard
var logger: ChatLogger

This property can be used to attach a custom logger implementing ChatLogger interface. It defaults to SystemLogger that logs output to logcat.

Link copied to clipboard
var logLevel: ChatLogLevel

Minimal level of severity of logs to be logged to logger. Defaults to ChatLogLevel.DEBUG

Link copied to clipboard
var state: ChatRoom.State

Current room state. Initial state is disconnected.

Extensions

Link copied to clipboard
suspend fun ChatRoom.awaitDeleteMessage(request: DeleteMessageRequest): DeleteMessageEvent

Sends a delete message request through a socket connection using suspending function.

Link copied to clipboard
suspend fun ChatRoom.awaitDisconnectUser(request: DisconnectUserRequest): DisconnectUserEvent

Sends a disconnect user request through a socket connection using suspending function.

Link copied to clipboard
suspend fun ChatRoom.awaitSendMessage(request: SendMessageRequest): ChatMessage

Sends a message request to the room through a socket connection using suspending function.

Link copied to clipboard
fun ChatRoom.deletedMessages(): Flow<DeleteMessageEvent>

Flow of DeleteMessageEvent instances delivered to a ChatRoom.

Link copied to clipboard
fun ChatRoom.disconnectedUsers(): Flow<DisconnectUserEvent>

Flow of DisconnectUserEvent instances delivered to a ChatRoom.

Link copied to clipboard
fun ChatRoom.receivedEvents(): Flow<ChatEvent>

Flow of ChatEvent instances delivered to a ChatRoom.

Link copied to clipboard
fun ChatRoom.receivedMessages(): Flow<ChatMessage>

Flow of ChatMessage instances delivered to a ChatRoom. The message can be sent by any of the users in the room, including the current user.

Link copied to clipboard
fun ChatRoom.stateChanges(): Flow<ChatRoom.State>

Flow for observing ChatRoom.state changes.