Skip to main content

Custom Remote Support

In DIVA WebTv we added sendCustomKeypress to make DIVA act in response of a preset of events.

Possible DIVA actions​

Keys parametervaluedescription
ON_KEYUPOnKeyUpwhen any button is released, important
ARROW_UPArrowUpup is pressed
ARROW_DOWNArrowDowndown is pressed
ARROW_LEFTArrowLeftleft is pressed
ARROW_RIGHTArrowRightright is pressed
ENTEREnterenter is pressed
BACKBackback is pressed (from version 5.5.0)
MOUSE_MOVEMouseMove(LG magic) remote moved (from version 5.5.0)
WHEEL_UPWheelUpremote wheel scrolled up (from version 5.5.0)
WHEEL_DOWNWheelDownremote wheel scrolled down
PLAYPlayplay is pressed
PAUSEPausepause is pressed
TOGGLE_PLAY_PAUSEPlay/Pausea button that cycle between play and pause is pressed
FAST_FORWARDFastForwardff is pressed
FAST_REWINDFastRewindrewind is pressed
OPEN_SUBTITLEOpenSubtitleshortcut to open subtitles/cc
OPEN_TIMELINE_EVENT_LISTOpenTimelineEventListshortcut to timeline events list
OPEN_VIDEO_LIST_MODEOpenVideoListModeshortcut to videoList
OPEN_AUDIO_PANELOpenAudioPanelshortcut to audio panels
TAB_NAVTabNavigationtab navigation
TAB_BACK_NAVTabBackNavinverse tab navigation
PLAY_FORCEDPlayForcedshortcut to force play
PAUSE_FORCEDPauseForcedshortcut to force pause
SKIP_FORWARD_FORCEDSkipForwardForcedshortcut to force skip forward
SKIP_BACKWARD_FORCEDSkipBackwardForcedshortcut to force skip backward
OPEN_SETTINGS_FORCEDOpenSettingsForcedshortcut to force open settings panel
OPEN_AUDIO_PANEL_FORCEDSkipBackwardForcedshortcut to force open audio panel
OPEN_SUBTITLE_FORCEDOpenSubtitleForcedshortcut to force open subtitles/cc panel
OPEN_VIDEO_LIST_MODE_FORCEDOpenVideoListModeshortcut to force open videolist panel

Code example​

** useCustomRemote.ts **

import { useCallback, useEffect, useRef } from "react";
import { DivaAPI, Key, Keys } from "@deltatre-vxp/diva-webtv-sdk/generic";

/**
* In this example it is used a map keyCode to DIVA WebTv possible reactions
*/
const customRemoteKeysRef: Record<string, Key> = {
"179": Keys.TOGGLE_PLAY_PAUSE,
"228": Keys.FAST_FORWARD,
"227": Keys.FAST_REWIND,

"40": Keys.ARROW_DOWN,
"38": Keys.ARROW_UP,
"37": Keys.ARROW_LEFT,
"39": Keys.ARROW_RIGHT,
"13": Keys.ENTER,
"27": Keys.BACK,
};

export const useCustomRemote = () => {
const divaApiRef = useRef<DivaAPI | undefined>(undefined);

useEffect(() => {
const onKeyPress = (e: KeyboardEvent) => {
const sckp = divaApiRef.current?.sendCustomKeypress;
const resultingKey = customRemoteKeysRef[`${e.keyCode}`] as unknown as
| Key
| undefined;
if (resultingKey) {
e.preventDefault();
e.stopPropagation();
sckp?.(resultingKey, e);
}
};
window.addEventListener("keydown", onKeyPress);
const onKeyUp = (e: globalThis.KeyboardEvent) => {
const sckp = divaApiRef.current?.sendCustomKeypress;
e.preventDefault();
e.stopPropagation();
sckp?.(Keys.ON_KEYUP, e);
};
window.addEventListener("keyup", onKeyUp);
return () => {
window.removeEventListener("keydown", onKeyPress);
window.addEventListener("keyup", onKeyUp);
};
}, [divaApiRef]);

const setApi = useCallback(
(api: DivaAPI) => {
divaApiRef.current = api;
},
[divaApiRef]
);

return {
divaApiRef,
setApi,
};
};

** App.tsx **

import { DivaWebTV } from "@deltatre-vxp/diva-webtv-sdk/generic";
import { useCustomRemote } from "./useCustomRemote";
// ...

const Player = () => {
// ...

const { setApi } = useCustomRemote();

return (
<DivaWebTV
// ...
setApi={setApi}
keyboardActive={false}
remoteActive={false}
// ...
/>
);
};

Note: it is suggested to disable standard remote navigation (remoteActive) and keyboard (keyboardActive) navigation to prevent that DIVA standard key configuration take the triggers for other tasks