Code Monkey home page Code Monkey logo

flat-server's Introduction

Agora Flat Server

Project flat-server is a Node.js server for the Agora Flat open source classroom.

中文

Features

  • Login via
  • Wechat
  • Github
  • Google
  • Room scheduling
    • Ordinary rooms
    • Periodic rooms
  • Signing tokens for Whiteboard, Real-time video/audio chat(RTC), Real-time messaging(RTM)
  • Cloud recording and replaying
  • Cloud Storage for multi-media courseware

Develop Locally

Execute the following steps to run flat-server:

Installation

yarn install --frozen-lockfile

Setup Environment

  1. Create files config/development.local.yaml.
  2. Add environment variables following the config/defaults.yaml format.

Run the Project

  1. Execute at project root:
   yarn run start
  1. Open another terminal and execute at project root:
   node ./dist/index.js

You should see ready on http://0.0.0.0:80 if everything is OK.

Deployment

Deployment is not needed for local development. If you want to bring the server up online, deploy anyway you like.

Warning If you have deployed this project before, please see the migration documentation

Environment Variables Reference

server:
    # Server port
    port: 80

redis:
    # Redis host
    host:
    # Redis port
    port:
    # Redis username
    username:
    # Redis password
    password:
    # Redis db name
    db:
    # Redis-based implementation of the deferred queue db name
    queueDB:

mysql:
    # MySQL host
    host:
    # MySQL port
    port:
    # MySQL username
    username:
    # MySQL password
    password:
    # MySQL database
    db:

jwt:
    # JWT secret
    secret:
    # JWT crypto algorithms, see: https://github.com/auth0/node-jsonwebtoken/tree/d71e383862fc735991fd2e759181480f066bf138#algorithms-supported
    algorithms:

# Front-end address
website: https://flat-web-dev.whiteboard.agora.io

log:
    # Log path name, see: https://github.com/netless-io/flat-server/blob/main/src/utils/EnvVariable.ts
    pathname: "{{PROJECT_DIR}}/logs"
    # Log file name, see: https://github.com/netless-io/flat-server/blob/main/src/utils/EnvVariable.ts
    filename: "{{DAY_DATE}}"

cloud_storage:
    # Maximum count of Cloud Storage uploading files. Default: 3
    concurrent: 3
    # Maximum size of a Cloud Storage file. Default: 500M
    single_file_size: 524288000
    # Maximum Cloud Storage size of a user. Default: 2G
    total_size: 2147483648
    # Cloud Storage upload path prefix. Default: cloud-storage (No / prefix or suffix)
    prefix_path: cloud-storage
    # Cloud Storage supported file extensions
    allow_file_suffix:
        - ppt
        - pptx
        - doc
        - docx
        - pdf
        - png
        - jpg
        - jpeg
        - gif
        - mp3
        - mp4

user:
    avatar:
        # Maximum size. Default: 5M
        size: 5242880
        # User supported upload image file extensions
        allow_suffix:
            - png
            - jpg
            - jpeg

oauth:
    logo:
        # Upload logo path prefix. Default: oauth-logo (No / prefix or suffix)
        prefix_path: oauth-logo
        # Maximum size. Default: 5M
        size: 5242880
        # Logo supported upload image file extensions
        allow_suffix:
            - png
            - jpg
            - jpeg

login:
    wechat:
        # See: https://developers.weixin.qq.com/doc/oplatform/Website_App/WeChat_Login/Wechat_Login.html
        web:
            # Whether to enable WeChat login on the web/desktop side
            enable: false
            # App ID
            app_id:
            # App Secret
            app_secret:
        # See: https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Login/Development_Guide.html
        mobile:
            # Whether to enable WeChat login on the mobile side
            enable: false
            # App ID
            app_id:
            # App Secret
            app_secret:
    # See: https://docs.github.com/cn/developers/apps/building-oauth-apps/authorizing-oauth-apps
    github:
        # Whether to enable GitHub login
        enable: false
        # GitHub Client ID
        client_id:
        # GitHub Client Secret
        client_secret:
    # In development, see: https://developers.google.com/identity/protocols/oauth2
    google:
        # Whether to enable Google login
        enable: false
        # Google Client ID
        client_id:
        # Google Client Secret
        client_secret:
        # Redirect URI
        redirect_uri:
    apple:
        # Whether to enable Apple login
        enable: false
    # Not open to the public at the moment
    agora:
        # Whether to enable Agora login
        enable: false
        # Agora Client ID
        client_id:
        # Agora Client Secret
        client_secret:
    # Phone message login
    sms:
        # Whether to enable SMS login
        enable: true
        # Is force binding phone
        force: false
        # Test user (Only valid if server.env is dev)
        # You need to run MYSQL yourself to insert the user
        # INSERT INTO user_phone (version, user_uuid, user_name, phone_number) VALUES (1, 'uuid', 'name', 'phone');
        # INSERT INTO users (version, user_uuid, user_name, user_password, avatar_url) VALUES (1, 'uuid', 'name', '', 'url');
        test_users:
            -   phone:
                code:
        chinese_mainland:
            # see:  https://help.aliyun.com/document_detail/419273.htm?spm=a2c4g.11186623.0.0.34371d58IYPbs3
            access_id:
            access_secret:
            template_code:
            sign_name:
        # Hong Kong, Macao and Taiwan regions of China
        hmt:
            access_id:
            access_secret:
            template_code:
            sign_name:
        global:
            access_id:
            access_secret:
            template_code:
            sign_name:

agora:
    # For RTC and RTM. See: https://docs.agora.io/en/Agora%20Platform/get_appid_token?platform=All%20Platforms
    app:
        # Agora App ID
        id:
        # Agora App Certificate
        certificate:
    # For classroom replaying. See: https://docs.agora.io/en/cloud-recording/faq/restful_authentication?platform=All%20Platforms
    restful:
        # Agora RESTful ID
        id:
        # Agora RESTful Secret
        secret:
    # For storing RTC Cloud Recording media files. See: https://docs.agora.io/en/cloud-recording/restfulapi/
    # Path: Cloud Recording Start -> Schema -> clientRequest -> storageConfig
    oss:
        access_id:
        access_secret:
        vendor:
        region:
        bucket:
        folder:
        prefix:
    # Video screenshot service
    # See: https://docs.agora.io/en/cloud-recording/cloud_recording_screen_capture?platform=RESTful
    screenshot:
        enable: false
        oss:
            access_id:
            access_secret:
            vendor:
            region:
            bucket:
            folder:
            prefix:
    # Message notification service
    # See: https://docs-preprod.agora.io/en/Agora%20Platform/ncs
    messageNotification:
        enable: false
        events:
            # Currently only supported `productID: 3` and `eventType: 45`
            -   productID:
                eventType:
                secret:

# See: https://docs.agora.io/en/whiteboard/generate_whiteboard_token_at_app_server?platform=RESTful
whiteboard:
    # Whiteboard AK
    access_key:
    # Whiteboard SK
    secret_access_key:
    # Convert Region
    # "cn-hz" | "us-sv" | "sg" | "in-mum" | "gb-lon"
    convert_region:

# Storage Service
storage_service:
    # Currently, only supported OSS
    type: oss
    oss:
        access_key:
        secret_key:
        endpoint:
        bucket:
        region:

# Content censorship
censorship:
    # Need to configure screenshot and messageNotification services under agora
    # messageNotification needs to be added: productID: 3 and eventType: 45 (see: https://docs.agora.io/en/cloud-recording/cloud_recording_callback_rest)
    # The principle is to take a screenshot of all the video streams in the room at regular intervals, get the screenshot address through the message notification service, and call a third party (e.g. AliCloud) to review the API to check it
    video:
        enable: false
        # Current only support aliCloud
        type: aliCloud
        # See: https://www.alibabacloud.com/help/en/content-moderation/latest/development-preparations-1
        aliCloud:
            access_id:
            access_secret:
            endpoint:
    # See: https://docs.agora.io/cn/cloud-recording/audio_inspect_restful?platform=RESTful
    # NOTE: No English description available at the moment
    voice:
        enable: false
        # Current only support aliCloud
        type: aliCloud
        aliCloud:
            uid:
            access_id:
            access_secret:
            callback_address:
    text:
        enable: false
        # Current only support aliCloud
        type: aliCloud
        # See: https://www.alibabacloud.com/help/en/content-moderation/latest/development-preparations-1
        aliCloud:
            access_id:
            access_secret:
            endpoint:

If deployment is required then you need to ensure that the following variables are present in the environment variables for deployment:

Variable Name Description Note
METRICS_ENABLED Whether to enable metrics monitoring
METRICS_ENDPOINT metrics url path e.g.: /metrics
METRICS_PORT metrics port e.g.: 9193

Tech Stack

Disclaimer

You may use Flat for commercial purposes but please note that we do not accept customizational commercial requirements and deployment supports. Nor do we offer customer supports for commercial usage. Please head to Flexible Classroom for such requirements.

flat-server's People

Contributors

alwaysmavs avatar blackhole1 avatar cheerego7 avatar crimx avatar dependabot[bot] avatar flat-bot avatar haoran965 avatar hyrious avatar leavesster avatar leooeloel avatar ooeyuna avatar rhnsharma avatar shunyue1320 avatar snyk-bot avatar vince-hz avatar ylduang avatar zhuangkh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flat-server's Issues

go web server framework discussion

Which is the most suitable framework?

  1. go mirco
  2. gin
  3. gf (go frame)
  4. go native
  5. echo

After my use and research, gin and echo are more similar to koa,they are faster and lighter,but not strong enough to build an cloud native appliction with unsound toolset, they can't track error or report log etc...
So gf is coming, and it has been verified by multiple companies, and also have full utils library.
@BlackHole1 what's your opinion?

[chore]: delete logs regularly

We currently generate log files automatically, but do not delete them.

This is not very friendly on the server and we should remove them periodically, e.g:

  • Delete logs from a few days ago (default value is 3 days)

And it should be configurable

[chore]: optimization local development

When developing locally, you need to manually build docker / redis and apply various ak / sk / token , which makes it very tedious to develop for the first time.

We should make redis / mysql creation automated, as well asƒ mock various ak / sk / token

`for await` reads all data in stream

for await (const item of stream) {

Have a look at this code:

import { Readable } from "stream";

class ScanStream extends Readable {
  index = 0;

  _read() {
    if (this.index < 5) {
      console.log("call _read", this.index);
      if (this.push(this.index.toString())) {
        this.index++;
      } else {
        this.index = 5;
      }
    } else {
      this.push(null);
    }
  }
}

async function main() {
  let stream: ScanStream;

  console.log("for await:");
  stream = new ScanStream();
  for await (const value of stream) {
    console.log(value);
    stream.destroy(); // this line doesn't help
    break;
    // even though I break the for loop,
    // "for await" still calls _read to the end
  }

  console.log("\nfor { await:");
  console.log("    read 1 byte:");
  stream = new ScanStream();
  console.log(stream.read(1));
  stream.destroy();

  console.log("\n    read 1 chunk (exactly 2 _reads call):");
  stream = new ScanStream();
  stream.on("data", (chunk) => {
    console.log(chunk);
    stream.destroy();
  });
}

main();

which outputs:

for await:
call _read 0
call _read 1
call _read 2
call _read 3
call _read 4
<Buffer 30>

for { await:
    read 1 byte:
call _read 0
<Buffer 30>

    read 1 chunk (exactly 2 _reads call):
call _read 0
call _read 1
<Buffer 30>
<Buffer 31>

yarn run start 之后没反应

 ~/Projects/flat-server   main  yarn run start
yarn run v1.22.10
$ cross-env NODE_ENV=development webpack --watch --progress --config webpack/webpack.dev.js
3% setup watch run webpack-cli[webpack-cli] Compilation starting...
99% done plugins webpack-cli[webpack-cli] Compilation finished
asset index.js 549 KiB [emitted] (name: main) 1 related asset
runtime modules 931 bytes 4 modules
cacheable modules 285 KiB
  modules by path ./src/v1/ 272 KiB 73 modules
  modules by path ./src/*.ts 4.69 KiB
    ./src/index.ts 1.32 KiB [built] [code generated]
    ./src/Constants.ts 2.03 KiB [built] [code generated]
    ./src/ErrorCode.ts 1.34 KiB [built] [code generated]
  modules by path ./src/utils/*.ts 5.97 KiB
    ./src/utils/Redis.ts 506 bytes [built] [code generated]
    ./src/utils/NetlessToken.ts 5.48 KiB [built] [code generated]
  ./src/plugins/Ajv.ts 855 bytes [built] [code generated]
  ./package.json 1.78 KiB [built] [code generated]
modules by path external "@babel/runtime/ 588 bytes 14 modules
16 modules
webpack 5.9.0 compiled successfully in 4791 ms
[webpack-cli] watching files for updates...
Issues checking in progress...
No issues found.

Hi, Could you share with me an effective method for initializing the MySQL database from your code?

Hi, I'm a student, and I'm eager to learn how to create a database directly from your code. My understanding in this area is somewhat limited, so I'm seeking guidance on the process.
As a student, I'm not entirely sure where to start or what tools to use for this task.
Any tips, resources, or examples would be greatly appreciated as I embark on this learning journey.
Thank you in advance for your assistance!

[chore]: use yml replace env config file

The env file format is hardly enough for our needs anymore and we need to use yml to replace it in order to support the array case. Also accessing ajv to validate it

Readme.md

Hello,

It seems to me that there are some bugs on the Readme.md :

  1. For the order :
    docker run -dit -p 3306:3306 --name mysql --restart always -v pwd/data:/var/lib/mysql -v pwd/conf.d:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=(value of MYSQL_PASSWORD) mysql

Error :
docker: Error response from daemon: create pwd/data: "pwd/data" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.

2. Folder thirdPartyService doesn't exist in src/v1/

3. Folder "dist" is created after the run and there is an Error :

C:\Users\Valery-Jerome\Desktop\Agora2\flat-server\node_modules\ali-oss\lib\common\client\initOptions.js:24
throw new Error('require accessKeyId, accessKeySecret');
^
Error: require accessKeyId, accessKeySecret
at module.exports (C:\Users\Valery-Jerome\Desktop\Agora2\flat-server\node_modules\ali-oss\lib\common\client\initOptions.js:24:11)
at Function.initOptions (C:\Users\Valery-Jerome\Desktop\Agora2\flat-server\node_modules\ali-oss\lib\client.js:54:10)
at new Client (C:\Users\Valery-Jerome\Desktop\Agora2\flat-server\node_modules\ali-oss\lib\client.js:32:27)
at createOSSClient (C:\Users\Valery-Jerome\Desktop\Agora2\flat-server\dist\webpack:\flat-server\src\v1\controller\cloudStorage\alibabaCloud\Utils.ts:57:12)
at Object../src/v1/controller/cloudStorage/alibabaCloud/Utils.ts (C:\Users\Valery-Jerome\Desktop\Agora2\flat-server\dist\webpack:\flat-server\src\v1\controller\cloudStorage\alibabaCloud\Utils.ts:68:21)
at webpack_require (C:\Users\Valery-Jerome\Desktop\Agora2\flat-server\dist\webpack:\flat-server\webpack\bootstrap:19:1)
at Object../src/abstract/login/index.ts (C:\Users\Valery-Jerome\Desktop\Agora2\flat-server\dist\webpack:\flat-server\src\abstract\login\index.ts:7:1)
at webpack_require (C:\Users\Valery-Jerome\Desktop\Agora2\flat-server\dist\webpack:\flat-server\webpack\bootstrap:19:1)
at Object../src/v1/controller/login/platforms/LoginWechat.ts (C:\Users\Valery-Jerome\Desktop\Agora2\flat-server\dist\webpack:\flat-server\src\v1\controller\login\platforms\LoginWechat.ts:1:1)
at webpack_require (C:\Users\Valery-Jerome\Desktop\Agora2\flat-server\dist\webpack:\flat-server\webpack\bootstrap:19:1)

if you know how to do, I would be happy :-)

Jérôme

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.