started adding the back to front api via websocket and json
Before Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 546 B |
Before Width: | Height: | Size: 913 B |
Before Width: | Height: | Size: 527 B |
Before Width: | Height: | Size: 794 B |
Before Width: | Height: | Size: 753 B |
Before Width: | Height: | Size: 506 B |
Before Width: | Height: | Size: 787 B |
Before Width: | Height: | Size: 251 B |
Before Width: | Height: | Size: 850 B |
Before Width: | Height: | Size: 565 B |
Before Width: | Height: | Size: 579 B |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 524 B |
Before Width: | Height: | Size: 219 B |
Before Width: | Height: | Size: 539 B |
Before Width: | Height: | Size: 728 B |
Before Width: | Height: | Size: 470 B |
Before Width: | Height: | Size: 1014 B |
@@ -1,49 +0,0 @@
|
||||
// Get the modal
|
||||
var modal = document.getElementById('addTorrentModal');
|
||||
|
||||
// Get the button that opens the modal
|
||||
var btn = document.getElementById("addTorrentLink");
|
||||
|
||||
// Get the <span> element that closes the modal
|
||||
var span = document.getElementsByClassName("addTorrentModalClose")[0];
|
||||
|
||||
|
||||
// When the user clicks the button, open the modal
|
||||
btn.onclick = function() {
|
||||
modal.style.display = "block";
|
||||
}
|
||||
|
||||
// When the user clicks on <span> (x), close the modal
|
||||
span.onclick = function() {
|
||||
modal.style.display = "none";
|
||||
}
|
||||
|
||||
// When the user clicks anywhere outside of the modal, close it
|
||||
window.onclick = function(event) {
|
||||
if (event.target == modal) {
|
||||
modal.style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
var torrentFileModal = document.getElementById('addTorrentFileModal');
|
||||
|
||||
var btnTorrentFile = document.getElementById("addTorrentFile");
|
||||
|
||||
var spanTorrentFile = document.getElementsByClassName("addTorrentFileModalClose")[0];
|
||||
|
||||
|
||||
btnTorrentFile.onclick = function() {
|
||||
torrentFileModal.style.display = "block";
|
||||
}
|
||||
|
||||
// When the user clicks on <span> (x), close the modal
|
||||
spanTorrentFile.onclick = function() {
|
||||
torrentFileModal.style.display = "none";
|
||||
}
|
||||
|
||||
// When the user clicks anywhere outside of the modal, close it
|
||||
window.onclick = function(event) {
|
||||
if (event.target == torrentFileModal) {
|
||||
torrentFileModal.style.display = "none";
|
||||
}
|
||||
}
|
@@ -73459,7 +73459,6 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // contains the font for material UI
|
||||
|
||||
//import PhotoCamera from 'material-ui-icons/PhotoCamera';
|
||||
|
||||
//Redux
|
||||
|
||||
@@ -73504,6 +73503,16 @@ var IconButtons = function (_React$Component) {
|
||||
|
||||
var _this = _possibleConstructorReturn(this, (IconButtons.__proto__ || Object.getPrototypeOf(IconButtons)).call(this, props));
|
||||
|
||||
_this.startTorrentState = {
|
||||
messageType: "startTorrents",
|
||||
Payload: _this.props.selection
|
||||
};
|
||||
|
||||
_this.startTorrent = function (selection) {
|
||||
console.log("Starting Torrents", selection);
|
||||
ws.send();
|
||||
};
|
||||
|
||||
_this.buttonHandler = function (buttonState) {
|
||||
console.log("BUTTONSTATE", buttonState);
|
||||
};
|
||||
@@ -73582,15 +73591,14 @@ IconButtons.propTypes = {
|
||||
|
||||
var mapStateToProps = function mapStateToProps(state) {
|
||||
return {
|
||||
buttonState: state.buttonState
|
||||
buttonState: state.buttonState,
|
||||
selection: state.selection
|
||||
};
|
||||
};
|
||||
|
||||
var mapDispatchToProps = function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
changeSelection: function changeSelection(selection) {
|
||||
return dispatch({ type: actionTypes.CHANGE_SELECTION, selection: selection });
|
||||
}
|
||||
//changeSelection: (selection) => dispatch({type: actionTypes.CHANGE_SELECTION, selection: selection})
|
||||
};
|
||||
};
|
||||
|
||||
@@ -81221,9 +81229,13 @@ var addTorrentPopup = function (_React$Component) {
|
||||
_this.setState({ open: false });
|
||||
}, _this.handleSubmit = function () {
|
||||
_this.setState({ open: false });
|
||||
var magnetLinkSubmit = _this.state.textValue;
|
||||
console.log("Sending magnet link: ", magnetLinkSubmit);
|
||||
ws.send(magnetLinkSubmit);
|
||||
//let magnetLinkSubmit = this.state.textValue;
|
||||
var magnetLinkMessage = {
|
||||
messageType: "magnetLinkSubmit",
|
||||
Payload: { MagnetLink: _this.state.textValue }
|
||||
};
|
||||
console.log("Sending magnet link: ", magnetLinkMessage);
|
||||
ws.send(JSON.stringify(magnetLinkMessage));
|
||||
}, _this.setTextValue = function (event) {
|
||||
_this.setState({ textValue: event.target.value });
|
||||
}, _temp), _possibleConstructorReturn(_this, _ret);
|
||||
@@ -89953,38 +89965,45 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
||||
var title = document.title; //Set the number of active torrents in the title
|
||||
var torrents = [];
|
||||
|
||||
//websocket is started in kickwebsocket.js and is picked up here so "ws" is already defined
|
||||
ws.onmessage = function (evt) {
|
||||
//When we recieve a message from the websocket
|
||||
if (evt.data == "clientUpdate") {
|
||||
console.log("Client Update Incoming...");
|
||||
} else {
|
||||
// recieving data
|
||||
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 torrentListRequest = {
|
||||
messageType: "torrentListRequest"
|
||||
|
||||
var newTitle = '(' + clientUpdate.total + ')' + title; //updating the title
|
||||
document.title = newTitle;
|
||||
//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
|
||||
var serverMessage = JSON.parse(evt.data);
|
||||
if (serverMessage.MessageType == "torrentList") {
|
||||
console.log("Recieved Client Update...");
|
||||
//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]
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -90029,11 +90048,8 @@ var BackendSocket = function (_React$Component) {
|
||||
}, {
|
||||
key: 'tick',
|
||||
value: function tick() {
|
||||
ws.send("clientUpdateRequest"); //talking to the server to get the torrent list
|
||||
ws.send(JSON.stringify(torrentListRequest)); //talking to the server to get the torrent list
|
||||
this.props.newTorrentList(torrents);
|
||||
|
||||
//console.log("STATE:", this.state.torrentList)
|
||||
//console.log("Torrents", torrents);
|
||||
}
|
||||
}, {
|
||||
key: 'render',
|
||||
@@ -92541,13 +92557,10 @@ var TorrentListTable = function (_React$Component) {
|
||||
|
||||
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
|
||||
|
||||
var selectedRows = []; //array of all the selected Rows
|
||||
|
||||
selection.forEach(function (element) {
|
||||
selectedRows.push(_this.props.torrentList[element]); //pushing the selected rows out of torrentlist
|
||||
});
|
||||
|
@@ -1,74 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"honnef.co/go/js/dom"
|
||||
"github.com/gopherjs/websocket/websocketjs"
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
"github.com/johanbrandhorst/gopherjs-json"
|
||||
"time"
|
||||
//"honnef.co/go/js/dom"
|
||||
|
||||
)
|
||||
|
||||
var (
|
||||
//d = dom.GetWindow().Document() //getting the dom to manipulate it
|
||||
document = dom.GetWindow().Document().(dom.HTMLDocument)
|
||||
//conn = func(){websocketjs.New("ws://192.168.1.141:8000/websocket")}//creating a global JS websocket connection
|
||||
)
|
||||
|
||||
|
||||
func main(){
|
||||
document.AddEventListener("DOMContentLoaded", false, func(_ dom.Event){
|
||||
println("DOMLoaded...")
|
||||
go ready()
|
||||
})
|
||||
}
|
||||
|
||||
func ready(){
|
||||
|
||||
//conn := conn()
|
||||
conn, err := websocketjs.New("ws://192.168.1.141:8000/websocket") // Blocks until connection is established.
|
||||
|
||||
if err != nil {
|
||||
println("Error creating client websocket connection") // handle error
|
||||
}
|
||||
onOpen := func(ev *js.Object){
|
||||
err := conn.Send("ping!") //on startup send the ping message
|
||||
if err != nil {
|
||||
println("Cannot send ping message")
|
||||
}
|
||||
}
|
||||
|
||||
onMessage := func(ev *js.Object){
|
||||
messageData := ev.Get("data").String()
|
||||
if messageData == "pong"{ //if the server says a pong, send a ping back
|
||||
time.Sleep(6 * time.Second)
|
||||
conn.Send("ping")
|
||||
} else {
|
||||
clientData, err := json.Unmarshal(messageData)
|
||||
if err != nil {
|
||||
println("Error unmarshalling server message")
|
||||
}
|
||||
|
||||
println(clientData.String())
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
onClose := func(ev *js.Object){
|
||||
println("Closing Connection....")
|
||||
}
|
||||
|
||||
|
||||
onError := func(ev *js.Object){
|
||||
println("Error....")
|
||||
}
|
||||
|
||||
conn.AddEventListener("open", false, onOpen)
|
||||
conn.AddEventListener("message", false, onMessage)
|
||||
conn.AddEventListener("close", false, onClose)
|
||||
conn.AddEventListener("error", false, onError)
|
||||
|
||||
|
||||
err = conn.Close()
|
||||
}
|
@@ -1,102 +0,0 @@
|
||||
d := dom.GetWindow().Document() //getting the dom to manipulate it
|
||||
|
||||
logTextArea := d.GetElementByID("loggerData")
|
||||
|
||||
torrentLinkSubmit := d.GetElementByID("torrentLinkSubmit")
|
||||
magnetLink := d.GetElementByID("magnetLink")
|
||||
|
||||
addTorrentModal := d.GetElementByID("addTorrentModal")
|
||||
addTorrentLinkBtn := d.GetElementByID("addTorrentLink") // Get the button that opens the modal
|
||||
|
||||
addTorrentFileModal := d.GetElementByID("addTorrentFile")
|
||||
addTorrentFileModalClose := d.GetElementsByClassName("addTorrentFileModalClose")
|
||||
|
||||
addTorrentModalClose := d.GetElementsByClassName("addTorrentModalClose") // Get the <span> element that closes the modal
|
||||
|
||||
|
||||
|
||||
//add magnet link modal
|
||||
addTorrentLinkBtn.AddEventListener("click", false, func(event dom.Event){
|
||||
addTorrentModal.SetAttribute("display", "block")
|
||||
|
||||
})
|
||||
//close torrent link modal
|
||||
addTorrentModalClose[0].AddEventListener("click", false, func(event dom.Event){
|
||||
addTorrentModal.SetAttribute("display", "none")
|
||||
})
|
||||
//show torrent file modal
|
||||
addTorrentFileModal.AddEventListener("click", false, func(event dom.Event){
|
||||
addTorrentFileModal.SetAttribute("display", "block")
|
||||
})
|
||||
//hide torrent file modal
|
||||
addTorrentFileModalClose[0].AddEventListener("click", false, func(event dom.Event){
|
||||
addTorrentFileModal.SetAttribute("display", "none")
|
||||
})
|
||||
|
||||
// When the user clicks anywhere outside of the modal, close it
|
||||
d.AddEventListener("click", false, func(event dom.Event){
|
||||
addTorrentModal.SetAttribute("display", "none")
|
||||
addTorrentLinkBtn.SetAttribute("display", "none")
|
||||
})
|
||||
|
||||
|
||||
|
||||
//websocket logic
|
||||
conn, err := websocketjs.New("ws://192.168.1.141:8000/websocket") // Blocks until connection is established.
|
||||
if err != nil {
|
||||
println("Error creating client websocket connection") // handle error
|
||||
}
|
||||
|
||||
onOpen := func(ev *js.Object){
|
||||
err := conn.Send("ping!") //on startup send the ping message
|
||||
if err != nil {
|
||||
println("Cannot send ping message")
|
||||
}
|
||||
}
|
||||
|
||||
onMessage := func(ev *js.Object){
|
||||
messageData := ev.Get("data").String()
|
||||
if messageData == "pong"{ //if the server says a pong, send a ping back
|
||||
time.Sleep(6 * time.Second)
|
||||
conn.Send("ping")
|
||||
} else {
|
||||
clientData, err := json.Unmarshal(messageData)
|
||||
if err != nil {
|
||||
println("Error unmarshalling server message")
|
||||
}
|
||||
|
||||
logTextArea.SetInnerHTML(logTextArea.InnerHTML() + "</br>" + "Client Update Event....")
|
||||
logTextArea.SetInnerHTML(logTextArea.InnerHTML() + "</br>" + clientData.String())
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
onClose := func(ev *js.Object){
|
||||
logTextArea.SetInnerHTML(logTextArea.InnerHTML() + "</br>" + "Connection closed")
|
||||
}
|
||||
|
||||
|
||||
onError := func(ev *js.Object){
|
||||
logTextArea.SetInnerHTML(logTextArea.InnerHTML() + "</br>" + "Error opening websocket")
|
||||
}
|
||||
|
||||
conn.AddEventListener("open", false, onOpen)
|
||||
conn.AddEventListener("message", false, onMessage)
|
||||
conn.AddEventListener("close", false, onClose)
|
||||
conn.AddEventListener("error", false, onError)
|
||||
|
||||
|
||||
err = conn.Close()
|
||||
|
||||
torrentLinkSubmit.AddEventListener("click", false, func(event dom.Event){ //listening to the submit button for magnet link
|
||||
|
||||
|
||||
|
||||
conn.Send(magnetLink.TextContent())
|
||||
logTextArea.SetInnerHTML(logTextArea.InnerHTML() + "</br>" + "Adding Magnet Link: " + magnetLink.TextContent()) //adding the magnet link to the log
|
||||
addTorrentModal.SetAttribute("display", "none")
|
||||
magnetLink.SetTextContent("")
|
||||
|
||||
})
|
||||
|
||||
}
|
@@ -1,7 +1,12 @@
|
||||
var ws = new WebSocket("ws://192.168.1.141:8000/websocket"); //creating websocket
|
||||
|
||||
var kickStart = {
|
||||
messageType: "torrentListRequest"
|
||||
}
|
||||
|
||||
ws.onopen = function()
|
||||
{
|
||||
ws.send("clientUpdateRequest"); //sending out the first ping
|
||||
console.log("Kicking off websocket to server on 192.168.1.141.....")
|
||||
|
||||
ws.send(JSON.stringify(kickStart)); //sending out the first ping
|
||||
console.log("Kicking off websocket to server on 192.168.1.141.....", JSON.stringify(kickStart))
|
||||
};
|
@@ -1,13 +0,0 @@
|
||||
function openTab(evt, tabName) {
|
||||
var i, x, tablinks;
|
||||
x = document.getElementsByClassName("tab");
|
||||
for (i = 0; i < x.length; i++) {
|
||||
x[i].style.display = "none";
|
||||
}
|
||||
tablinks = document.getElementsByClassName("tablink");
|
||||
for (i = 0; i < x.length; i++) {
|
||||
tablinks[i].className = tablinks[i].className.replace(" activeButton", "");
|
||||
}
|
||||
document.getElementById(tabName).style.display = "block";
|
||||
evt.currentTarget.className += " activeButton";
|
||||
}
|
@@ -1,65 +0,0 @@
|
||||
function myWebsocketStart()
|
||||
{
|
||||
|
||||
var torrentLinkSubmit = document.getElementById('torrentLinkSubmit');
|
||||
var magnetLink = document.getElementById('magnetLink');
|
||||
var addTorrentModal = document.getElementById('addTorrentModal');
|
||||
var myTextArea = document.getElementById("loggerData");
|
||||
var torrentHash = document.getElementById("hash");
|
||||
|
||||
|
||||
var ws = new WebSocket("ws://192.168.1.141:8000/websocket"); //creating websocket
|
||||
|
||||
ws.onopen = function()
|
||||
{
|
||||
// Web Socket is connected, send data using send()
|
||||
ws.send("ping");
|
||||
|
||||
myTextArea.innerHTML = myTextArea.innerHTML + "</br>" + "First message sent";
|
||||
};
|
||||
|
||||
ws.onmessage = function (evt)
|
||||
{
|
||||
var myTextArea = document.getElementById("loggerData");
|
||||
if(evt.data == "pong") {
|
||||
setTimeout(function(){ws.send("ping");}, 2000);
|
||||
} else {
|
||||
|
||||
var clientUpdate = JSON.parse(evt.data);
|
||||
myTextArea.innerHTML = myTextArea.innerHTML + "</br>" + "Client Update Event...";
|
||||
//myTextArea.innerHTML = myTextArea.innerHTML + "</br>" + clientUpdate.LocalTorrentInfo.DateAdded;
|
||||
myTextArea.innerHTML = myTextArea.innerHTML + "</br>" + evt.data;
|
||||
//myTextArea.innerHTML = myTextArea.innerHTML + "</br>" + clientUpdate[0].TorrentHashString;
|
||||
|
||||
//torrentHash.innerHTML = "Hash: " + clientUpdate[0].TorrentHashString;
|
||||
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
ws.onclose = function()
|
||||
{
|
||||
var myTextArea = document.getElementById("loggerData");
|
||||
myTextArea.innerHTML = myTextArea.innerHTML + "</br>" + "Connection closed";
|
||||
};
|
||||
|
||||
|
||||
torrentLinkSubmit.onclick = function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var magnetLinkjs = magnetLink.value;
|
||||
|
||||
ws.send(magnetLinkjs);
|
||||
myTextArea.innerHTML = myTextArea.innerHTML + "</br> Send:" + magnetLinkjs
|
||||
addTorrentModal.style.display = "none";
|
||||
magnetLink.value = '';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function sendEvent(message)
|
||||
{
|
||||
ws.send(message);
|
||||
}
|