diff --git a/src/socket.js b/src/socket.js index 1a255aa..a75dded 100644 --- a/src/socket.js +++ b/src/socket.js @@ -41,3 +41,7 @@ export function ws_init(uri, open, close) { ws.addEventListener("message", ws_recv); ws.addEventListener("close", close); } + +export function ws_disconnect() { + ws.close(); +} diff --git a/src/ui/connection.js b/src/ui/connection.js index 4be45dd..8db29cf 100644 --- a/src/ui/connection.js +++ b/src/ui/connection.js @@ -16,14 +16,18 @@ import { SOCKET_STATE } from '../actions/socket'; class ConnectionOverlay extends Component { constructor() { super(); - this.state = { - uri: "ws://127.0.0.1:8412", - autoconnect: false, - connecting: false - }; - // TODO: "connecting..." UI - // TODO: autoconnect - // TODO: gracefully handle dis/reconnections + const uri = localStorage.getItem("autoconnect"); + this.state = { uri: uri || "ws://127.0.0.1:8412", autoconnect: !!uri }; + if (uri) { + initialize(this.state.uri); + } + } + + connect() { + if (this.state.autoconnect) { + localStorage.setItem("autoconnect", this.state.uri); + } + initialize(this.state.uri); } render() { @@ -72,7 +76,7 @@ class ConnectionOverlay extends Component { diff --git a/src/ui/server.js b/src/ui/server.js index cb55707..7712d19 100644 --- a/src/ui/server.js +++ b/src/ui/server.js @@ -1,19 +1,26 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import { formatBitrate } from '../bitrate'; +import { ws_disconnect } from '../socket'; -function throttle(v) { - return v === null ? "Unlimited" : formatBitrate(v); -} +const throttle = _ => _ === null ? "Unlimited" : formatBitrate(_); function Server({ server }) { if (!server.id) { - // TODO: websocket status? return null; } return (
-

Server

+

+ Server + +

Running since
{/* TODO: pretty print dates */}