Skip to content

Commit 067bcae

Browse files
authored
#72: Update WebSocket URL, 1.0.0 (#76)
* #72: update ws url * update doc * 1.0.0
1 parent 20e0d37 commit 067bcae

File tree

7 files changed

+182
-171
lines changed

7 files changed

+182
-171
lines changed

README.md

Lines changed: 162 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,162 +1,162 @@
1-
<p align="center">
2-
<img src="/assets/tesjs_logo_stroke.png?raw=true" height="175px" alt="TESjs logo"/>
3-
</p>
4-
<p align="center">
5-
<img src="https://github.com/mitchwadair/tesjs/workflows/code%20analysis/badge.svg?branch=main" alt="code analysis"/>
6-
<img src="https://github.com/mitchwadair/tesjs/workflows/tests/badge.svg?branch=main" alt="tests"/>
7-
<a href="LICENSE"><img src='https://img.shields.io/npm/l/tesjs' alt="license"></a>
8-
<a href="https://www.npmjs.com/package/tesjs"><img src='https://img.shields.io/npm/dt/tesjs' alt="downloads"></a>
9-
</p>
10-
11-
A module to streamline the use of Twitch EventSub in Node.js applications
12-
13-
# WebSockets now Available!
14-
WebSocket transport is now available in TESjs! You can use TESjs with WebSocket transport in your client and server-side applications. Keep in mind that the WebSocket transport is currently in [open beta](https://discuss.dev.twitch.tv/t/eventsub-websockets-are-now-available-in-open-beta/41639), so changes could be made that may affect your application negatively until TESjs is able to update. You can try this out in TESjs `v1.0.0-beta.0` and higher.
15-
16-
# Documentation
17-
Learn how to use TESjs by reading through the [documentation](/doc). Supplement your development with the Twitch EventSub [documentation](https://dev.twitch.tv/docs/eventsub) as well.
18-
19-
# Install
20-
TESjs is available for install through npm
21-
```sh
22-
npm install tesjs
23-
```
24-
Or in browsers through a CDN
25-
```html
26-
<script src="https://cdn.jsdelivr.net/gh/mitchwadair/tesjs@v1.0.0-beta.0/dist/tes.min.js"></script>
27-
```
28-
29-
# Basic Usage
30-
Keep in mind that in order for your subscriptions to work when using `webhook` transport, the url you are pointing to for the listener **MUST** use `HTTPS` and port `443`. More information can be found in the Twitch documentation [here](https://dev.twitch.tv/docs/eventsub). Their suggestion for testing locally is to use a product like [ngrok](https://ngrok.com/) to create an `HTTPS` endpoint to forward your local server (which is hosted on `HTTP`).
31-
```js
32-
const TES = require("tesjs");
33-
34-
// initialize TESjs
35-
const tes = new TES({
36-
identity: {
37-
id: YOUR_CLIENT_ID,
38-
secret: YOUR_CLIENT_SECRET //do not ship this in plaintext!! use environment variables so this does not get exposed
39-
},
40-
listener: {
41-
type: "webhook",
42-
baseURL: "https://example.com",
43-
secret: WEBHOOKS_SECRET,
44-
}
45-
});
46-
47-
// define an event handler for the `channel.update` event
48-
// NOTES:
49-
// this handles ALL events of that type
50-
// events will not be fired until there is a subscription made for them
51-
tes.on("channel.update", (event) => {
52-
console.log(`${event.broadcaster_user_name}'s new title is ${event.title}`);
53-
});
54-
55-
// create a new subscription for the `channel.update` event for broadcaster "1337"
56-
tes.subscribe("channel.update", { broadcaster_user_id: "1337" })
57-
.then(() => {
58-
console.log("Subscription successful");
59-
}).catch(err => {
60-
console.log(err);
61-
});
62-
```
63-
64-
# Browser
65-
TESjs supports WebSocket transport, and can be used in a browser environment
66-
```html
67-
<script src="https://cdn.jsdelivr.net/gh/mitchwadair/tesjs@v1.0.0-beta.0/dist/tes.min.js"></script>
68-
<script>
69-
const config = {
70-
identity: {
71-
id: YOUR_CLIENT_ID,
72-
accessToken: YOUR_USER_ACCESS_TOKEN,
73-
},
74-
listener: { type: "websocket" },
75-
};
76-
const tes = new TES(config);
77-
78-
// define an event handler for the `channel.update` event
79-
// NOTES:
80-
// this handles ALL events of that type
81-
// events will not be fired until there is a subscription made for them
82-
tes.on("channel.update", (event) => {
83-
console.log(`${event.broadcaster_user_name}'s new title is ${event.title}`);
84-
});
85-
86-
// create a new subscription for the `channel.update` event for broadcaster "1337"
87-
tes.subscribe("channel.update", { broadcaster_user_id: "1337" })
88-
.then(() => {
89-
console.log("Subscription successful");
90-
}).catch(err => {
91-
console.log(err);
92-
});
93-
</script>
94-
```
95-
96-
# Use an Existing Express Server
97-
TESjs uses Express under the hood to host a webhooks endpoint. If you already have a server running on Express that you want to use, you can pass it into the configuration object for TESjs.
98-
```js
99-
const TES = require("tesjs");
100-
const express = require("express");
101-
102-
// create our Express server
103-
const app = express();
104-
105-
app.get("/", (req, res) => {
106-
res.send("OK");
107-
});
108-
109-
app.listen(8080);
110-
111-
// initialize TESjs
112-
const tes = new TES({
113-
identity: {
114-
id: YOUR_CLIENT_ID,
115-
secret: YOUR_CLIENT_SECRET //do not ship this in plaintext!! use environment variables so this does not get exposed
116-
},
117-
listener: {
118-
type: "webhook",
119-
baseURL: "https://example.com",
120-
secret: WEBHOOKS_SECRET,
121-
server: app
122-
}
123-
});
124-
125-
// define an event handler for the `channel.update` event
126-
// NOTES:
127-
// this handles ALL events of that type
128-
// events will not be fired until there is a subscription made for them
129-
tes.on("channel.update", (event) => {
130-
console.log(`${event.broadcaster_user_name}'s new title is ${event.title}`);
131-
});
132-
133-
// create a new subscription for the `channel.update` event for broadcaster "1337"
134-
tes.subscribe("channel.update", { broadcaster_user_id: "1337" })
135-
.then(() => {
136-
console.log("Subscription successful");
137-
}).catch(err => {
138-
console.log(err);
139-
});
140-
```
141-
142-
# Problems/Suggestions/Questions?
143-
If you have any questions, suggestions, need to report a bug, etc, [submit an issue](https://github.com/mitchwadair/tesjs/issues/new/choose).
144-
145-
# Contribute
146-
Want to contribute to TESjs? Check out the [contribution guidelines](/CONTRIBUTING.md) to see how.
147-
148-
# Support
149-
Want to help support me in maintaining TESjs? Consider sponsoring me on [GitHub Sponsors](https://github.com/sponsors/mitchwadair). You can also give a one-time donation through [PayPal](https://paypal.me/mitchwadair).
150-
151-
<p align="center">
152-
<a href="https://paypal.me/mitchwadair">
153-
<img src="https://www.paypalobjects.com/webstatic/mktg/logo/pp_cc_mark_111x69.jpg" height="75px" alt="PayPal Logo">
154-
</a>
155-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
156-
<a href="https://github.com/sponsors/mitchwadair">
157-
<img src="https://github.githubassets.com/images/modules/site/sponsors/logo-mona-2.svg" height="75px" alt="GH Sponsors">
158-
</a>
159-
</p>
160-
161-
# Community
162-
Have you made something with TESjs? I'd love to hear about it! You can tweet me [@imMtB_](https://twitter.com/imMtB_) and show off your project.
1+
<p align="center">
2+
<img src="/assets/tesjs_logo_stroke.png?raw=true" height="175px" alt="TESjs logo"/>
3+
</p>
4+
<p align="center">
5+
<img src="https://github.com/mitchwadair/tesjs/workflows/code%20analysis/badge.svg?branch=main" alt="code analysis"/>
6+
<img src="https://github.com/mitchwadair/tesjs/workflows/tests/badge.svg?branch=main" alt="tests"/>
7+
<a href="LICENSE"><img src='https://img.shields.io/npm/l/tesjs' alt="license"></a>
8+
<a href="https://www.npmjs.com/package/tesjs"><img src='https://img.shields.io/npm/dt/tesjs' alt="downloads"></a>
9+
</p>
10+
11+
A module to streamline the use of Twitch EventSub in Node.js and Web applications
12+
13+
# WebSockets now Available!
14+
WebSocket transport is now available in TESjs! You can use TESjs with WebSocket transport in your client and server-side applications. Keep in mind that the WebSocket transport is currently in [open beta](https://discuss.dev.twitch.tv/t/eventsub-websockets-are-now-available-in-open-beta/41639), so changes could be made that may affect your application negatively until TESjs is able to update. You can try this out in TESjs `v1.0.0` and higher.
15+
16+
# Documentation
17+
Learn how to use TESjs by reading through the [documentation](/doc). Supplement your development with the Twitch EventSub [documentation](https://dev.twitch.tv/docs/eventsub) as well.
18+
19+
# Install
20+
TESjs is available for install through npm
21+
```sh
22+
npm install tesjs
23+
```
24+
Or in browsers through a CDN
25+
```html
26+
<script src="https://cdn.jsdelivr.net/gh/mitchwadair/tesjs@v1.0.0/dist/tes.min.js"></script>
27+
```
28+
29+
# Basic Usage
30+
Keep in mind that in order for your subscriptions to work when using `webhook` transport, the url you are pointing to for the listener **MUST** use `HTTPS` and port `443`. More information can be found in the Twitch documentation [here](https://dev.twitch.tv/docs/eventsub). Their suggestion for testing locally is to use a product like [ngrok](https://ngrok.com/) to create an `HTTPS` endpoint to forward your local server (which is hosted on `HTTP`).
31+
```js
32+
const TES = require("tesjs");
33+
34+
// initialize TESjs
35+
const tes = new TES({
36+
identity: {
37+
id: YOUR_CLIENT_ID,
38+
secret: YOUR_CLIENT_SECRET //do not ship this in plaintext!! use environment variables so this does not get exposed
39+
},
40+
listener: {
41+
type: "webhook",
42+
baseURL: "https://example.com",
43+
secret: WEBHOOKS_SECRET,
44+
}
45+
});
46+
47+
// define an event handler for the `channel.update` event
48+
// NOTES:
49+
// this handles ALL events of that type
50+
// events will not be fired until there is a subscription made for them
51+
tes.on("channel.update", (event) => {
52+
console.log(`${event.broadcaster_user_name}'s new title is ${event.title}`);
53+
});
54+
55+
// create a new subscription for the `channel.update` event for broadcaster "1337"
56+
tes.subscribe("channel.update", { broadcaster_user_id: "1337" })
57+
.then(() => {
58+
console.log("Subscription successful");
59+
}).catch(err => {
60+
console.log(err);
61+
});
62+
```
63+
64+
# Browser
65+
TESjs supports WebSocket transport, and can be used in a browser environment
66+
```html
67+
<script src="https://cdn.jsdelivr.net/gh/mitchwadair/tesjs@v1.0.0/dist/tes.min.js"></script>
68+
<script>
69+
const config = {
70+
identity: {
71+
id: YOUR_CLIENT_ID,
72+
accessToken: YOUR_USER_ACCESS_TOKEN,
73+
},
74+
listener: { type: "websocket" },
75+
};
76+
const tes = new TES(config);
77+
78+
// define an event handler for the `channel.update` event
79+
// NOTES:
80+
// this handles ALL events of that type
81+
// events will not be fired until there is a subscription made for them
82+
tes.on("channel.update", (event) => {
83+
console.log(`${event.broadcaster_user_name}'s new title is ${event.title}`);
84+
});
85+
86+
// create a new subscription for the `channel.update` event for broadcaster "1337"
87+
tes.subscribe("channel.update", { broadcaster_user_id: "1337" })
88+
.then(() => {
89+
console.log("Subscription successful");
90+
}).catch(err => {
91+
console.log(err);
92+
});
93+
</script>
94+
```
95+
96+
# Use an Existing Express Server
97+
TESjs uses Express under the hood to host a webhooks endpoint. If you already have a server running on Express that you want to use, you can pass it into the configuration object for TESjs.
98+
```js
99+
const TES = require("tesjs");
100+
const express = require("express");
101+
102+
// create our Express server
103+
const app = express();
104+
105+
app.get("/", (req, res) => {
106+
res.send("OK");
107+
});
108+
109+
app.listen(8080);
110+
111+
// initialize TESjs
112+
const tes = new TES({
113+
identity: {
114+
id: YOUR_CLIENT_ID,
115+
secret: YOUR_CLIENT_SECRET //do not ship this in plaintext!! use environment variables so this does not get exposed
116+
},
117+
listener: {
118+
type: "webhook",
119+
baseURL: "https://example.com",
120+
secret: WEBHOOKS_SECRET,
121+
server: app
122+
}
123+
});
124+
125+
// define an event handler for the `channel.update` event
126+
// NOTES:
127+
// this handles ALL events of that type
128+
// events will not be fired until there is a subscription made for them
129+
tes.on("channel.update", (event) => {
130+
console.log(`${event.broadcaster_user_name}'s new title is ${event.title}`);
131+
});
132+
133+
// create a new subscription for the `channel.update` event for broadcaster "1337"
134+
tes.subscribe("channel.update", { broadcaster_user_id: "1337" })
135+
.then(() => {
136+
console.log("Subscription successful");
137+
}).catch(err => {
138+
console.log(err);
139+
});
140+
```
141+
142+
# Problems/Suggestions/Questions?
143+
If you have any questions, suggestions, need to report a bug, etc, [submit an issue](https://github.com/mitchwadair/tesjs/issues/new/choose).
144+
145+
# Contribute
146+
Want to contribute to TESjs? Check out the [contribution guidelines](/CONTRIBUTING.md) to see how.
147+
148+
# Support
149+
Want to help support me in maintaining TESjs? Consider sponsoring me on [GitHub Sponsors](https://github.com/sponsors/mitchwadair). You can also give a one-time donation through [PayPal](https://paypal.me/mitchwadair).
150+
151+
<p align="center">
152+
<a href="https://paypal.me/mitchwadair">
153+
<img src="https://www.paypalobjects.com/webstatic/mktg/logo/pp_cc_mark_111x69.jpg" height="75px" alt="PayPal Logo">
154+
</a>
155+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
156+
<a href="https://github.com/sponsors/mitchwadair">
157+
<img src="https://github.githubassets.com/images/modules/site/sponsors/logo-mona-2.svg" height="75px" alt="GH Sponsors">
158+
</a>
159+
</p>
160+
161+
# Community
162+
Have you made something with TESjs? I'd love to hear about it! You can tweet me [@imMtB_](https://twitter.com/imMtB_) and show off your project.

0 commit comments

Comments
 (0)