Browse Source

camera play

develop
Robin Thoni 8 years ago
parent
commit
095a29cb21
3 changed files with 71 additions and 20 deletions
  1. 54
    10
      camotion/controllers/cameras.controller.js
  2. 12
    10
      camotion/controllers/sensors.controller.js
  3. 5
    0
      sdk/cameras.js

+ 54
- 10
camotion/controllers/cameras.controller.js View File

@@ -1,30 +1,74 @@
1 1
 angular.module('camotion')
2
-    .controller('CamerasController', ['$scope', 'CamerasService',
3
-        function($scope, CamerasService) {
2
+    .controller('CamerasController', ['$scope', 'CamerasService', '$timeout',
3
+        function($scope, CamerasService, $timeout) {
4 4
 
5 5
             $scope.cameras = [];
6
-            $scope.rowCameras = [];
7
-
8
-            $scope.playingCameras = [];
6
+            $scope.images = {};
7
+            $scope.interval = 1000;
9 8
 
10 9
             $scope.playPause = function(camera)
11 10
             {
12
-                var idx = $scope.playingCameras.indexOf(camera.Id);
13
-                if (idx > -1) {
14
-                    $scope.playingCameras.splice(idx, 1);
11
+                if ($scope.isPlaying(camera)) {
12
+                    $scope.pause(camera);
15 13
                 }
16 14
                 else {
17
-                    $scope.playingCameras.push(camera.Id);
15
+                    $scope.play(camera);
16
+                }
17
+            };
18
+
19
+            $scope.play = function(camera)
20
+            {
21
+                if (!$scope.isPlaying(camera)) {
22
+                    $scope.images[camera.Id] = {
23
+                        image: null,
24
+                        timerId: 0
25
+                    };
26
+                    $scope.updateCamera(camera);
27
+                }
28
+            };
29
+
30
+            $scope.pause = function(camera)
31
+            {
32
+                if ($scope.isPlaying(camera)) {
33
+                    $scope.images[camera.Id] = null;
18 34
                 }
19 35
             };
20 36
 
21 37
             $scope.isPlaying = function(camera)
22 38
             {
23
-                return $scope.playingCameras.indexOf(camera.Id) > -1;
39
+                return $scope.images[camera.Id] != null;
40
+            };
41
+
42
+            $scope.updateCamera = function(camera)
43
+            {
44
+                if ($scope.isPlaying(camera)) {
45
+                    CamerasService.getImage({camera_id: camera.Id})
46
+                        .then(function (image) {
47
+                            if ($scope.isPlaying(camera)) {
48
+                                $scope.images[camera.Id] = {
49
+                                    image: image.Image,
50
+                                    timerId: $timeout(function () {
51
+                                        $scope.updateCamera(camera);
52
+                                    }, $scope.interval)
53
+                                }
54
+                            }
55
+                        }, function (error) {
56
+                            $scope.pause(camera);
57
+                        });
58
+                }
24 59
             };
25 60
 
26 61
             CamerasService.getAll({}).then(function(cameras)
27 62
             {
63
+                $scope.images = {};
28 64
                 $scope.cameras = cameras.Data;
65
+                for (var i = 0; i < $scope.cameras.length; ++i) {
66
+                    var camera = angular.copy($scope.cameras[i]);
67
+                    $scope.play(camera);
68
+                }
69
+            });
70
+
71
+            $scope.$on('$destroy', function(){
72
+                $scope.images = {};
29 73
             });
30 74
     }]);

+ 12
- 10
camotion/controllers/sensors.controller.js View File

@@ -52,17 +52,19 @@ angular.module('camotion')
52 52
 
53 53
             $scope.updateSensor = function(sensor)
54 54
             {
55
-                SensorsService.getValue({sensor_id: sensor.Id})
56
-                    .then(function(value) {
57
-                        if (typeof $scope.values[sensor.Id] != 'undefined') {
58
-                            $scope.values[sensor.Id] = {
59
-                                value: value,
60
-                                timerId: $timeout(function () {
61
-                                    $scope.updateSensor(sensor);
62
-                                }, $scope.interval)
55
+                if (typeof $scope.values[sensor.Id] != 'undefined') {
56
+                    SensorsService.getValue({sensor_id: sensor.Id})
57
+                        .then(function (value) {
58
+                            if (typeof $scope.values[sensor.Id] != 'undefined') {
59
+                                $scope.values[sensor.Id] = {
60
+                                    value: value,
61
+                                    timerId: $timeout(function () {
62
+                                        $scope.updateSensor(sensor);
63
+                                    }, $scope.interval)
64
+                                }
63 65
                             }
64
-                        }
65
-                    });
66
+                        });
67
+                }
66 68
             };
67 69
 
68 70
             $scope.$on('$destroy', function(){

+ 5
- 0
sdk/cameras.js View File

@@ -39,6 +39,11 @@
39 39
                 return luticateRequest.post("/api/cameras/" + data.camera_id + "/del", null, null, promise);
40 40
             };
41 41
 
42
+            CamerasService.getImage = function(data, promise)
43
+            {
44
+                return luticateRequest.post("/api/cameras/" + data.camera_id + "/image", null, null, promise);
45
+            };
46
+
42 47
             return CamerasService;
43 48
         }]);
44 49
 })();

Loading…
Cancel
Save