-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
52 lines (42 loc) · 1.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const _oauth = require( 'googleapis' ).auth.OAuth2;
exports.connect = function( oauth, youtubeCreds, liveChatId, callback )
{
const oauthClient = _getOAuthClient( oauth );
oauthClient.setCredentials({
access_token: youtubeCreds.access_token,
refresh_token: youtubeCreds.refresh_token,
expiry_token: youtubeCreds.token_expiry
});
const responseHandler = _curryHandleResponse( callback );
const stream = require( './src/stream.js' );
stream._init( oauthClient, liveChatId, responseHandler );
return stream;
};
const _curryHandleResponse = function( callback )
{
return function( err, response )
{
_handleResponse( err, response, callback );
};
};
const _handleResponse = function( err, response, callback )
{
if( err )
{
callback( err );
return;
}
if(response !== null)
{
if( typeof response.access_token !== undefined)
callback(undefined, response);
else if( response.items.length > 0 )
{
callback( undefined, response.items );
}
}
};
const _getOAuthClient = function( oauth )
{
return new _oauth( oauth.client_id, oauth.client_secret, oauth.redirect_uris[0] );
};