Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added documentation for the existing Websocket Interface #542

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions pkg/debugger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## Websocket Interface

### Connection

* Each Mir module, when running in 'debugger' mode, starts a websocket server at the port address `xxxx` given at runtime using the flag `-port=xxxx` (e.g., `go run ./pinpong -d -port=8080 0` runs the websocket server of the node on port 8080).
* Before the node starts, it waits for a websocket client to connect. (The frontend will act as the client.)
* The frontend connects to the specified port using `ws://localhost:${this.port}/ws`.
* Upon connection, the server module sends an "init" event.
* Upon receiving the "init" event, the frontend responds with the JSON `{"Type": "start"}`.
* The connection closes when the server stops or the client disconnects using a message of `{"Type": "close"}`.
.

### Event Format (JSON)

```json
{
"event": "protojson.Marshal(event)",
"timestamp": "timestamp"
}

```
_(To note, there is a double JSON parsing for the event)_


### Frontend Response Format (JSON)

```json
{
"Type": "",
"Value": ""
}

```

### Supported Response Types, Expected Values, and Actions

| Type | Value | Frontend Action | Backend Action |
|---------|-------------------------------------------------------------------|----------------------------------------------------------|-------------------------------------------------------------------------------|
| start | null | Initialize the connection | Send the first event |
| accept | null | Add accepted event to the log and wait for the next event | Update the list of events with the accepted one and send the next event |
| decline | null | Drop the declined event and wait for the next event | Drop the declined event and send the next event |
| replace | Modified event (in the format mentioned [above](#event-format-json)) | Add modified event to the log and wait for the next event | Update the list of events with the modified event received and send next event |
| close | null | Close the websocket connection | Stop sending data to the client |
Loading