<commit_before># Longhouse

A user presence service.

## Prerequisites

- nvm

## Install

```sh
git clone <EMAIL>:usecanvas/longhouse.git
cd longhouse
nvm install
nvm use
npm install
echo "REDIS_URL=redis://localhost:6379" > .env
echo "PRESENCE_TTL=30000" > .env
npm run dev
```

## Use

Longhouse tracks user presence as soon as they connect. To connect to space in
Longhouse, open a WebSocket connection to a URL like:

```
wss://longhouse.example.com/space_uuid?identity=<EMAIL>
```

### Actions

#### `ping`

Sending this action will renew the client's presence lease.

This is currently the only action that should be sent to Longhouse. It needs to
be sent less frequently than the value of `$PRESENCE_TTL` (in milliseconds).

```json
{"action": "ping"}
```

### Remove Events

When relevant events happen on remote clients, Longhouse will send a message to
each client connected to the space where the event occurred.

#### `remote join`

A client has joined the space.

```json
{ "event": "remote join", identity: "<EMAIL>" }
```

#### `remote leave`

A client has left the space (either by expiration or closing their connection).

```json
{ "event": "remote leave", identity: "<EMAIL>" }
```

### Configuration

- `process.env.PRESENCE_TTL` The time (in ms) after which client presence will
  automatically expire

### Errors

When an error occurs that is relevant to the client, an error message will be
sent in this format:

```json
{ error: "Error message" }
```

An error may or may not result in Longhouse terminating the socket connection.

## How does it work?

Longhouse is extremely simple. When a user joins, it sets a key in Redis with
the format `longhouse.spaces.${spaceID}.${clientUUID}.${userIdentity}` with a
value of the user identity.

These keys have a default expire time of 60 seconds.
<commit_msg>Fix quoting in README<commit_after># Longhouse

A user presence service.

## Prerequisites

- nvm

## Install

```sh
git clone <EMAIL>:usecanvas/longhouse.git
cd longhouse
nvm install
nvm use
npm install
echo "REDIS_URL=redis://localhost:6379" > .env
echo "PRESENCE_TTL=30000" > .env
npm run dev
```

## Use

Longhouse tracks user presence as soon as they connect. To connect to space in
Longhouse, open a WebSocket connection to a URL like:

```
wss://longhouse.example.com/space_uuid?identity=<EMAIL>
```

### Actions

#### `ping`

Sending this action will renew the client's presence lease.

This is currently the only action that should be sent to Longhouse. It needs to
be sent less frequently than the value of `$PRESENCE_TTL` (in milliseconds).

```json
{"action": "ping"}
```

### Remove Events

When relevant events happen on remote clients, Longhouse will send a message to
each client connected to the space where the event occurred.

#### `remote join`

A client has joined the space.

```json
{ "event": "remote join", "identity": "<EMAIL>" }
```

#### `remote leave`

A client has left the space (either by expiration or closing their connection).

```json
{ "event": "remote leave", "identity": "<EMAIL>" }
```

### Configuration

- `process.env.PRESENCE_TTL` The time (in ms) after which client presence will
  automatically expire

### Errors

When an error occurs that is relevant to the client, an error message will be
sent in this format:

```json
{ "error": "Error message" }
```

An error may or may not result in Longhouse terminating the socket connection.

## How does it work?

Longhouse is extremely simple. When a user joins, it sets a key in Redis with
the format `longhouse.spaces.${spaceID}.${clientUUID}.${userIdentity}` with a
value of the user identity.

These keys have a default expire time of 60 seconds.

{'fraction_non_alphanumeric': 0.10784313725490197, 'fraction_numerical': 0.005991285403050109, 'mean_word_length': 4.449554896142433, 'pattern_counts': {'":': 9, '<': 11, '<?xml version=': 0, '>': 15, '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': '4566660', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1077, 'n_words': 491}