Skip to content
This repository was archived by the owner on Mar 28, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/DatafeedClient/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ DatafeedClient.getEventsFromDatafeed = datafeedId => {

if (response.statusCode === 200) {
return { status: 'success', body: JSON.parse(response.body) }
} else if (response.statusCode === 401) {
return { status: 'reauth' }
} else if (response.statusCode === 204) {
return { status: 'timeout' }
} else {
Expand Down
38 changes: 29 additions & 9 deletions lib/DatafeedEventsService/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,19 @@ class DatafeedEventsService extends EventEmitter {
_read() {
DatafeedClient.getEventsFromDatafeed(this.id).then(
response => {
if (response.status === 'success') {
if (response.status === 'reauth') {
if (SymBotAuth.debug) {
console.log(
'[DEBUG]',
'Session expired, trying to reauthenticate')
}
// session expired, try to reauthenticate to keep the DF loop running
SymBotAuth.authenticate(SymBotAuth.symConfig)
.then(() => {
this.continueReading();
})

} else if (response.status === 'success') {
const eventsByType = response.body.reduce((acc, event) => {
const type = event.type.toLowerCase()
if (!acc[type]) {
Expand All @@ -134,24 +146,32 @@ class DatafeedEventsService extends EventEmitter {
this.emit(type, events)
}
})
}

if (this.liveStatus) {
// continue reading from datafeed
this._read()
this.continueReading()
} else {
this.emit('stopped')
this.unregisterShutdownHooks()
// empty content, just keep reading DF
this.continueReading()
}

this.retries = 0

},
err => {
this._retryConnection(err)
}
)
}

continueReading() {
if (this.liveStatus) {
// continue reading from datafeed
this._read()
} else {
this.emit('stopped')
this.unregisterShutdownHooks()
}

this.retries = 0
}

stop(onStopped) {
console.log(`The BOT ${SymBotAuth.botUser.displayName} is shutting down`)
this.liveStatus = false
Expand Down
1 change: 0 additions & 1 deletion lib/SymBotAuth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ SymBotAuth.sessionAuthenticate = (symConfig) => {

if (symConfig.authType === 'rsa') {
body = { 'token': SymBotAuth.getJwtToken(symConfig) }
body = { 'token': SymBotAuth.getJwtToken(symConfig) }

options = {
'hostname': symConfig.podHost,
Expand Down
Loading