From 16c2a7a0f3894b9ac187b1a1584985694cc3fd63 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Tue, 6 Feb 2018 01:35:24 +0530 Subject: [PATCH] Fix https://github.com/wso2/product-iots/issues/1659 --- .../analytics-view.hbs | 4 ++++ .../public/js/device-stats.js | 11 +++++++++++ .../analytics-view.hbs | 3 +++ .../public/js/device-stats.js | 10 ++++++++++ 4 files changed, 28 insertions(+) diff --git a/modules/distribution/src/core/samples/connectedcup/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.connectedcup.realtime.analytics-view/analytics-view.hbs b/modules/distribution/src/core/samples/connectedcup/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.connectedcup.realtime.analytics-view/analytics-view.hbs index 72dd2a83..9f73a6ce 100644 --- a/modules/distribution/src/core/samples/connectedcup/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.connectedcup.realtime.analytics-view/analytics-view.hbs +++ b/modules/distribution/src/core/samples/connectedcup/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.connectedcup.realtime.analytics-view/analytics-view.hbs @@ -52,6 +52,10 @@ View Device Analytics + +
+ Realtime Analytics for $sensorType 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/modules/distribution/src/core/samples/connectedcup/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.connectedcup.realtime.analytics-view/public/js/device-stats.js b/modules/distribution/src/core/samples/connectedcup/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.connectedcup.realtime.analytics-view/public/js/device-stats.js index de7e6c6b..669fc0ef 100644 --- a/modules/distribution/src/core/samples/connectedcup/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.connectedcup.realtime.analytics-view/public/js/device-stats.js +++ b/modules/distribution/src/core/samples/connectedcup/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.connectedcup.realtime.analytics-view/public/js/device-stats.js @@ -114,6 +114,17 @@ function connect(wsConnection, target, chartData, graph, sensorType) { chartData.shift(); graph.update(); }; + wsConnection.onerror = function (event) { + var websocketURL = event.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('\\$sensorType', 'g'), sensorType); + errorMsg = errorMsg.replace(new RegExp('\\$webSocketURL', 'g'), websocketURL); + $(graph.element).parent().html("
" + errorMsg + "
"); + $(graph.element).hide(); + }; } if (sensorType == "temperature") { wsConnectionTemperature = wsConnection; diff --git a/modules/distribution/src/core/samples/sampledevice/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.sampledevice.realtime.analytics-view/analytics-view.hbs b/modules/distribution/src/core/samples/sampledevice/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.sampledevice.realtime.analytics-view/analytics-view.hbs index 98600ffc..a62e5a7f 100644 --- a/modules/distribution/src/core/samples/sampledevice/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.sampledevice.realtime.analytics-view/analytics-view.hbs +++ b/modules/distribution/src/core/samples/sampledevice/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.sampledevice.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/modules/distribution/src/core/samples/sampledevice/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.sampledevice.realtime.analytics-view/public/js/device-stats.js b/modules/distribution/src/core/samples/sampledevice/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.sampledevice.realtime.analytics-view/public/js/device-stats.js index 61258406..fb2e9ca9 100644 --- a/modules/distribution/src/core/samples/sampledevice/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.sampledevice.realtime.analytics-view/public/js/device-stats.js +++ b/modules/distribution/src/core/samples/sampledevice/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.sampledevice.realtime.analytics-view/public/js/device-stats.js @@ -104,6 +104,16 @@ function connect(wsConnection, target, chartData, graph) { chartData.shift(); graph.update(); }; + wsConnection.onerror = function (event) { + var websocketURL = event.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); + $(graph.element).parent().html("
" + errorMsg + "
"); + $(graph.element).hide(); + }; } }