-
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.
add api client from the broadcaster to change stream
- Loading branch information
Showing
6 changed files
with
68 additions
and
34 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
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,33 @@ | ||
const config = require('./config') | ||
const {RefreshingAuthProvider} = require("@twurple/auth"); | ||
const TokenService = require("./services/token"); | ||
const {ApiClient} = require("@twurple/api"); | ||
|
||
class BroadcasterApiClient { | ||
constructor() { | ||
this.apiClient = null | ||
} | ||
|
||
async getApiClient () { | ||
if (this.apiClient === null) { | ||
const authProvider = new RefreshingAuthProvider( | ||
{ | ||
clientId: config.twitch.clientId, | ||
clientSecret: config.twitch.clientSecret | ||
} | ||
) | ||
const tokenData = await TokenService.getToken(config.twitch.roomId) | ||
|
||
authProvider.onRefresh(async (userId, newTokenData) => { | ||
await TokenService.updateToken(userId, newTokenData) | ||
}) | ||
|
||
await authProvider.addUserForToken(tokenData); | ||
|
||
this.apiClient = new ApiClient({authProvider}) | ||
} | ||
return this.apiClient | ||
} | ||
} | ||
|
||
module.exports = new BroadcasterApiClient() |
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
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