A realtime server for Kronos protocol.
- 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
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 |
Once connected, the client can send requests. A request is a simple stringified JSON.
Authenticates a user.
interface Login {
type: 'login'
user_id?: string // If omitted, auto-generated
device_id?: string // If omitted, auto-generated
}
interface Login {
success: boolean
type: 'login'
user_id: string
device_id: string
version: string
}
Reads the server database.
interface ReadAll {
type: 'read-all'
user_id: string
device_id: string
}
interface ReadAll {
success: boolean
type: 'read-all'
tasks: Task[] // (1)
}
(1) Task
Writes the entire client locale database to the server database.
interface WriteAll {
success: boolean
type: 'write-all'
data: Database // (1)
user_id: string
device_id: string
}
(1) Database
No output generated.
Adds a new task into the database. Triggers a notification.
interface Create {
type: 'create'
task: Task // (1)
user_id: string
device_id: string
}
(1) Task
No output generated.
Updates a task from database. Triggers a notification.
interface Update {
type: 'update'
task: Task // (1)
user_id: string
device_id: string
}
(1) Task
No output generated.
Deletes a task from database. Triggers a notification.
interface Delete {
type: 'delete'
task_id: number
user_id: string
device_id: string
}
No output generated.
When an error occurres, the server sends a special stringified JSON request:
interface Error {
success: false
error: string
}
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.
interface Create {
type: 'create'
task: Task // (1)
device_id: string
version: string
}
(1) Task
interface Update {
type: 'update'
task: Task // (1)
device_id: string
version: string
}
(1) Task
interface Delete {
type: 'delete'
task_id: number
device_id: string
version: string
}