Setup/teardown events
This commit is contained in:
@@ -107,26 +107,6 @@ export class Convo {
|
|||||||
} else {
|
} else {
|
||||||
DEBUG_ACTIVE_CHAT = this.convoId
|
DEBUG_ACTIVE_CHAT = this.convoId
|
||||||
}
|
}
|
||||||
|
|
||||||
this.events.on(
|
|
||||||
event => {
|
|
||||||
switch (event.type) {
|
|
||||||
case 'connect': {
|
|
||||||
this.onFirehoseConnect()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case 'error': {
|
|
||||||
this.onFirehoseError(event.error)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case 'logs': {
|
|
||||||
this.ingestFirehose(event.logs)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{convoId: this.convoId},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private commit() {
|
private commit() {
|
||||||
@@ -225,6 +205,7 @@ export class Convo {
|
|||||||
case ConvoDispatchEvent.Init: {
|
case ConvoDispatchEvent.Init: {
|
||||||
this.status = ConvoStatus.Initializing
|
this.status = ConvoStatus.Initializing
|
||||||
this.setup()
|
this.setup()
|
||||||
|
this.setupFirehose()
|
||||||
this.requestPollInterval(ACTIVE_POLL_INTERVAL)
|
this.requestPollInterval(ACTIVE_POLL_INTERVAL)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -246,12 +227,14 @@ export class Convo {
|
|||||||
}
|
}
|
||||||
case ConvoDispatchEvent.Suspend: {
|
case ConvoDispatchEvent.Suspend: {
|
||||||
this.status = ConvoStatus.Suspended
|
this.status = ConvoStatus.Suspended
|
||||||
|
this.cleanupFirehoseConnection?.()
|
||||||
this.withdrawRequestedPollInterval()
|
this.withdrawRequestedPollInterval()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case ConvoDispatchEvent.Error: {
|
case ConvoDispatchEvent.Error: {
|
||||||
this.status = ConvoStatus.Error
|
this.status = ConvoStatus.Error
|
||||||
this.error = action.payload
|
this.error = action.payload
|
||||||
|
this.cleanupFirehoseConnection?.()
|
||||||
this.withdrawRequestedPollInterval()
|
this.withdrawRequestedPollInterval()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -272,12 +255,14 @@ export class Convo {
|
|||||||
}
|
}
|
||||||
case ConvoDispatchEvent.Suspend: {
|
case ConvoDispatchEvent.Suspend: {
|
||||||
this.status = ConvoStatus.Suspended
|
this.status = ConvoStatus.Suspended
|
||||||
|
this.cleanupFirehoseConnection?.()
|
||||||
this.withdrawRequestedPollInterval()
|
this.withdrawRequestedPollInterval()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case ConvoDispatchEvent.Error: {
|
case ConvoDispatchEvent.Error: {
|
||||||
this.status = ConvoStatus.Error
|
this.status = ConvoStatus.Error
|
||||||
this.error = action.payload
|
this.error = action.payload
|
||||||
|
this.cleanupFirehoseConnection?.()
|
||||||
this.withdrawRequestedPollInterval()
|
this.withdrawRequestedPollInterval()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -300,12 +285,14 @@ export class Convo {
|
|||||||
}
|
}
|
||||||
case ConvoDispatchEvent.Suspend: {
|
case ConvoDispatchEvent.Suspend: {
|
||||||
this.status = ConvoStatus.Suspended
|
this.status = ConvoStatus.Suspended
|
||||||
|
this.cleanupFirehoseConnection?.()
|
||||||
this.withdrawRequestedPollInterval()
|
this.withdrawRequestedPollInterval()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case ConvoDispatchEvent.Error: {
|
case ConvoDispatchEvent.Error: {
|
||||||
this.status = ConvoStatus.Error
|
this.status = ConvoStatus.Error
|
||||||
this.error = action.payload
|
this.error = action.payload
|
||||||
|
this.cleanupFirehoseConnection?.()
|
||||||
this.withdrawRequestedPollInterval()
|
this.withdrawRequestedPollInterval()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -615,6 +602,33 @@ export class Convo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private cleanupFirehoseConnection: (() => void) | undefined
|
||||||
|
private setupFirehose() {
|
||||||
|
// remove old listeners, if exist
|
||||||
|
this.cleanupFirehoseConnection?.()
|
||||||
|
|
||||||
|
// reconnect
|
||||||
|
this.cleanupFirehoseConnection = this.events.on(
|
||||||
|
event => {
|
||||||
|
switch (event.type) {
|
||||||
|
case 'connect': {
|
||||||
|
this.onFirehoseConnect()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'error': {
|
||||||
|
this.onFirehoseError(event.error)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'logs': {
|
||||||
|
this.ingestFirehose(event.logs)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{convoId: this.convoId},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
onFirehoseConnect() {
|
onFirehoseConnect() {
|
||||||
this.footerItems.delete(ConvoItemError.FirehoseFailed)
|
this.footerItems.delete(ConvoItemError.FirehoseFailed)
|
||||||
this.commit()
|
this.commit()
|
||||||
@@ -727,6 +741,8 @@ export class Convo {
|
|||||||
id: tempId,
|
id: tempId,
|
||||||
message,
|
message,
|
||||||
})
|
})
|
||||||
|
// remove on each send, it might go through now without user having to click
|
||||||
|
this.footerItems.delete(ConvoItemError.PendingFailed)
|
||||||
this.commit()
|
this.commit()
|
||||||
|
|
||||||
if (!this.isProcessingPendingMessages) {
|
if (!this.isProcessingPendingMessages) {
|
||||||
|
|||||||
Reference in New Issue
Block a user