跳转到主要内容

安装

  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 以更新本地在线状态。 在线状态是临时的。它不是一个持久的房间成员身份表。