# twitchclient

> Lightweight (2kb gzipped) Twitch client the Browser to connect to the chat and interact with it. Can also do some Api calls like following/unfollowing channels.

Latest version **0.0.29** (published 2019-09-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install twitchclient
pnpm add twitchclient
yarn add twitchclient
bun add twitchclient
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.29 |
| Published | 2019-09-25 |
| First published | 2019-09-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 18.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | teyd |
| Maintainers | teyd |
| Keywords | twitch, client, bot |

## Links

- npm: https://www.npmjs.com/package/twitchclient
- Repository: https://github.com/teyd/TwitchClient
- Homepage: https://github.com/teyd/TwitchClient#readme
- Issues: https://github.com/teyd/TwitchClient/issues
- npm.io page: https://npm.io/package/twitchclient

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.0.29 (latest) — 2019-09-25
- 0.0.28 — 2019-09-25
- 0.0.26 — 2019-09-23
- 0.0.25 — 2019-09-23
- 0.0.24 — 2019-09-23
- 0.0.23 — 2019-09-22
- 0.0.22 — 2019-09-22
- 0.0.21 — 2019-09-22
- 0.0.20 — 2019-09-22
- 0.0.19 — 2019-09-22
- 0.0.18 — 2019-09-22
- 0.0.17 — 2019-09-22
- 0.0.16 — 2019-09-22
- 0.0.15 — 2019-09-22
- 0.0.14 — 2019-09-22
- … 35 more at https://npm.io/package/twitchclient/versions

## README

# TwitchClient()

Lightweight *2.5kb gzipped* Twitch client for the *Browser* to connect to the chat and interact with it.
Supports third party emotes from BetterTTV & FrankerFaceZ.

## Installation

```
npm i twitchclient
```

## Message Object

```
let message = {
  raw: '@badge-info=subscriber/1;badges=subscriber/0;color=#1E90FF;display-name=BDJoe_;emotes=120232:13-19;flags=;id=5a253ad7-7e42-4021-a364-44d0c9af7821;mod=0;room-id=22484632;subscriber=1;tmi-sent-ts=1568822980541;turbo=0;user-id=453114423;user-type= :bdjoe_!bdjoe_@bdjoe_.tmi.twitch.tv PRIVMSG #forsen :TriHard Kapp forsenPls forsenPls test',
  msg_type: 'PRIVMSG',
  modified_irc: '@badge-info=subscriber/1;badges=subscriber/0;color=#1E90FF;display-name=BDJoe_;emotes=120232:13-19;flags=;id=5a253ad7-7e42-4021-a364-44d0c9af7821;mod=0;room-id=22484632;subscriber=1;tmi-sent-ts=1568822980541;turbo=0;user-id=453114423;user-type=;msg-before=bdjoe_!bdjoe_@bdjoe_.tmi.twitch.tv;msg-type=PRIVMSG;channel=#forsen;msg-content=TriHard Kapp forsenPls forsenPls test',
  badge_info: 'subscriber/1',
  badges: 'subscriber/0',
  color: '#1E90FF',
  display_name: 'BDJoe_',
  emotes: '120232:13-19',
  flags: '',
  id: '5a253ad7-7e42-4021-a364-44d0c9af7821',
  mod: '0',
  room_id: '22484632',
  subscriber: '1',
  tmi_sent_ts: '1568822980541',
  turbo: '0',
  user_id: '453114423',
  user_type: '',
  msg_before: 'bdjoe_!bdjoe_@bdjoe_.tmi.twitch.tv',
  channel: '#forsen',
  msg_content: 'TriHard Kapp forsenPls forsenPls test',
  parsed_emotes: {"Twitch":[{"name":"TriHard","urls":["https://static-cdn.jtvnw.net/emoticons/v1/120232/1.0","https://static-cdn.jtvnw.net/emoticons/v1/120232/2.0","https://static-cdn.jtvnw.net/emoticons/v1/120232/3.0"],"host":"Twitch","indexes":"0-6,"}],"BTTV":[{"name":"forsenPls","urls":["https://cdn.betterttv.net/emote/55e2096ea6fa8b261f81b12a/1x","https://cdn.betterttv.net/emote/55e2096ea6fa8b261f81b12a/2x","https://cdn.betterttv.net/emote/55e2096ea6fa8b261f81b12a/3x"],"host":"BTTV","indexes":"13-23,23-33,"}],"FFZ":[{"name":"Kapp","urls":["https://cdn.frankerfacez.com/93d93138f176a98e4b09c81e8de56372.PNG","https://cdn.frankerfacez.com/6e50ed6052f4398ffc67a92ee782d79d.PNG","https://cdn.frankerfacez.com/f92ee27b25b813e2618b0d34a96402b5.png"],"host":"FFZ","indexes":"8-13,"}]},
  msg_html: '<img src=\"https://static-cdn.jtvnw.net/emoticons/v1/120232/1.0\"> <img src=\"https://cdn.frankerfacez.com/93d93138f176a98e4b09c81e8de56372.PNG\"> <img src=\"https://cdn.betterttv.net/emote/55e2096ea6fa8b261f81b12a/1x\"> <img src=\"https://cdn.betterttv.net/emote/55e2096ea6fa8b261f81b12a/1x\"> test ',
}
```

## Browser Example
```html
<html>
<head>
    <!-- <script src="https://unpkg.com/twitchclient@0.0.7/lib/twitchclient.browser.js"></script> -->
    <script src="https://unpkg.com/twitchclient/lib/twitchclient.browser.js"></script>
    <script>
        let twitchClient = new TwitchClient("gzipped", "fw7kd79xuzpjwu8qbl4c18we78fssd", true);
        twitchClient.joinChannel("forsen");

        twitch.on("LOG", log => {
            console.log(log);
        })

        twitch.on("PRIVMSG", privmsg => {
            document.querySelector("body").innerHTML += `<p>[${privmsg.channel}] ${privmsg.display_name}: ${privmsg.msg_html}</p>`;
        })
    </script>
</head>
<body>
</body>
</html>
```

## Index
- [Methods](#methods)
    - [`joinChannel()`](#joinchannel)
    - [`leaveChannel()`](#leavechannel)
    - [`parseMessage()`](#parseMessage)
    - [`sendMessage()`](#sendMessage)
- [Events](#events)
    - [`LOG`](#onlog)
    - [`PRIVMSG`](#onprivmsg)
    - [`CLEARCHAT`](#onclearchat)
    - [`CLEARMSG`](#onclearmsg)
    - [`GLOBALUSERSTATE`](#onglobaluserstate)
    - [`ROOMSTATE`](#onroomstate)
    - [`USERNOTICE`](#onusernotice)
    - [`USERSTATE`](#onuserstate)


### `TwitchClient()`
Creates a new TwitchClient().
```javascript
let twitchClient = new TwitchClient(); // Anon
let twitchClient = new TwitchClient("forsen", "oauthtokenwithscope", true); // Username - OAuth Token - Third party emote parsing
// You can get the OAuth token from https://twitchapps.com/tmi/ for example or create your own https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/
```

## Methods

### `joinChannel()`
Joins a Twitch channel.
```javascript
TwitchClient.joinChannel("forsen")
```

### `leaveChannel()`
Leaves a Twitch channel.
```javascript
TwitchClient.leaveChannel("forsen")
```

### `parseMessage()`
Parses a raw IRC message to an object.
```javascript
TwitchClient.parseMessage("@badge-info=subscriber/1;badges=subscriber/0;color=#1E90FF;dis...")
```

### `sendMessage()`
Sends a message to a specific channel.
```javascript
TwitchClient.sendMessage("forsen", "TriHard")
```

## Events

### `on("LOG")`
This event is emitted when something happens what could be important for debugging.
```javascript
TwitchClient.on("LOG", log => { . . .});
```

### `on("PRIVMSG")`
This event is emitted when a message has been sent.
```javascript
TwitchClient.on("PRIVMSG", privmsg => { . . .});
```
### `on("CLEARCHAT")`
This event is emitted when a user gets timeouted or banned.
```javascript
TwitchClient.on("CLEARCHAT", clearchat => { . . .});
```

### `on("CLEARMSG")`
This event is emitted when a single message got deleted via /delete <target-msg-id>.
```javascript
TwitchClient.on("CLEARMSG", clearmsg => { . . .});
```

### `on("GLOBALUSERSTATE")`
This event is emitted when a message has been sent.
```javascript
TwitchClient.on("GLOBALUSERSTATE", globaluserstate => { . . .});
```

### `on("ROOMSTATE")`
This event is emitted when a user joins the chat or room setting got changed.
```javascript
TwitchClient.on("ROOMSTATE", roomstate => { . . .});
```

### `on("USERNOTICE")`
This event is emitted when any of several events occurs.
```javascript
TwitchClient.on("USERNOTICE", usernotice => { . . .});
```

### `on("USERSTATE")`
This event is emitted when a user joins a channel or sends a PRIVMSG to a channel.
```javascript
TwitchClient.on("USERSTATE", userstate => { . . .});
```

## License
[MIT](https://choosealicense.com/licenses/mit/)

---
_Source: https://npm.io/package/twitchclient · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
