Skip to content

Commit

Permalink
use custom payload format
Browse files Browse the repository at this point in the history
  • Loading branch information
256dpi committed Sep 8, 2020
1 parent b1567ff commit 999f959
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 4 additions & 1 deletion debug/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ function viz() {
const ws = new WebSocket('ws://0.0.0.0:8080');

ws.onmessage = (event) => {
// get message
const msg = event.data.toString();

// parse sample
const sample = JSON.parse(event.data.toString());
const sample = msg.split(',').map(v => parseFloat(v));

// prepare entry
const entry = {
Expand Down
13 changes: 8 additions & 5 deletions stream.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"sync"
"sync/atomic"

Expand Down Expand Up @@ -43,10 +43,13 @@ func stream(addr string) {
}

func emit(values sample) {
// encode
payload, err := json.Marshal(values)
if err != nil {
panic(err)
// build payload
payload := make([]byte, 0, 256)
for i, v := range values {
if i > 0 {
payload = append(payload, ',')
}
payload = strconv.AppendFloat(payload, v, 'f', 2, 64)
}

// broadcast
Expand Down
8 changes: 5 additions & 3 deletions ui_files.go

Large diffs are not rendered by default.

0 comments on commit 999f959

Please sign in to comment.