# Nchan-base messenger for QFQ

| Directory | Documentation                | Intention                                           |
|-----------|------------------------------|-----------------------------------------------------|
|`js`       |[doc/JS.md](doc/JS.md)        | JavaScript SDK for listeners and publishers         |
|`testjs`   |                              | Jest tests                                          |
|`php`      |[doc/PHP.md](doc/PHP.md)      | PHP SDK for publishing messages and creating tokens |
|`testphp`  |                              | PHPUnit tests                                       |
|`nginx`    |[nchan.io](https://nchan.io/) | A flexible nchan configuration                      |
|`example`  | (see below)                  | A comprehensive example                             |

## Installation

Install with
```
$ npm install
$ composer install
```
Run tests with
```
$ npm test
$ phpunit --bootstrap vendor/autoload.php
```

## Running the example

1. Configure nginx
   1. Install nchan module for nginx
   1. Copy `nginx/messenger-vars.conf` to `etc/nginx/conf.d`
   1. Copy `nginx/messenger-local.conf` and `nginx/messenger-global.conf` to `/etc/nginx/snippets/`
   1. Include the snippets
      * `messenger-local.conf` in the configuration of `localhost`
      * `messenger-global.conf` in the configuration of the public server
1. Install libraries in `/var/www/html/messenger/`
   1. Copy folders `js` and `php`
   1. Copy `vendor/psr/log/src` to `vendor`
1. Install website files:
   1. Copy files from `example` to `/var/www/html/messenger/`
   1. If necessary, update  constants in `hooks/request.php`
1. Open the page `https://servername.com/messenger/` in the browser and start playing!
