Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame^] | 1 | angular.module('bmcApp').factory('IPMIData', [ |
| 2 | '$websocket', '$location', |
| 3 | function($websocket, $location) { |
| 4 | |
| 5 | var host = $location.host(); |
| 6 | var port = $location.port(); |
| 7 | var protocol = "ws://"; |
| 8 | if ($location.protocol() === 'https') { |
| 9 | protocol = 'wss://'; |
| 10 | } |
| 11 | // Open a WebSocket connection |
| 12 | var dataStream = $websocket(protocol + host + port + "/ipmiws"); |
| 13 | var blob = new Blob([0x06, 0x00, 0xff, 0x07, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x20, 0x18, 0xc8, 0x81, 0x04, 0x38, 0x8e, 0x04, 0xb1]); |
| 14 | dataStream.send(blob); |
| 15 | |
| 16 | dataStream.onMessage(function(message) { |
| 17 | collection.push(JSON.parse(message.data)); |
| 18 | }); |
| 19 | |
| 20 | var methods = { |
| 21 | |
| 22 | get : function() { |
| 23 | var blob = new Blob([0x06, 0x00, 0xff, 0x07, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x20, 0x18, 0xc8, 0x81, 0x04, 0x38, 0x8e, 0x04, 0xb1]); |
| 24 | dataStream.send(blob); |
| 25 | } |
| 26 | }; |
| 27 | |
| 28 | return methods; |
| 29 | } |
| 30 | ]); |
| 31 | angular.module('bmcApp').controller('ipmiController', [ |
| 32 | '$scope', 'IPMIData', function($scope, IPMIData) { $scope.IPMIData = IPMIData; } |
| 33 | ]); |