Skip to content
Code-Schnipsel Gruppen Projekte
README.md 2,01 KiB
Newer Older
Henning Leutz's avatar
Henning Leutz committed

The QUIQQER Socket module extends QUIQQER with an integrated socket server.

## Feature

- Socket Server
- Socket Client
- Socket API - other modules are able to extend the Socket Server
- based on PHP Ratchet

## Todo

- Andere Domains prüfen wegen Security Headers
- Connection Limits
- php quiqqer light header "header.php" -> wegen zu viel RAM
- https://dev.quiqqer.com/quiqqer/rabbitmqserver/-/blob/master/src/RabbitConsumer/RabbitConsumerServer
- apache virtual host ins wiki
    - nginx darf mor machen
- quiqqer sessions in websocket verfügbar machen
### Set up socket server

#### Apache install

```bash

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests
sudo a2enmod proxy_wstunnel

```

#### Apache site settings:

Example for an apache site.conf

```
<VirtualHost host:443>
  ...
        ProxyRequests off
        ProxyVia on
        
        # YOUR_HOST = replace this with your host
        RewriteEngine On
        RewriteCond %{HTTP:Connection} Upgrade [NC]
        RewriteCond %{HTTP:Upgrade} websocket [NC]
        RewriteRule /(.*) ws://YOUR_HOST:5002/$1 [P,L]

        ProxyPass /websocket http://127.0.0.1:5002/websocket
        ProxyPassReverse /websocket http://127.0.0.1:5002/websocket
  ...
</VirtualHost>
```

#### Starting socket server

```bash

cd packages/quiqqer/socketserver;

php socketserver.php

```

### Get JS socket client

```js

require(['package/quiqqer/socketserver/bin/frontend/Client'], function (Client) {

    // with the echo test endpoint
    Client.getClient('/echo').then(function (WebSocketClient) {

        WebSocketClient.onmessage = function (e) {
            console.log('message', e.data);
        };

        WebSocketClient.onopen = function (e) {

            WebSocketClient.send(JSON.stringify({
                type   : 'message',
                message: 'HUHU'
            }));

        };
    });

});

```
Henning Leutz's avatar
Henning Leutz committed

### Test Websockets via console

```bash
websocat wss://YOUR_HOST:YOUR_PORT/echo
```