Skip to content

Commit

Permalink
feat: Use new panrpc TypeScript API, bump panrpc version
Browse files Browse the repository at this point in the history
Signed-off-by: Felicitas Pojtinger <felicitas@pojtinger.com>
  • Loading branch information
pojntfx committed Aug 15, 2024
1 parent 977fa27 commit 334d98d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
7 changes: 6 additions & 1 deletion pkg/backend/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func StartServer(ctx context.Context, addr string, heartbeat time.Duration, loca
if err := recover(); err != nil {
w.WriteHeader(http.StatusInternalServerError)

log.Printf("Client disconnected with error: %v", err)
log.Println("Client disconnected with error:", err)
}
}()

Expand Down Expand Up @@ -288,11 +288,16 @@ func StartServer(ctx context.Context, addr string, heartbeat time.Duration, loca
conn := websocket.NetConn(ctx, c, websocket.MessageText)
defer conn.Close()

linkCtx, cancelLinkCtx := context.WithCancel(r.Context())
defer cancelLinkCtx()

encoder := json.NewEncoder(conn)
decoder := json.NewDecoder(conn)

go func() {
if err := registry.LinkStream(
linkCtx,

func(v rpc.Message[json.RawMessage]) error {
return encoder.Encode(v)
},
Expand Down
10 changes: 5 additions & 5 deletions pkg/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@patternfly/react-charts": "^8.0.0-alpha.20",
"@patternfly/react-core": "^6.0.0-alpha.57",
"@patternfly/react-icons": "^6.0.0-alpha.20",
"@pojntfx/panrpc": "^0.8.1",
"@pojntfx/panrpc": "^0.9.0",
"@streamparser/json-whatwg": "^0.0.21",
"papaparse": "^5.4.1",
"react": "^18.3.1",
Expand Down
5 changes: 5 additions & 0 deletions pkg/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ const App = () => {
socket.addEventListener("error", rej);
});

const linkSignal = new AbortController();

const encoder = new WritableStream({
write(chunk) {
socket.send(JSON.stringify(chunk));
Expand Down Expand Up @@ -272,9 +274,12 @@ const App = () => {
socket.addEventListener("close", () => {
parserReader.cancel();
parserWriter.abort();
linkSignal.abort();
});

registry.linkStream(
linkSignal.signal,

encoder,
decoder,

Expand Down

0 comments on commit 334d98d

Please sign in to comment.