Awesome
Kronos.server
A realtime server for Kronos protocol.
TODO
- Rewrite all in TypeScript
- database.js
- device.js
- index.js
- server.js
- session.js
- task.js
- tcp.js
- user.js
- ws.js
- Split everything as much as possible (KISS & DRY)
- Refactor to respect the Kronos protocol
Table of contents
Connect
Kronos.server is a realtime server that handles basic socket and web socket requests. Here some exemples in different languages on how to open a socket connection:
Language | Code | Link |
---|---|---|
JavaScript (Node.js) | socket.connect(port[, host][, connectListener]) | https://nodejs.org |
JavaScript (Browser) | new WebSocket(url[, protocols]) | https://developer.mozilla.org |
Vim8+ | ch_open({address} [, {options}]) | http://vimhelp.appspot.com |
Neovim | sockconnect({mode}, {address}, {opts}) | https://neovim.io/ |
C | int socket(int domain, int type, int protocol); | http://man7.org |
Request
Once connected, the client can send requests. A request is a simple stringified JSON.
Login
Authenticates a user.
Input
interface Login {
type: 'login'
user_id?: string // If omitted, auto-generated
device_id?: string // If omitted, auto-generated
}
Output
interface Login {
success: boolean
type: 'login'
user_id: string
device_id: string
version: string
}
Read all
Reads the server database.
Input
interface ReadAll {
type: 'read-all'
user_id: string
device_id: string
}
Output
interface ReadAll {
success: boolean
type: 'read-all'
tasks: Task[] // (1)
}
(1) Task
Write all
Writes the entire client locale database to the server database.
Input
interface WriteAll {
success: boolean
type: 'write-all'
data: Database // (1)
user_id: string
device_id: string
}
(1) Database
Output
No output generated.
Create
Adds a new task into the database. Triggers a notification.
Input
interface Create {
type: 'create'
task: Task // (1)
user_id: string
device_id: string
}
(1) Task
Output
No output generated.
Update
Input
Updates a task from database. Triggers a notification.
interface Update {
type: 'update'
task: Task // (1)
user_id: string
device_id: string
}
(1) Task
Output
No output generated.
Delete
Input
Deletes a task from database. Triggers a notification.
interface Delete {
type: 'delete'
task_id: number
user_id: string
device_id: string
}
Output
No output generated.
Error
When an error occurres, the server sends a special stringified JSON request:
interface Error {
success: false
error: string
}
Database event
Kronos server uses a realtime database called RethinkDB. When a task is created / updated / deleted, a notification is sent to all connected user's devices.
Create
interface Create {
type: 'create'
task: Task // (1)
device_id: string
version: string
}
(1) Task
Update
interface Update {
type: 'update'
task: Task // (1)
device_id: string
version: string
}
(1) Task
Delete
interface Delete {
type: 'delete'
task_id: number
device_id: string
version: string
}