Thrown away excess data. Camera re-stream

This commit is contained in:
ftc
2023-05-18 22:55:26 +03:00
parent 4232800cb9
commit bb28c8372c
11 changed files with 60 additions and 442 deletions
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
class CameraController extends Controller
{
public function actionStream($id)
{
$cms = Yii::$app->params['cameras'];
if (!isset($cms[$id]))
{
throw new NotFoundHttpException();
}
$zm_id = $cms[$id];
$source_url = Yii::$app->params['zmUrl'].'/cgi-bin/nph-zms?scale=50&mode=jpeg&maxfps=30&buffer=1000&monitor='.$zm_id.'&connkey='.rand(0, 65536);
$fp = fopen($source_url, 'r', false);
if ($fp)
{
Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
// send mjpeg header:
header("Cache-Control: no-cache");
header("Cache-Control: private");
header("Pragma: no-cache");
header("Content-type: multipart/x-mixed-replace; boundary=boundarydonotcross");
// pass data
fpassthru($fp);
fclose($fp);
}
else throw new NotFoundHttpException();
}
}
+10 -102
View File
@@ -3,40 +3,11 @@
namespace app\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\Response;
use yii\filters\VerbFilter;
use app\models\LoginForm;
use app\models\ContactForm;
use yii\helpers\Url;
class SiteController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::class,
'only' => ['logout'],
'rules' => [
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'logout' => ['post'],
],
],
];
}
/**
* {@inheritdoc}
@@ -47,82 +18,19 @@ class SiteController extends Controller
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
/**
* Displays homepage.
*
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
/**
* Login action.
*
* @return Response|string
*/
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
}
$model->password = '';
return $this->render('login', [
'model' => $model,
]);
}
/**
* Logout action.
*
* @return Response
*/
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
/**
* Displays contact page.
*
* @return Response|string
*/
public function actionContact()
{
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
}
return $this->render('contact', [
'model' => $model,
]);
}
/**
* Displays about page.
*
* @return string
*/
public function actionAbout()
{
return $this->render('about');
$cameras = [];
foreach (Yii::$app->params['cameras'] as $id => $zm_id)
{
$cameras[$id] = Url::to(['camera/stream', 'id' => $id]);
}
return $this->render('index',
[
'cameras' => $cameras
]);
}
}