Skip to content

LukasWieditz/streamLabs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StreamLabs

Build Status Coverage Status

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

Installation:

Add the latest version of streamlabs to your package.json:

npm install streamlabs --save

Usage:

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');

Authorization

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();

Get Access Token

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);

Refresh Access Token

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);

Get Donations:

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);

Add Donation:

For add donations you have to call addDonations and send an object params

Params Description Optional
Donation Object with
  • Name (string)
  • Identifier (string)
  • Amount (decimal)
  • Currency: (string) - See Currency Codes
  • Message (string)
false
{
  name: 'Name of user donation',
  identifier: 'Identify user',
  amount: 'Amount',
  currency: 'USD',
  message: 'A message'	
}

Get alerts real time:

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));

Get Credentials:

If you need to save credentials, you have to call getCredentials and you will get an object

{
  accessToken,
  refreshToken,
  expiresIn,
  socketToken
}

Promises

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)))

Test Integration:

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/

Urls:

About

This module is a implementation of Streamlabs API https://dev.streamlabs.com/

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%