PHP code example of jakharbek / yii2-chat

1. Go to this page and download the library: Download jakharbek/yii2-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/ */

    

jakharbek / yii2-chat example snippets


yii migrate --migrationPath=@vendor/jakharbek/yii2-chat/migrations

\jakharbek\chat\Bootstrap

...
controllerMap => [
'server' => \jakharbek\chat\api\ChatController::class
]
...

...
controllerMap => [
'server' => \jakharbek\chat\commands\ServerController::class
]
...

php yii server/start [port]

\jakharbek\chat\assets\ChatAsset::register($this);


$js = <<<JS
var chat = new ChatClient("ws://localhost:8080",'{$token}','{chat_id}');
chat.onMessage = function(type,data,event){
    //сдесь будет ваша логика для UI
}
chat.init();
$(".msg_send_btn").click(function () {
    chat.sendMessage($('.write_msg').val());
});
JS;

$this->registerJs($js);

php composer.phar