PHP code example of programmis / socket-chat

1. Go to this page and download the library: Download programmis/socket-chat library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

programmis / socket-chat example snippets


$loader = = new chat\Server();
$server->start();

class Server extends \chat\Server
{
    /** @inheritdoc */
    public static function getConfigClass()
    {
        return "Your config class implemented 
            from \chat\interfaces\ConfigInterface
            or extend from \chat\libs\Config";
        //return MyConfig::class;
    }
}

class MyConfig extends \chat\libs\Config
{
    //you can override any chat class
}

$server = new your\project\namespace\Server();

$server->start();
//or for you daemon
$server->tick(); //in your daemon loop method

UserProcessor:createUser    //maybe init user from your database by $connection_info data
User:findOne                //find and return user in your database by user id
User:getAccessList          //return user ids list of access to send messages
User:getSendRight           //return user right for send messages
User:getInfo                //return array with user info
User:onConnect              //called if user connect
User:onDisconnect           //called if user disconnect
User:onChangeRecipient      //called if user change recipient
Message:getHistory          //find and return users messages in your database
Message:beforeSend          //called before send message
Message:afterSend           //called after send message
Chat:sendMessageText        //you may send any text message to user

Server::$port = 1337;
Server::$proxy_port = 1338;
Server::$proxy_connection_type = 'wss';

server {
    server_name localhost _;
    listen 1338 ssl;
    proxy_connect_timeout       600;
    proxy_send_timeout          600;
    proxy_read_timeout          600;
    send_timeout                600;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    root /home/project.ru/web;
    location / {
        proxy_pass http://127.0.0.1:1337;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}