diff --git a/src/ui/connection.js b/src/ui/connection.js index 8db29cf..5ac417b 100644 --- a/src/ui/connection.js +++ b/src/ui/connection.js @@ -13,21 +13,31 @@ import { import { initialize } from '..'; import { SOCKET_STATE } from '../actions/socket'; +const getURI = (uri, password) => `${uri}${password ? + `?password=${encodeURIComponent(password)}` : ''}`; + class ConnectionOverlay extends Component { constructor() { super(); + this.connect = this.connect.bind(this); const uri = localStorage.getItem("autoconnect"); - this.state = { uri: uri || "ws://127.0.0.1:8412", autoconnect: !!uri }; + const password = localStorage.getItem("password"); + this.state = { + uri: uri || "ws://127.0.0.1:8412", + password: null, + autoconnect: !!uri + }; if (uri) { - initialize(this.state.uri); + initialize(getURI(this.state.uri, this.state.password)); } } connect() { if (this.state.autoconnect) { localStorage.setItem("autoconnect", this.state.uri); + localStorage.setItem("password", this.state.password); } - initialize(this.state.uri); + initialize(getURI(this.state.uri, this.state.password)); } render() { @@ -48,7 +58,7 @@ class ConnectionOverlay extends Component { ); } - const { uri, autoconnect } = this.state; + const { uri, password, autoconnect } = this.state; return (