useCtx

useCtx hooks 方法用于获取播放器上下文实例。

function useCtx(options: Options): Ctx

入参 Options

参数名类型是否必传含义
devIdstring是设备 ID
initTopLeftContentComponentConfig[]否位于左上角的 Widget 初始值
initTopRightContentComponentConfig[]否位于右上角的 Widget 初始值
initBottomLeftContentComponentConfig[]否位于左下角 Widget 初始值
initBottomRightContentComponentConfig[]否位于右下角 Widget 初始值
initAbsoluteContentComponentConfig[]否绝对定位的 Widget 初始值
saveToAlbum0 或 1否保存文件的时候,保存到 0 系统相册,1 IPC 相册,默认为 1

返回参数 Ctx

参数名类型含义
devIdstring设备 ID
brandColorRetAtom<string>主题色 注:RetAtom 类型的值需要使用 useStore 读取
setBrandColor(value: string) => void设置 brandColor
verticalMicRetAtom<string>竖屏状态下,是否展示对讲,默认为 true
setVerticalMic(value: string) => void设置 verticalMic
saveToAlbum0 或者 1
screenTypeRetAtom<ScreenType>full 横屏,vertical竖屏
setScreenType(value: ScreenType) => void设置 screenType
recordingRetAtom<boolean>是否正在录像中
setRecording(value: boolean) => void设置 recording
recordingDisabledRetAtom<boolean>是否禁止录像
setRecordingDisabledRetAtom<boolean>设置 recordingDisabled
muteRetAtom<boolean>当前是否为静音状态
setMute(value: boolean) => Promise<boolean>设置 mute,会改变播放器静音状态
intercomRetAtom<boolean>当前是否对讲中
setIntercom(value: boolean) => Promise<boolean>设置 intercom,会改变播放器对讲状态
intercomModeRetAtom<IntercomMode>当前为单向对讲还是双向对讲, OneWay 单向对讲、TwoWay 双向对讲
intercomSupportedRetAtom<boolean>当前摄像头
对讲
resolutionRetAtom<string>播放器当前清晰度
setResolution(type: string) => void设置清晰度
resolutionListRetAtom<string[]>当前支持的清晰度列表
setResolutionList(type: string[]) => void设置 resolutionList
playStateRetAtom<PlayState>播放器状态 0 连接中、1 播放中、2 暂停
IPCPlayerInstanceIpcContext播放器上下文,详情:IPcContext
topLeftContentRetAtom<ComponentConfig[]>位于左上角的 Widget
topRightContentRetAtom<ComponentConfig[]>位于右上角的 Widget
bottomLeftContentRetAtom<ComponentConfig[]>位于左下角的 Widget
bottomRightContentRetAtom<ComponentConfig[]>位于右下角的 Widget
absoluteContentRetAtom<ComponentConfig[]>绝对定位的 Widget
getStreamStatus() => PlayerStreamStatus获取当前拉流状态
addContent添加 Widget,ContentPlaceType:"topLeft" 、 "topRight" 、"bottomLeft" 、"bottomRight" 、 "absolute"
deleteContent(type: ContentPlaceType, id: string) => void删除 Widget
hasContent(type: ContentPlaceType, id: string) => boolean判断某个 Widget 是否存在
hideContent(type: ContentPlaceType, id: string) => void隐藏 Widget
showContent(type: ContentPlaceType, id: string) => void显示 Widget
eventEventInstance事件系统

返回参数中,类型为 RetAtom 的值都无法直接使用,需要使用 useStore hooks 进行读取

使用示例

import { useCtx, useStore } from '@ray-js/ipc-player-integration';

export function Component() {

  const deviceId = '1234567890xxxxxx';
  const instance = useCtx({
    devId: deviceId
  })
  // 使用 useStore 读取 screenType
  const { screenType } = useStore({ screenType: instance.screenType });

  // 开启静音
  instance.setMute(true)
}