SDKsuni-app / uni-app x
发送自定义信令
在指定通话房间内发送轻量级业务协商数据。
signalingSendCustomSignaling() 用于向指定通话房间发送轻量业务数据,例如举手、布局切换提示或产品自定义状态。它不是聊天消息接口,也不能替代媒体引擎的数据通道。
import {
signalingSendCustomSignaling,
} from '@/uni_modules/unix-openim-sdk'
const signal = {
version: 1,
eventID: createBusinessEventID(),
type: 'hand-raised',
userID: currentUserID,
sentAt: Date.now(),
}
await signalingSendCustomSignaling({
roomID,
customInfo: JSON.stringify(signal),
})| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
roomID | string | 是 | 当前通话房间 ID。 |
customInfo | string | 是 | 业务自定义字符串;传 JSON 时应包含协议版本和唯一事件 ID。 |
Promise 成功表示 OpenIMServer 已接受发送请求,不表示其他参与者已经处理。自定义信令适合传递轻量、短期的业务协商数据,大文件、聊天记录和长期状态不属于该接口的适用范围。
接收自定义信令
onReceiveCustomSignal() 的载荷类型为 string,SDK 没有公开外层字段。业务应把解析集中在自己的协议适配层,验证 JSON、版本、事件 ID 和房间上下文后再更新界面。
import {
off,
onReceiveCustomSignal,
} from '@/uni_modules/unix-openim-sdk'
const handleCustomSignal = (payload: string) => {
const signal = parseAndValidateCallSignal(payload)
if (signal == null) return
if (hasAppliedSignal(signal.eventID)) return
applyCallSignal(signal)
}
const customSignalSubscription =
onReceiveCustomSignal(handleCustomSignal)
// 离开通话功能或账号切换时:
off(customSignalSubscription)如果收到的事件字符串包含 SDK 外层结构,应由适配层先取出 customInfo,并统一处理不同平台的载荷格式。
这个页面有帮助吗?