freelancerua / yii2-chat
Yii2 实时聊天
dev-master
2018-10-04 09:05 UTC
Requires
- bower-asset/axios: ~0.18.0
- bower-asset/momentjs: ~2.22.2
- bower-asset/socket.io-client: ~2.1.1
- bower-asset/vue: ~2.5.17
- bower-asset/vuex: ~3.0.1
- yiisoft/yii2: ~2.0.0
- yiisoft/yii2-redis: ~2.0.0
This package is auto-updated.
Last update: 2024-09-04 22:19:50 UTC
README
添加到 composer.json
"freelancerua/yii2-chat": "@dev"
配置
-
应用迁移。要应用迁移,请在控制台应用程序中设置配置如下
'controllerMap' => [ // Migrations for the yii2-chat extension 'migrate-chat' => [ 'class' => \freelancerua\yii2\chat\migrations\MigrationController::class, 'migrationNamespaces' => ['freelancerua\yii2\chat\migrations'], 'migrationPath' => null, 'migrationTable' => 'migration_chat', 'userTable' => '{{%user}}', // Change it if user table has different name ], ],现在您可以运行
./yii migrate-chat/up -
设置 Redis。对于 Ubuntu,您可以遵循以下说明: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-redis-on-ubuntu-16-04
-
配置 yii2-chat 扩展
modules' => [ 'chat' => [ 'class' => \freelancerua\yii2\chat\Module::class, 'socketAddress' => 'http://[domain|IP]:[port]', // Required 'userClass' => path\to\user::class, // Required 'onlineWidow' => (60 * 3), // Required (3 minutes or other time) ... ], ],您可以使用其他模块名称,例如 yiichat。最佳方式是将此配置添加到 main-local.php(用于高级应用程序)
-
按照以下说明更新/设置 Node.js 至 10.x 版本
https://github.com/nodesource/distributions#debinstall -
安装 pm2 管理器
npm install pm2 -g -
在终端中转到
[@vendor]/freelancerua/yii2-chat/node/ -
更新模块
npm update -
将 config.example.json 复制到 config.json 并设置配置值
{ "serverPort": 8890, "serverIP": "[IP]", // Exact as your domain or IP set in socketAddress (https required for ssl) "redisPort": 6379, "redisName": "127.0.0.1", "redisAuth": null "ssl": false, "key": "path_to_key", "cert": "path_to_pem" } -
启动并将进程添加到 pm2 进程列表
pm2 start [@vendor]/freelancerua/yii2-chat/node/server.js --name yii2-chat-server -
在用户类中实现 IChatInterface
- getChatImage() & getChatName() 取决于您类的实现
- getIsOnline() & setIsOnline() 必须与以下完全一致
getIsOnline() { return (\freelancerua\yii2\chat\Module::getInstance()->onlineWidow + $this->chat_is_online) > time(); } setIsOnline() { $this->chat_is_online = time(); return $this->update(false); }如果您计划在不模块上下文中使用此功能,请勿忘记启动此模块。
'bootstrap' => [..., 'chat']
您可以更改模块配置选项
```
/**
* {@inheritdoc}
*/
public $db = 'db';
/**
* Default chat assets folder
* @var string
*/
public $assets = '@vendor/freelancerua/yii2-chat/assets';
/**
* Default chat style file
* @var string
*/
public $styleFile = 'css/chat.css';
/**
* Default chat js file
* @var string
*/
public $jsFile = 'js/chat.js';
/**
* Format message date when send and update state
* @var string
*/
public $jsDateFormat = 'DD/MM/YYYY H:mm:ss';
/**
* Format message date with PHP
* @var string
*/
public $phpDateFormat = 'php:d/m/Y H:m:s';
/**
* Redis instance name
* @var type
*/
public $redis = 'redis';
/**
* Redis DB host
* @var string
*/
public $redisHost = '127.0.0.1';
/**
* Redis DB port
* @var integer
*/
public $redisPort = 6379;
```