mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Adds websocket support on the front end via angular-websocket
This commit is contained in:
@@ -13,7 +13,8 @@ angular.module('myApp', [
|
||||
'myApp.enabledExchanges',
|
||||
'myApp.buyOrders',
|
||||
'myApp.sellOrders',
|
||||
'myApp.stringUtils'
|
||||
'myApp.stringUtils',
|
||||
'myApp.webSocket'
|
||||
]).
|
||||
config(['$locationProvider', '$routeProvider', 'NotificationProvider', function($locationProvider, $routeProvider, NotificationProvider) {
|
||||
NotificationProvider.setOptions({
|
||||
|
||||
@@ -1,25 +1,9 @@
|
||||
angular.module('myApp.stringUtils', [])
|
||||
.filter('removeSpaces', [function () {
|
||||
return function (string) {
|
||||
if (!angular.isString(string)) {
|
||||
return string;
|
||||
}
|
||||
return string.replace(/[\s]/g, '');
|
||||
};
|
||||
}]);
|
||||
/*
|
||||
angular.module('myApp.currenctExchangeFactory', []).factory('currentExchangeCurrency', function() {
|
||||
var currentExchangeAndCurrency = {};
|
||||
var exchangeService = {};
|
||||
|
||||
exchangeService.get = function() {
|
||||
return currentExchangeAndCurrency;
|
||||
};
|
||||
exchangeService.update = function(exchange, currency) {
|
||||
currentExchangeAndCurrency.Exchange = exchange;
|
||||
currentExchangeAndCurrency.Currency = currency;
|
||||
};
|
||||
|
||||
return exchangeService;
|
||||
});
|
||||
*/
|
||||
.filter('removeSpaces', [function() {
|
||||
return function(string) {
|
||||
if (!angular.isString(string)) {
|
||||
return string;
|
||||
}
|
||||
return string.replace(/[\s]/g, '');
|
||||
};
|
||||
}]);
|
||||
21
web/app/components/helpers/webSocket.js
Normal file
21
web/app/components/helpers/webSocket.js
Normal file
@@ -0,0 +1,21 @@
|
||||
angular.module('myApp.webSocket', ['ngWebSocket'])
|
||||
.factory('webSocket', function($websocket) {
|
||||
// Open a WebSocket connection
|
||||
var dataStream = $websocket('ws://localhost:9050/');
|
||||
|
||||
var collection = [];
|
||||
|
||||
dataStream.onMessage(function(message) {
|
||||
collection.push(JSON.parse(message.data));
|
||||
});
|
||||
|
||||
var methods = {
|
||||
collection: collection,
|
||||
get: function() {
|
||||
dataStream.send(JSON.stringify({ action: 'get' }));
|
||||
}
|
||||
};
|
||||
|
||||
return methods;
|
||||
|
||||
})
|
||||
@@ -25,7 +25,7 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav class="navbar navbar-default navbar-fixed-top navbar" role="navigation">
|
||||
<nav class="navbar navbar-default navbar-fixed-top navbar navbar-inverse" role="navigation">
|
||||
<div class="container-fluid">
|
||||
|
||||
<div class="navbar-header">
|
||||
@@ -60,6 +60,7 @@
|
||||
<script src="/bower_components/angular/angular.js"></script>
|
||||
<script src="/bower_components/angular-ui-notification/dist/angular-ui-notification.min.js"></script>
|
||||
<script src="/bower_components/angular-route/angular-route.js"></script>
|
||||
<script src="/bower_components/angular-websocket/dist/angular-websocket.js"></script>
|
||||
<script src="/app.js"></script>
|
||||
<script src="/views/settings/settings.js"></script>
|
||||
<script src="/views/home/home.js"></script>
|
||||
@@ -73,6 +74,7 @@
|
||||
<script src="/components/version/version-directive.js"></script>
|
||||
<script src="/components/version/interpolate-filter.js"></script>
|
||||
<script src="/components/helpers/stringUtils.js"></script>
|
||||
<script src="/components/helpers/webSocket.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -9,7 +9,7 @@ angular.module('myApp.home', ['ngRoute'])
|
||||
});
|
||||
}])
|
||||
|
||||
.controller('HomeController', function($scope, $rootScope, $timeout) {
|
||||
.controller('HomeController', function($scope, $rootScope, $timeout, webSocket) {
|
||||
$scope.loaded = false;
|
||||
|
||||
$rootScope.$on('CurrencyChanged', function(event, args) {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"angular-loader": "~1.5.0",
|
||||
"angular-mocks": "~1.5.0",
|
||||
"html5-boilerplate": "^5.3.0",
|
||||
"angular-ui-notification":"latest"
|
||||
"angular-ui-notification":"latest",
|
||||
"angular-websocket":"2.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user