forked from ElTheLedge/Audio-Over-IP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdaters.go
More file actions
77 lines (65 loc) · 2.25 KB
/
updaters.go
File metadata and controls
77 lines (65 loc) · 2.25 KB
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
package main
import (
wRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
)
// Per-server status update channel; carries server ID and status text as JSON
var connStatus = make(chan ConnStatusMessage, 100)
type ConnStatusMessage struct {
ServerID string `json:"serverId"`
StatusText string `json:"statusText"`
}
type ConnStatuses struct {
Idle string
Connected string
ConnectionFailed string
Connecting string
ConnectionLost string
InvalidIpOrPort string
ResamplingFailed string
AudioConfigRetrievalFailed string
CaptureDeviceUnavailable string
}
var connStatuses = ConnStatuses{
Idle: "Idle",
Connected: "Connected",
ConnectionFailed: "Connection failed",
Connecting: "Connecting...",
ConnectionLost: "Connection lost",
InvalidIpOrPort: "Invalid IP or Port",
ResamplingFailed: "Resampling failed",
AudioConfigRetrievalFailed: "Could not retrieve server audio config",
CaptureDeviceUnavailable: "Capture Device Unavailable",
}
func connStatusUpdater() {
for msg := range connStatus {
// Update server registry status under lock so snapshots reflect current state
serversMu.Lock()
if s, ok := servers[msg.ServerID]; ok {
s.Status = msg.StatusText
}
serversMu.Unlock()
// Emit the per-server status update
wRuntime.EventsEmit(app.ctx, "updateConnStatus", msg)
servers := ListServers()
wRuntime.EventsEmit(app.ctx, "serversUpdated", servers)
app.notifyTrayServerListChanged(servers)
}
}
// ServerStats holds statistics about the server.
type ServerStats struct {
ConnectedClients int `json:"connectedClients"`
Bandwidth int `json:"bandwidth"` // in kbps
}
// ConnectedClient represents a connected client's information
type ConnectedClient struct {
RemoteAddr string `json:"remoteAddr"`
Hostname string `json:"hostname"`
}
// serverStats is a channel for ServerStats updates.
var serverStats = make(chan ServerStats, 10)
// serverStatsUpdater listens for server stats updates and emits them to the frontend.
func serverStatsUpdater() {
for stats := range serverStats {
wRuntime.EventsEmit(app.ctx, "updateServerStats", stats)
}
}