Skip to content

Commit

Permalink
Change formatter to use 4 spaces (#79)
Browse files Browse the repository at this point in the history
* Added .prettierrc

* Formatting
  • Loading branch information
hello-amal authored Jul 19, 2024
1 parent 4d33c53 commit 7d2983d
Show file tree
Hide file tree
Showing 96 changed files with 12,600 additions and 12,243 deletions.
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tabWidth": 4
}
150 changes: 75 additions & 75 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
{
"name": "stretch_web_teleop",
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/createjs": "^0.0.29",
"@types/react": "^18.0.34",
"@types/react-dom": "^18.0.11",
"@types/roslib": "^1.3.0",
"browser": "^0.2.6",
"buffer": "^6.0.3",
"createjs-module": "^0.8.3",
"css-loader": "^6.7.3",
"dotenv": "^16.0.3",
"eslint-config-react-app": "^7.0.1",
"express": "^4.18.2",
"file-loader": "^6.2.0",
"firebase": "^9.22.1",
"html-webpack-plugin": "^4.5.2",
"jpeg-js": "^0.4.4",
"latest-createjs": "^1.0.24",
"nodejs": "^0.0.0",
"nodemon": "^3.0.1",
"playwright": "^1.33.0",
"pm2": "^5.3.0",
"process": "^0.11.10",
"react": "^18.2.0",
"react-device-detect": "^2.2.3",
"react-dom": "^18.2.0",
"react-native-keyboard-aware-scrollview": "^2.1.0",
"react-native-web": "^0.19.7",
"react-path-tooltip": "^1.0.25",
"roslib": "github:hello-vinitha/roslibjs#ros2actionclient",
"socket.io": "^4.6.1",
"socket.io-client": "^4.6.1",
"style-loader": "^3.3.2",
"three": "^0.157.0"
},
"scripts": {
"firebase": "webpack --mode development --progress --env storage='firebase'",
"localstorage": "webpack --mode development --progress --env storage='localstorage'",
"styleguide": "styleguidist server"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/plugin-transform-runtime": "^7.21.4",
"@babel/preset-env": "^7.22.6",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.4",
"@types/node": "^20.6.0",
"@types/three": "^0.157.0",
"babel-loader": "^9.1.2",
"babel-polyfill": "^6.26.0",
"react-docgen-typescript": "^2.2.2",
"react-styleguidist": "^13.1.1",
"typescript": "^5.2.2",
"webpack": "^5.88.2",
"webpack-cli": "^5.0.2"
}
"name": "stretch_web_teleop",
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/createjs": "^0.0.29",
"@types/react": "^18.0.34",
"@types/react-dom": "^18.0.11",
"@types/roslib": "^1.3.0",
"browser": "^0.2.6",
"buffer": "^6.0.3",
"createjs-module": "^0.8.3",
"css-loader": "^6.7.3",
"dotenv": "^16.0.3",
"eslint-config-react-app": "^7.0.1",
"express": "^4.18.2",
"file-loader": "^6.2.0",
"firebase": "^9.22.1",
"html-webpack-plugin": "^4.5.2",
"jpeg-js": "^0.4.4",
"latest-createjs": "^1.0.24",
"nodejs": "^0.0.0",
"nodemon": "^3.0.1",
"playwright": "^1.33.0",
"pm2": "^5.3.0",
"process": "^0.11.10",
"react": "^18.2.0",
"react-device-detect": "^2.2.3",
"react-dom": "^18.2.0",
"react-native-keyboard-aware-scrollview": "^2.1.0",
"react-native-web": "^0.19.7",
"react-path-tooltip": "^1.0.25",
"roslib": "github:hello-vinitha/roslibjs#ros2actionclient",
"socket.io": "^4.6.1",
"socket.io-client": "^4.6.1",
"style-loader": "^3.3.2",
"three": "^0.157.0"
},
"scripts": {
"firebase": "webpack --mode development --progress --env storage='firebase'",
"localstorage": "webpack --mode development --progress --env storage='localstorage'",
"styleguide": "styleguidist server"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/plugin-transform-runtime": "^7.21.4",
"@babel/preset-env": "^7.22.6",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.4",
"@types/node": "^20.6.0",
"@types/three": "^0.157.0",
"babel-loader": "^9.1.2",
"babel-polyfill": "^6.26.0",
"react-docgen-typescript": "^2.2.2",
"react-styleguidist": "^13.1.1",
"typescript": "^5.2.2",
"webpack": "^5.88.2",
"webpack-cli": "^5.0.2"
}
}
126 changes: 64 additions & 62 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ var fs = require("fs");
require("dotenv").config();

