跳轉到主要內容

安裝

  1. Add InsForge dependencies to your project
build.gradle.kts:
  1. Initialize InsForge SDK
  1. Enable Logging (Optional)
For debugging, you can configure the SDK log level:
Log LevelDescription
NONENo logging (default, recommended for production)
ERROROnly errors
WARNWarnings and errors
INFOInformational messages
DEBUGDebug info (request method, URL, response status)
VERBOSEFull details (headers, request/response bodies)
Use NONE or ERROR in production to avoid exposing sensitive data in logs.

Android Initialization

  1. Add Chrome Custom Tabs dependency to your build.gradle.kts:
  1. Initialize InsForge SDK (With Chrome Custom Tabs and Session Storage)
  1. Use Jetpack DataStore for Session Storage (Optional)

心智模型

Kotlin SDK 透過 Socket.IO 連線到 InsForge 即時系統。訂閱頻道名稱(如 order:123chat:room-1),然後監聽發佈到這些頻道的事件名稱。 事件由資料庫觸發程式發佈,這些觸發程式呼叫 realtime.publish(...) 或由已加入頻道的用戶端發佈。有關頻道和 RLS 模型,請參閱即時概述

快速開始

connect()

建立即時連線。
監視連線狀態:

subscribe()

訂閱頻道並接收目前在線狀態快照。

publish()

將事件發佈到頻道。
用戶端必須訂閱頻道才能向該頻道發佈。
如果在 realtime.messages 上啟用了 RLS,發佈也會根據 INSERT 原則進行檢查。

on()

註冊事件接聽程式。
連線和系統事件:
事件說明
presence:join邏輯成員在頻道中變為在線。
presence:leave邏輯成員不再在頻道中在線。
realtime:error訂閱或發佈失敗。

once()

僅監聽一次事件。

off()

移除事件接聽程式。

unsubscribe()

離開頻道。

disconnect()

關閉即時連線。

getSubscribedChannels()

傳回本機訂閱的頻道。

在線狀態

成功的訂閱會傳回在線狀態快照。監聽 presence:joinpresence:leave 以更新本機在線狀態。 在線狀態是暫時的。它不是一個持久的房間成員身份表。