Skip to content

Commit

Permalink
Set connect timeout configurable
Browse files Browse the repository at this point in the history
Close #76
  • Loading branch information
nioc committed Jan 21, 2023
1 parent a50ff51 commit d3592b2
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ XMPP Web can be installed:
| `defaultMuc` | `APP_DEFAULT_MUC` | `null` | Autocomplete MUC address (ex: `conference.domain.ltd`) if user do not provide a full room jid (join & create)
| `isStylingDisabled` | `APP_IS_STYLING_DISABLED` | `false` | Set to `true` for disable messages styling
| `hasSendingEnterKey` | `APP_HAS_SENDING_ENTER_KEY` | `false` | If `true`, `Enter` key sends message, it adds new line otherwise (`Control`+`Enter` always sends message)
| `connectTimeout` | `XMPP_CONNECT_TIMEOUT` | `5000` | Timeout in ms before XMPP connection is considered as rejected
| N/A | `XMPP_WS` | `"http://localhost:5280/xmpp-websocket"` | Websocket endpoint proxyfied by Nginx (on a docker installation)

## Credits
Expand Down
4 changes: 4 additions & 0 deletions docs/docker/998-update-local.js.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ update_localjs() {
sed -i -r "s|hasSendingEnterKey: false|hasSendingEnterKey: true|g" $localjs
fi

if [ "$XMPP_CONNECT_TIMEOUT" != "" ]; then
sed -i -r "s|connectTimeout: 5000|connectTimeout: $XMPP_CONNECT_TIMEOUT|g" $localjs
fi

echo "done"
}

Expand Down
1 change: 1 addition & 0 deletions docs/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ ENV APP_DEFAULT_DOMAIN=localhost
ENV APP_DEFAULT_MUC=
ENV APP_IS_STYLING_DISABLED=0
ENV APP_HAS_SENDING_ENTER_KEY=0
ENV XMPP_CONNECT_TIMEOUT=
ENV XMPP_WS=http://localhost:5280/xmpp-websocket
EXPOSE 80/tcp

Expand Down
1 change: 1 addition & 0 deletions docs/docker/Dockerfile-multiarch
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ENV APP_DEFAULT_DOMAIN=localhost
ENV APP_DEFAULT_MUC=
ENV APP_IS_STYLING_DISABLED=0
ENV APP_HAS_SENDING_ENTER_KEY=0
ENV XMPP_CONNECT_TIMEOUT=
ENV XMPP_WS=http://localhost:5280/xmpp-websocket
EXPOSE 80/tcp

Expand Down
1 change: 1 addition & 0 deletions public/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ var config = {
// defaultMuc: 'conference.domain-xmpp.ltd',
isStylingDisabled: false,
hasSendingEnterKey: false,
connectTimeout: 5000,
}
3 changes: 2 additions & 1 deletion src/services/XmppSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const transports = window.config.transports
const resource = window.config.resource
const defaultDomain = window.config.defaultDomain
const defaultMuc = window.config.defaultMuc
const connectTimeout = window.config.connectTimeout

function logError (error, defaultLevel) {
const args = Array.prototype.slice.call(arguments, 2)
Expand Down Expand Up @@ -71,7 +72,7 @@ export default {

// connect client to XMPP server
connect () {
const timeoutDuration = 5000
const timeoutDuration = connectTimeout || 5000
let timeoutId = null
const timeoutPromise = new Promise((resolve, reject) => {
timeoutId = setTimeout(() => {
Expand Down

0 comments on commit d3592b2

Please sign in to comment.