# Server-sent events (SSE)

**Server-sent events (SSE)** is a technology enabling a browser to receive automatic updates from a server via HTTP connection. The Server-Sent Events EventSource API is standardized as part of HTML5 by the W3C. [Wikipedia](https://en.wikipedia.org/wiki/Server-sent_events)

PeepSo shipped with SSE as an **advanced feature** which, when enabled, replace long-polling method which currently used to update the browser if new data from the server is available, for example, are notification and chat. To enable this feature, a setup needed on the server.

### Technical Requirements
There are some requirements to enable this feature which described here:
  - **Node.js**  
    The server needs to have Node.js installed to run the SSE endpoint. Info regarding Node.js installation can be found [here](https://nodejs.org/en/).
  
  - **Open port**  
    To avoid conflict with Apache, Node.js SSE endpoint listen to a different port. By default it listens to port 8000, however, this can be changed on the configuration. Therefore, this port needs to be open.
  
  - **A reverse proxy or dedicated subdomain (optional)**  
    As an alternative to opening a non-default port, a reverse proxy can be set up to direct access to SSE endpoint to the Node.js server. Same goes with dedicated subdomain which can be set to handle requests to the SSE endpoint.

### Setup
When technical requirements are already met, to run the SSE endpoint can be done with this example below:

```sh
$ cd WP_PATH/wp-content/plugins/peepso/sse/
$ npm start # using default setting
$ npm start -- --config="../../../peepso/config.js" # alternatively, CLI argument can be set to point to a config file
```

You will see this message below if the SSE endpoint is run correctly:
`PeepSo SSE endpoint is running at http://localhost:${PORT}`

You can then set up a reverse proxy (and maybe a dedicated domain/subdomain) to map request to said domain to the SSE endpoint so that it can be accessed from the internet. If your main domain is `example.com`, your SSE endpoint can be set to `sse.example.com` or anything else you see fit.

After all of the above setup is done, as the last step, you need to point the PeepSo SSE configuration to the SSE endpoint you just created. See the screenshot below for illustration:

<img src="data:image/png;base64,[encoded data, 46336 characters]" alt="" />