Created
November 16, 2020 21:21
-
-
Save JordanSchuetz/218306eb17ebbc91cd8277e2a574e6fd to your computer and use it in GitHub Desktop.
MuleSoft Websockets Connector Tutorial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js"></script> | |
</head> | |
<body> | |
<div width="400" height="400"> | |
<canvas id="myChart"></canvas> | |
</div> | |
<script type = "text/javascript"> | |
data = { | |
datasets: [{ | |
data: [100,0], | |
backgroundColor: [ 'rgba(0, 255, 0, 0.6)', 'rgba(255, 0, 0, 0.6)' ], | |
borderColor: [ 'rgba(0, 255, 0, 1.0)', 'rgba(255, 0, 0, 1.0)' ], | |
borderWidth: 1 | |
}], | |
labels: [ 'Success', 'Error' ] | |
}; | |
if ("WebSocket" in window) { | |
var ws = new WebSocket("ws://localhost:8091/log"); | |
ws.onopen = function() { ws.send("Hello WebSocket"); }; | |
ws.onmessage = function (evt) { | |
var received_msg = evt.data; | |
var percent = parseInt(received_msg); | |
data.datasets[0].data=[percent,100-percent] | |
var ctx = document.getElementById('myChart'); | |
var myDoughnutChart = new Chart(ctx, { | |
type: 'doughnut', | |
data: data | |
}); | |
}; | |
ws.onclose = function() { alert("Connection is closed..."); }; | |
} else { alert("WebSocket NOT supported by your Browser!"); } | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment