Git Product home page Git Product logo

nya-chat's Introduction

nya-chat

依赖

  • laravel
  • swoole扩展

安装

composer require nya/chat

添加命令到app/console/Kernel.php

use Nya\Chat\Coo;
...
 protected $commands = [
    Coo::class
];

配置文件config/nya.php

<?php

return [

    'host' =>'0.0.0.0',

    'port'=>2333,

    'class' => 'App\Nya',

    'pid_file' => storage_path('/logs/swoole.pid'),
    
    'use_ssl' =>   false,
    
    'ssl_key_file' =>  '/data/ssl/vgamer.im/vgamer.im.key',
    
    'ssl_cert_file' => '/data/ssl/vgamer.im/vgamer.im_bundle.crt',

    'message' => 'message_',

    'open' => 'open',

    'close' => 'close',

    'type' => 'type',

    'data' => 'data'

];

其中message以下都有默认

使用

新建示例类app/Nya.php

<?php

namespace App;

class Nya{

    public function message_say($fd, $type){
        $this->nya->push($fd, 'nya?');
    }

    // 非必要
    public function open($fd){
        $this->nya->push($fd, 'link');
    }

    public function close($fd){
        // ...
    }

}

开启聊天服务:php artisan nya start stop可以停止

前台websocket连接端口2333,返回 'link'

发送

{
    "type": "say",
    "data": "nyanyanya"
}

后台返回'nya?'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.