jakharbek/yii2-chat

聊天

安装: 103

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 1

开放问题: 1

类型:yii2-extension

3.0 2019-04-10 15:43 UTC

This package is not auto-updated.

Last update: 2024-09-24 17:28:40 UTC


README

聊天

安装

安装此扩展的首选方式是通过 composer

运行

php composer.phar require --prefer-dist jakharbek/yii2-chat "*"

或添加

"jakharbek/yii2-chat": "*"

到您的 composer.json 文件的 require 部分中。

目录结构

api/                 api
assets/              assets
command/             daimons and console
dto/                 data transfer object
exceptions/          exceptions
factory/             factories
forms/               forms
interfaces/          interfaces
migrations/          migrations
models/              models
repositories/        repositories
services/            services

用法

此扩展没有划分权限和访问权限,此特性留由您自行决定以增加灵活性。

开始使用之前,您应应用迁移

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

之后,您需要应用 Bootstrap 类。

\jakharbek\chat\Bootstrap

API

要使用它,您需要连接控制器。

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

或者您可以复制它或从它继承,并按您的意愿连接它

连接 soket

启动 web soket 服务器

您需要在您的控制台应用程序中连接到 web soket 控制器

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

之后,将此控制台命令作为 daimon 运行。例如

php yii server/start [port]

连接 asset

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

示例连接 soket 客户端。

$js = <<<JS
var chat = new ChatClient("ws://: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);