forked from Github/ocrcc-chatbox
add flag to disable encryption
This commit is contained in:
parent
5252321f56
commit
f0b43743f7
@ -37,8 +37,9 @@ const DEFAULT_CONFIRMATION_MESSAGE = "Waiting for a facilitator to join the chat
|
|||||||
const DEFAULT_EXIT_MESSAGE = "The chat is closed. You may close this window."
|
const DEFAULT_EXIT_MESSAGE = "The chat is closed. You may close this window."
|
||||||
const DEFAULT_ANONYMOUS_DISPLAY_NAME="Anonymous"
|
const DEFAULT_ANONYMOUS_DISPLAY_NAME="Anonymous"
|
||||||
const DEFAULT_CHAT_UNAVAILABLE_MESSAGE = "The chat service is not available right now. Please try again later."
|
const DEFAULT_CHAT_UNAVAILABLE_MESSAGE = "The chat service is not available right now. Please try again later."
|
||||||
const DFAULT_CHAT_OFFLINE_MESSAGE = "There are no facilitators currently available. For immediate service, please call 123-456-7890."
|
const DEFAULT_CHAT_OFFLINE_MESSAGE = "There are no facilitators currently available. For immediate service, please call 123-456-7890."
|
||||||
const DEFAULT_WAIT_MESSAGE = "Please be patient, our online facilitators are currently responding to other support requests."
|
const DEFAULT_WAIT_MESSAGE = "Please be patient, our online facilitators are currently responding to other support requests."
|
||||||
|
const DEFAULT_ENCRYPTION_DISABLED = true
|
||||||
|
|
||||||
|
|
||||||
class ChatBox extends React.Component {
|
class ChatBox extends React.Component {
|
||||||
@ -237,14 +238,14 @@ class ChatBox extends React.Component {
|
|||||||
try {
|
try {
|
||||||
await client.initCrypto()
|
await client.initCrypto()
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
return this.initializeUnencryptedChat()
|
return this.restartWithoutCrypto()
|
||||||
}
|
}
|
||||||
|
|
||||||
await client.startClient()
|
await client.startClient()
|
||||||
await this.createRoom(client)
|
await this.createRoom(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeUnencryptedChat = async () => {
|
restartWithoutCrypto = async () => {
|
||||||
if (this.state.client) {
|
if (this.state.client) {
|
||||||
this.state.client.leave(this.state.roomId)
|
this.state.client.leave(this.state.roomId)
|
||||||
this.state.client.stopClient()
|
this.state.client.stopClient()
|
||||||
@ -287,7 +288,21 @@ class ChatBox extends React.Component {
|
|||||||
console.log("error", err)
|
console.log("error", err)
|
||||||
this.handleInitError(err)
|
this.handleInitError(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
initializeUnencryptedChat = async () => {
|
||||||
|
this.setState({ ready: false })
|
||||||
|
|
||||||
|
const client = await this.createClientWithAccount()
|
||||||
|
this.setState({
|
||||||
|
client: client
|
||||||
|
})
|
||||||
|
client.setDisplayName(this.props.anonymousDisplayName)
|
||||||
|
this.setMatrixListeners(client)
|
||||||
|
|
||||||
|
await client.startClient()
|
||||||
|
await this.createRoom(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleInitError = (err) => {
|
handleInitError = (err) => {
|
||||||
@ -570,7 +585,11 @@ class ChatBox extends React.Component {
|
|||||||
this.setState({ awaitingAgreement: false })
|
this.setState({ awaitingAgreement: false })
|
||||||
this.startWaitTimeForFacilitator()
|
this.startWaitTimeForFacilitator()
|
||||||
try {
|
try {
|
||||||
this.initializeChat()
|
if (this.props.isEncryptionDisabled) {
|
||||||
|
this.initializeUnencryptedChat()
|
||||||
|
} else {
|
||||||
|
this.initializeChat()
|
||||||
|
}
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
this.handleInitError(err)
|
this.handleInitError(err)
|
||||||
}
|
}
|
||||||
@ -678,7 +697,7 @@ class ChatBox extends React.Component {
|
|||||||
<div className={`message from-bot`}>
|
<div className={`message from-bot`}>
|
||||||
<div className="text buttons">
|
<div className="text buttons">
|
||||||
{`Restart chat without encryption?`}
|
{`Restart chat without encryption?`}
|
||||||
<button className="btn" id="accept" onClick={this.initializeUnencryptedChat}>RESTART</button>
|
<button className="btn" id="accept" onClick={this.restartWithoutCrypto}>RESTART</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@ -738,6 +757,7 @@ ChatBox.propTypes = {
|
|||||||
anonymousDisplayName: PropTypes.string,
|
anonymousDisplayName: PropTypes.string,
|
||||||
waitMessage: PropTypes.string,
|
waitMessage: PropTypes.string,
|
||||||
chatOfflineMessage: PropTypes.string,
|
chatOfflineMessage: PropTypes.string,
|
||||||
|
isEncryptionDisabled: PropTypes.bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatBox.defaultProps = {
|
ChatBox.defaultProps = {
|
||||||
@ -752,7 +772,8 @@ ChatBox.defaultProps = {
|
|||||||
anonymousDisplayName: DEFAULT_ANONYMOUS_DISPLAY_NAME,
|
anonymousDisplayName: DEFAULT_ANONYMOUS_DISPLAY_NAME,
|
||||||
chatUnavailableMessage: DEFAULT_CHAT_UNAVAILABLE_MESSAGE,
|
chatUnavailableMessage: DEFAULT_CHAT_UNAVAILABLE_MESSAGE,
|
||||||
waitMessage: DEFAULT_WAIT_MESSAGE,
|
waitMessage: DEFAULT_WAIT_MESSAGE,
|
||||||
chatOfflineMessage: DFAULT_CHAT_OFFLINE_MESSAGE
|
chatOfflineMessage: DEFAULT_CHAT_OFFLINE_MESSAGE,
|
||||||
|
isEncryptionDisabled: DEFAULT_ENCRYPTION_DISABLED
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ChatBox;
|
export default ChatBox;
|
||||||
|
Loading…
Reference in New Issue
Block a user