Home

Awesome

Kronos.server

A realtime server for Kronos protocol.

TODO

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:

LanguageCodeLink
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
Neovimsockconnect({mode}, {address}, {opts})https://neovim.io/
Cint 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
}