Skip to content

Commit

Permalink
prototype build for test
Browse files Browse the repository at this point in the history
  • Loading branch information
Gkiokan committed Feb 24, 2024
1 parent 4720dfe commit 97e3385
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 23 deletions.
15 changes: 11 additions & 4 deletions src/renderer/pages/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
})
}
Expand Down
44 changes: 36 additions & 8 deletions src/renderer/plugins/ps5.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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)
Expand Down Expand Up @@ -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) => {

}
)
},

}
Expand Down
12 changes: 6 additions & 6 deletions src/test/net-send.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function send(socket, packet){
}

socket.write(packet)

socket.on('data', (data) => {
resolve(data.toString())
})
Expand All @@ -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) => {
Expand Down
14 changes: 9 additions & 5 deletions src/test/net-server.js
Original file line number Diff line number Diff line change
@@ -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))
})
})

Expand Down

0 comments on commit 97e3385

Please sign in to comment.