# Chookchat Server

This is the code for Chookchat's server program. The server program:

* Starts a server on port 7070

* Hosts the web client files (index.html at the root)

* Adjusts index.html based on your config file (a backup index.html is still avaliable at localhost:7070/index.html)

* Handles user signups

* Opens a websocket allowing for flexible user input

* Handles file uploads

**Note:** Chookchat does not support HTTPS natively. We recommend the usage of a reverse proxy like Caddy (caddyserver.com) to enable HTTPS on your website, as well as a firewall to block HTTP connections.

## Server Configuration

Chookchat looks for a chookchat.config file in the directory where you start Chookchat. An example is provided in this directory. Your file must look like the following:
```
address:localhost;port:7070;security:false;serviceName:Chookchat;
```

Address: Where your server is hosted (a domain or IP address usually)
Port: Your server's port (default 7070, 443 if you route it through Caddy with HTTPS)
Security: Whether or not to use WSS/HTTPS (either `true` or `false`)
ServiceName: What your server's name comes up as.

## API Documentation

Chookchat uses websockets to send and recieve messages. Each websocket request (except pinging and ponging) contains JSON to show what kind of data we are sending, what user is sending it (and token while being sent to the server), and the actual message content. A chookchat websocket message to the server looks like this:
```json
{
    "type": "message",
    "username": "max",
    "token": "(hash of password)",
    "content": "dongus"
}
```
And a message from the server would look like this (it's the same without the token):
```json
{
    "type": "message",
    "username": "max",
    "content": "dongus"
}
```
The server will send a `ping` every five seconds (without JSON) to stop the connection from timing out. When you recieve this, send back a `pong`. 

### Message Types

**message**: A message. Not much going on. It's recommended to display it like ${username}: ${content}

**call**: A link to a Jitsi call. Treat this how you'd like.

**file**: A file sent by a user. For now, it appears as if the `system` user has sent the file, so in a client send a message describing who's uploaded the file shortly after sending the file.

**connect**: A user joining the room. If this is not sent by the `system` user, ignore. 

**users**: A list of users currently in the room, seperated by ", ". In order of who joined first. If this is not sent by the `system` user, ignore.
