Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Oceankoh committed Jan 20, 2024
1 parent 8152cf2 commit bb0641b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions backend/client-test/client-connect.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import socketClusterClient from "socketcluster-client";

import socketClusterClient from 'socketcluster-client';
// Make an HTTP request to localhost/create-room
const response = await fetch("http://localhost:8000/create-room");
const data = await response.json();

// Parse the JSON response to get the roomCode
const roomCode = data.roomCode;
console.log("Room Code:", roomCode);

// Initiate the connection to the server
let socket = socketClusterClient.create({ hostname: 'localhost', port: '8000', path: '/socketcluster/NFHHHQ'});
let socket = socketClusterClient.create({
hostname: "localhost",
port: "8000",
path: "/socketcluster/" + roomCode,
});

(async () => {
for await (let { error } of socket.listener('error')) {
console.error(error);
}
for await (let { error } of socket.listener("error")) {
console.error(error);
}
})();

(async () => {
for await (let event of socket.listener('connect')) {
console.log('Socket is connected');
}
for await (let event of socket.listener("connect")) {
console.log("Socket is connected");
}
})();
2 changes: 1 addition & 1 deletion backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ expressApp.get("/create-room", (req, res) => {
// SocketCluster/WebSocket connection handling loop.
(async () => {
for await (let { socket } of agServer.listener("connection")) {
// Handle socket connection.
console.log(socket.id + " connected to room " + roomCode);
}
})();

Expand Down

0 comments on commit bb0641b

Please sign in to comment.