This module is a implementation of Streamlabs API https://dev.streamlabs.com/
You need nodejs version > 6x because this module was made with ES6.
node --version
Add the latest version of streamlabs
to your package.json:
npm install streamlabs --save
let streamLabsApi = require('streamlabs');
Give the credentials of the StreamLabs to the constructor
Params | Description | Optional |
---|---|---|
ClientId | The Client Id | false |
ClientSecret | The Client Secret | false |
RedirectUrl | The RedirectUrl with format 'http://yourdomain/callback' | false |
Scopes | They are 4 scopes: donations.read donations.create alerts.create socket.token | false |
SocketToken | The socket token | true |
AccessToken | The access token if you have one | true |
let streamLabs = new streamLabsApi('clientId', 'clientSecret', 'http://yourdomain/youraction', 'donations.read donations.create alerts.create socket.token');
To authenticate with OAuth you will call authorizationUrl
and will return an URL, you will make a request with a browser and authorizate in OAuth. After that you will be redirect to RedirectUrl
and you will get a code
on QueryString ?code='hjqweassxzass'
let urlAuthorization = streamLabs.authorizationUrl();
For generate an access token and refresh token you have to call connect
with the code
you got on QueryString
Params | Description | Optional |
---|---|---|
Code | The code you got in the querystring | false |
streamLabs.connect(code);
If you need refresh the access token, you have to call reconnect
and send the refreshToken
Params | Description | Optional |
---|---|---|
RefreshToken | The refresh token you got in credentials | false |
streamLabs.reconnect(refreshToken);
For get donations you have to call getDonations
and stablish how much donations you want of the collection
Params | Description | Optional |
---|---|---|
Limit | Stablish how much donations you want of the collection | false |
streamLabs.getDonations(10);
For add donations you have to call addDonations
and send an object params
Params | Description | Optional |
---|---|---|
Donation | Object with
|
false |
{
name: 'Name of user donation',
identifier: 'Identify user',
amount: 'Amount',
currency: 'USD',
message: 'A message'
}
For get alerts on real time you have to call connectWebSocket
and you will get a token, it should be used on WebSocket in the client
Server Side
streamLabs.connectWebSocket();
let socketToken = streamLabs.getCredentials().socketToken;
Client Side
let socket = io('https://sockets.streamlabs.com?token=' + socketToken);
socket.on('event', (eventData) => console.log(eventData));
If you need to save credentials, you have to call getCredentials
and you will get an object
{
accessToken,
refreshToken,
expiresIn,
socketToken
}
If you add then
to call you will take the success of response and if you add catch
you will take the error of response.
streamLabs.getDonations(10)
.then((res) => console.log(res)))
.catch((err) => console.log(err)))
You can test the module with your productive credentials.
First change the clientId
and clientSecret
in tests/integration.js
with yours credentials, open a console and run npm start
, open browser and type http://localhost:8080/
http://localhost:8080/
return the url of authorization, copy and paste into the url of the browserhttp://localhost:8080/getDonations?limit=2
return two donationshttp://localhost:8080/addDonation
add donations and return de idhttp://localhost:8080/credentials
get credentialshttp://localhost:8080/connectSocket
return the socket tokenhttp://localhost:8080/reconnect
refresh access token