var options = {
key: fs.readFileSync(`certificates/${process.env.keyfile}`),
cert: fs.readFileSync(`certificates/${process.env.certfile}`),
key: fs.readFileSync(`certificates/${process.env.keyfile}`),
cert: fs.readFileSync(`certificates/${process.env.certfile}`),
};

// const http = require('http');
Expand All @@ -25,20 +25,20 @@ var app = express();
app.all("*", ensureSecure); // at top of routing calls

function ensureSecure(req, res, next) {
if (!req.secure) {
// handle port numbers if you need non defaults
console.log("redirecting insecure request");
return res.redirect("https://" + req.hostname + req.url);
// res.redirect(`https://${req.hostname}${process.env.NGROK_URL}`);
}
if (!req.secure) {
// handle port numbers if you need non defaults
console.log("redirecting insecure request");
return res.redirect("https://" + req.hostname + req.url);
// res.redirect(`https://${req.hostname}${process.env.NGROK_URL}`);
}

return next();
return next();
}

var server = require("http").Server(app);
var secure_server = require("https").Server(options, app);
const io = socket(secure_server, {
allowEIO3: true,
allowEIO3: true,
});
app.enable("trust proxy");
app.set("port", 443);
Expand All @@ -51,63 +51,65 @@ app.use("/", express.static(path.join(__dirname, "dist")));
app.listen(process.env.port);

io.on("connect_error", (err) => {
console.log(`connect_error due to ${err.message}`);
console.log(`connect_error due to ${err.message}`);
});

io.on("connection", function (socket) {
console.log("new socket.io connection");
// console.log('socket.handshake = ');
// console.log(socket.handshake);
console.log("new socket.io connection");
// console.log('socket.handshake = ');
// console.log(socket.handshake);

socket.on("join", function (room) {
console.log("Received request to join room " + room);
// A room can have atmost two clients
if (
!io.sockets.adapter.rooms.get(room) ||
io.sockets.adapter.rooms.get(room).size < 2
) {
socket.join(room);
socket.emit("join", room, socket.id);
} else {
console.log("room full");
socket.emit("full", room);
}
});
socket.on("join", function (room) {
console.log("Received request to join room " + room);
// A room can have atmost two clients
if (
!io.sockets.adapter.rooms.get(room) ||
io.sockets.adapter.rooms.get(room).size < 2
) {
socket.join(room);
socket.emit("join", room, socket.id);
} else {
console.log("room full");
socket.emit("full", room);
}
});

socket.on("add operator to robot room", (callback) => {
// The robot room is only available if another operator is not connected to it
if (io.sockets.adapter.rooms.get("robot")) {
if (io.sockets.adapter.rooms.get("robot").size < 2) {
socket.join("robot");
socket.in("robot").emit("joined", "robot");
callback({ success: true });
} else {
console.log("could not connect because robot room is full");
callback({ success: false });
}
} else {
console.log("could not connect because robot is not available");
callback({ success: false });
}
});
socket.on("add operator to robot room", (callback) => {
// The robot room is only available if another operator is not connected to it
if (io.sockets.adapter.rooms.get("robot")) {
if (io.sockets.adapter.rooms.get("robot").size < 2) {
socket.join("robot");
socket.in("robot").emit("joined", "robot");
callback({ success: true });
} else {
console.log("could not connect because robot room is full");
callback({ success: false });
}
} else {
console.log("could not connect because robot is not available");
callback({ success: false });
}
});

socket.on("signalling", function (message) {
if (io.sockets.adapter.rooms.get("robot")) {
socket.to("robot").emit("signalling", message);
} else {
console.log(
"robot_operator_room is none, so there is nobody to send the WebRTC message to",
);
}
});
socket.on("signalling", function (message) {
if (io.sockets.adapter.rooms.get("robot")) {
socket.to("robot").emit("signalling", message);
} else {
console.log(
"robot_operator_room is none, so there is nobody to send the WebRTC message to",
);
}
});

socket.on("bye", (role) => {
console.log(role, socket.rooms);
if (socket.rooms.has("robot")) {
socket.to("robot").emit("bye");
console.log("Attempting to have the " + role + " leave the robot room.");
console.log("");
socket.leave("robot");
}
});
socket.on("bye", (role) => {
console.log(role, socket.rooms);
if (socket.rooms.has("robot")) {
socket.to("robot").emit("bye");
console.log(
"Attempting to have the " + role + " leave the robot room.",
);
console.log("");
socket.leave("robot");
}
});
});
Loading

0 comments on commit 7d2983d

Please sign in to comment.