Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
june07 committed Jan 17, 2023
1 parent 7a3e5b2 commit 7605f8f
Showing 1 changed file with 0 additions and 123 deletions.
123 changes: 0 additions & 123 deletions background-old.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,129 +2,6 @@ var ngApp = angular.module('NimBackgroundApp', []);
ngApp
.run(function() {})
.controller('nimController', ['$scope', '$window', '$http', '$q', function($scope, $window, $http, $q) {
class PubSub {
constructor() {
let self = this;
this.init();
$scope.$on('brakecode-logged-in', () => {
self.init();
self.pubnub.reconnect();
});
$scope.$on('brakecode-logged-out', () => {
self.pubnub.stop();
self.pubnub = null;
});
}
init() {
let self = this;
let authKeyProfileString = DEVEL ? 'http://localhost/pubsub_auth_keys' : 'https://brakecode.com/pubsub_auth_keys';
this.pubnub = new PubNub({
subscribeKey: env.PUBNUB_SUBSCRIBE_KEY,
authKey: localStorage.profile ? JSON.parse(localStorage.profile)[authKeyProfileString] : [],
ssl: true
});
this.pubnub.subscribe({
channels: this.getChannels()
});
this.pubnub.addListener({
message: function(m) {
let msg = m.message;
if (msg.report) {
msg.report = self.parseReport(msg);
$scope.nodeReportMessages.push(msg);
}
try {
Object.values(connections).forEach(c => c.postMessage({ event: 'newNodeReportMessage', report: msg.report }));
} catch (error) {
if (DEVEL) console.log(`Error ${error}`)
}
self.sortMessagesByHost();
self.pruneMessages();
}
});
}
getChannels() {
if (localStorage.profile) {
let channels = [];
if (DEVEL && JSON.parse(localStorage.profile)['http://localhost/apikey']) channels.push(`${JSON.parse(localStorage.profile)['http://localhost/apikey']}`);
else channels.push(`${JSON.parse(localStorage.profile)['https://brakecode.com/apikey']}`);
return channels;
}
}
parseReport(msg) {
let reportString = msg.report,
reportObject = {};

if (msg.type === 'node-reports') {
let metrics = [
'dump event time',
'module load time',
'process id',
'command line',
'node.js version',
'os version',
'machine',
'Total heap memory size',
'Total heap committed memory',
'Total used heap memory',
'Total available heap memory',
'Heap memory limit'
];
reportObject.string = reportString;
reportString.split('\n').map(line => {
metrics.find((metric, index) => {
let regex = new RegExp(`(^${metric}):(.*)`, 'i')
reportObject.temp = line.match(regex) ? line.match(regex) : '';
if (reportObject.temp) {
metrics.splice(index, 1);
reportObject[metric] = {
title: reportObject.temp[1],
value: reportObject.temp[2].trim()
}
return true;
}
});
});
reportObject.id = reportObject.machine.value + ' ' + reportObject['dump event time'].value;
} else {
reportObject = msg.report;
reportObject.machine = { title: 'machine', value: msg.host || reportObject.header.host };
reportObject.id = reportObject.machine.value + ' ' + reportObject.header.dumpEventTime;
}
return reportObject;
}
sortMessagesByHost() {
if ($scope.nodeReportMessages.length === 0) return [];
let hosts = {};
$scope.nodeReportMessages.map(message => {
let host = message.report.id.split(' ')[0],
report = message.report;
if (!hosts[host]) {
hosts[host] = [ {report} ];
} else {
if (hosts[host].find(message => message.report.id === report.id)) {
console.log(`SOMETHING IS WRONG! found duplicate message`);
} else {
hosts[host].push({report});
}
}
});
$scope.nodeReportSortedMessages = hosts;
}
pruneMessages() {
Object.entries($scope.nodeReportSortedMessages).map((kv, i, groups) => {
let host = kv[0],
messages = kv[1];
while (messages.length > $scope.settings.diagnosticReports.maxMessages) {
messages.shift();
}
while ($scope.nodeReportMessages.length > groups.length * $scope.settings.diagnosticReports.maxMessages) {
$scope.nodeReportMessages.shift();
}
$scope.nodeReportSortedMessages[`${host}`] = messages;
});
}
}
$scope.tabNotification = function(instance) {
let tabId = $scope.tabId_HostPort_LookupTable.find(r => r.host === instance.host && r.port == instance.port);
if (tabId === undefined) return;
Expand Down

0 comments on commit 7605f8f

Please sign in to comment.