Skip to content

Commit

Permalink
cameracontroller added
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Mar 1, 2021
1 parent 8d8e11d commit 1598053
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 219 deletions.
2 changes: 1 addition & 1 deletion client/.eslintcache

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions client/src/components/camera/CameraView.jsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import React, {useRef, useEffect} from 'react'
import React, { useRef, useEffect } from 'react'
import Box from '@material-ui/core/Box'
import JSMpeg from '@cycjimmy/jsmpeg-player'
//const JSMpeg = React.lazy(() => import('@cycjimmy/jsmpeg-player'));

const CameraView = () => {
const ref=useRef(null);
const CameraView = ({ cameraAdress = "" }) => {
const ref = useRef(null);

useEffect(() => {
if(!ref || !ref.current) return;
if (!ref || !ref.current) return;
/* new JSMpeg.VideoElement(
ref.current,
`ws:https://${window.location.host}:2000/api/stream/${encodeURIComponent(
'rtsp:https://admin:[email protected]:8001')}`
) */
new JSMpeg.VideoElement(
ref.current,
`ws:https://${window.location.host}:2000/api/stream/test`
ref.current,
`ws:https://${window.location.host}:2000/api/customstream?cam=${cameraAdress}}`
)

/* new JSMpeg.VideoElement(
ref.current,
`ws:https://${window.location.host}:2000/api/customstream?cam=${cameraAdress})}`
) */

}, [])

return (
<Box width={500} height={300} ref={ref}>
</Box>
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const Dashboard = (props) => {
<Card>
<CardHeader title="Dashboard"/>
<CardContent>
<CameraView/>
<CameraView cameraAdress="rtsp:https://admin:[email protected]:1000/11"/>
<CameraView cameraAdress="rtsp:https://admin:[email protected]:9000/"/>
<BuildingRosenstrasse/>
</CardContent>
</Card>
Expand Down
14 changes: 7 additions & 7 deletions src/controllers/accessController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ export function getAccesses(req: Request, res: Response) {
}


export async function getAccess(req: Request, res: Response){
export async function getAccess(req: Request, res: Response) {
try {
const result=await getRepository(AccessLog).findOne(req.params.id);
if(!result) return res.status(404).send({message: `could not find access log with id: ${req.params.id}`})
const result = await getRepository(AccessLog).findOne(req.params.id);
if (!result) return res.status(404).send({ message: `could not find access log with id: ${req.params.id}` })
} catch (error) {
res.status(500).send(error)
}
}

export async function editAccess(req: Request, res: Response){
export async function editAccess(req: Request, res: Response) {
try {
const result=await getRepository(AccessLog).save(req.body);
const result = await getRepository(AccessLog).save(req.body);
return res.send(result);
} catch (error) {
res.status(500).send(error)
}
}

export async function deleteAccess(req: Request, res: Response){
export async function deleteAccess(req: Request, res: Response) {
try {
const result=await getRepository(AccessLog).delete(req.params.id)
const result = await getRepository(AccessLog).delete(req.params.id)
return res.send(result);
} catch (error) {
res.status(500).send(error)
Expand Down
9 changes: 9 additions & 0 deletions src/controllers/basecontroller/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Repository } from "typeorm";

export default abstract class BaseController<T> {
protected readonly service: Repository<T>;
constructor(service: Repository<T>) {
this.service = service;
}

}
66 changes: 66 additions & 0 deletions src/controllers/cameraController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Request, Response } from "express";
import { Repository, getRepository } from "typeorm";
import { Camera } from "../entity/Camera";
import getList from "../util/getList";
import BaseController from "./basecontroller";

export class CameraController<T> extends BaseController<T>{
constructor(service: Repository<T>) {
super(service)
}
}









export async function getCameras(req: Request, res: Response) {
getList(getRepository(Camera), req, res)
}

export async function getCamera(req: Request, res: Response) {
try {
const { id } = req.params;
const result = await getRepository(Camera).findOne(id)

if (!result) {
return res.status(404).send({ message: `could not find building with the provided id ${id}` })
}
return res.send(result);
} catch (error) {
console.log(error)
res.status(500).send({ error: "server error" })
}
}


export async function createCamera(req: Request, res: Response) {
try {
const result = await getRepository(Camera).save(req.body);
res.send(result)
} catch (error) {
res.status(500).send({
error: error
})
}

}


export async function deleteCamera(req: Request, res: Response) {
try {
const result = await getRepository(Camera).delete(req.params.id)
return res.send(result);
} catch (error) {
res.status(500).send(error)
}
}





Loading

0 comments on commit 1598053

Please sign in to comment.