Skip to content

Protocol

jbyuki edited this page Nov 16, 2020 · 10 revisions

This is a prototype. All protocol decisions are subject to change rapidely!

Protocol

The protocol is as follows:

  • The first client connects to the server via InstantStartSingle

    • Websocket handshake
    • Send an available message from client
    • The server responds if server is available or not
      • If not available: close client with error
      • If available, everything OK
  • A second client connects to the server via InstantJoinSingle

    • Websocket handshake
    • Send an available message from client
      • If available: close client with error
    • If not available send request message from client
    • Server sends the request to another already connected client
    • Client responds with initial message which contains the whole content
    • Server broadcasts to clients
    • Client receives initial message and sets the buffer content
      • Note: other clients also receives it but discards it
  • During text edit:

    • Client send text message with edits
    • Server broadcast to other clients
    • Client receive the edit
      • If the edit is in a open buffer apply the edit
      • Otherwise queue up the edit and apply it eventually

Messages

All messages are encoded in JSON.

The available message

{
	type: "available"
}

The response message sent by the server when an available message is received

{
	type: "response",
	is_first: boolean,
	client_id: integer
}

The request message

{
	type: "request"
}

The initial message

{
	type: "initial",
	contents : {
		filename : string,
		text : string
	}
}

The text message. start and end designates the first and last lines where the edit takes place.

{
	type: "text",

	ops: [
		[ "ins", char, pid, pid ] |
		[ "del", pid ]
	],

	author: string,
}

The ins operation contains the newly inserted character as well, as the unique ID of the preceding char and the new char.

The del operation contains the pid of the deleted char.

Clone this wiki locally