edit readme md

This commit is contained in:
2025-07-06 22:15:39 +09:00
parent 73c0247692
commit 2c5d942562

119
README.md
View File

@@ -4,111 +4,101 @@
This is the javascript sdk package required to create a javascript tap server responsible for the audio of `zako`, a discord audio bot. This is the javascript sdk package required to create a javascript tap server responsible for the audio of `zako`, a discord audio bot.
## Requirements ## Dependencies
| package | version | | package | version |
| --- | --- | | --- | --- |
| eventemitter | 0.2.0 | | eventemitter3 | 5.0.1" |
| requests | 2.32.4 | | got | 14.4.7 |
| websockets | 15.0.1 | | jest | 30.0.4 |
| ws | 8.18.3 |
| zod | 3.25.72 |
## Quickstart Example ## Quickstart Example
First, you need to download `zako-sdk-py` on your project. First, you need to download `zako-sdk-js` on your project.
```bash ```bash
pip install zako-sdk-py npm install zako-sdk-js
``` ```
Then, you can use the sdk. Then, you can use the sdk.
Here is some example. Here is some example.
```py ```js
import io import { createClient } from "zako-sdk-js"
import asyncio
from zakotap import Client, ClientData, HelloResponse, AudioRequest
streamFile = io.BytesIO(b"test audio data") const client = createClient({
name: "your zako tap server name",
token: "your zako tap server token",
zakoEndpoint: "zako endpoint (default is https://api.zako.ac)"
});
clientData: ClientData = { client.events.on("ready", () => {
"name": "your tap name", console.log("ready");
"token": "your tap token", });
"zakoEndpoint": "zako endpoint (default is https://api.zako.ac)"
}
client = Client(clientData) client.events.on("request", (handle) => {
handle.respond("audio stream on here")
});
def on_ready(data: HelloResponse): client.events.on("connectionError", (e) => {
print("Client is ready. Connected Tab Hub version", data.get("version")) console.error(e);
});
def on_close(message: str): client.events.on("error", (e) => {
print("Connection closed:", message) console.error(e);
});
def on_warn(message: str): client.connect();
print("Warning:", message)
def on_error(message: str):
print("Error:", message)
def on_audio_sync(audio_request: AudioRequest):
print("Audio")
loop = asyncio.get_event_loop()
task = loop.create_task(on_audio(audio_request))
async def on_audio(audio_request: AudioRequest):
print("Received audio request:", audio_request, flush = True)
await client.send(audio_request.get("id"), streamFile)
client.on("warn", on_warn)
client.on("error", on_error)
client.on("ready", on_ready)
client.on("close", on_close)
client.on("audio", on_audio_sync)
client.connect()
await new Promise((r) => setTimeout(r, 100000));
``` ```
## Client Description ## Client Description
### 1. Create Client and Connect ### 1. Create Client and Connect
You can create tap server client by call `Client` class in `zakotap` package. You can create tap server client by call `createClient` function in `tap-sdk-js` package.
You should put the client data written as `ClientData` type inside the parentheses of `Client`. You should put the client data written as `ZakoTapConfig` type inside the argument of `createClient`.
You can then connect to the tab server using `client.connect()`. You can then connect to the tab server using `client.connect()`.
```py ```js
from zakotap import Client, ClientData import { createClient } from "zako-sdk-js"
clientData: ClientData = { const client = createClient({
"name": "your tap server name", name: "your zako tap server name",
"token": "your tap server token", token: "your zako tap server token",
"zakoEndpoint": "zako tap hub endpoint (option)" zakoEndpoint: "zako endpoint (option)"
} backoffBaseMs: "loop waiting time (option)";
});
client = Client(clientData) client.connect();
client.connect()
``` ```
### 2. Client Event ### 2. Client Event
Using the client created above, you can use client.on to perform a specific function when the EventEmitter's event is called. Using the client created above, you can use client.on to perform a specific function when the EventEmitter's event is called.
```py ```js
client.on("event name", function) client.events.on("event name", function)
``` ```
The types of events are specified in EmitterEvents among the types in the zakotap package. The types of events are specified in TapEvents among the types in the zakotap package.
#### Emitter Events #### Tap Events
- `"ready"`: This event is called when the zako tap server successfully connects to the `zako tap hub`. - `ready`: This event is called when the zako tap server successfully connects to the `zako tap hub`.
- `"close"`: This event is called when the `web socket` between the `zako tap server` and `tap hub` is closed. - `request`: This event is called when an `audio request` is received from the `zako tap hub`.
- `"audio"`: This event is called when an `audio request` is received from the `zako tap hub`. - `connectionError`: This event is called when an connection error occurs within the zakotap package.
- `"warn"`: This event is called when a warning occurs within the zakotap package that should notify the developer. - `error`: This event is called when an error occurs within the zakotap package.
- `"error"`: This event is called when an error occurs within the zakotap package.
### 3. Send Audio ### 3. Send Audio
You can send your audio stream by using `handle.respond()` function.
```js
handle.respond("your audio stream")
```
You can get `audio request handle` from request event parameter. If you don't send an audio stream, your tap server will be considered offline and you may be disconnected.
## Work Flow ## Work Flow
```mermaid ```mermaid
@@ -129,4 +119,3 @@ sequenceDiagram
## Authors ## Authors
- [@ridanit-ruma](https://github.com/ridanit-ruma) (Discord: `ruma0607`) - [@ridanit-ruma](https://github.com/ridanit-ruma) (Discord: `ruma0607`)
- [@MincoMK](https://github.com/MincoMK) (Discord: `minco_rl`)