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.