-
-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathdashboard.js
218 lines (180 loc) · 7.7 KB
/
dashboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// dashboard.js - Supporting JavaScript for Social Stream Ninja background page
// Function to update connection status indicators
function updateConnectionStatus() {
// These values would be populated by the actual background.js state
const wsConnected = window.socketserver && window.socketserver.readyState === 1;
const wsStatus = document.getElementById('websocket-status');
const wsText = document.getElementById('websocket-status-text');
if (wsConnected) {
wsStatus.className = 'status-indicator status-active';
wsText.textContent = 'Connected';
} else {
wsStatus.className = 'status-indicator status-inactive';
wsText.textContent = 'Disconnected';
}
// WebRTC status depends on iframe and connectedPeers
const hasIframe = !!window.iframe;
const peerCount = Object.keys(window.connectedPeers || {}).length;
const webrtcConnected = hasIframe && peerCount > 0;
const rtcStatus = document.getElementById('webrtc-status');
const rtcText = document.getElementById('webrtc-status-text');
if (hasIframe) {
if (webrtcConnected) {
rtcStatus.className = 'status-indicator status-active';
// Get the peer labels
const peerLabels = {};
Object.values(window.connectedPeers || {}).forEach(label => {
if (label) {
peerLabels[label] = (peerLabels[label] || 0) + 1;
}
});
// Format the peer label information
let peerInfo = '';
if (Object.keys(peerLabels).length > 0) {
peerInfo = ' (';
peerInfo += Object.entries(peerLabels)
.map(([label, count]) => `${label}: ${count}`)
.join(', ');
peerInfo += ')';
} else {
peerInfo = ` (${peerCount} unlabeled peers)`;
}
rtcText.textContent = 'Connected' + peerInfo;
} else {
rtcStatus.className = 'status-indicator status-inactive';
rtcText.textContent = 'Waiting for peers (iframe active)';
}
} else {
rtcStatus.className = 'status-indicator status-inactive';
rtcText.textContent = 'Iframe not initialized';
}
// Extension status
const extensionActive = window.isExtensionOn;
const extStatus = document.getElementById('extension-status');
const extText = document.getElementById('extension-status-text');
if (extensionActive) {
extStatus.className = 'status-indicator status-active';
extText.textContent = 'Active';
} else {
extStatus.className = 'status-indicator status-inactive';
extText.textContent = 'Inactive';
}
// Session ID
const sessionIdEl = document.getElementById('session-id');
sessionIdEl.textContent = window.streamID || 'Not set';
}
// Function to update message statistics
function updateMessageStats() {
const messageCount = document.getElementById('message-count');
const activeSources = document.getElementById('active-sources');
// We'll use messageCounter from background.js
if (window.messageCounter - window.messageCounterBase) {
messageCount.textContent = window.messageCounter - window.messageCounterBase;
}
// Count active sources from tabs or metadata
if (window.metaDataStore) {
activeSources.textContent = window.metaDataStore.size || 0;
}
}
// Function to update feature status
function updateFeatureStatus() {
const settings = window.settings || {};
// MIDI status
const midiStatus = document.getElementById('midi-status');
midiStatus.className = 'status-indicator ' + (settings.midi ? 'status-active' : 'status-inactive');
// Sentiment Analysis
const sentimentStatus = document.getElementById('sentiment-status');
sentimentStatus.className = 'status-indicator ' + (settings.addkarma ? 'status-active' : 'status-inactive');
// Waitlist Mode
const waitlistStatus = document.getElementById('waitlist-status');
waitlistStatus.className = 'status-indicator ' + (settings.waitlistmode ? 'status-active' : 'status-inactive');
// Hype Mode
const hypeStatus = document.getElementById('hype-status');
hypeStatus.className = 'status-indicator ' + (settings.hypemode ? 'status-active' : 'status-inactive');
}
// Function to add a log message
function addLogMessage(message, isError = false) {
const debugOutput = document.getElementById('debugOutput');
const logElement = document.createElement('div');
logElement.className = isError ? 'error-message' : 'log-message';
logElement.textContent = message;
debugOutput.appendChild(logElement);
// Auto-scroll to bottom
debugOutput.scrollTop = debugOutput.scrollHeight;
// Keep only the last 10 messages
while (debugOutput.children.length > 10) {
debugOutput.removeChild(debugOutput.firstChild);
}
}
// Function to update the detailed peer list
function updatePeerList() {
const peerListContent = document.getElementById('peer-list-content');
if (!peerListContent) return;
const connectedPeers = window.connectedPeers || {};
const peerCount = Object.keys(connectedPeers).length;
if (peerCount === 0) {
peerListContent.innerHTML = 'No connected peers';
return;
}
// Group peers by label
const peersByLabel = {};
Object.entries(connectedPeers).forEach(([uuid, label]) => {
const peerLabel = label || 'Unlabeled';
if (!peersByLabel[peerLabel]) {
peersByLabel[peerLabel] = [];
}
// Store just first 8 chars of UUID to keep display compact
peersByLabel[peerLabel].push(uuid.substring(0, 8) + '...');
});
// Create HTML for the peer list
let html = '<strong>Connected Peers:</strong><br>';
Object.entries(peersByLabel).forEach(([label, uuids]) => {
html += `<span style="color: var(--primary-color);">${label}</span> (${uuids.length}): `;
if (uuids.length <= 3) {
html += uuids.join(', ');
} else {
html += `${uuids.slice(0, 2).join(', ')} and ${uuids.length - 2} more`;
}
html += '<br>';
});
peerListContent.innerHTML = html;
}
// Set up periodically updated data
function setupPeriodicUpdates() {
// Initial update
setTimeout(function() {
updateConnectionStatus();
updateMessageStats();
updateFeatureStatus();
updatePeerList();
// Set up regular updates
setInterval(function() {
updateConnectionStatus();
updateMessageStats();
updateFeatureStatus();
updatePeerList();
}, 5000);
}, 1000);
}
// Intercept console logs
function setupConsoleHook() {
const originalConsoleLog = console.log;
const originalConsoleError = console.error;
console.log = function() {
originalConsoleLog.apply(console, arguments);
const message = Array.from(arguments).join(' ');
addLogMessage(message);
};
console.error = function() {
originalConsoleError.apply(console, arguments);
const message = Array.from(arguments).join(' ');
addLogMessage(message, true);
};
}
// Main initialization function
function initDashboard() {
setupConsoleHook();
setupPeriodicUpdates();
}
// Start dashboard when DOM is ready
document.addEventListener('DOMContentLoaded', initDashboard);