Skip to content

Commit

Permalink
Use MSE video format for camera feed (#2202)
Browse files Browse the repository at this point in the history
  • Loading branch information
developedBySJ authored Apr 2, 2022
1 parent 1d888de commit 8f17488
Show file tree
Hide file tree
Showing 9 changed files with 4,880 additions and 11,340 deletions.
14,733 changes: 4,047 additions & 10,686 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
},
"scripts": {
"prebuild": "npm run re:build && npm run generate-build-meta",
"build:react": "cross-env NODE_ENV=production react-scripts build",
"build:react": "DISABLE_ESLINT_PLUGIN='true' cross-env NODE_ENV=production react-scripts build",
"build:tailwind": "cross-env NODE_ENV=production postcss src/style/index.tailwind.css -o src/style/index.css",
"build": "npm run build:tailwind && INLINE_RUNTIME_CHUNK=false npm run build:react",
"start:react": "cross-env PORT=4000 react-scripts start",
Expand Down
48 changes: 48 additions & 0 deletions src/Common/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,51 @@ export const GENDER: { [key: number]: string } = GENDER_TYPES.reduce(
(acc, curr) => ({ ...acc, [curr.id]: curr.text }),
{}
);

export const getCameraPTZ = (precision: number) => [
{
icon: "fa fa-arrow-up",
label: "Up",
action: "up",
loadingLabel: "Moving Up",
},
{
icon: "fa fa-arrow-down",
label: "Down",
action: "down",
loadingLabel: "Moving Down",
},
{
icon: "fa fa-arrow-left",
label: "Left",
action: "left",
loadingLabel: "Moving Left",
},
{
icon: "fa fa-arrow-right",
label: "Right",
action: "right",
loadingLabel: "Moving Right",
},
{
value: precision,
label: "Precision",
action: "precision",
loadingLabel: "Setting Precision",
},
{
icon: "fa fa-search-plus",
label: "Zoom In",
action: "zoomIn",
loadingLabel: "Zooming In",
},
{
icon: "fa fa-search-minus",
label: "Zoom Out",
action: "zoomOut",
loadingLabel: "Zooming Out",
},
{ icon: "fa fa-stop", label: "Stop", action: "stop" },
{ icon: "fa fa-undo", label: "Reset", action: "reset" },
{ icon: "fas fa-expand", label: "Full Screen", action: "fullScreen" },
];
165 changes: 165 additions & 0 deletions src/Common/hooks/useFeedPTZ.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import axios from "axios";

export interface IAsset {
username: string;
password: string;
hostname: string;
middlewareHostname: string;
port: number;
}

interface PTZPayload {
x: number;
y: number;
zoom: number;
}

interface UseMSEMediaPlayerOption {
config: IAsset;
}

export interface ICameraAssetState {
id: string;
username: string;
password: string;
hostname: string;
port: number;
}

export enum StreamStatus {
Playing,
Stop,
Loading,
Offline,
}

interface UseMSEMediaPlayerReturnType {
absoluteMove: (payload: PTZPayload, options: IOptions) => void;
relativeMove: (payload: PTZPayload, options: IOptions) => void;
getPTZPayload: (action: PTZ) => PTZPayload;
getCameraStatus: (options: IOptions) => void;
getPresets: (options: IOptions) => void;
gotoPreset: (payload: IGotoPresetPayload, options: IOptions) => void;
}

interface IOptions {
onSuccess?: (resp: any) => void;
onError?: (err: any) => void;
}

enum PTZ {
Up = "up",
Down = "down",
Left = "left",
Right = "right",
ZoomIn = "zoomIn",
ZoomOut = "zoomOut",
}

const getCameraStatus =
(config: IAsset) =>
(options: IOptions = {}) => {
const { hostname, middlewareHostname, password, port, username } = config;
axios
.get(
`https://${middlewareHostname}/status?hostname=${hostname}&port=${port}&username=${username}&password=${password}`
)
.then((resp: any) => options?.onSuccess && options.onSuccess(resp))
.catch((err: any) => options?.onError && options.onError(err));
};

const getPresets =
(config: IAsset) =>
(options: IOptions = {}) => {
const { hostname, middlewareHostname, password, port, username } = config;
axios
.get(
`https://${middlewareHostname}/presets?hostname=${hostname}&port=${port}&username=${username}&password=${password}`
)
.then((resp: any) => options?.onSuccess && options.onSuccess(resp))
.catch((err: any) => options?.onError && options.onError(err));
};

interface IGotoPresetPayload {
preset: string;
}

const gotoPreset =
(config: IAsset) =>
(payload: IGotoPresetPayload, options: IOptions = {}) => {
const { middlewareHostname } = config;
axios
.post(`https://${middlewareHostname}/gotoPreset`, {
...payload,
...config,
})
.then((resp: any) => options?.onSuccess && options.onSuccess(resp))
.catch((err: any) => options?.onError && options.onError(err));
};

const absoluteMove =
(config: IAsset) =>
(payload: PTZPayload, options: IOptions = {}) => {
const { middlewareHostname } = config;
axios
.post(`https://${middlewareHostname}/absoluteMove`, {
...config,
...payload,
})
.then((resp: any) => options?.onSuccess && options.onSuccess(resp))
.catch((err: any) => options?.onError && options.onError(err));
};

const relativeMove =
(config: IAsset) =>
(payload: PTZPayload, options: IOptions = {}) => {
const { middlewareHostname } = config;
axios
.post(`https://${middlewareHostname}/relativeMove`, {
...payload,
...config,
})
.then((resp: any) => options?.onSuccess && options.onSuccess(resp))
.catch((err: any) => options?.onError && options.onError(err));
};

export const getPTZPayload = (action: PTZ): PTZPayload => {
let x = 0;
let y = 0;
let zoom = 0;
switch (action) {
case PTZ.Up:
y = 0.1;
break;
case PTZ.Down:
y = -0.1;
break;
case PTZ.Left:
x = -0.1;
break;
case PTZ.Right:
x = 0.1;
break;
case PTZ.ZoomIn:
zoom = 0.1;
break;
case PTZ.ZoomOut:
zoom = -0.1;
break;
}

return { x, y, zoom };
};

export const useFeedPTZ = ({
config,
}: UseMSEMediaPlayerOption): UseMSEMediaPlayerReturnType => {
return {
absoluteMove: absoluteMove(config),
relativeMove: relativeMove(config),
getPTZPayload,
getCameraStatus: getCameraStatus(config),
getPresets: getPresets(config),
gotoPreset: gotoPreset(config),
};
};
Loading

0 comments on commit 8f17488

Please sign in to comment.