<commit_before># some spec

all communication is done via a websocket from the browser to the server. The data format is JSON.

## receiving (client)

when receiving, the packets should look like:

    {
      event: <event>,
      payload: <data>
    }

types of packets:

 * `user_list`
 * `user_join`
 * `user_part`
 * `draw`
 * `draw_end`

### user_list

Received to list all users on this whiteboard

Data:

    {
      users: [ <nick>, ... ]
    }

Where it's an array of nicks.

### user_join

Received when a user joins.

Data:

    {
      user: <nick>
    }

`<nick>` is a string

### user_part

Received when a user disconnects from the session.

Data:

    {
      user: <nick>
    }

Where `<nick>` is the user's nickname.

### draw

Received when a user is drawing.

Data:

    {
      user: <nick>,
      penWidth: <penWidth>,
      penColor: <penColor>,
      x: <x>,
      y: <y>
    }

 * `<nick>` is the user who is drawing.
 * `<penWidth>` is an integer > 0 that is the thickness of the pen
 * `<penColor>` a hex value (without hash) which is the color of this pen as a string (eg: "ff0000")
 * `<x>` is the x coordinate
 * `<y>` is the y coordinate

### draw_end

Received when a user picks up his pen

Data:

    {
      user: <nick>
    }

The user who lifted his pen.

## Sending (server)

This is the format of packets that are sent from the client to the server

Base structure (same as receiving):

    {
      event: <event>,
      payload: <data>
    }

Where `<event>` is the name of the action and payload is packet-specific.

The types of events:

 * `pen_up`
 * `draw`
 * `user_list`

### pen_up

Sent when the user stops drawing.

no payload is sent with this. it just signals the server that the user stopped drawing.

### draw
<commit_msg>updated docs to be more accurate<commit_after># some spec

all communication is done via a websocket from the browser to the server. The data format is JSON.

## receiving (client)

when receiving, the packets should look like:

    {
      event: <event>,
      headers: {},
      payload: <data>
    }

types of packets:

 * `user_list`
 * `user_join`
 * `user_part`
 * `draw`
 * `draw_end`

Headers should contain a `sequence` or other data.

*note*: Future versions of the protocol may shorten these names to `e`, `h`, and `p` or even treat the whole
structure as an array.

### user_list

Received to list all users on this whiteboard

Data:

    {
      users: [ { userId: <id>, nick: <nick> }, ... ]
    }

Where it's an array of user objects.

### user_join

Received when a user joins.

Data:

    {
      user: { userId: <id>, nick: <nick> }
    }

`<userId>` is a string that uniquely identifies an individual user.

`<nick>` is a string

### user_part

Received when a user disconnects from the session.

Data:

    {
      user: <id>
    }

Where `<id>` is the user's userId.

### draw

Received when a user is drawing.

Data:

    {
      userId: <id>,
      penWidth: <penWidth>,
      penColor: <penColor>,
      x: <x>,
      y: <y>
    }

 * `<id>` is the user who is drawing.
 * `<penWidth>` is an integer > 0 that is the thickness of the pen
 * `<penColor>` a hex value (without hash) which is the color of this pen as a string (eg: "ff0000")
 * `<x>` is the x coordinate
 * `<y>` is the y coordinate

#### Future

Future versions may optimize this structure so that it uses less data over the wire. For instance,
something like: `[ <userId>, [ <penWidth>, <penColor> ], [ x, y ] ]`.

Comparing:

    {"userId":"#PID<0.257.0>","penWidth":4,"penColor":"ff0000","x":500,"y":500}

to

    ["#PID<0.257.0>",[4,"ff0000"],[500,500]]

That's 53% of the size.


### draw_end

Received when a user picks up his pen

Data:

    {
      userId: <id>
    }

The user who lifted his pen.

## Sending (server)

This is the format of packets that are sent from the client to the server

Base structure (same as receiving, but no headers):

    {
      event: <event>,
      payload: <data>
    }

Where `<event>` is the name of the action and payload is packet-specific.

The types of events:

 * `pen_up`
 * `draw`
 * `user_list`

### pen_up

Sent when the user stops drawing.

no payload is sent with this. it just signals the server that the user stopped drawing.

### draw

{'fraction_non_alphanumeric': 0.11933286351891004, 'fraction_numerical': 0.0103359173126615, 'mean_word_length': 2.808586762075134, 'pattern_counts': {'":': 5, '<': 53, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1926953', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1379, 'n_words': 578}