PHP code example of programmis / yii2-socket-chat

1. Go to this page and download the library: Download programmis/yii2-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 / yii2-socket-chat example snippets


'components' => [
    'chat'   => [
        'class'                 => '\path\to\Server',
        'configClass'           => '\path\to\Config',
        'listen_host'           => '0.0.0.0',
        'server_host'           => '127.0.0.1',
        'port'                  => 1337,
        'proxy_port'            => 1338,
        'connection_type'       => 'wss',
        'proxy_connection_type' => 'ws',
        'wss' => [
            'local_cert' => '/path/to/cert',    //cert.pem
            'local_pk'   => '/path/to/cert.pk'  //primary key
        ]
    ],
]

SocketChatWidget::widget([
    'room'              => 'my_room',
    'hash'              => 'you_hash, /* in UserProcessor->createUser */
    'message_area_id'   => 'chat_text_area',
    'send_on_enter'     => true,
    'current_user_id'   => $user->id,
    /* 'recipient_id' => $recipient_id */
]);