Skip to content

Commit

Permalink
Added docker and fixed build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
computer committed Jan 25, 2024
1 parent 0435aaf commit 307ee29
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Backend/.env-openvidu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
OPENVIDU_SECRET=MY_SECRET
OPENVIDU_WEBHOOK=true
OPENVIDU_WEBHOOK_ENDPOINT=https://192.168.129.175:8080/media-server
OPENVIDU_WEBHOOK_ENDPOINT=https://backend:8080/media-server


23 changes: 23 additions & 0 deletions Frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Use the official Node.js image as the base image
FROM node:14-alpine

# Set the working directory inside the container
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the entire app to the working directory
COPY . .

# Build the Next.js app
RUN npm run build

# Expose the port that your Next.js app will run on
EXPOSE 3000

# Start the Next.js app
CMD ["npm", "start"]
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ type RequestHeaderOptions = {
Authorization?: string;
};

const accessToken = sessionStorage.getItem("access_token");
const headers: RequestHeaderOptions = {};

if (accessToken) {
headers.Authorization = `Bearer ${sessionStorage.getItem("access_token")}`;
}
export const axiosClient = axios.create({
baseURL: process.env.NEXT_PUBLIC_BACKEND_URL,
headers: { ...headers },
Expand Down
2 changes: 1 addition & 1 deletion Frontend/src/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type PropsType = {

/** This component renders a input field */
export const Input = React.forwardRef<HTMLInputElement, PropsType>(
({ label, password = false, error = undefined, ...props }, ref) => {
({ label, password = false, error = undefined, ...props }, ref:any) => {
return (
<div className="py-1">
<div className={"font-bold pb-2"}>{label}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ export const AuthorizedCounterContainer: FC = () => {
<div className={"flex flex-col gap-2 justify-center items-center"}>
<span>No of attempts on:</span>
<div>
<DatePicker
{/* <DatePicker
format={timeOption === "month" ? "MMM-YYYY" : "DD-MMM-YYYY"}
onChange={setDate}
defaultValue={date}
allowClear={false}
picker={timeOption === "month" ? timeOption : undefined}
/>
/> */}
</div>
</div>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,13 @@ export const AuthorizedUnauthorizedLineContainer: FC = () => {
<div className={"pt-3 flex gap-2 items-center"}>
<span>Date:</span>
<div>
<DatePicker
{/* <DatePicker
format={timeOption === "month" ? "MMM-YYYY" : "DD-MMM-YYYY"}
onChange={setDate}
defaultValue={date}
allowClear={false}
picker={timeOption === "month" ? timeOption : undefined}
/>
/> */}
</div>
</div>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ export const AuthorizedUnauthorizedPieContainer: FC = () => {
<div className={"flex flex-col gap-2 justify-center items-center"}>
<span>Date:</span>
<div>
<DatePicker
{/* <DatePicker
format={timeOption === "month" ? "MMM-YYYY" : "DD-MMM-YYYY"}
onChange={setDate}
defaultValue={date}
allowClear={false}
picker={timeOption === "month" ? timeOption : undefined}
/>
/> */}
</div>
</div>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { Card, Table } from "@/components";
import { recentActivitiesData, recentActivitiesColumns } from "@/data";

export const RecentAuthorizedContainer: FC = () => {
const authorizedEntities = recentActivitiesData
.filter((item) => item.entity !== undefined)
.slice(0, 5);
// const authorizedEntities = recentActivitiesData
// .filter((item) => item.entity !== undefined)
// .slice(0, 5);
return (
<>
<Card header={"Recent Authorzied Activities"}>
<div className="py-4">
<Table columns={recentActivitiesColumns} data={authorizedEntities} rowKey={"id"} />
{/* <Table columns={recentActivitiesColumns} data={authorizedEntities} rowKey={"id"} /> */}
</div>
</Card>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { Card, Table } from "@/components";
import { recentActivitiesData, recentActivitiesColumns } from "@/data";

export const RecentUnauthorizedContainer: FC = () => {
const authorizedEntities = recentActivitiesData
.filter((item) => item.entity === undefined)
.slice(0, 5);
// const authorizedEntities = recentActivitiesData
// .filter((item) => item.entity === undefined)
// .slice(0, 5);
return (
<>
<Card header={"Recent Unauthorzied Activities"}>
<div className="py-4">
<Table columns={recentActivitiesColumns} data={authorizedEntities} rowKey={"id"} />
{/* <Table columns={recentActivitiesColumns} data={authorizedEntities} rowKey={"id"} /> */}
</div>
</Card>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ export const UnauthorizedCounterContainer: FC = () => {
<div className={"flex flex-col gap-2 justify-center items-center"}>
<span>No of attempts on:</span>
<div>
<DatePicker
{/* <DatePicker
format={timeOption === "month" ? "MMM-YYYY" : "DD-MMM-YYYY"}
onChange={setDate}
defaultValue={date}
allowClear={false}
picker={timeOption === "month" ? timeOption : undefined}
/>
/> */}
</div>
</div>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type { AnyObject, AuthorizedEntity, Camera } from "@/types";
export const UserAreaBarContainer: FC = () => {
const cameraOptions = cameras.map((item) => ({
label: item.name,
value: item.key,
value: item.id,
}));
const entityOptions = authorizedEntitiesData.map((item) => ({
label: item.name,
Expand Down Expand Up @@ -70,7 +70,7 @@ export const UserAreaBarContainer: FC = () => {
};

const handleCameraSelectChange = (value: string[]) => {
const selectedCamerasObject = getObjectArray(value, "key", cameras);
const selectedCamerasObject = getObjectArray(value, "id", cameras);
setSelectedCameras(selectedCamerasObject);
};

Expand Down Expand Up @@ -130,13 +130,13 @@ export const UserAreaBarContainer: FC = () => {
<div className={"pt-3 flex gap-4 items-center"}>
<div className={"flex gap-2 items-center"}>
<span>Date:</span>
<DatePicker
{/* <DatePicker
format={timeOption === "month" ? "MMM-YYYY" : "DD-MMM-YYYY"}
onChange={setDate}
defaultValue={date}
allowClear={false}
picker={timeOption === "month" ? timeOption : undefined}
/>
/> */}
</div>

<div className={"grow flex gap-2 items-center"}>
Expand Down
20 changes: 14 additions & 6 deletions Frontend/src/containers/layout-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useSessionSlice, useCameraSlice } from "@/hooks";
import { ProtectionContainer } from "./protection-container";
import { NotificationContainer } from "./notification-container";
import { useQuery } from "react-query";
import { getCameras } from "@/api";
import { axiosClient, getCameras } from "@/api";
import { ModalContainer } from "./modal-container";
const { Header, Content, Footer, Sider } = Layout;

Expand All @@ -20,7 +20,7 @@ export const LayoutContainer = ({
children: React.ReactNode;
}) => {
/* state to check if ant design styled loaded */
const { session, logOut } = useSessionSlice();
const { session, logOut, logIn } = useSessionSlice();
const { isFullScreenGrid, setCameras } = useCameraSlice();
const [antStyleLoaded, setAntStyleLoaded] = useState<boolean>(false);
const [currentNavMenu, setCurrentNavMenu] = useState<NavBarItem[]>([]);
Expand All @@ -44,6 +44,13 @@ export const LayoutContainer = ({
/* useEffect */
useEffect(() => {
setAntStyleLoaded(true);
const accessToken = sessionStorage.getItem("access_token");
if (accessToken) {
axiosClient.defaults.headers.common[
"Authorization"
] = `Bearer ${sessionStorage.getItem("access_token")}`;
logIn({ accessToken: accessToken });
}
}, []);

useEffect(() => {
Expand Down Expand Up @@ -92,10 +99,11 @@ export const LayoutContainer = ({
<Layout>
<Header className="bg-primary flex justify-end" />
<Content
className={`${isFullScreenGrid
? "fixed top-0 left-0 w-screen h-screen"
: "pt-6 px-4 p-0"
}`}
className={`${
isFullScreenGrid
? "fixed top-0 left-0 w-screen h-screen"
: "pt-6 px-4 p-0"
}`}
>
<div className="p-2 bg-white min-h-[360px]">{children}</div>
</Content>
Expand Down
25 changes: 14 additions & 11 deletions Frontend/src/containers/recent-activities-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,22 @@ export const RecentActivitiesContainer: FC<PropsType> = () => {

useEffect(() => {
if (isErrorRecentActivities) {
const error: any = isErrorRecentActivities;
openNotification({
type: "error",
message: isErrorRecentActivities?.response?.data
? isErrorRecentActivities?.response?.data?.message
: isErrorRecentActivities?.message,
message: error?.response?.data
? error?.response?.data?.message
: error?.message,
});
}

if (isErrorRecentActivitiesCount) {
const error: any = isErrorRecentActivitiesCount;
openNotification({
type: "error",
message: isErrorRecentActivitiesCount?.response?.data
? isErrorRecentActivitiesCount?.response?.data?.message
: isErrorRecentActivitiesCount?.message,
message: error?.response?.data
? error?.response?.data?.message
: error?.message,
});
}
}, [isErrorRecentActivities, isErrorRecentActivitiesCount]);
Expand All @@ -68,11 +70,12 @@ export const RecentActivitiesContainer: FC<PropsType> = () => {
columns={recentActivitiesColumns}
data={
/* recentActivitiesFetchedData */ recentActivitiesData?.map(
(event) => ({
...event,
cameraName: cameras.find((item) => item.id == event.cameraId)?.name,
})
)
(event) => ({
...event,
cameraName: cameras.find((item) => item.id == event.cameraId)
?.name,
})
)
}
pagination={{
total: recentActivitiesCountFetchedData,
Expand Down
1 change: 0 additions & 1 deletion Frontend/src/containers/settings-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const SettingsContainer: FC<PropsType> = () => {
/* state*/
const [isLoading, setIsLoading] = useState<boolean>(false);
const { cameras } = useCameraSlice();
console.log(cameras);
const {
control,
handleSubmit,
Expand Down
20 changes: 10 additions & 10 deletions Frontend/src/containers/video-stream-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ const webSocketURL = process.env.NEXT_PUBLIC_BACKEND_URL
? process.env.NEXT_PUBLIC_BACKEND_URL
: "";

const socket = io(webSocketURL, {
transportOptions: {
polling: {
extraHeaders: {
Authorization: `Bearer ${sessionStorage.getItem("access_token")}`,
},
},
},
});

/* This container renders different video recording screens */
export const VideoStreamContainer: FC<PropsType> = ({ sizePerScreen = 9 }) => {
const [subscribers, setSubscribers] = useState<any[]>([]);
Expand Down Expand Up @@ -60,6 +50,16 @@ export const VideoStreamContainer: FC<PropsType> = ({ sizePerScreen = 9 }) => {

/* useEffect hooks */
useEffect(() => {
const socket = io(webSocketURL, {
transportOptions: {
polling: {
extraHeaders: {
Authorization: `Bearer ${sessionStorage.getItem("access_token")}`,
},
},
},
});

const openVidu = new OpenVidu();
const session = openVidu.initSession();

Expand Down
5 changes: 0 additions & 5 deletions Frontend/src/store/slices/session-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ let initialState = {
currentSession: null,
} as SessionState;

const accessToken = sessionStorage.getItem("access_token");
if (accessToken) {
initialState.currentSession = { accessToken: accessToken };
}

export const sessionSlice = createSlice({
name: "session",
// `createSlice` will infer the state type from the `initialState` argument
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ BCRYPT_SALT=...
OPENVIDU_URL= http://localhost:4443/
# Put the OPENVIDU_SECRET of the component that you have launched earlier
OPENVIDU_SECRET=MY_SECRET
# NVR IP
NVR_IP_ADDRESS=localhost:2314
```
Then you can run
```bash
Expand Down
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ services:
env_file:
- .secrets.yml

openvidu:
image: openvidu/openvidu-dev:2.29.0
restart: on-failure # always
ports:
- "4443:4443"
env_file:
- ./Backend/.env-openvidu

backend:
container_name: backend
image: node:21-alpine
depends_on:
- mongo
- openvidu
restart: on-failure # always
ports:
- 8080:8080
Expand All @@ -26,3 +35,16 @@ services:
env_file:
- .secrets.yml
command: npm run docker:dev

frontend:
build:
context: ./Frontend
dockerfile: Dockerfile
restart: on-failure # always
ports:
- "3000:3000"
env_file:
- ./Frontend/.env
depends_on:
- backend

0 comments on commit 307ee29

Please sign in to comment.