-
-
-
-
+export function initialize(uri) {
+ ws_init(uri, () => {
+ store.dispatch(socket_connected());
+ store.dispatch(filter_subscribe());
+ store.dispatch(filter_subscribe('server'));
+ });
+}
+
+ReactDOM.render(
+
+
+
+
+
+
-
- , root);
-});
+
+
+ , root);
navigator.registerProtocolHandler("magnet",
window.location.origin + "/add-torrent/%s",
diff --git a/src/reducers/index.js b/src/reducers/index.js
index 2fed523..47ce565 100644
--- a/src/reducers/index.js
+++ b/src/reducers/index.js
@@ -1,5 +1,6 @@
import { combineReducers } from 'redux';
import { routerReducer } from 'react-router-redux'
+import socket from './socket';
import selection from './selection';
import subscribe from './subscribe';
import filter_subscribe from './filter_subscribe';
@@ -11,6 +12,7 @@ import trackers from './trackers';
import pieces from './pieces';
const root = combineReducers({
+ socket,
selection,
subscribe,
filter_subscribe,
diff --git a/src/reducers/socket.js b/src/reducers/socket.js
new file mode 100644
index 0000000..2d332fd
--- /dev/null
+++ b/src/reducers/socket.js
@@ -0,0 +1,12 @@
+import { SOCKET_CONNECTED, SOCKET_DISCONNECTED } from '../actions/socket';
+
+export default function socket(state = { connected: false }, action) {
+ switch (action.type) {
+ case SOCKET_CONNECTED:
+ return { ...state, connected: true };
+ case SOCKET_DISCONNECTED:
+ return { ...state, connected: false };
+ default:
+ return state;
+ }
+}
diff --git a/src/socket.js b/src/socket.js
index d355947..5724ce6 100644
--- a/src/socket.js
+++ b/src/socket.js
@@ -35,8 +35,8 @@ function ws_recv(e) {
handler && handler(msg);
}
-export function ws_init(cb) {
- ws = new WebSocket("ws://127.0.0.1:8412");
+export function ws_init(uri, cb) {
+ ws = new WebSocket(uri);
ws.addEventListener("open", cb);
ws.addEventListener("message", ws_recv);
ws.addEventListener("close", () => console.log("ws closed"));
diff --git a/src/ui/connection.js b/src/ui/connection.js
index 7d547dc..6373397 100644
--- a/src/ui/connection.js
+++ b/src/ui/connection.js
@@ -1,9 +1,60 @@
import React, { Component } from 'react';
+import {
+ Card,
+ CardHeader,
+ CardBlock,
+ FormGroup,
+ Label,
+ Input
+} from 'reactstrap';
+import { initialize } from '..';
+
+export default 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
+ }
-export default class Connection extends Component {
render() {
+ const { uri, autoconnect } = this.state;
return (
-
Connecting...
+
+
+ Connect to synapse
+
+
+
+ this.setState({ uri: e.target.value })}
+ />
+
+
+
+
+
+
+
+
);
}
}
diff --git a/src/ui/main.js b/src/ui/main.js
index dc206f9..66e9fa6 100644
--- a/src/ui/main.js
+++ b/src/ui/main.js
@@ -1,11 +1,13 @@
import React, { Component } from 'react';
import { Route, DefaultRoute } from 'react-router';
+import { connect } from 'react-redux';
import TorrentTable from './torrent_table';
import AddTorrent from './add_torrent';
import TorrentDetails from './torrent_details';
import Server from './server';
+import ConnectionOverlay from './connection';
-export default class Main extends Component {
+class Main extends Component {
render() {
return (
@@ -18,7 +20,10 @@ export default class Main extends Component {
+ {this.props.socket.connected ||
}
);
}
}
+
+export default connect(state => ({ socket: state.socket }))(Main);