Skip to content

Commit

Permalink
Create JS client
Browse files Browse the repository at this point in the history
  • Loading branch information
Finchiedev committed Nov 3, 2018
1 parent 939496f commit b3ae915
Show file tree
Hide file tree
Showing 4 changed files with 1,992 additions and 1,024 deletions.
61 changes: 61 additions & 0 deletions App/JS/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

var net = require('net')
var client = new net.Socket()

function terminateConnection(connection) {
connection.write("01-0000")
connection.write("02-0000")
connection.write("03-0000")
connection.write("04-0000")


function axisValue(dynamixel, axis) {
var gamepad = navigator.getGamepads()[0]
var val = Math.round((gamepad.axes[axis]+1) * 512)
//if (dynamixel == 1 || dynamixel == 3) {
// val -= 1024
//}
var out = ""
if (val < 10) {
out += "000"
out += val
} else if (val < 100) {
out += "00"
out += val
} else if (val < 1000) {
out += "0"
out += val
} else {
out += val
}
return out
}

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function pollGamepad(interval) {
while (true) {
client.write('01-' + axisValue(1, 3))
await sleep(interval)
client.write('02-' + axisValue(2, 1))
await sleep(interval)
client.write('03-' + axisValue(3, 3))
await sleep(interval)
client.write('04-' + axisValue(4, 1))
}
client.connect(9999, '192.168.100.1', function() {
window.addEventListener("gamepadconnected", function(event) {
pollGamepad(100)
})
})

// client.on('close', function(){
// console.warn("Client terminated connection!")
// })
// client.on('end', function(){
// console.warn("Server terminated connection!")
// })
// client.on('error', function(){
// console.warn("Connection to server terminated unexpectedly!")
// })
5 changes: 1 addition & 4 deletions App/controlTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@

<title>test</title>
<script type="text/javascript" src="JS/main.js"></script>
<script>
execute('netcat -l -p 5000 | mplayer -fps 60 -cache 4096 -')
</script>
<script type="text/javascript" src="JS/client.js"></script>

</head>

<body>
<video src="http://192.168.100.1:5000"></video>
</body>

</html>
4 changes: 2 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ function createWindow() {
width: 800,
height: 600
})
win.loadFile('App/camera.html')
win.loadFile('App/controlTest.html')
// win.loadURL('http://localhost:8080')
// win.webContents.openDevTools()
win.webContents.openDevTools()

win.on('closed', () => {
win = null
Expand Down
Loading

0 comments on commit b3ae915

Please sign in to comment.