-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs_interface.js
More file actions
67 lines (55 loc) · 2.07 KB
/
Copy pathjs_interface.js
File metadata and controls
67 lines (55 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
PyWebsockets 04.21.2024
_________________________
js_interface.js
Written by Warren
Back-end for controlling interface and handling data.
*/
// Send Data (by send button)
// -----------------------------
var myHost = "127.0.0.1";
var myPort = "54123";
var client = new io_SocketClient(myHost, myPort, "pyServer");
document.getElementById('pyInput').innerHTML = "<br>"
document.getElementById('pyDisconnect').onclick = function(e) {
client.sendData("pyServer:::Disconnect");
}
// Send Button.
// ---------------
document.getElementById('pySend').onclick = function(e) {
var data_to_send = document.getElementById('pyOutput').value;
console.log("Sending Data ?? ");
client.sendData("pyServer:::PRINTDATA:::" + data_to_send);
}
// Connect Button.
// ------------------
document.getElementById('pyConnect').onclick = function(e) {
var myHost = "127.0.0.1";
var myPort = "54123";
if (client == null) {
client = new io_SocketClient(myHost, myPort, "pyServer");
}
client.connect(myHost, myPort);
}
// Disconnect Button.
// ---------------------
document.getElementById('pyDisconnect').onclick = function(e) {
console.log("Disconnecting . . .")
client.sendData("pyServer:::Disconnect"); // Soft Disconnect. (Requests the socket server close the socket from python)
}
document.addEventListener("DOMContentLoaded", function(event) {
// Socket Command Input.
// ------------------------
client.onCommand = function(text) {
// Commands received from py server. (Split by ::: delimiter)
var newCmd = text.split(":::");
var pyStatus = document.getElementById('pyStatus');
if (newCmd[1] == "connected") {
pyStatus.innerText = "Connected.";
}
}
client.onData = function(text) {
var pyInput = document.getElementById('pyInput');
pyInput.innerHTML = pyInput.innerHTML + "<br>" + text;
}
});