小程序(微信) API 参考
构建时从公开 SDK 接口定义生成:接口、方法重载、属性、事件、枚举与错误码。
接口概览
本页列出 小程序(微信) 端公开 API 的类、方法、重载、属性、事件与错误码,接口定义与 SDK 包版本一致。
| 核对项 | 数量 |
|---|---|
| 接口 / 类 | 4 |
| 方法 | 32 |
| 方法重载 | 45 |
| 属性 | 4 |
| 枚举 | 4 |
| 错误码常量 | 0 |
可用性
该端 SDK:正式可用。接口定义与 SDK 包版本一致;运行时的能力边界以实际发布的 SDK 包为准。
加入频道核心链路
按 join / leave / publish / subscribe 的典型调用顺序整理;参数表在“最小可运行链路”一节展开。
| 步骤 | 接口 | 方法 | 重载数 |
|---|---|---|---|
| 加入频道 | Client | join | 1 |
| 离开频道 | Client | leave | 1 |
| 发布本地轨道 | Client | publish | 1 |
| 续期 Token | Client | renewToken | 1 |
| 订阅远端媒体 | Client | subscribe | 1 |
最小可运行链路的参数
| 参数 | 类型 | 可选 | 可变参数 |
|---|---|---|---|
channelKey | string | 否 | 否 |
channel | string | 否 | 否 |
uid | number|string | 否 | 否 |
isAudioOnly | boolean | 否 | 否 |
UidType | UidType | 是 | 否 |
onSuccess | function | 是 | 否 |
onFailure | function | 是 | 否 |
onSuccess | function | 是 | 否 |
onFailure | function | 是 | 否 |
onSuccess | function | 是 | 否 |
onFailure | function | 是 | 否 |
token | string | 否 | 否 |
onSuccess | function | 是 | 否 |
onFailure | function | 是 | 否 |
uid | number | 否 | 否 |
options | object | 是 | 否 |
onSuccess | function | 是 | 否 |
onFailure | function | 是 | 否 |
接口索引
| 接口 | 方法 | 属性 | 事件 |
|---|---|---|---|
ChannelMediaError | 0 | 3 | 0 |
ChannelMediaRelayConfiguration | 3 | 0 | 0 |
Client | 27 | 0 | 14 |
Log | 2 | 1 | 0 |
全部接口
ChannelMediaError 0 方法 / 3 属性
| 属性 | 类型 | 只读 |
|---|---|---|
code | number | 否 |
data | any | 否 |
message | string | 否 |
ChannelMediaRelayConfiguration 3 方法 / 0 属性
removeDestChannelInfo(channelName: string): void
setDestChannelInfo(channelName: string, destInfo: any): void
setSrcChannelInfo(srcInfo: any): void方法明细:3 / 3(参数、返回值、错误码)
Client 27 方法 / 0 属性
constructor(options: object): Client
destroy(onSuccess?: function, onFailure?: function): Promise<void>
init(appId: string, onSuccess?: function, onFailure?: function): Promise<void>
join(channelKey: string, channel: string, uid: number|string, isAudioOnly: boolean, UidType?: UidType, onSuccess?: function, onFailure?: function): Promise<void>
leave(onSuccess?: function, onFailure?: function): Promise<void>
mute(uid: number, target: string, onSuccess?: function, onFailure?: function): Promise<void>
muteLocal(target: string, onSuccess?: function, onFailure?: function): Promise<void>
off(event: string): void
on(event: "channel-media-relay-event", callback: function): void
on(event: "channel-media-relay-state", callback: function): void
on(event: "client-banned"): void
on(event: "error", callback: function): void
on(event: "mute-audio", callback: function): void
on(event: "mute-video", callback: function): void
on(event: "stream-added", callback: function): void
on(event: "stream-removed", callback: function): void
on(event: "token-privilege-did-expire"): void
on(event: "token-privilege-will-expire"): void
on(event: "unmute-audio", callback: function): void
on(event: "unmute-video", callback: function): void
on(event: "update-url", callback: function): void
on(event: "video-rotation", callback: function): void
publish(onSuccess?: function, onFailure?: function): Promise<string>
rejoin(channelKey: string, channel: string, uid: number|string, uids: number, isAudioOnly: boolean, UidType?: UidType, onSuccess?: function, onFailure?: function): Promise<void>
renewToken(token: string, onSuccess?: function, onFailure?: function): Promise<void>
setAudioCodec(audioCodec: AudioCodec): void
setRemoteVideoStreamType(uid: number, streamType: 0|1, onSuccess?: function, onFailure?: function): Promise<void>
setRole(role: string, onSuccess?: function, onFailure?: function): Promise<void>
startChannelMediaRelay(config: ChannelMediaRelayConfiguration, callback: function): void
stopChannelMediaRelay(callback: function): void
subscribe(uid: number, options?: object, onSuccess?: function, onFailure?: function): Promise<object>
unmute(uid: number, target: string, onSuccess?: function, onFailure?: function): Promise<void>
unmuteLocal(target: string, onSuccess?: function, onFailure?: function): Promise<void>
unpublish(onSuccess?: function, onFailure?: function): Promise<void>
unsubscribe(uid: number, onSuccess?: function, onFailure?: function): Promise<void>
updateChannelMediaRelay(config: ChannelMediaRelayConfiguration, callback: function): void
updatePlayerNetStatus(uid: number, event: any): void
updatePlayerStateChange(uid: number, event: any): void
updatePusherNetStatus(event: any): void
updatePusherStateChange(event: any): void方法明细:27 / 27(参数、返回值、错误码)
| 方法 | 参数 | 返回值 | 错误 |
|---|---|---|---|
constructor | options: object | Client | 错误码索引 |
destroy | onSuccess?: function, onFailure?: function | Promise<void> | 错误码索引 |
init | appId: string, onSuccess?: function, onFailure?: function | Promise<void> | 错误码索引 |
join | channelKey: string, channel: string, uid: number|string, isAudioOnly: boolean, UidType?: UidType, onSuccess?: function, onFailure?: function | Promise<void> | 错误码索引 |
leave | onSuccess?: function, onFailure?: function | Promise<void> | 错误码索引 |
mute | uid: number, target: string, onSuccess?: function, onFailure?: function | Promise<void> | 错误码索引 |
muteLocal | target: string, onSuccess?: function, onFailure?: function | Promise<void> | 错误码索引 |
off | event: string | void | 错误码索引 |
on | event: "channel-media-relay-event", callback: function | void | 错误码索引 |
publish | onSuccess?: function, onFailure?: function | Promise<string> | 错误码索引 |
rejoin | channelKey: string, channel: string, uid: number|string, uids: number, isAudioOnly: boolean, UidType?: UidType, onSuccess?: function, onFailure?: function | Promise<void> | 错误码索引 |
renewToken | token: string, onSuccess?: function, onFailure?: function | Promise<void> | 错误码索引 |
setAudioCodec | audioCodec: AudioCodec | void | 错误码索引 |
setRemoteVideoStreamType | uid: number, streamType: 0|1, onSuccess?: function, onFailure?: function | Promise<void> | 错误码索引 |
setRole | role: string, onSuccess?: function, onFailure?: function | Promise<void> | 错误码索引 |
startChannelMediaRelay | config: ChannelMediaRelayConfiguration, callback: function | void | 错误码索引 |
stopChannelMediaRelay | callback: function | void | 错误码索引 |
subscribe | uid: number, options?: object, onSuccess?: function, onFailure?: function | Promise<object> | 错误码索引 |
unmute | uid: number, target: string, onSuccess?: function, onFailure?: function | Promise<void> | 错误码索引 |
unmuteLocal | target: string, onSuccess?: function, onFailure?: function | Promise<void> | 错误码索引 |
unpublish | onSuccess?: function, onFailure?: function | Promise<void> | 错误码索引 |
unsubscribe | uid: number, onSuccess?: function, onFailure?: function | Promise<void> | 错误码索引 |
updateChannelMediaRelay | config: ChannelMediaRelayConfiguration, callback: function | void | 错误码索引 |
updatePlayerNetStatus | uid: number, event: any | void | 错误码索引 |
updatePlayerStateChange | uid: number, event: any | void | 错误码索引 |
updatePusherNetStatus | event: any | void | 错误码索引 |
updatePusherStateChange | event: any | void | 错误码索引 |
| 事件名 | 回调参数 |
|---|---|
channel-media-relay-event | Function |
channel-media-relay-state | Function |
client-banned | Function |
error | Function |
mute-audio | Function |
mute-video | Function |
stream-added | Function |
stream-removed | Function |
token-privilege-did-expire | Function |
token-privilege-will-expire | Function |
unmute-audio | Function |
unmute-video | Function |
update-url | Function |
video-rotation | Function |
Log 2 方法 / 1 属性
setLogLevel(level: number): void
uploadLogs(onSuccess?: function, onFailure?: function): Promise<void>方法明细:2 / 2(参数、返回值、错误码)
| 方法 | 参数 | 返回值 | 错误 |
|---|---|---|---|
setLogLevel | level: number | void | 错误码索引 |
uploadLogs | onSuccess?: function, onFailure?: function | Promise<void> | 错误码索引 |
| 属性 | 类型 | 只读 |
|---|---|---|
onLog | Function | 否 |
枚举
| 枚举 | 成员数 | 示例值 |
|---|---|---|
AudioCodec | 3 | G722 = 9 |
ENCRYPTION_MODE | 10 | AES_128_ECB = 2 |
StreamType | 2 | HIGH = null |
UidType | 2 | INT = null |
AudioCodec 3 个成员
| 成员 | 值 |
|---|---|
G722 | 9 |
PCMA | 8 |
PCMU | 0 |
ENCRYPTION_MODE 10 个成员
| 成员 | 值 |
|---|---|
AES_128_ECB | 2 |
AES_128_GCM | 5 |
AES_128_GCM2 | 7 |
AES_128_XTS | 1 |
AES_256_GCM | 6 |
AES_256_GCM2 | 8 |
AES_256_XTS | 3 |
MODE_END | 9 |
NONE | 0 |
SM4_128_ECB | 4 |
StreamType 2 个成员
| 成员 | 值 |
|---|---|
HIGH | null |
LOW | null |
UidType 2 个成员
| 成员 | 值 |
|---|---|
INT | null |
STRING | null |
错误码常量
该端 SDK 未提供错误码常量(见“已知限制”)。平台 REST 错误码见 错误码全表,跨端 SDK 错误标识见 各端 SDK 错误标识。