-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters