Skip to content

Commit 206b360

Browse files
authored
Merge pull request #102 from jacktrip/feature/extra-ping-stats
Adding some extra ping stats and adding DeviceHeartbeatWithConfig
2 parents cd441c6 + 9c65c08 commit 206b360

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
sha256sum ${FILENAME} | tee -a ${FILENAME}.sha256
6666
- name: Archive artifacts
6767
if: github.event_name != 'pull_request'
68-
uses: actions/upload-artifact@v3
68+
uses: actions/upload-artifact@v4
6969
with:
7070
name: jacktrip-agent-arm
7171
path: jacktrip-agent-arm-*

pkg/client/devices.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ type PingStats struct {
125125
// LatestRtt is the latest rtt sent via socket ping.
126126
LatestRtt time.Duration `json:"latest_rtt" db:"latest_rtt"`
127127

128+
// AudioInputLatency is the latest client-side audio input device latency
129+
AudioInputLatency time.Duration `json:"audio_input_latency" db:"audio_input_latency"`
130+
131+
// AudioOutputLatency is the latest client-side audio output device latency
132+
AudioOutputLatency time.Duration `json:"audio_output_latency" db:"audio_output_latency"`
133+
134+
// ClientBufferLatency is the latest client-side receiver buffer latency
135+
ClientBufferLatency time.Duration `json:"client_buffer_latency" db:"client_buffer_latency"`
136+
137+
// ServerBufferLatency is the latest server-side receiver buffer latency
138+
ServerBufferLatency time.Duration `json:"server_buffer_latency" db:"server_buffer_latency"`
139+
128140
// timestamp when the device stats were last updated
129141
StatsUpdatedAt time.Time `json:"stats_updated_at" db:"stats_updated_at"`
130142

@@ -162,3 +174,37 @@ type DeviceHeartbeat struct {
162174
// Type of sound device ("snd_rpi_hifiberry_dacplusadcpro")
163175
Type string `json:"type" db:"type"`
164176
}
177+
178+
// DeviceHeartbeatWithConfig is used to represent ping statistics with config for an audio device
179+
type DeviceHeartbeatWithConfig struct {
180+
PingStats
181+
DeviceConfig
182+
ALSAConfig
183+
184+
// unique identifier for an audio device
185+
ID string `json:"id" db:"id"`
186+
187+
// MAC address of the device
188+
MAC string `json:"mac" db:"mac"`
189+
190+
// User identifier of the device's owner
191+
OwnerID string `json:"ownerId" db:"owner_id"`
192+
193+
// audio server that the device is connected to (may be empty)
194+
ServerID string `json:"serverId" db:"server_id"`
195+
196+
// Current image version for the device
197+
Version string `json:"version" db:"version"`
198+
199+
// Descriptive name for the device
200+
Name string `json:"name" db:"name"`
201+
202+
// frames per period
203+
Period int `json:"period" db:"period"`
204+
205+
// size of jitter queue buffer
206+
QueueBuffer int `json:"queueBuffer" db:"queue_buffer"`
207+
208+
// strategy to use for the network jitter buffer
209+
BufferStrategy int `json:"bufferStrategy" db:"buffer_strategy"`
210+
}

pkg/client/devices_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,23 @@ func TestDeviceHeartbeat(t *testing.T) {
155155
assert.Equal(-1*time.Duration(10291), target.StdDevRtt)
156156
assert.Equal("2021-08-11 10:28:32.487013776 +0000 UTC", target.StatsUpdatedAt.String())
157157
}
158+
159+
func TestStructDeviceHeartbeatWithConfig(t *testing.T) {
160+
assert := assert.New(t)
161+
var data string
162+
var device DeviceHeartbeatWithConfig
163+
// Construct using JSON
164+
data = `{"id": "lmnop", "mac": "mac-address", "ownerId": "mr-rogers", "serverID": "thatserveroverthere", "version": "v1.0.0", "name": "myJacktripDevice", "period": 128, "queueBuffer": 16}`
165+
device = DeviceHeartbeatWithConfig{}
166+
err := json.Unmarshal([]byte(data), &device)
167+
assert.Nil(err)
168+
assert.Equal("lmnop", device.ID)
169+
assert.Equal("mac-address", device.MAC)
170+
assert.Equal("mr-rogers", device.OwnerID)
171+
assert.Equal("thatserveroverthere", device.ServerID)
172+
assert.Equal("v1.0.0", device.Version)
173+
assert.Equal("myJacktripDevice", device.Name)
174+
assert.Equal(128, device.Period)
175+
assert.Equal(16, device.QueueBuffer)
176+
assert.Equal(false, bool(device.EnableUSB))
177+
}

0 commit comments

Comments
 (0)