A Pomodoro Server
Find a file
Sebastian Mark 6ffd9f1e38 refactor: move broadcast package to websocket
- update import paths to reflect the new package name
- change function call to use the new websocket package
- adjust client iteration to use the renamed Clients variable

🤖
2024-10-21 13:07:19 +02:00
cmd/server refactor: move broadcast package to websocket 2024-10-21 13:07:19 +02:00
internal refactor: move broadcast package to websocket 2024-10-21 13:07:19 +02:00
pkg/models feat: implement permanent broadcast message functionality 2024-10-21 13:07:19 +02:00
.renovaterc.json chore: add .renovaterc.json 2024-10-20 23:42:25 +02:00
Dockerfile feat: add Dockerfile for GoTomato 2024-10-19 17:13:15 +02:00
go.mod feat(server): restructure Pomodoro server into modular components 2024-10-19 16:49:09 +02:00
go.sum Genesis 2024-10-19 16:49:09 +02:00
GoTomato.go feat: (re)add GoTomato.go 2024-10-19 16:49:09 +02:00
index.html break: update ServerMessage model 2024-10-20 23:42:25 +02:00
README.md feat: implement permanent broadcast message functionality 2024-10-21 13:07:19 +02:00

GoTomato

A pomodoro server written in Go

[[TOC]]

Installation

go install git.smsvc.net/pomodoro/GoTomato@latest

Usage

See GoTomato --help for Parameters

Client Commands and Server Messages

This section describes the WebSocket commands that clients can send to the Pomodoro server and the messages that the server sends to clients during a Pomodoro session.

Message Format

Both client commands (sent to the server) and server messages (sent to the client) use the JSON format. The structure of these messages are described in the sections below.

Client Commands

Clients communicate with the server by sending JSON-encoded commands. Each command must include a command field specifying the action to perform. Here are the available commands:

Command Action Example Sent by Client
start Starts a new Pomodoro session {"command": "start"}
pause Pauses the current session {"command": "pause"}
resume Resumes a paused session {"command": "resume"}
reset Stops and resets the current session {"command": "reset"}

Optional Start Parameters

The Start-Command may contain an optional Pomodoro-Config, which allows you to customize the length of the work session, short break, long break, and the number of sessions. If no configuration is provided, the server will use default values.

Example:

{
    command: "start",
    config: {
        "work": 10,          // Length of the work session in seconds
        "shortBreak": 5,     // Length of the short break in seconds
        "longBreak": 10,     // Length of the long break in seconds
        "sessions": 2        // Number of total sessions
    }
}

Server Messages

The server periodically (every second) sends JSON-encoded messages to all connected clients to update them on the current state of the Pomodoro session. These messages contain the following fields:

  • mode: Indicates the current phase of the Pomodoro session ("Work", "ShortBreak", "LongBreak", or "none" if no session is running).
  • session: The current session number (e.g., 1 for the first work session).
  • total_sessions: The total number of sessions for the current Pomodoro cycle (e.g., 4 if the cycle consists of 4 work/break sessions).
  • time_left: The remaining time for the current mode, in seconds (e.g., 900 for 15 minutes).
  • ongoing: Wether a pomodoro is currently ongoing
  • paused: Wether the timer is paused
Message Type Example
Welcome Message {"mode": "none", "session":0, "total_sessions":0, "time_left":0, "ongoing": false, "paused": false}
Session Running {"mode": "Work", "session": 1, "total_sessions": 4, "time_left": 900, "ongoing": true, "paused": false}
Session Running {"mode": "ShortBreak", "session": 2, "total_sessions": 4, "time_left": 50, "ongoing": true, "paused": false}
Session Paused {"mode": "Work", "session": 2, "total_sessions": 4, "time_left": 456, "ongoing": true, "paused": true}
Session End/Reset {"mode": "none", "session": 0, "total_sessions": 0, "time_left": 0, "ongoing": false, "paused": false}

Testing

docker run --rm -d --name pomodoro-client -v $PWD:/usr/share/nginx/html/ -p 8081:80 nginx
go run .

open http://localhost:8081