2024-07-21 14:58:38 -04:00
|
|
|
// Import necessary modules
|
|
|
|
import dotenv from "dotenv";
|
2024-10-24 20:00:50 -06:00
|
|
|
import { io, Socket } from "socket.io-client";
|
2024-07-21 14:58:38 -04:00
|
|
|
|
|
|
|
dotenv.config();
|
|
|
|
|
|
|
|
interface CallbackResponse {
|
|
|
|
success: boolean;
|
|
|
|
apps?: string[];
|
|
|
|
message?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
let socketRef: Socket = io(
|
2024-07-23 22:17:36 -04:00
|
|
|
`http://localhost:4000?userId=user_2hFB6KcK6bb3Gx9241UXsxFq4kO&sandboxId=v30a2c48xal03tzio7mapt19`,
|
2024-07-21 14:58:38 -04:00
|
|
|
{
|
|
|
|
timeout: 2000,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
socketRef.on("connect", async () => {
|
|
|
|
console.log("Connected to the server");
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
|
|
|
2024-10-24 20:00:50 -06:00
|
|
|
socketRef.emit("list", {}, (response: CallbackResponse) => {
|
2024-07-21 14:58:38 -04:00
|
|
|
if (response.success) {
|
|
|
|
console.log("List of apps:", response.apps);
|
|
|
|
} else {
|
|
|
|
console.log("Error:", response.message);
|
|
|
|
}
|
|
|
|
});
|
2024-07-23 22:17:36 -04:00
|
|
|
|
2024-10-24 20:00:50 -06:00
|
|
|
socketRef.emit("deploy", {}, (response: CallbackResponse) => {
|
2024-07-23 22:17:36 -04:00
|
|
|
if (response.success) {
|
|
|
|
console.log("It worked!");
|
|
|
|
} else {
|
|
|
|
console.log("Error:", response.message);
|
|
|
|
}
|
|
|
|
});
|
2024-07-21 14:58:38 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
socketRef.on("disconnect", () => {
|
|
|
|
console.log("Disconnected from the server");
|
|
|
|
});
|
|
|
|
|
|
|
|
socketRef.on("connect_error", (error: Error) => {
|
|
|
|
console.error("Connection error:", error);
|
|
|
|
});
|