Skip to content

Commit

Permalink
feat: Update socket URL in App constructor
Browse files Browse the repository at this point in the history
- Updated the `App` constructor to include an optional `socketUrl` parameter.
- If `socketUrl` is provided, it will be used as the URL for the socket server.
- If `socketUrl` is not provided, the `serverUrl` will be used as the default socket URL.
- This change ensures that the `GameNetwork` instance in the `game.ejs` file uses the correct socket URL.
  • Loading branch information
TKanX committed Sep 5, 2024
1 parent 261f08e commit 65d5e97
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ class App {
/**
* Create a new App object.
* @param {string} serverUrl - The URL of the server.
* @param {string} socketUrl - The URL of the socket server. (Optional, defaults to the server URL.)
*/
constructor(serverUrl) {
constructor(serverUrl, socketUrl) {
this.serverUrl = serverUrl;
this.session.serverUrl = serverUrl;

this.socketUrl = socketUrl || serverUrl;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions public/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
class GameNetwork {
/**
* Create a game network.
* @param {string} serverUrl - The server URL.
* @param {string} socketUrl - The socket URL.
*/
constructor(serverUrl) {
this.socket = io(serverUrl, {
constructor(socketUrl) {
this.socket = io(socketUrl, {
withCredentials: true,
});
}
Expand Down
2 changes: 1 addition & 1 deletion views/pages/game.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
const gameUI = new GameUI("/img/game/wood-texture.jpg");
// Create a new game network instance
const gameNetwork = new GameNetwork(app.serverUrl);
const gameNetwork = new GameNetwork(app.socketUrl);
// Add disconnect event listener
const disconnectListener = () => {
Expand Down

0 comments on commit 65d5e97

Please sign in to comment.