forked from Github/ocrcc-chatbox
handle bot signal
This commit is contained in:
parent
90815f361a
commit
91bec23c48
@ -25,7 +25,7 @@
|
|||||||
anonymousDisplayName: 'Anonymous',
|
anonymousDisplayName: 'Anonymous',
|
||||||
position: 'bottom right',
|
position: 'bottom right',
|
||||||
size: 'large',
|
size: 'large',
|
||||||
maxWaitTime: 6000*3,
|
maxWaitTime: 1000*60*3, // 3 minutes
|
||||||
}
|
}
|
||||||
|
|
||||||
EmbeddableChatbox.mount(config);
|
EmbeddableChatbox.mount(config);
|
||||||
|
@ -167,6 +167,7 @@ class ChatBox extends React.Component {
|
|||||||
await this.state.client.stopClient()
|
await this.state.client.stopClient()
|
||||||
await this.state.client.clearStores()
|
await this.state.client.clearStores()
|
||||||
this.setState({ client: null })
|
this.setState({ client: null })
|
||||||
|
window.clearInterval(this.state.waitIntervalId) // no more waiting messages
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state.localStorage.clear()
|
this.state.localStorage.clear()
|
||||||
@ -487,8 +488,6 @@ class ChatBox extends React.Component {
|
|||||||
|
|
||||||
handleChatOffline = () => {
|
handleChatOffline = () => {
|
||||||
this.exitChat(false) // close the chat connection but keep chatbox state
|
this.exitChat(false) // close the chat connection but keep chatbox state
|
||||||
window.clearInterval(this.state.waitIntervalId) // no more waiting messages
|
|
||||||
window.clearInterval(this.state.waitTimeoutId) // no more waiting messages
|
|
||||||
this.setState({ ready: true }) // no more loading animation
|
this.setState({ ready: true }) // no more loading animation
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,7 +545,6 @@ class ChatBox extends React.Component {
|
|||||||
this.verifyAllRoomDevices(client, room)
|
this.verifyAllRoomDevices(client, room)
|
||||||
this.setState({ facilitatorId: sender, ready: true })
|
this.setState({ facilitatorId: sender, ready: true })
|
||||||
window.clearInterval(this.state.waitIntervalId)
|
window.clearInterval(this.state.waitIntervalId)
|
||||||
window.clearInterval(this.state.waitTimeoutId)
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -568,6 +566,23 @@ class ChatBox extends React.Component {
|
|||||||
this.setState({ typingStatus: null })
|
this.setState({ typingStatus: null })
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client.on("event", (event) => {
|
||||||
|
const eventType = event.getType()
|
||||||
|
const content = event.getContent()
|
||||||
|
|
||||||
|
if (eventType === 'm.bot.signal') {
|
||||||
|
this.handleBotSignal(content.signal)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
handleBotSignal = (signal) => {
|
||||||
|
switch (signal) {
|
||||||
|
case 'END_CHAT':
|
||||||
|
this.displayBotMessage({ body: this.props.exitMessage })
|
||||||
|
return this.exitChat(false); // keep chat state
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps, prevState) {
|
componentDidUpdate(prevProps, prevState) {
|
||||||
@ -624,14 +639,7 @@ class ChatBox extends React.Component {
|
|||||||
}
|
}
|
||||||
}, this.props.waitInterval)
|
}, this.props.waitInterval)
|
||||||
|
|
||||||
const waitTimeoutId = window.setTimeout(() => {
|
this.setState({ waitIntervalId })
|
||||||
if (!this.state.facilitatorId && !this.state.ready) {
|
|
||||||
this.displayBotMessage({ body: this.props.chatUnavailableMessage })
|
|
||||||
this.handleChatOffline()
|
|
||||||
}
|
|
||||||
}, this.props.maxWaitTime)
|
|
||||||
|
|
||||||
this.setState({ waitIntervalId, waitTimeoutId })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRejectTerms = () => {
|
handleRejectTerms = () => {
|
||||||
|
3
src/setupTests.js
Normal file
3
src/setupTests.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import { configure } from 'enzyme';
|
||||||
|
import Adapter from 'enzyme-adapter-react-16';
|
||||||
|
configure({ adapter: new Adapter() });
|
Loading…
Reference in New Issue
Block a user