5 Commits

Author SHA1 Message Date
Sharon Kennedy
977fe1afa5 2.3.2 2021-01-20 22:45:00 -05:00
Sharon Kennedy
bf29508e8c update admin app endpoint and ensure chatbox closes even if leaveRoom fails 2021-01-20 22:44:53 -05:00
Sharon Kennedy
40e968fcee 2.3.1 2020-12-15 10:24:42 -05:00
Sharon Kennedy
c45182a574 add default settings endpoint' 2020-12-15 10:24:20 -05:00
Sharon Kennedy
819d9b8ebb cleanup 2020-12-14 17:37:26 -05:00
10 changed files with 45 additions and 45 deletions

View File

@@ -45,7 +45,6 @@ Options:
| `chatOfflineMessage` (optional) | Text to show if there is no-one online respond | `All of the chat facilitators are currently offline.` |
| `size` (optional) | The size of the start button. Can be 'small' or 'large' | `large` |
| `position` (optional) | The position of the start button. Can be 'top left', 'top right', 'bottom left', 'bottom right'. | `bottom right` |
| `maxWaitTime` (optional) | The maximum time (in ms) the chatbox will wait for someone to join before closing the chat and displaying the chat unavailable message | 600000 |
| `waitInterval` (optional) | The interval (in ms) at which the bot sends the wait message | 120000 |

10
dist/bookmarklet.js vendored

File diff suppressed because one or more lines are too long

10
dist/chatbox.js vendored

File diff suppressed because one or more lines are too long

2
dist/component.js vendored

File diff suppressed because one or more lines are too long

4
dist/index.html vendored
View File

@@ -13,10 +13,8 @@
<script src="./chatbox.js"></script>
<script>
var config = {
settingsEndpoint: 'https://safesupport-admin.herokuapp.com/api/get-settings',
matrixServerUrl: 'https://matrix.safesupport.chat'
}
};
EmbeddableChatbox.mount(config);
</script>

View File

@@ -1,6 +1,6 @@
{
"name": "private-safesupport-chatbox",
"version": "2.3.0",
"version": "2.3.2",
"description": "A secure and private embeddable chatbox that connects to Riot",
"main": "dist/chatbox.js",
"scripts": {

View File

@@ -13,10 +13,8 @@
<script src="./chatbox.js"></script>
<script>
var config = {
settingsEndpoint: 'https://safesupport-admin.herokuapp.com/api/get-settings',
matrixServerUrl: 'https://matrix.safesupport.chat'
}
};
EmbeddableChatbox.mount(config);
</script>

View File

@@ -1,16 +1,21 @@
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import Chatbox from './chatbox';
import { DEFAULT_SETTINGS_ENDPOINT } from '../utils/constants';
const ChatboxWithSettings = ({ settingsEndpoint, matrixServerUrl, ...rest }) => {
const ChatboxWithSettings = ({ settingsEndpoint = null, matrixServerUrl, ...rest }) => {
const [settings, setSettings] = useState({});
const [shifts, setShifts] = useState();
const [isAvailable, setAvailability] = useState(false);
const settingsObj = {};
const getSettings = async () => {
if (!settingsEndpoint) {
const endpoint = settingsEndpoint || DEFAULT_SETTINGS_ENDPOINT;
const url = `${endpoint}?homeserver=${encodeURIComponent(matrixServerUrl)}`;
const res = await fetch(url);
const data = await res.json();
const { fields, schedule = [] } = data;
if (!fields) {
const props = {
...rest,
enabled: true,
@@ -20,10 +25,7 @@ const ChatboxWithSettings = ({ settingsEndpoint, matrixServerUrl, ...rest }) =>
return setSettings(props);
}
const url = `${settingsEndpoint}?homeserver=${encodeURIComponent(matrixServerUrl)}`;
const res = await fetch(url);
const data = await res.json();
const { fields, schedule = [] } = data;
const settingsObj = {};
setShifts(schedule);

View File

@@ -41,7 +41,6 @@ const DEFAULT_WAIT_MESSAGE = "Please be patient, our online facilitators are cur
const DEFAULT_ENCRYPTION_DISABLED = false
const DEFAULT_POSITION = 'bottom right'
const DEFAULT_SIZE = 'large'
const DEFAULT_MAX_WAIT_MS = 600000 // 10 minutes
const DEFAULT_WAIT_INTERVAL_MS = 120000 // 2 minutes
const DEFAULT_DOCK_LABEL = 'Start a new chat'
const DEFAULT_ENABLED = false
@@ -152,23 +151,28 @@ class ChatBox extends React.Component {
exitChat = async (resetState=true) => {
if (this.state.client) {
await this.state.client.leave(this.state.roomId)
try {
await this.state.client.leave(this.state.roomId)
const auth = {
type: 'm.login.password',
user: this.state.userId,
identifier: {
type: "m.id.user",
user: this.state.userId,
},
password: this.state.password,
};
const auth = {
type: 'm.login.password',
user: this.state.userId,
identifier: {
type: "m.id.user",
user: this.state.userId,
},
password: this.state.password,
};
await this.state.client.deactivateAccount(auth, true)
await this.state.client.stopClient()
await this.state.client.clearStores()
this.setState({ client: null, ready: true }) // no more loading animation
window.clearInterval(this.state.waitIntervalId) // no more waiting messages
await this.state.client.deactivateAccount(auth, true)
await this.state.client.stopClient()
await this.state.client.clearStores()
} catch (err) {
console.log("Error exiting chat", err)
} finally {
this.setState({ client: null, ready: true }) // no more loading animation
window.clearInterval(this.state.waitIntervalId) // no more waiting messages
}
}
if (this.state.localStorage) {
@@ -785,7 +789,6 @@ ChatBox.propTypes = {
isEncryptionDisabled: PropTypes.bool,
position: PropTypes.oneOf(['top left', 'top right', 'bottom left', 'bottom right']),
size: PropTypes.oneOf(['small', 'large']),
maxWaitTime: PropTypes.number,
waitInterval: PropTypes.number,
dockLabel: PropTypes.string,
enabled: PropTypes.bool
@@ -807,7 +810,6 @@ ChatBox.defaultProps = {
isEncryptionDisabled: DEFAULT_ENCRYPTION_DISABLED,
position: DEFAULT_POSITION,
size: DEFAULT_SIZE,
maxWaitTime: DEFAULT_MAX_WAIT_MS,
waitInterval: DEFAULT_WAIT_INTERVAL_MS,
dockLabel: DEFAULT_DOCK_LABEL,
enabled: DEFAULT_ENABLED,

1
src/utils/constants.js Normal file
View File

@@ -0,0 +1 @@
export const DEFAULT_SETTINGS_ENDPOINT = 'https://admin.safesupport.chat/api/get-settings';