From afe66f237a269a49d59698e6b8acac469efd5849 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Tue, 6 Feb 2018 15:11:32 +0530 Subject: [PATCH] Fix https://github.com/wso2/product-iots/issues/1659 (#1177) --- .../analytics-view.hbs | 3 +++ .../public/js/device-stats.js | 9 +++++++++ .../cdmf.unit.geo-dashboard/public/js/websocket.js | 12 ++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.hbs index 6911c698fc..a1159a5643 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/analytics-view.hbs @@ -37,6 +37,9 @@ View Device Analytics +
+ Realtime Analytics is not available. Failed to connect to the websocket. Please make sure; '$webSocketURL' is available and re-try again. +
{{#zone "bottomJs"}} {{js "js/moment.min.js"}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/public/js/device-stats.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/public/js/device-stats.js index be1f1e7c0c..e84224d15a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/public/js/device-stats.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.default.device.type.realtime.analytics-view/public/js/device-stats.js @@ -48,6 +48,15 @@ function connect(target) { } $("#time-mode").text("Real Time Mode"); }; + ws.onerror = function (webSocketData) { + var websocketURL = webSocketData.currentTarget.url; + websocketURL = websocketURL.replace("wss://","https://"); + var uriParts = websocketURL.split("/"); + websocketURL = uriParts[0] + "//" + uriParts[2]; + var errorMsg = $("#websocker-onerror").html(); + errorMsg = errorMsg.replace(new RegExp('\\$webSocketURL', 'g'), websocketURL); + $("#div-chart").html("
" + errorMsg + "
"); + }; } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/websocket.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/websocket.js index fbecf66217..027de4459f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/websocket.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/websocket.js @@ -571,7 +571,11 @@ var webSocketOnAlertClose = function (e) { }; var webSocketOnAlertError = function (e) { - noty({text: 'Something went wrong when trying to connect to ' + alertWebSocketURL + '', type: 'error'}); + var wsURL = alertWebSocketURL; + wsURL = wsURL.replace("wss://","https://"); + var uriParts = wsURL.split("/"); + wsURL = uriParts[0] + "//" + uriParts[2]; + noty({text: 'Something went wrong when trying to connect to ' + wsURL + '', type: 'error'}); }; var webSocketSpatialOnOpen = function () { @@ -598,7 +602,11 @@ var webSocketSpatialOnClose = function (e) { }; var webSocketSpatialOnError = function (err) { - noty({text: 'Something went wrong when trying to connect to ' + webSocketURL + '', type: 'error'}); + var wsURL = webSocketURL; + wsURL = wsURL.replace("wss://","https://"); + var uriParts = wsURL.split("/"); + wsURL = uriParts[0] + "//" + uriParts[2]; + noty({text: 'Something went wrong when trying to connect to ' + wsURL + '', type: 'error'}); };