Skip to content

Commit

Permalink
Cleanup: Remove unused stopStream and type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Aug 30, 2024
1 parent 25cfcd6 commit 5afdb38
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 88 deletions.
8 changes: 1 addition & 7 deletions src/Components/CameraFeed/CameraFeedOld.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,7 @@ const CameraFeedOld = (props: any) => {

const videoEl = liveFeedPlayerRef.current as HTMLVideoElement;

const { startStream } = useMSEMediaPlayer({
config: {
middlewareHostname,
...cameraAsset,
},
videoEl,
});
const { startStream } = useMSEMediaPlayer({ videoEl });

const refreshPresetsHash = props.refreshPresetsHash;

Expand Down
22 changes: 0 additions & 22 deletions src/Components/CameraFeed/useFeedPTZ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,11 @@ interface PTZPayload {
zoom: number;
}

export interface PTZState {
x: number;
y: number;
zoom: number;
precision: number;
}

interface UseMSEMediaPlayerOption {
config: IAsset;
dispatch: any;
}

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;
Expand Down
55 changes: 2 additions & 53 deletions src/Components/CameraFeed/useMSEplayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,23 @@ import { useEffect, useRef } from "react";

declare const ManagedMediaSource: typeof MediaSource;

export interface IAsset {
middlewareHostname: string;
}

interface UseMSEMediaPlayerOption {
config: IAsset;
videoEl: HTMLVideoElement | null;
}

export interface ICameraAssetState {
id: string;
accessKey: string;
middleware_address: string;
location_middleware: string;
}

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

interface UseMSEMediaPlayerReturnType {
stopStream: (config: { id: string }, options: IOptions) => void;
startStream: (options?: IOptions) => void;
}

export interface IOptions {
url?: string;
onSuccess?: (resp: any) => void;
onError?: (err: any) => void;
}
const stopStream =
({
middlewareHostname,
ws,
}: {
middlewareHostname: string;
ws?: WebSocket;
}) =>
(payload: { id: string }, options: IOptions) => {
const { id } = payload;
ws?.close();
fetch(`https://${middlewareHostname}/stop`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ id }),
})
.then((res) => {
if (!res.ok) {
throw new Error("network response was not ok");
}
return res.json();
})
.then((res) => options?.onSuccess && options.onSuccess(res))
.catch((err) => options.onError && options.onError(err));
};

export const useMSEMediaPlayer = ({
config,
videoEl,
}: UseMSEMediaPlayerOption): UseMSEMediaPlayerReturnType => {
export const useMSEMediaPlayer = ({ videoEl }: UseMSEMediaPlayerOption) => {
const mseQueue: any[] = [];
let mseStreamingStarted = false;
const wsRef = useRef<WebSocket>();
Expand Down Expand Up @@ -177,8 +129,5 @@ export const useMSEMediaPlayer = ({
};
}, []);

return {
startStream: startStream,
stopStream: stopStream({ ...config, ws: wsRef.current }),
};
return { startStream };
};
7 changes: 1 addition & 6 deletions src/Components/CameraFeed/usePlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ export default function usePlayer(
const [playedOn, setPlayedOn] = useState<Date>();
const [status, setStatus] = useState<StreamStatus>("stop");

const { startStream } = useMSEMediaPlayer({
// Voluntarily set to "" as it's used by `stopStream` only (which is not
// used by this hook)
config: { middlewareHostname: "" },
videoEl: ref.current as HTMLVideoElement,
});
const { startStream } = useMSEMediaPlayer({ videoEl: ref.current });

const initializeStream = useCallback(
({ url, onSuccess, onError }: IOptions) => {
Expand Down

0 comments on commit 5afdb38

Please sign in to comment.