mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-07-04 03:51:00 +00:00
* dev: start LiveChat refactor * dev: implement simple module system to separate classes + add a few Live Chat actions * dev: add fundamental Live Chat classes * chore: update type declarations * feat: finalize Live Chat Now supporting almost all kinds of messages! Next up: add a ability to send messages. * chore: update type declarations * chore: update contributors list * feat(livechat): add `sendMessage()` method * chore: remove unneeded files * style: format code * chore: remove outdated examples * chore: update tests * chore: remove trailing spaces * chore: remove trailing spaces x2
73 lines
1.5 KiB
Markdown
73 lines
1.5 KiB
Markdown
## Live Chat
|
|
|
|
The library's Live Chat parser and poller were highly based on YouTube's original compiled code, this makes it behave in a similar if not identical way to YouTube's Live Chat. Here you can do all sorts of funny things, ex; track messages, donations, polls, and much more.
|
|
|
|
## Usage
|
|
|
|
Before fetching a Live Chat, you have to retrieve the target livestream's info:
|
|
|
|
```js
|
|
const info = await session.getInfo('video_id');
|
|
```
|
|
|
|
Then you may request a Live Chat instance:
|
|
```js
|
|
const livechat = await info.getLiveChat();
|
|
```
|
|
|
|
## API
|
|
|
|
* LiveChat
|
|
* [.ev](#ev) ⇒ `EventEmitter`
|
|
* [.start](#start) ⇒ `function`
|
|
* [.stop](#stop) ⇒ `function`
|
|
* [.sendMessage](#sendmessage) ⇒ `function`
|
|
|
|
<a name="ev"></a>
|
|
### ev
|
|
Live Chat's EventEmitter.
|
|
|
|
**Events:**
|
|
|
|
- `start`
|
|
|
|
Arguments:
|
|
| Type | Description |
|
|
| --- | --- |
|
|
| `object` | Initial chat data, actions, info, etc. |
|
|
|
|
- `chat-update`
|
|
|
|
Arguments:
|
|
| Type | Description |
|
|
| --- | --- |
|
|
| `object` | Chat Action |
|
|
|
|
- `metadata-update`
|
|
|
|
Arguments:
|
|
| Type | Description |
|
|
| --- | --- |
|
|
| `object` | LiveStream Metadata |
|
|
|
|
<a name="start"></a>
|
|
### start()
|
|
Starts the Live Chat.
|
|
|
|
<a name="stop"></a>
|
|
### stop()
|
|
Stops the Live Chat.
|
|
|
|
<a name="sendmessage"></a>
|
|
### sendMessage(text)
|
|
Sends a message.
|
|
|
|
| Param | Type | Description |
|
|
| --- | --- | --- |
|
|
| text | `string` | Message content |
|
|
|
|
**Returns:** `Promise.<object>`
|
|
|
|
## Example
|
|
See [`index.js`]('./index.js').
|