started adding the back to front api via websocket and json
This commit is contained in:
		@@ -14,45 +14,58 @@ var title = document.title; //Set the number of active torrents in the title
 | 
			
		||||
let torrents= []; 
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
var torrentListRequest = {
 | 
			
		||||
    messageType: "torrentListRequest"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//websocket is started in kickwebsocket.js and is picked up here so "ws" is already defined 22
 | 
			
		||||
ws.onmessage = function (evt) { //When we recieve a message from the websocket
 | 
			
		||||
    if(evt.data == "clientUpdate") {
 | 
			
		||||
        console.log("Client Update Incoming...")
 | 
			
		||||
    } else {  // recieving data
 | 
			
		||||
    var serverMessage = JSON.parse(evt.data)
 | 
			
		||||
    if (serverMessage.MessageType == "torrentList"){
 | 
			
		||||
        console.log("Recieved Client Update...")
 | 
			
		||||
        var clientUpdate = JSON.parse(evt.data);
 | 
			
		||||
        if (clientUpdate.total) { // if it has a total field it is a torrentlist update
 | 
			
		||||
            torrents = []; //clearing out the torrent array to make room for new (so that it does keep adding)
 | 
			
		||||
            for(var i = 0; i < clientUpdate.total; i++){
 | 
			
		||||
                torrents.push({
 | 
			
		||||
                    TorrentHashString: clientUpdate.data[i].TorrentHash,
 | 
			
		||||
                    TorrentName: clientUpdate.data[i].TorrentName,
 | 
			
		||||
                    DownloadedSize: clientUpdate.data[i].DownloadedSize,
 | 
			
		||||
                    Size: clientUpdate.data[i].Size,
 | 
			
		||||
                    DownloadSpeed: clientUpdate.data[i].DownloadSpeed,
 | 
			
		||||
                    UploadSpeed: clientUpdate.data[i].UploadSpeed,
 | 
			
		||||
                    PercentDone: clientUpdate.data[i].PercentDone,
 | 
			
		||||
                    StoragePath: clientUpdate.data[i].StoragePath,
 | 
			
		||||
                    DateAdded: clientUpdate.data[i].DateAdded,
 | 
			
		||||
                    Status: clientUpdate.data[i].Status,
 | 
			
		||||
                    BytesCompleted: clientUpdate.data[i].BytesCompleted,
 | 
			
		||||
                    ActivePeers: clientUpdate.data[i].ActivePeers,
 | 
			
		||||
                    ETA: clientUpdate.data[i].ETA,
 | 
			
		||||
                })    
 | 
			
		||||
            } 
 | 
			
		||||
            var newTitle = '(' + clientUpdate.total + ')' + title; //updating the title
 | 
			
		||||
            document.title = newTitle;
 | 
			
		||||
        } else if (clientUpdate) {
 | 
			
		||||
        //var serverMessage = JSON.parse(evt.data);
 | 
			
		||||
        
 | 
			
		||||
        torrents = []; //clearing out the torrent array to make room for new (so that it does keep adding)
 | 
			
		||||
        for(var i = 0; i < serverMessage.total; i++){
 | 
			
		||||
            torrents.push({
 | 
			
		||||
                TorrentHashString: serverMessage.data[i].TorrentHash,
 | 
			
		||||
                TorrentName: serverMessage.data[i].TorrentName,
 | 
			
		||||
                DownloadedSize: serverMessage.data[i].DownloadedSize,
 | 
			
		||||
                Size: serverMessage.data[i].Size,
 | 
			
		||||
                DownloadSpeed: serverMessage.data[i].DownloadSpeed,
 | 
			
		||||
                UploadSpeed: serverMessage.data[i].UploadSpeed,
 | 
			
		||||
                PercentDone: serverMessage.data[i].PercentDone,
 | 
			
		||||
                StoragePath: serverMessage.data[i].StoragePath,
 | 
			
		||||
                DateAdded: serverMessage.data[i].DateAdded,
 | 
			
		||||
                Status: serverMessage.data[i].Status,
 | 
			
		||||
                BytesCompleted: serverMessage.data[i].BytesCompleted,
 | 
			
		||||
                ActivePeers: serverMessage.data[i].ActivePeers,
 | 
			
		||||
                ETA: serverMessage.data[i].ETA,
 | 
			
		||||
            })    
 | 
			
		||||
        } 
 | 
			
		||||
        var newTitle = '(' + serverMessage.total + ')' + title; //updating the title
 | 
			
		||||
        document.title = newTitle;
 | 
			
		||||
            
 | 
			
		||||
    } else if (serverMessage.MessageType == "fileList"){
 | 
			
		||||
        console.log("Recieved FileListUpdate", serverMessage.fileList)
 | 
			
		||||
        fileList = [];
 | 
			
		||||
        for (var i = 0; i < serverMessage.total; i++){
 | 
			
		||||
            fileList.push({
 | 
			
		||||
                FileList: serverMessage.fileList[i]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            })
 | 
			
		||||
        }
 | 
			
		||||
                                    
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
                                    
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
ws.onclose = function() {
 | 
			
		||||
    console.log('Closing connection')
 | 
			
		||||
};
 | 
			
		||||
@@ -76,19 +89,15 @@ class BackendSocket extends React.Component {
 | 
			
		||||
          2000
 | 
			
		||||
        );    
 | 
			
		||||
 
 | 
			
		||||
    }
 | 
			
		||||
    } 
 | 
			
		||||
 | 
			
		||||
    componentWillUnmount() {
 | 
			
		||||
        clearInterval(this.timerID);
 | 
			
		||||
    } 
 | 
			
		||||
 | 
			
		||||
    tick() {
 | 
			
		||||
        ws.send("clientUpdateRequest")//talking to the server to get the torrent list
 | 
			
		||||
        this.props.newTorrentList(torrents)
 | 
			
		||||
        
 | 
			
		||||
        //console.log("STATE:", this.state.torrentList)
 | 
			
		||||
        //console.log("Torrents", torrents);
 | 
			
		||||
        
 | 
			
		||||
        ws.send(JSON.stringify(torrentListRequest))//talking to the server to get the torrent list
 | 
			
		||||
        this.props.newTorrentList(torrents)      
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    render() {
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,8 @@ import Icon from 'material-ui/Icon';
 | 
			
		||||
import IconButton from 'material-ui/IconButton';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const button = {
 | 
			
		||||
  fontSize: '60px',
 | 
			
		||||
  paddingRight: '20px',
 | 
			
		||||
@@ -29,6 +31,8 @@ const inlineStyle = {
 | 
			
		||||
 | 
			
		||||
export default class addTorrentPopup extends React.Component {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  state = {
 | 
			
		||||
    open: false,
 | 
			
		||||
  };
 | 
			
		||||
@@ -43,9 +47,13 @@ export default class addTorrentPopup extends React.Component {
 | 
			
		||||
 | 
			
		||||
  handleSubmit = () => {
 | 
			
		||||
      this.setState({ open: false });
 | 
			
		||||
      let magnetLinkSubmit = this.state.textValue;
 | 
			
		||||
      console.log("Sending magnet link: ", magnetLinkSubmit);
 | 
			
		||||
      ws.send(magnetLinkSubmit);
 | 
			
		||||
      //let magnetLinkSubmit = this.state.textValue;
 | 
			
		||||
      let magnetLinkMessage = {
 | 
			
		||||
        messageType: "magnetLinkSubmit",
 | 
			
		||||
        Payload: { MagnetLink: this.state.textValue}
 | 
			
		||||
      }
 | 
			
		||||
      console.log("Sending magnet link: ", magnetLinkMessage);
 | 
			
		||||
      ws.send(JSON.stringify(magnetLinkMessage));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  setTextValue = (event) => {
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,6 @@ import ReactTooltip from 'react-tooltip'
 | 
			
		||||
 | 
			
		||||
import DeleteIcon from 'material-ui-icons/Delete';
 | 
			
		||||
import AddShoppingCartIcon from 'material-ui-icons/AddShoppingCart';
 | 
			
		||||
//import PhotoCamera from 'material-ui-icons/PhotoCamera';
 | 
			
		||||
 | 
			
		||||
import BackendSocket from './BackendComm/backendWebsocket';
 | 
			
		||||
 | 
			
		||||
@@ -63,12 +62,22 @@ const styles = theme => ({
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class IconButtons extends React.Component {
 | 
			
		||||
  constructor(props){
 | 
			
		||||
    super(props);
 | 
			
		||||
    
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  startTorrentState = {
 | 
			
		||||
    messageType: "startTorrents",
 | 
			
		||||
    Payload: this.props.selection,
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
  startTorrent = (selection) => {
 | 
			
		||||
    console.log("Starting Torrents", selection)
 | 
			
		||||
    ws.send()
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
  buttonHandler = (buttonState) => {
 | 
			
		||||
    console.log("BUTTONSTATE", buttonState)
 | 
			
		||||
@@ -128,12 +137,13 @@ IconButtons.propTypes = {
 | 
			
		||||
const mapStateToProps = state => {
 | 
			
		||||
  return {
 | 
			
		||||
    buttonState: state.buttonState,
 | 
			
		||||
    selection: state.selection,
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const mapDispatchToProps = dispatch => {
 | 
			
		||||
  return {
 | 
			
		||||
    changeSelection: (selection) => dispatch({type: actionTypes.CHANGE_SELECTION, selection: selection})
 | 
			
		||||
    //changeSelection: (selection) => dispatch({type: actionTypes.CHANGE_SELECTION, selection: selection})
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -95,12 +95,9 @@ class TorrentListTable extends React.Component {
 | 
			
		||||
        this.props.changeSelection(selection) //dispatch selection to redux
 | 
			
		||||
 | 
			
		||||
        if (selection.length === 0) { //if selection is empty buttons will be default
 | 
			
		||||
            console.log("No Selection")
 | 
			
		||||
            this.props.setButtonState(this.props.buttonStateDefault) //if no selection dispatch that to redux
 | 
			
		||||
        } else { // if we have selection continue on with logic to determine button state
 | 
			
		||||
        
 | 
			
		||||
            const selectedRows = [] //array of all the selected Rows
 | 
			
		||||
 | 
			
		||||
            selection.forEach(element => {   
 | 
			
		||||
                selectedRows.push(this.props.torrentList[element])   //pushing the selected rows out of torrentlist
 | 
			
		||||
            });
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user