Skip to content

Commit

Permalink
Add proof-of-concept websocket connection to twitch
Browse files Browse the repository at this point in the history
  • Loading branch information
joelpurra committed Jan 18, 2018
1 parent 78fa713 commit 7ccad02
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules/
29 changes: 29 additions & 0 deletions index.js
@@ -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();
});
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions package.json
@@ -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/",
}

0 comments on commit 7ccad02

Please sign in to comment.