useCtx

The useCtx hook is used to obtain the player context instance.

function useCtx(options: Options): Ctx

Input: Options

ParameterTypeRequiredDescription
devIdstringYesDevice ID
initTopLeftContentComponentConfig[]NoInitial widgets in the top-left corner
initTopRightContentComponentConfig[]NoInitial widgets in the top-right corner
initBottomLeftContentComponentConfig[]NoInitial widgets in the bottom-left corner
initBottomRightContentComponentConfig[]NoInitial widgets in the bottom-right corner
initAbsoluteContentComponentConfig[]NoInitial absolutely positioned widgets
saveToAlbum0 or 1NoWhen saving a file, save to 0 system album or 1 IPC album. Default is 1

Return: Ctx

ParameterTypeDescription
devIdstringDevice ID
brandColorRetAtom<string>Theme color. Note: values of type RetAtom must be read with useStore
setBrandColor(value: string) => voidSets brandColor
verticalMicRetAtom<string>Whether intercom is shown in vertical mode. Default is true
setVerticalMic(value: string) => voidSets verticalMic
saveToAlbum0 or 1
screenTypeRetAtom<ScreenType>full for landscape, vertical for portrait
setScreenType(value: ScreenType) => voidSets screenType
recordingRetAtom<boolean>Whether recording is in progress
setRecording(value: boolean) => voidSets recording
recordingDisabledRetAtom<boolean>Whether recording is disabled
setRecordingDisabledRetAtom<boolean>Sets recordingDisabled
muteRetAtom<boolean>Whether the player is currently muted
setMute(value: boolean) => Promise<boolean>Sets mute and changes the player's mute state
intercomRetAtom<boolean>Whether intercom is currently active
setIntercom(value: boolean) => Promise<boolean>Sets intercom and changes the player's intercom state
intercomModeRetAtom<IntercomMode>Whether the current mode is one-way or two-way intercom. OneWay means one-way intercom, TwoWay means two-way intercom
intercomSupportedRetAtom<boolean>Whether the current camera supports intercom
resolutionRetAtom<string>Current player resolution
setResolution(type: string) => voidSets the resolution
resolutionListRetAtom<string[]>List of currently supported resolutions
setResolutionList(type: string[]) => voidSets resolutionList
playStateRetAtom<PlayState>Player status: 0 connecting, 1 playing, 2 paused
IPCPlayerInstanceIpcContextPlayer context. See IpcContext
topLeftContentRetAtom<ComponentConfig[]>Widgets in the top-left corner
topRightContentRetAtom<ComponentConfig[]>Widgets in the top-right corner
bottomLeftContentRetAtom<ComponentConfig[]>Widgets in the bottom-left corner
bottomRightContentRetAtom<ComponentConfig[]>Widgets in the bottom-right corner
absoluteContentRetAtom<ComponentConfig[]>Absolutely positioned widgets
getStreamStatus() => PlayerStreamStatusGets the current stream status
addContentAdds a widget. ContentPlaceType: "topLeft", "topRight", "bottomLeft", "bottomRight", "absolute"
deleteContent(type: ContentPlaceType, id: string) => voidDeletes a widget
hasContent(type: ContentPlaceType, id: string) => booleanChecks whether a widget exists
hideContent(type: ContentPlaceType, id: string) => voidHides a widget
showContent(type: ContentPlaceType, id: string) => voidShows a widget
eventEventInstanceEvent system

In the return values, items of type RetAtom cannot be used directly. You must read them with useStore.

Usage Example

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

export function Component() {

  const deviceId = '1234567890xxxxxx';
  const instance = useCtx({
    devId: deviceId
  })
  // Read screenType with useStore
  const { screenType } = useStore({ screenType: instance.screenType });

  // Enable mute
  instance.setMute(true)
}