Skip to content

Commit

Permalink
Migrated to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Feb 3, 2025
1 parent b8e1de5 commit 3a4e033
Show file tree
Hide file tree
Showing 35 changed files with 711 additions and 74 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2024 bluefox <[email protected]>
Copyright (c) 2020-2025 bluefox <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ sendTo('cameras.0', 'image', {
The result is always in `jpg` format.

Supported cameras:
- Reolink E1 Pro via RTSP (important, without `Pro` it will not work)
- Eufy via eusec adapter
- `Reolink E1 Pro` via RTSP (important, without `Pro` it will not work)
- `Eufy` via eusec adapter
- [HiKam](https://support.hikam.de/support/solutions/articles/16000070656-zugriff-auf-kameras-der-2-generation-via-onvif-f%C3%BCr-s6-q8-a7-2-generation-) of second and third generation via ONVIF (für S6, Q8, A7 2. Generation), A7 Pro, A9
- [WIWICam M1 via HiKam adapter](https://www.wiwacam.com/de/mw1-minikamera-kurzanleitung-und-faq/)
- RTSP Native - if your camera supports RTSP protocol
Expand All @@ -47,7 +47,7 @@ This is URL request for image, where all parameters are in URL, but you can prov

### FFmpeg
If you want to access snapshots on RTSP cameras, you can use ffmpeg. You need to install ffmpeg on your system:
- Windows has precompiled ffmpeg and there is no need to download anything. (Windows version is taken from here: https://www.gyan.dev/ffmpeg/builds/ffmpeg-git-essentials.7z)
- Windows has precompiled ffmpeg and there is no need to download anything. (Windows version is taken from here: https://www.gyan.dev/ffmpeg/builds/ffmpeg-git-full.7z)
- Linux: `sudo apt-get install ffmpeg -y`

Here is an example of how to add Reolink E1:
Expand All @@ -56,8 +56,8 @@ Here is an example of how to add Reolink E1:

## How to add a new camera (For developers)
To add a new camera, you must create a Pull Request on GitHub with the following changes:
- Add new file into `cameras` folder. This is a backend to read the single image from the camera.
- Add GUI file in the `src/src/Types/` folder. This is the configuration dialog for the camera
- Add a new file into `cameras` folder. This is a backend to read the single image from the camera.
- Add a GUI file in the `src/src/Types/` folder. This is the configuration dialog for the camera
- Add this dialog in `src/src/Tabs/Cameras.js` file analogical as other cameras are added. Only two lines should be added:
- Import new configuration dialog like `import RTSPMyCamConfig from '../Types/RTSPMyCam';`
- Extend `TYPES` structure with the new camera like `mycam: { Config: RTSPMyCamConfig, name: 'MyCam' },`
Expand Down Expand Up @@ -140,7 +140,7 @@ To add a new camera, you must create a Pull Request on GitHub with the following
## License
MIT License

Copyright (c) 2020-2024 bluefox <[email protected]>
Copyright (c) 2020-2025 bluefox <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
614 changes: 614 additions & 0 deletions admin/assets/index-DSdrsOJ-.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions admin/assets/index-DZVxZX2g.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added admin/cameras.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added admin/favicon.ico
Binary file not shown.
30 changes: 30 additions & 0 deletions admin/index_m.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link
rel="shortcut icon"
href="favicon.ico"
/>
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<meta
name="theme-color"
content="#000000"
/>
<link
rel="manifest"
href="manifest.json"
/>
<script type="text/javascript" onerror="setTimeout(function(){window.location.reload()}, 5000)" src="./lib/js/socket.io.js"></script>
<title>ioBroker.cameras</title>
<script type="module" crossorigin src="./assets/index-DSdrsOJ-.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-DZVxZX2g.css">
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
15 changes: 15 additions & 0 deletions admin/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "ioBroker.cameras",
"name": "ioBroker.cameras",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
17 changes: 10 additions & 7 deletions build/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/main.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default [
{
ignores: [
'src-admin/**/*',
'src-widgets/**/*',
'admin/**/*',
'widgets/**/*',
'node_modules/**/*',
'test/**/*',
'build/**/*',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"sinon-chai": "^3.7.0",
"typescript": "^5.7.3"
},
"main": "main.js",
"main": "build/main.js",
"files": [
"admin/",
"build/",
Expand All @@ -68,7 +68,7 @@
],
"scripts": {
"test": "mocha --exit",
"lint": "eslint",
"lint": "eslint -c eslint.config.mjs",
"prepublishOnly": "node tasks",
"build": "npm run build-backend && node tasks",
"build-backend": "tsc -p tsconfig.build.json",
Expand Down
4 changes: 2 additions & 2 deletions src-admin/src/Types/ConfigGeneric.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type JSX, Component } from 'react';
import type { AdminConnection, IobTheme, ThemeType } from '@iobroker/adapter-react-v5';
import type { CameraAdapterConfig } from '../types';
import type { CamerasAdapterConfig } from '../types';

export interface ConfigProps<T> {
onChange: (
Expand All @@ -13,7 +13,7 @@ export interface ConfigProps<T> {
T,
'name' | 'type' | 'desc' | 'timeout' | 'cacheTimeout' | 'addTime' | 'title' | 'id' | 'enabled' | 'rtsp'
>;
native: CameraAdapterConfig;
native: CamerasAdapterConfig;
decrypt: (text: string, callback: (decrypted: string) => void) => void;
encrypt: (text: string, callback: (encrypted: string) => void) => void;
theme: IobTheme;
Expand Down
7 changes: 6 additions & 1 deletion src-admin/src/Types/RTSPImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ export default class RTSPImageConfig extends ConfigGeneric<CameraConfigRtsp, { u
});
}

buildCommand(options: Omit<CameraConfigRtsp, 'type' | 'name'>): string[] {
buildCommand(
options: Omit<
CameraConfigRtsp,
'name' | 'type' | 'desc' | 'timeout' | 'cacheTimeout' | 'addTime' | 'id' | 'title' | 'enabled' | 'rtsp'
>,
): string[] {
const parameters = ['-y'];
options.prefix && parameters.push(options.prefix);
parameters.push('-rtsp_transport');
Expand Down
9 changes: 6 additions & 3 deletions src-admin/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
export type ContentType = string;
export type CameraType = 'url' | 'urlBasicAuth' | 'rtsp' | 'reolinkE1' | 'eufy' | 'hikam';

export type CameraName = string;

export interface CameraConfig {
name: string;
name: CameraName;
type: CameraType;
id: number;
rtsp: boolean;
desc?: string;
timeout?: number | string;
cacheTimeout?: number | string;
addTime?: boolean;
title?: string;
enabled?: boolean;
rtsp: boolean;
}

export interface CameraConfigUrl extends CameraConfig {
Expand Down Expand Up @@ -72,7 +75,7 @@ export type CameraConfigAny =

export interface CamerasAdapterConfig {
bind: string;
port: number;
port: string | number;
key: string;
webInstance: string;
defaultTimeout: number | string;
Expand Down
1 change: 0 additions & 1 deletion src-widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"eslint-plugin-only-warn": "^1.1.0",
"eslint-plugin-react": "^7.37.4",
"eslint-plugin-react-hooks": "^5.1.0",
"hls.js": "^1.5.20",
"moment": "^2.30.1",
"node-sass": "^9.0.0",
"prop-types": "^15.8.1",
Expand Down
2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export interface CameraConfig {
name: CameraName;
type: CameraType;
id: number;
rtsp: boolean;
desc?: string;
timeout?: number | string;
cacheTimeout?: number | string;
addTime?: boolean;
title?: string;
enabled?: boolean;
rtsp?: boolean;
}

export interface CameraConfigUrl extends CameraConfig {
Expand Down
8 changes: 4 additions & 4 deletions tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { deleteFoldersRecursive, buildReact, npmInstall, copyFiles, patchHtmlFile
const { copyFileSync } = require('node:fs');

async function copyAllFiles() {
deleteFoldersRecursive(`${__dirname}/admin`);
deleteFoldersRecursive(`${__dirname}/admin`, ['cameras.png', 'cameras.svg']);
copyFiles(['src-admin/build/**/*', '!src-admin/build/index.html', 'admin-config/*'], 'admin/');

await patchHtmlFile(`${__dirname}/src-admin/build/index.html`);
Expand Down Expand Up @@ -69,7 +69,7 @@ if (process.argv.includes('--0-clean')) {
});
}
} else if (process.argv.includes('--2-build')) {
buildReact('src-admin', { rootDir: 'src-admin', tsc: true, vite: true }).catch(e => {
buildReact(`${__dirname}/src-admin`, { rootDir: `${__dirname}/src-admin`, tsc: true, vite: true }).catch(e => {
console.error(`Cannot build: ${e}`);
process.exit(2);
});
Expand All @@ -81,7 +81,7 @@ if (process.argv.includes('--0-clean')) {
} else if (process.argv.includes('--build-admin')) {
clean();
npmInstall('src-admin')
.then(() => buildReact('src-admin', { rootDir: 'src-admin', tsc: true, vite: true }))
.then(() => buildReact(`${__dirname}/src-admin`, { rootDir: `${__dirname}/src-admin`, tsc: true, vite: true }))
.then(() => copyAllFiles());
} else if (process.argv.includes('--widget-0-clean')) {
widgetsClean();
Expand Down Expand Up @@ -114,7 +114,7 @@ if (process.argv.includes('--0-clean')) {
} else {
clean();
npmInstall('src-admin')
.then(() => buildReact('src-admin', { rootDir: 'src-admin', tsc: true, vite: true }))
.then(() => buildReact(`${__dirname}/src-admin`, { rootDir: `${__dirname}/src-admin`, tsc: true, vite: true }))
.then(() => copyAllFiles())
.then(() => widgetsClean())
.then(() => npmInstall('src-widgets'))
Expand Down
2 changes: 1 addition & 1 deletion widgets/cameras/customWidgets.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion widgets/cameras/customWidgets.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion widgets/cameras/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"Camera": "Camera",
"Close": "Close",
"videoWidth": "Video width",
"tooltip_videoWidth": "Do not set width of video too hight to save broadband. It is for both: small and full videos. If not set, the initial size of widget will be taken.",
"tooltip_videoWidth": "Do not set width of video too high to save broadband. It is for both: small and full videos. If not set, the initial size of widget will be taken.",
"Camera instance %s inactive": "Camera instance %s inactive",
"disabled": "disabled",
"pollingInterval": "Polling interval",
Expand Down

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Loading

0 comments on commit 3a4e033

Please sign in to comment.