docs/api/create-live-pusher-context.md
::: sourceCode
:::
创建并返回 live-pusher 组件上下文 LivePusherContext 对象
参考文档: live-pusher组件文档
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> | <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> | 4.81 | 4.81 | <a style="color:unset;" href="https://vote.dcloud.net.cn/#/?name=uni-app%20x">x</a> |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| livePusherId | string | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x | |
| component | ComponentPublicInstance | 否 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x |
| 类型 | 描述 | 必备 |
|---|---|---|
| LivePusherContext | live-pusher 组件上下文对象 | 否 |
start 开始推流
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | 4.81 | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| options | LivePusherOptions | 否 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x |
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| success | (res: UTSJSONObject) => void | 否 | - | Web: x; 微信小程序: x; Android: 4.81; iOS: 4.81; HarmonyOS: x | 接口调用成功的回调函数 |
| fail | (res: UTSJSONObject) => void | 否 | - | Web: x; 微信小程序: x; Android: 4.81; iOS: 4.81; HarmonyOS: x | 接口调用失败的回调函数 |
| complete | (res: any) => void | 否 | - | Web: x; 微信小程序: x; Android: 4.81; iOS: 4.81; HarmonyOS: x | 接口调用结束的回调函数(调用成功、失败都会执行) |
stop 停止推流
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | 4.81 | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| options | LivePusherOptions | 否 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x | - |
switchCamera 切换前后摄像头
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | 4.81 | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| options | LivePusherOptions | 否 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x | - |
toggleTorch 开关闪光灯
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | 4.81 | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| options | LivePusherOptions | 否 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x | - |
pause 暂停推流
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | 4.81 | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| options | LivePusherOptions | 否 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x | - |
resume 恢复推流
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | 4.81 | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| options | LivePusherOptions | 否 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x | - |
getMaxZoom 获取最大缩放值
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | 4.81 | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| options | LivePusherOptions | 否 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x | - |
setZoom 设置缩放
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | 4.81 | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| zoom | number | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x | |
| options | LivePusherOptions | 否 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x | - |
startPreview 开启摄像头预览
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | 4.81 | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| options | LivePusherOptions | 否 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x | - |
stopPreview 关闭摄像头预览
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | 4.81 | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| options | LivePusherOptions | 否 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x | - |
snapshot 快照
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | 4.81 | 4.81 | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| options | LivePusherOptions | 否 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x | - |
sendMessage
| Web | 微信小程序 | Android | iOS | HarmonyOS |
|---|---|---|---|---|
| x | x | - | - | x |
| 名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| message | string | 是 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x | |
| options | LivePusherOptions | 否 | - | Web: x; 微信小程序: x; Android: -; iOS: -; HarmonyOS: x | - |
示例代码另见live-pusher组件文档
<!-- UTSAPIJSON.createLivePusherContext.example -->| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| errMsg | string | 是 | - | Web: -; 微信小程序: 4.41; Android: -; iOS: -; HarmonyOS: - | 错误信息 |