-
Notifications
You must be signed in to change notification settings - Fork 549
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use MSE video format for camera feed (#2202)
- Loading branch information
1 parent
1d888de
commit 8f17488
Showing
9 changed files
with
4,880 additions
and
11,340 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}; | ||
}; |
Oops, something went wrong.