承接 programmis/socket-chat 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

programmis/socket-chat

Composer 安装命令:

composer require programmis/socket-chat

包简介

Simple socket chat

README 文档

README

Installing

1) Download composer:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

2) Install:

php composer.phar require programmis/socket-chat

Starting chat server

$loader = require __DIR__ . '/vendor/autoload.php';

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

or in your project

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;
    }
}

and in your config class

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

and to start

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

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

simple daemon provider and how to connect this chat to YII2 framework

popular methods

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

Client side

<script src="js/socketChat.js"></script>

Init java constants

<script type="application/javascript">
    $(function () {
        <?= Server::fillJavaConstants(); ?>
    });
</script>

Settings

socketChat.connection_type = "Maybe 'ws' or 'wss'"
socketChat.current_user_id = "Current user id in chat";
socketChat.socket_url = "You're server address : and port";
socketChat.send_on_enter = "If this true, then all messages sending by press on enter key, ctrl+enter default"
socketChat.recipient_id = 'Message recipient id, you can fill it before send messages';
socketChat.room = "Chat room name is required fill";
socketChat.hash = "You're secret hash for processing with UserProcessor";
socketChat.user_typing_timeout = "For auto disable user typing status";
socketChat.message_history_period = "For default request message history";

Functions

socketChat.open();                                  //open connect with server
socketChat.close();                                 //close connect with server
socketChat.setMessageAreaId(id);                    //set textarea id for messages
socketChat.send();                                  //send message from message_area to socketChat.recipient_id 
socketChat.getUserList();                           //get all users in current room
socketChat.getUserInfo(user_id);                    //get info about user
socketChat.getMessageHistory(with_user_id, period); //get all messages for current user and with_user_id by period

Events

socketChat.onConnect            //called if chat connected to server
socketChat.onDisconnect         //call if chat disconnected with server
socketChat.onMessageRender      //called if render message with "message" in parameter 
socketChat.onMessageListRender  //called if render message list with "message_list" in parameter
socketChat.onUserConnect        //called if user connect to chat with "user" in parameter
socketChat.onUserDisconnect     //called if user disconnect from chat with "user" in parameter
socketChat.onUserRemoved        //called if user removed from chat with "user" in parameter
socketChat.onAboutMeInfo        //about you info 
socketChat.onUserInfo           //called if received user info with "user" in parameter
socketChat.onUserList           //called if user list received with "user_list" in parameter
socketChat.onUserTypingStart    //called if user start typing with "user_id" in parameter
socketChat.onUserTypingEnd      //called if user end typing with "user_id" in parameter

For nginx ssl encrypt

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";
    }
}

How to enable another config param see example how to connect this chat to YII2 framework

For example see index.php and socketChatDemo.js files

Sorry for my english

programmis/socket-chat 适用场景与选型建议

programmis/socket-chat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.63k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2016 年 10 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 programmis/socket-chat 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 programmis/socket-chat 我们能提供哪些服务?
定制开发 / 二次开发

基于 programmis/socket-chat 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.63k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 5
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-10-26