Skip to content

Commit f185826

Browse files
committed
fix habpanel.js
1 parent fe4f12c commit f185826

File tree

2 files changed

+83
-37
lines changed

2 files changed

+83
-37
lines changed

conf/html/shared/habpanel/js/helper.js

+80-35
Original file line numberDiff line numberDiff line change
@@ -1236,70 +1236,114 @@ var mvInitializer = function(){
12361236
template: '<div><img></div>',
12371237
link: function(scope, element, attrs) {
12381238
var inlineUrl = "//" + authType + domain + "/" + scope.ngModel.config.imageUrl;
1239-
var popupUrl = "//" + authType + domain + "/" + scope.ngModel.config.streamUrl;
1239+
var popupUrl = scope.ngModel.config.streamUrl ? "//" + authType + domain + "/" + scope.ngModel.config.streamUrl : null;
12401240
var inlineRefreshInterval = scope.ngModel.config.imageRefresh;
12411241
var imageWidth = 0;
12421242
var imageHeight = 0;
12431243
var timeoutRef = null;
12441244

1245-
function setInlineUrl( element )
1245+
function setUrl( element, url, interval, width, height, timeoutRef, callback )
12461246
{
1247-
let _url = inlineUrl;
1247+
let _url = url;
12481248

1249-
_url += ( _url.indexOf("?") == -1 ? "?" : "&" ) + 'rand=' + Math.random();
1249+
_url += ( _url.indexOf("?") == -1 ? "?" : "&" ) + 'time=' + ( new Date().getTime() );
1250+
1251+
//console.log(element[0].firstChild.firstChild.clientWidth);
12501252

1251-
_url = _url.replace("{width}",imageWidth);//element.parent()[0].clientWidth);
1252-
_url = _url.replace("{height}",imageHeight);//:,element.parent()[0].clientHeight);
1253-
_url = _url.replace("{age}",inlineRefreshInterval * 1000);
1253+
_url = _url.replace("{width}",width);//element.parent()[0].clientWidth);
1254+
_url = _url.replace("{height}",height);//:,element.parent()[0].clientHeight);
1255+
_url = _url.replace("{age}",interval * 1000);
12541256

1255-
var img = new Image();
1256-
img.onload = function()
1257-
{
1258-
//console.log("set real");
1259-
element[0].firstChild.firstChild.src = _url;
1257+
const startTime = performance.now();
1258+
var xhr = new XMLHttpRequest();
1259+
xhr.open("GET", _url);
1260+
xhr.withCredentials = true;
1261+
xhr.responseType = 'blob';
1262+
xhr.onreadystatechange = function() {
1263+
if (this.readyState != 4) return;
1264+
1265+
if( this.status == 200 )
1266+
{
1267+
var image = element[0].firstChild.firstChild;
1268+
var imageURL = window.URL.createObjectURL(this.response);
1269+
image.onload = function()
1270+
{
1271+
sessionStorage.setItem('mvWidgetImagePopup.inlineUrl_'+inlineUrl, _url);
1272+
1273+
const duration = performance.now() - startTime;
1274+
callback(duration, timeoutRef);
1275+
}
1276+
image.onerror = function(event)
1277+
{
1278+
console.error("Image loading error");
1279+
const duration = performance.now() - startTime;
1280+
callback(duration, timeoutRef);
1281+
}
1282+
image.src = imageURL;
1283+
}
1284+
else
1285+
{
1286+
console.error("Image response error: " + this.status);
1287+
const duration = performance.now() - startTime;
1288+
callback(duration, timeoutRef);
1289+
}
1290+
};
1291+
xhr.send();
1292+
}
12601293

1261-
sessionStorage.setItem('mvWidgetImagePopup.inlineUrl_'+inlineUrl, _url);
1294+
function handleImageRefresh(element, url, interval, width, height)
1295+
{
1296+
function handleTrigger()
1297+
{
1298+
setUrl( element, url, interval, width, height, timeoutRef, function(duration, _timeoutRef){
1299+
if( timeoutRef != _timeoutRef) return;
1300+
var _interval = ( interval * 1000 ) - duration;
1301+
if( _interval > 0 ) timeoutRef = $timeout( handleTrigger, _interval, 0, false);
1302+
else handleTrigger();
1303+
});
12621304
}
1263-
img.src = _url;
1305+
1306+
handleTrigger();
12641307
}
12651308

12661309
function togglePopup( element, forceInline )
12671310
{
1311+
$timeout.cancel(timeoutRef);
1312+
timeoutRef = null;
1313+
12681314
if( forceInline || element[0].firstChild.classList.contains("popup") )
12691315
{
12701316
//console.log("mvWidgetImagePopup: start inline refresh " + inlineRefreshInterval );
12711317

12721318
element[0].firstChild.classList.remove("popup");
1273-
1274-
function handleTrigger()
1275-
{
1276-
//console.log("mvWidgetImagePopup: call inline refresh");
1277-
setInlineUrl( element );
12781319

1279-
timeoutRef = $timeout( handleTrigger, inlineRefreshInterval * 1000, 0, false);
1280-
}
1281-
1282-
handleTrigger();
1283-
1284-
scope.$on('$destroy', function (event)
1285-
{
1286-
//console.log("mvWidgetImagePopup: cancel inline refresh");
1287-
$timeout.cancel(timeoutRef);
1288-
});
1320+
handleImageRefresh(element, inlineUrl, inlineRefreshInterval, imageWidth, imageHeight);
12891321
}
12901322
else
12911323
{
12921324
//console.log("mvWidgetImagePopup: stop inline refresh");
12931325

12941326
element[0].firstChild.classList.add("popup");
1295-
element[0].firstChild.firstChild.src = popupUrl;
1296-
1297-
$timeout.cancel(timeoutRef);
1327+
1328+
if( popupUrl )
1329+
{
1330+
element[0].firstChild.firstChild.src = popupUrl;
1331+
}
1332+
else
1333+
{
1334+
handleImageRefresh(element, inlineUrl, 1, 0, 0);
1335+
}
12981336
}
12991337
}
13001338

13011339
function initLoader( $timeout, scope, element )
13021340
{
1341+
scope.$on('$destroy', function (event)
1342+
{
1343+
//console.log("mvWidgetImagePopup: cancel inline refresh");
1344+
$timeout.cancel(timeoutRef);
1345+
});
1346+
13031347
//console.log( element[0].clientWidth);
13041348
if( element[0].clientWidth > 0 )
13051349
{
@@ -1316,11 +1360,12 @@ var mvInitializer = function(){
13161360
}
13171361

13181362
var timeout = 0;
1363+
var _url = sessionStorage.getItem( 'mvWidgetImagePopup.inlineUrl_'+inlineUrl);
13191364
// force last cached img
1320-
if( sessionStorage.getItem( 'mvWidgetImagePopup.inlineUrl_'+inlineUrl) )
1365+
if( _url )
13211366
{
1322-
//console.log("use cache");
1323-
element[0].firstChild.firstChild.src = sessionStorage.getItem( 'mvWidgetImagePopup.inlineUrl_'+inlineUrl);
1367+
//console.log("use cache " + _url);
1368+
element[0].firstChild.firstChild.src = _url;
13241369
timeout = 1000;
13251370
}
13261371

python/shared/helper.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -559,15 +559,16 @@ def _sendNotification(notification_config, notification_type, mapped_sound, mapp
559559
if notification_type == "telegram":
560560
success = action.sendTelegram("*" + header + "*: " + message)
561561
elif notification_type == "pushover":
562-
success = action.sendMessage(message, header, mapped_sound, None, None, None, None, mapped_priority, notification_config[2] )
562+
success = action.sendMessage(message, header, mapped_sound, None, None, None, None, mapped_priority, notification_config[2], None )
563563
else:
564564
log.error(u"Unknown notification type {}".format(notification_type))
565565
success = None
566566
else:
567567
if notification_type == "telegram":
568568
success = action.sendTelegramPhoto(url,"*" + header + "*: " + message)
569569
elif notification_type == "pushover":
570-
success = action.sendMessage(message, header, mapped_sound, None, None, url, None, mapped_priority, notification_config[2] )
570+
#sendMessage(String message, @Nullable String title, @Nullable String sound, @Nullable String url, @Nullable String urlTitle, @Nullable String attachment, @Nullable String contentType, @Nullable Integer priority, @Nullable String device, @Nullable Duration ttl)
571+
success = action.sendMessage(message, header, mapped_sound, None, None, url, None, mapped_priority, notification_config[2], None )
571572
else:
572573
log.error(u"Unknown notification type {}".format(notification_type))
573574
success = None

0 commit comments

Comments
 (0)