-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,285 additions
and
2 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,6 @@ | ||
TWITCH_CHANNEL_ID="" | ||
TWITCH_TOKEN="" | ||
HUE_CLIENT_ID="" | ||
HUE_CLIENT_SECRET="" | ||
HUE_TOKEN="" | ||
HUE_REFRESH_TOKEN="" |
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,2 @@ | ||
node_modules/** | ||
.env |
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 |
---|---|---|
@@ -1 +1,20 @@ | ||
# Twitch Hue | ||
# 💡💡 lights | ||
|
||
> Let your streaming control your Philips Hue lights 🙈 | ||
## How to setup | ||
|
||
Copy the .env.example file and complete the required values. | ||
|
||
``` | ||
cp .env.example .env | ||
``` | ||
|
||
| Env var | Description | Required | | ||
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | -------- | | ||
| TWITCH_CHANNEL_ID | Your [Twitch Channel Id](https://dev.twitch.tv/docs/v5/reference/channels/#get-channel) | **true** | | ||
| TWITCH_TOKEN | Your [Twitch Access Token](https://dev.twitch.tv/docs/authentication#getting-tokens) with **channel:read:redemptions** scope | **true** | | ||
| HUE_CLIENT_ID | The client id from a [Philips Hue Remote](https://developers.meethue.com/develop/hue-api/remote-api-quick-start-guide/) | **true** | | ||
| HUE_CLIENT_SECRET | The client secret from a [Philips Hue Remote](https://developers.meethue.com/develop/hue-api/remote-api-quick-start-guide/) | **true** | | ||
| HUE_TOKEN | The [hue access token](https://developers.meethue.com/develop/hue-api/remote-authentication/) generated with the same Philips Hue Remote | **true** | | ||
| HUE_REFRESH_TOKEN | The [hue refresh token](https://developers.meethue.com/develop/hue-api/remote-authentication/) generated with the same Philips Hue Remote | **true** | |
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
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,21 @@ | ||
const v3 = require("node-hue-api").v3; | ||
|
||
const updateLightStatus = async ({ on } = { on: false }) => { | ||
const remote = v3.api.createRemote( | ||
process.env.HUE_CLIENT_ID, | ||
process.env.HUE_CLIENT_SECRET | ||
); | ||
|
||
const api = await remote.connectWithTokens( | ||
process.env.HUE_TOKEN, | ||
process.env.HUE_REFRESH_TOKEN | ||
); | ||
|
||
await Promise.all([ | ||
api.lights.setLightState(5, { on }), | ||
api.lights.setLightState(6, { on }), | ||
api.lights.setLightState(9, { on }), | ||
]); | ||
}; | ||
|
||
module.exports = updateLightStatus; |
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,45 @@ | ||
const WebSocket = require("ws"); | ||
const hue = require("./hue"); | ||
|
||
const ws = new WebSocket("wss://pubsub-edge.twitch.tv"); | ||
|
||
ws.on("open", function open() { | ||
console.log("connected"); | ||
ws.send( | ||
JSON.stringify({ | ||
type: "LISTEN", | ||
nonce: "44h1k13746815ab1r2", | ||
data: { | ||
topics: [`channel-points-channel-v1.${process.env.TWITCH_CHANNEL_ID}`], | ||
auth_token: process.env.TWITCH_TOKEN, | ||
}, | ||
}) | ||
); | ||
}); | ||
|
||
ws.on("close", function close() { | ||
console.log("disconnected"); | ||
}); | ||
|
||
ws.on("message", function incoming(data) { | ||
const json = JSON.parse(data); | ||
if (!json.data) { | ||
return; | ||
} | ||
|
||
const message = JSON.parse(json.data.message); | ||
|
||
if (!message.data.redemption.reward) { | ||
return; | ||
} | ||
|
||
const reward = message.data.redemption.reward; | ||
|
||
if (reward.id === "3cc420c0-2198-4cd8-9a07-c68f489c50be") { | ||
hue({ on: false }); | ||
|
||
setTimeout(() => { | ||
hue({ on: true }); | ||
}, 10 * 1000); | ||
} | ||
}); |
Oops, something went wrong.