Skip to content

Commit

Permalink
Updated readme and fixed test files
Browse files Browse the repository at this point in the history
  • Loading branch information
computer committed Jan 19, 2024
1 parent ff21b9e commit 85e65d6
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 13 deletions.
1 change: 1 addition & 0 deletions Backend/.env-openvidu
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
OPENVIDU_SECRET=MY_SECRET
OPENVIDU_WEBHOOK=true
OPENVIDU_WEBHOOK_ENDPOINT=https://localhost:8080/media-server

Expand Down
2 changes: 2 additions & 0 deletions Backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { LoginController } from './app/login.controller';
import { CameraStreamGateway } from './cameraStream/cameraStream.gateway';
import { LoginService } from './login/login.service';
import { MediaServerController } from './app/mediaServer/mediaServer.controller';
import { OpenVidu } from './cameraStream/OpenVidu';

@Module({
imports: [
Expand All @@ -35,6 +36,7 @@ import { MediaServerController } from './app/mediaServer/mediaServer.controller'
TelegramService,
CameraStreamGateway,
LoginService,
OpenVidu
],
exports: [DatabaseService, TelegramService],
})
Expand Down
18 changes: 18 additions & 0 deletions Backend/src/cameraStream/OpenVidu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Injectable } from '@nestjs/common';
const MainOpenVidu = require('openvidu-node-client').OpenVidu;

@Injectable()
export class OpenVidu {
private instance: any;

constructor() {
this.instance = new MainOpenVidu(
process.env.OPENVIDU_URL,
process.env.OPENVIDU_SECRET,
);
}

getInstance() {
return this.instance;
}
}
2 changes: 2 additions & 0 deletions Backend/src/cameraStream/cameraStream.gateway.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CameraStreamGateway } from './cameraStream.gateway';
import { JwtModule } from '@nestjs/jwt';
const OpenVidu = require('openvidu-node-client').OpenVidu;


describe('WebStreamGateway', () => {
let gateway: CameraStreamGateway;
Expand Down
12 changes: 4 additions & 8 deletions Backend/src/cameraStream/cameraStream.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { cameraData } from './cameraData';
const OpenVidu = require('openvidu-node-client').OpenVidu;
import { OpenVidu } from './OpenVidu';

@Catch(WsException, HttpException)
export class WsExceptionFilter implements WsExceptionFilter {
Expand All @@ -44,17 +44,13 @@ type Message = { id: number; data: Buffer };
@UseFilters(WsExceptionFilter)
export class CameraStreamGateway implements OnGatewayConnection {
@WebSocketServer() io: Server;
openvidu = new OpenVidu(
process.env.OPENVIDU_URL,
process.env.OPENVIDU_SECRET,
);
sessionId = null;

constructor(private readonly jwtService: JwtService) {}
constructor(private readonly jwtService: JwtService,private readonly openvidu:OpenVidu) {}

async afterInit() {
try {
const session = await this.openvidu.createSession({});
const session = await this.openvidu.getInstance().createSession({});
this.sessionId = session.sessionId;
cameraData.map((camera) => {
const connectionProperties = {
Expand Down Expand Up @@ -113,7 +109,7 @@ export class CameraStreamGateway implements OnGatewayConnection {
) {
try {
const message = JSON.parse(data) as { sessionId: string };
const session = this.openvidu.activeSessions.find(
const session = this.openvidu.getInstance().activeSessions.find(
(s) => s.sessionId === message.sessionId,
);

Expand Down
97 changes: 92 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,58 @@
# camera-security-system-monorepo
The repository contains the sources code for the Camera Security System project.
The repository contains the sources code for the Camera Security System project(CSS).

# Architecture
The CSS is mainly composed of three 5 components:
1. Frontend: It is the UI that enables the user to view and use the project in the browser.
2. Backend: It is responsible for authentication, logging detection events, and establish communication between the frontend and the media server to access the IP Cameras.
3. Media Server: It is responsible for delivering the camera streams from the IP Cameras to the frontend. We have used [OpenVidu](openvidu.io/) for implementing the media server.
4. Machine learning: It is responsible for analyzing the camera streams and check if an object is
detected.
5. IPCameras: These are the cameras that captures videos of the surrounding.

In order to successfully run the full project components in your local machine, launch the components in the following order:
1. Install your IP Cameras in the areas desired and connect it to the network.
2. Run the media server.
3. Run the backend.
4. Run the frontend.
5. Run the machine learning component.

Below, you will get full details on how to run each component.

# Media Server

### 0- Prerequisite
You should first install docker in your machine.
You can get more information [here](https://docs.docker.com/engine/)
### 1- Open terminal

First open the terminal and move to the backend directory.

If you are currently in root directory of this repo. Type the following in the terminal to change directory:
```yaml
cd ./Backend/
```

### 2- Define environment variables(Configuration)
In order to run the application you will need to define the environment variable by creating
by specifying environment variable file in the root Backend directory.

You can use the .env-openvidu file found in the Backend root directory. You can modify some variables according to your need.

### 3- Run the component

Install the required packages by running:
```yaml
docker run -p 4443:4443 --rm --env-file .env-openvidu openvidu/openvidu-dev:2.29.0
```


# Backend

## Just Run

If you prefer running the backend using docker do the following:

Firstly add .secrets.yml file to root directory using the following template
```yaml
# mongodb+srv is the protocol when connecting to cloud mongodb
Expand All @@ -25,16 +73,55 @@ CSD_PASSWORD=Password
TELEGRAM_TOKEN=api_token
# Should be of the format of BCrypt hash
BCRYPT_SALT=...
# folder path. It is relative to the backend location. The folder directory should never be absolute or start with /
HLS_OUTPUT_DIRECTORY=HLS_OUTPUT
# Master file name of HLS stream
HLS_FILE_NAME=index.m3u8
# Put the openvidu URL of the component that you have launched earlier
OPENVIDU_URL= http://localhost:4443/
# Put the OPENVIDU_SECRET of the component that you have launched earlier
OPENVIDU_SECRET=MY_SECRET
```
Then you can run
```bash
$ docker compose up -d
```

If you prefer running the backend directly using the terminal do the following:

### 0- Prerequisite

You should first install node.js in your machine.
You can get more information [here](https://nodejs.org/en/learn/getting-started/how-to-install-nodejs)

### 1- Open terminal

First open the terminal and move to the backend directory.

If you are currently in root directory of this repo. Type the following in the terminal to change directory:
```yaml
cd ./Backend/
```

### 2- Define environment variables
In order to run the application you will need to define the environment variable by creating
.env file in the root Backend directory.

Copy the content of .env_example found in the Backend root directory and change the variable values
accordingly.

### 3- Install packages

Install the required packages by running:
```yaml
npm install
```

### 4- Run the application

Run the application using this command:

```yaml
npm run start
```
Note: If you are running the backend locally make sure that you followed the steps in the [Media Server Section](#media-server).

# Frontend

This is the frontend part of the camera security system. It is this part that enables
Expand Down

0 comments on commit 85e65d6

Please sign in to comment.