Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add proof-of-concept websocket connection to twitch
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const WebSocket = require('ws'); | ||
|
||
// TODO: better token/config handling. | ||
var authToken = process.env['TWITCH_CLIENT_ACCESS_TOKEN']; | ||
|
||
const ws = new WebSocket('wss://pubsub-edge.twitch.tv/'); | ||
|
||
ws.on('open', function open() { | ||
console.log('connected'); | ||
|
||
const data = { | ||
type: "PING" | ||
}; | ||
const message = JSON.stringify(data); | ||
|
||
ws.send(message); | ||
}); | ||
|
||
ws.on('close', function close() { | ||
console.log('disconnected'); | ||
}); | ||
|
||
ws.on('message', function incoming(message) { | ||
const data = JSON.parse(message); | ||
|
||
console.log(`Message: ${JSON.stringify(data, null, 2)}`); | ||
|
||
process.exit(); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "botten-nappet", | ||
"version": "1.0.0", | ||
"description": "A Twitch bot and streaming tool", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"twitch", | ||
"bot", | ||
"streaming" | ||
], | ||
"author": { | ||
"name": "Joel Purra", | ||
"email": "mig@joelpurra.se", | ||
"url": "https://joelpurra.com/" | ||
}, | ||
"license": "AGPL-3.0", | ||
"dependencies": { | ||
"ws": "^4.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/joelpurra/botten-nappet.git" | ||
}, | ||
"bugs": { | ||
"url": "https://joelpurra.com/support/" | ||
}, | ||
"homepage": "https://joelpurra.com/projects/botten-nappet/", | ||
} |