From b59f36cd234e68b6b7fcb982da9efdd1a2cb393c Mon Sep 17 00:00:00 2001 From: lurume84 Date: Tue, 16 Jul 2019 16:50:45 +0200 Subject: [PATCH] allow to abandon liveview --- css/style.css | 5 ++++ js/camera/CameraInteractor.js | 24 ++++++++++++++++- js/camera/CameraPresenter.js | 19 +++++++++++++- js/camera/CameraView.js | 49 ++++++++++++++++++++++++++++++----- 4 files changed, 89 insertions(+), 8 deletions(-) diff --git a/css/style.css b/css/style.css index fec8414..284264d 100644 --- a/css/style.css +++ b/css/style.css @@ -311,4 +311,9 @@ top: 0; left: 0; display:none; +} + +.mdl-card__actions .live +{ + color: red !important; } \ No newline at end of file diff --git a/js/camera/CameraInteractor.js b/js/camera/CameraInteractor.js index 428071d..e4bff03 100644 --- a/js/camera/CameraInteractor.js +++ b/js/camera/CameraInteractor.js @@ -189,7 +189,29 @@ }); }, enumerable: false - } + }, + requestUnjoin : { + value: function( camera, listener) + { + $.ajax + ({ + type: "DELETE", + url: "http://127.0.0.1:9191/live", + data: JSON.stringify({camera_id: camera}), + dataType: 'json', + contentType: 'application/json', + success: function (data) + { + listener.onSuccess(data); + }, + error: function (jqxhr, textStatus, error) + { + listener.onError(error); + } + }); + }, + enumerable: false + }, }); interactors.CameraInteractor = CameraInteractor; diff --git a/js/camera/CameraPresenter.js b/js/camera/CameraPresenter.js index 3ae9b96..65e6b39 100644 --- a/js/camera/CameraPresenter.js +++ b/js/camera/CameraPresenter.js @@ -146,7 +146,24 @@ })); }, enumerable: false - } + }, + requestUnjoin : { + value: function(camera) + { + var self = this; + + this.interactor.requestUnjoin(camera, new blink.listeners.BaseDecisionListener( + function(data) + { + self.cameraView.onUnjoin(data, camera); + }, + function(data) + { + self.cameraView.showError(data); + })); + }, + enumerable: false + }, }); presenters.CameraPresenter = CameraPresenter; diff --git a/js/camera/CameraView.js b/js/camera/CameraView.js index 6b1caec..3867175 100644 --- a/js/camera/CameraView.js +++ b/js/camera/CameraView.js @@ -38,7 +38,7 @@ }); actions.find(".thumbnail-button").click(function(){self.requestThumbnail(data);}); - actions.find(".live-view-button").click(function(){self.requestLiveView(data);}); + actions.find(".live-view-button").click(function(){self.clickLiveView(data);}); title.appendTo(card); text.appendTo(card); @@ -163,16 +163,24 @@ }, enumerable: false }, - requestLiveView : { + clickLiveView : { value: function(data) { var card = $("#card" + data.camera_id); - if(!card.find(".mdl-button").prop('disabled')) + var button = card.find(".live-view-button"); + + if(!button.prop('disabled')) { - card.find(".mdl-button").attr("disabled", true); - - self.presenter.requestLiveView(data.network_id, data.camera_id); + if(!button.hasClass("live")) + { + self.presenter.requestLiveView(data.network_id, data.camera_id); + } + else + { + button.attr("disabled", true); + self.presenter.requestUnjoin(data.camera_id); + } } }, enumerable: false @@ -180,10 +188,33 @@ onRequestLiveView : { value: function(data, camera_id) { + var card = $("#card" + camera_id); + card.find(".live-view-button").attr("disabled", true); + self.presenter.requestJoin(camera_id, data.server, self.onJoin); }, enumerable: false }, + onUnjoin : { + value: function(data, camera_id) + { + var card = $("#card" + camera_id); + card.find(".live-view-button").attr("disabled", true); + + var video = card.find("video"); + + var button = card.find(".live-view-button"); + + button.attr("disabled", false); + button.removeClass("live"); + button.find(".action").removeClass("fa-eye-slash").addClass("fa-eye"); + + video.hide(); + + video[0].stop(); + }, + enumerable: false + }, onJoin : { value: function(data) { @@ -193,6 +224,12 @@ var video = card.find("video"); + var button = card.find(".live-view-button"); + + button.attr("disabled", false); + button.addClass("live"); + button.find(".action").removeClass("fa-eye").addClass("fa-eye-slash"); + video.show(); var hlsConfig = {