diff --git a/assets/AppAsset.php b/assets/AppAsset.php
index 732d48e..444bc5b 100644
--- a/assets/AppAsset.php
+++ b/assets/AppAsset.php
@@ -21,8 +21,10 @@ class AppAsset extends AssetBundle
public $baseUrl = '@web';
public $css = [
'css/site.css',
+ 'css/video-js.css',
];
public $js = [
+ 'js/video.min.js',
];
public $depends = [
'yii\web\YiiAsset',
diff --git a/components/ApiClient.php b/components/ApiClient.php
index 2684e14..2e626e0 100644
--- a/components/ApiClient.php
+++ b/components/ApiClient.php
@@ -54,4 +54,8 @@ class ApiClient
urlencode('StartTime >=:'.$start_time).'.json?page='.$page);
}
+ public function getEvent($id)
+ {
+ return $this->sendRequest('events/'.$id.'.json');
+ }
}
\ No newline at end of file
diff --git a/config/console.php b/config/console.php
index ca429af..71f2591 100644
--- a/config/console.php
+++ b/config/console.php
@@ -4,7 +4,7 @@ $params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$config = [
- 'id' => 'basic-console',
+ 'id' => 'glade-cameras',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'app\commands',
diff --git a/config/web.php b/config/web.php
index ed1bb9d..528e5a8 100644
--- a/config/web.php
+++ b/config/web.php
@@ -4,7 +4,8 @@ $params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$config = [
- 'id' => 'basic',
+ 'id' => 'glade',
+ 'name' => 'Ясная Поляна',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'aliases' => [
diff --git a/controllers/CameraController.php b/controllers/CameraController.php
index c332a42..41e46fa 100644
--- a/controllers/CameraController.php
+++ b/controllers/CameraController.php
@@ -5,6 +5,9 @@ namespace app\controllers;
use Yii;
use yii\web\Controller;
+use yii\web\NotFoundHttpException;
+use yii\web\ForbiddenHttpException;
+
class CameraController extends Controller
{
public function actionStream($id, $scale = 50)
@@ -72,12 +75,54 @@ class CameraController extends Controller
return $result;
}
- public function actionViewArchive($event_id)
+ private function getZMEvent($event_id)
{
+ $client = new \app\components\ApiClient(Yii::$app->params['zmUrl'].'zm/api');
+ $json = $client->getEvent($event_id);
+ $r = json_decode($json, true);
+ $e = new \app\models\zm\Event($r['event']['Event']);
+ return $e;
+ }
+
+ private function checkCameraAccess($camera_id, $event_id)
+ {
+ $cms = Yii::$app->params['cameras'];
+ if (!isset($cms[$camera_id]))
+ {
+ throw new NotFoundHttpException();
+ }
+ $e = $this->getZMEvent($event_id);
+ if ($e->monitor_id !== $camera_id)
+ {
+ throw new ForbiddenHttpException();
+ }
+
+ }
+
+ public function actionViewArchive($camera_id, $event_id)
+ {
+ $this->checkCameraAccess($camera_id, $event_id);
return $this->render('view_archive',
[
+ 'camera_id' => $camera_id,
'id' => $event_id,
+ 'event' => $this->getZMEvent($event_id),
]);
}
+
+ public function actionStreamEvent($camera_id, $event_id)
+ {
+ $this->checkCameraAccess($camera_id, $event_id);
+ $source_url = Yii::$app->params['zmUrl'].'/zm/index.php?mode=mpeg&format=h264&eid='.$event_id.'&view=view_video';
+ $fp = fopen($source_url, 'r', false);
+ if ($fp)
+ {
+ Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
+ // pass data
+ fpassthru($fp);
+ fclose($fp);
+ }
+ else throw new NotFoundHttpException();
+ }
}
diff --git a/views/camera/view.php b/views/camera/view.php
index 4b63aab..50b8bce 100644
--- a/views/camera/view.php
+++ b/views/camera/view.php
@@ -16,7 +16,7 @@ $this->title = 'Камера '.$id;
Архив записей: