開発

常に開発したい機能について話し合い、問題に取り組むためのイシューを作成または見つけてコメントし、作業を開始する前にコミュニティに通知し、そのイシューに取り組むことを宣言してください。

プルリクエストは、mainブランチで行ってください。

メモ

2023年3月までは、コントリビューションはdevelopブランチで行っていました。このプロシージャは現在非推奨になっています。

このプラグインをビルドするための前提要件

次の概念を理解しておくことを強く推奨いたします:

  • Git
  • NodeJS
  • NPM
  • Typescript

プラグインをビルドするには、次のパッケージが必要です:

  • git
  • npm (>=8.x)
  • nodejs (>=14.x)
  • build-essential
  • coreutils
  • wget
  • reuse

このプラグインは、Prosody XMPPサーバー用のAppImageが必要です。 このAppImageは、Prosody AppImage sideprojectにより提供されています。 build-prosody.shスクリプトは、このリモートリポジトリに添付されているバイナリをダウンロードし、ダウンロードしたファイルのsha256ハッシュサムが正しいかどうかを確認します。

開発

リポジトリをクローン、プラグインをビルド、機能ブランチを作成:

# リポジトリをクローンしてください。 サブモジュールもクローンするために --recursive を付与するのを忘れないでください。
git clone https://github.com/JohnXLivingston/peertube-plugin-livechat.git --recursive

cd peertube-plugin-livechat

# NPM依存関係をインストールし、初回のモジュールのビルドを実施します:
npm install

# 変更後、プラグインをビルドします:
npm run build

# リポジトリからフォークした場合、リモートとして追加してください (例):
git remote add me git@github.com:MY_GITHUB_ACCOUNT/peertube-plugin-livechat.git

# 開発のために、ローカルブランチを作成してください (例):
git checkout my_development # 注意: イシューに関連している場合は、ブランチ名に fix_1234 のような形式を付与します (1234はイシューの番号)
# 変更を提案するため、ブランチをリポジトリにプッシュしてください (例):
git push --set-upstream me my_development
# その後、WebブラウザーからGitHubリポジトリに移動し、プルリクエストを送ってください(詳しくは以下をお読みください)

Once you are ready to show your code to ask for feedback, submit a draft Pull Request. Once you are ready for a code review before merge, submit a Pull Request. In any case, please link your PR to the issues it solves by using the GitHub syntax: “fixes #issue_number”.

The front-end code is in the client folder, the back-end code in server. There are some shared code in shared folder.

For general instructions (developping plugins, building, installation, …), please refer to the Peertube documentation.

You can build the plugin with extra debug features simply by using:

NODE_ENV=dev npm run build

This plugin is REUSE compliant: it uses SPDX headers to identify licensing information of its source code. More information on the REUSE website. You can use the reuse command line tool to help you update headers. The npm run lint command will use the reuse command to check compliance. Don’t forget to add your copyright information in SPDX headers when you modify some code.

ESBuild vs Typescript

This plugin uses ESBuild for frontend code generation, as the official peertube-plugin-quickstart plugin. ESBuild can handle Typescript, but does not check types (see ESBuild documentation). That’s why we first compile Typescript with the -noEmit option, just to check types (check:client:ts in package.json file). Then, if everything is okay, we run ESBuild to generate the compiled javascript.

Debug Mode

There is a debug mode for this plugin, that shorten some delay. For example, some log files will rotate every two minutes, instead of once per day. This permit to test more easily certain actions, for which it could normally take hours or days to wait.

To enable this mode, you juste have to create the /var/www/peertube/storage/plugins/data/peertube-plugin-livechat/debug_mode file (replacing /var/www/peertube/storage/ by the correct path on your installation).

The simple existence of this file is sufficient to trigger the debug mode. To make sure it’s taken into account, you can restart your Peertube instance.

This file can contain some JSON to enable more advanced options. To have a list of existing parameters, check server/lib/debug.ts. Restart Peertube after each content modification.

警告

Don’t enable this mode on a production server, neither on a public server. This could cause security issues.

Restart Prosody

When debug mode is enabled, you can restart Prosody using this API call: http://your_instance.tld/plugins/livechat/router/api/restart_prosody. This call don’t need any authentificaiton. It can be done from a command line, for example using curl http://your_instance.tld/plugins/livechat/router/api/restart_prosody.

Prosody debugger

It is possible to connect the Prosody AppImage to a remote debugger using MobDebug.

To do so, you have to setup MobDebug in a folder that can be accessed by the peertube user. Then, add this in the debub_mode file:

{
  "debug_prosody": {
    "debugger_path": "/the_path_to_mobdebug/src",
    "host": "localhost",
    "port": "8172"
  }
}

host and port are optional. debugger_path must point to the folder where the MobDebug .lua file is.

Restart Peertube.

Start your debugger server.

For Prosody to connect to the debugger, call the API http://your_instance.tld/plugins/livechat/router/api/restart_prosody?debugger=true. This call does not need any authentication. It can be done from a command line, for example with curl http://your_instance.tld/plugins/livechat/router/api/restart_prosody?debugger=true. You can even configure your debug server to launch this request automatically.

Prosody will then restart, connecting to the debugger.

Quick dev environment using Docker

There is a tutorial, in french, on the Peertube forum that explains how to quickly build a dev env using Docker.

A repo was made out of it, check out pt-plugin-dev.

Note: for an unknown reason, Prosody can’t resolve containers DNS address when using the lua-unbound library. There is a dirty hack in the plugin: just create a /data/plugins/data/peertube-plugin-livechat/no_lua_unbound file in your docker-volumes, then restart containers.

Quickly rebuild and install the plugin

When you do modification, you don’t have to always rebuild the full project, and reinstall the plugin on your dev environment. You can build only the modified part (for example, if you only modified client files: npm run build:client). Check the package.json files for available build scripts.

When the plugin is already installed on your dev instance, and you haven’t changed any dependency, you can quickly install your work by following these steps:

  • re-build necessary parts of the plugin (client, styles, …),
  • overwrite the data/plugins/node_modules/peertube-plugin-livechat/dist/ content of your dev instance by the content of the plugin’s dist folder,
  • change recursively plugins/node_modules/peertube-plugin-livechat/dist/ files owner to your peertube user,
  • restart your instance.

Performance tests

The livechat-perf-test repository contains some tools to make performance tests. It can be used to evaluate code improvements, or find bottlenecks.