diff --git a/src/renderer/pages/Index.vue b/src/renderer/pages/Index.vue index f3d5dd0..a3107c8 100644 --- a/src/renderer/pages/Index.vue +++ b/src/renderer/pages/Index.vue @@ -291,10 +291,17 @@ export default { return await this.$ps5.install( file, (socket) => { this.setStatus(file, "Send to PS5") this.$message({ message: file.name + ' send to PS5', file, type: "success" }) - }). - catch( e => { - this.log(e) - this.$message({ message: e, type: 'error' }) + }) + .then( (data) => { + this.log({ type: 'PS5 Response', response: data }) + console.log(data) + + this.$message({ message: data, type: "info" }) + }) + .catch( e => { + console.log("Error in Install Request", e) + this.log(e.msg) + this.$message({ message: e.msg, type: 'error' }) }) } diff --git a/src/renderer/plugins/ps5.js b/src/renderer/plugins/ps5.js index b7ea108..3739a36 100644 --- a/src/renderer/plugins/ps5.js +++ b/src/renderer/plugins/ps5.js @@ -35,7 +35,7 @@ let ps5 = { return timeout < min ? min : timeout }, - request( onSuccess=null ){ + request( onSuccess=null, onResponse=null ){ console.log("Build up TCP Connection") return new Promise( (resolve, reject) => { @@ -56,18 +56,40 @@ let ps5 = { console.log("PS5 Connection to ", connectTo) const socket = new net.Socket() + socket.connect(connectTo, () => { clearTimeout(connectionTimeout) console.log("PS5:api Connection available") if( typeof onSuccess == 'function' ){ onSuccess(socket) - resolve(true) } else { resolve(true) } }) + + socket.on('data', (r) => { + let response = r.toString() + let json = null + + // console.log(response) + + try { + json = JSON.parse(response) + } + catch(jsonError) { + reject(jsonError) + } + + if( typeof onResponse == 'function'){ + onResponse(json, response) + resolve(json, response) + } + else { + resolve(json, response) + } + }) socket.on('error', (err) => { clearTimeout(connectionTimeout) @@ -135,12 +157,18 @@ let ps5 = { return console.log("Cannot find path for file " + file.name ) } - return this.request( (socket) => { - socket.write(JSON.stringify({ url: file.url })) - socket.end() - if( typeof cb == 'function') - cb() - }) + return this.request( + (socket) => { + socket.write(JSON.stringify({ url: file.url })) + + if( typeof cb == 'function') + cb() + }, + + (json, response) => { + + } + ) }, } diff --git a/src/test/net-send.js b/src/test/net-send.js index b284f50..9de249f 100644 --- a/src/test/net-send.js +++ b/src/test/net-send.js @@ -7,6 +7,7 @@ function send(socket, packet){ } socket.write(packet) + socket.on('data', (data) => { resolve(data.toString()) }) @@ -20,22 +21,21 @@ function send(socket, packet){ const socket = new net.Socket() -// let connectTo = { host: '127.0.0.1', port: 9090} -let connectTo = '127.0.0.1:9090' +let connectTo = { host: '127.0.0.1', port: 9090} socket.connect(connectTo, async () => { - console.log("Connected") + // console.log("Connected") + // console.log("Send test JSON") - console.log("Send test JSON") let packet = { url: "http://127.0.0.1/random" } let data = await send(socket, JSON.stringify(packet)) - console.log("Response", data) + console.log({ data }) - socket.end() + // socket.end() }) socket.on('error', (err) => { diff --git a/src/test/net-server.js b/src/test/net-server.js index 66afe1a..486b91b 100644 --- a/src/test/net-server.js +++ b/src/test/net-server.js @@ -1,16 +1,20 @@ const net = require('net') -console.log("Test net-server.js\\rn") +// console.log("Test net-server.js\\rn") var server = net.createServer( function(socket){ - socket.write('NET Client Server\r\n') + // socket.write('NET Client Server\r\n') socket.pipe(socket) socket.on('data', (data) => { data = data.toString() - data = JSON.parse(data) - - console.log( data ) + data = JSON.parse(data) + console.log( JSON.stringify(data) ) + + // let response = { + // res: (new Date).getTime() + // } + // socket.write(JSON.stringify(data)) }) })