Skip to content

Commit

Permalink
Callback fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Chase committed Oct 18, 2016
1 parent aac8cf8 commit 4dd2b51
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
15 changes: 9 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const _oauth = require( 'googleapis' ).auth.OAuth2;

exports.connect = function( oauth, youtubeCreds, liveChatId, callback )
{
console.log('CONNECT');
const oauthClient = _getOAuthClient( oauth );

oauthClient.setCredentials({
Expand Down Expand Up @@ -36,11 +35,15 @@ const _handleResponse = function( err, response, callback )
return;
}

console.log('response');
console.log(response);

//if( response.items.length > 0 )
// callback( undefined, response.items );
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 )
Expand Down
7 changes: 3 additions & 4 deletions src/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports._init = function( auth, liveChatId, callback )
const _step = function( auth, liveChatId, pageToken, callback )
{
_getMessages(auth, liveChatId, pageToken, function( err, response )
{
{
if( err )
{
if(err.errors[0].reason === 'authError')
Expand All @@ -23,7 +23,7 @@ const _step = function( auth, liveChatId, pageToken, callback )
}
}

if( response !== undefined )
if( response !== undefined && response.items.length > 0)
callback( undefined, response );

const pollingInterval = response == undefined ? 10000 : response.pollingIntervalMillis;
Expand Down Expand Up @@ -78,8 +78,7 @@ const _getMessages = function( accessToken, liveChatId, pageToken, callback )

const _refreshToken = function(auth, callback)
{
console.log('REFRESH');
auth.refreshAccessToken(function(err, tokens, callback) {
auth.refreshAccessToken(function(err, tokens) {
// your access_token is now refreshed and stored in oauth2Client
// store these new tokens in a safe place (e.g. database)
if(err)
Expand Down

0 comments on commit 4dd2b51

Please sign in to comment.