Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for webrtc stream #6457

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
245 changes: 41 additions & 204 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
"rehype-raw": "^6.1.1",
"rescript-webapi": "^0.8.0",
"use-keyboard-shortcut": "^1.1.6",
"uuid": "^9.0.1"
"uuid": "^9.0.1",
"webrtc-adapter": "^8.2.3"
},
"devDependencies": {
"@storybook/addon-essentials": "^7.0.26",
Expand Down
3 changes: 3 additions & 0 deletions public/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
"kasp_full_string": "Karunya Arogya Suraksha Padhathi",
"sample_format_asset_import": "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=11JaEhNHdyCHth4YQs_44YaRlP77Rrqe81VSEfg1glko&exportFormat=xlsx",
"sample_format_external_result_import": "https://docs.google.com/spreadsheets/d/17VfgryA6OYSYgtQZeXU9mp7kNvLySeEawvnLBO_1nuE/export?format=csv&id=17VfgryA6OYSYgtQZeXU9mp7kNvLySeEawvnLBO_1nuE",
"enable_abdm": true,
"jwt_token_refresh_interval": 300000,
"use_webrtc": true
"enable_abdm": true
}
4 changes: 4 additions & 0 deletions src/Common/hooks/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export interface IConfig {
*/
wartime_shifting: boolean;
jwt_token_refresh_interval?: number;
/**
* Env to use webrtc for media streaming
*/
use_webrtc?: boolean;
}

const useConfig = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Common/hooks/useHLSPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export const useHLSPLayer = (ref: ReactPlayer | null) => {
};
return {
startStream,
stopStream: undefined,
stopStream: () => {},
};
};
36 changes: 11 additions & 25 deletions src/Common/hooks/useMSEplayer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useEffect, useRef } from "react";
import axios from "axios";

export interface IAsset {
middlewareHostname: string;
accessKey: string;
}

interface PTZPayload {
Expand Down Expand Up @@ -30,8 +30,8 @@ export enum StreamStatus {
}

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

export interface IOptions {
Expand All @@ -48,25 +48,6 @@ enum PTZ {
ZoomOut = "zoomOut",
}

const stopStream =
({
middlewareHostname,
ws,
}: {
middlewareHostname: string;
ws?: WebSocket;
}) =>
(payload: { id: string }, options: IOptions) => {
const { id } = payload;
ws?.close();
axios
.post(`https://${middlewareHostname}/stop`, {
id,
})
.then((res) => options?.onSuccess && options.onSuccess(res))
.catch((err) => options.onError && options.onError(err));
};

export const getPTZPayload = (action: PTZ): PTZPayload => {
let x = 0;
let y = 0;
Expand Down Expand Up @@ -244,14 +225,19 @@ export const useMSEMediaPlayer = ({
}
});

const stopStream = () => {
wsRef.current?.close();
fetch(`https://${config.middlewareHostname}/stop`, {
method: "POST",
body: JSON.stringify({ id: config.accessKey }),
});
};

useEffect(() => {
return () => {
wsRef.current?.close();
};
}, []);

return {
startStream: startStream,
stopStream: stopStream({ ...config, ws: wsRef.current }),
};
return { startStream, stopStream };
};
Loading
Loading