Haruka041 commited on
Commit ·
7a3a7a4
1
Parent(s): 1a1e853
fix: repair peerjs path and prevent infinite room creation loading
Browse files
monopoly-client/global.config.ts
CHANGED
|
@@ -10,8 +10,8 @@ export const __PROTOCOL__ = protocol;
|
|
| 10 |
export const __MONOPOLYSERVER__ = "/monopoly-server";
|
| 11 |
export const __USERSERVER__ = "/user-server";
|
| 12 |
export const __LOGINPAGEURL__ = `${origin}/81/`;
|
| 13 |
-
// PeerJS
|
| 14 |
-
export const __ICE_SERVER_PATH__ = "ice-server
|
| 15 |
|
| 16 |
export const __FATPAPER_HOST__ = host;
|
| 17 |
export const __ICE_SERVER_PORT__ = port;
|
|
|
|
| 10 |
export const __MONOPOLYSERVER__ = "/monopoly-server";
|
| 11 |
export const __USERSERVER__ = "/user-server";
|
| 12 |
export const __LOGINPAGEURL__ = `${origin}/81/`;
|
| 13 |
+
// PeerJS client appends its own "/peerjs" segment, so we only keep the reverse-proxy prefix here.
|
| 14 |
+
export const __ICE_SERVER_PATH__ = "ice-server";
|
| 15 |
|
| 16 |
export const __FATPAPER_HOST__ = host;
|
| 17 |
export const __ICE_SERVER_PORT__ = port;
|
monopoly-client/src/classes/monopoly-client/PeerClient.ts
CHANGED
|
@@ -56,13 +56,21 @@ export class PeerClient {
|
|
| 56 |
},
|
| 57 |
}
|
| 58 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
peer.addListener("open", (id) => {
|
|
|
|
| 60 |
console.log("ice服务器连接成功, ID:", id);
|
| 61 |
peer.removeAllListeners();
|
| 62 |
resolve(peer);
|
| 63 |
});
|
| 64 |
peer.addListener("error", (e) => {
|
| 65 |
-
|
|
|
|
|
|
|
| 66 |
});
|
| 67 |
});
|
| 68 |
return new PeerClient(peer);
|
|
|
|
| 56 |
},
|
| 57 |
}
|
| 58 |
);
|
| 59 |
+
const timeout = window.setTimeout(() => {
|
| 60 |
+
peer.destroy();
|
| 61 |
+
reject(new Error("连接房间服务超时,请稍后再试"));
|
| 62 |
+
}, 12000);
|
| 63 |
+
|
| 64 |
peer.addListener("open", (id) => {
|
| 65 |
+
window.clearTimeout(timeout);
|
| 66 |
console.log("ice服务器连接成功, ID:", id);
|
| 67 |
peer.removeAllListeners();
|
| 68 |
resolve(peer);
|
| 69 |
});
|
| 70 |
peer.addListener("error", (e) => {
|
| 71 |
+
window.clearTimeout(timeout);
|
| 72 |
+
peer.destroy();
|
| 73 |
+
reject(new Error(e?.message || "连接房间服务失败"));
|
| 74 |
});
|
| 75 |
});
|
| 76 |
return new PeerClient(peer);
|
monopoly-client/src/classes/monopoly-host/MonopolyHost.ts
CHANGED
|
@@ -199,7 +199,7 @@ export class MonopolyHost {
|
|
| 199 |
}
|
| 200 |
|
| 201 |
public static async create(roomId: string, host: string, port: number, heartContinuationTimeMs: number) {
|
| 202 |
-
const peer = await new Promise<Peer>((resolve) => {
|
| 203 |
const isHTTP = __PROTOCOL__ === "http";
|
| 204 |
const peer = new Peer(
|
| 205 |
isHTTP
|
|
@@ -213,10 +213,21 @@ export class MonopolyHost {
|
|
| 213 |
},
|
| 214 |
}
|
| 215 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
peer.on("open", () => {
|
|
|
|
| 217 |
console.info("MonopolyHost开启成功");
|
| 218 |
resolve(peer);
|
| 219 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
});
|
| 221 |
const { roleList } = await getRoleList();
|
| 222 |
const room = new Room(roomId, roleList);
|
|
|
|
| 199 |
}
|
| 200 |
|
| 201 |
public static async create(roomId: string, host: string, port: number, heartContinuationTimeMs: number) {
|
| 202 |
+
const peer = await new Promise<Peer>((resolve, reject) => {
|
| 203 |
const isHTTP = __PROTOCOL__ === "http";
|
| 204 |
const peer = new Peer(
|
| 205 |
isHTTP
|
|
|
|
| 213 |
},
|
| 214 |
}
|
| 215 |
);
|
| 216 |
+
const timeout = window.setTimeout(() => {
|
| 217 |
+
peer.destroy();
|
| 218 |
+
reject(new Error("连接房主节点超时,请稍后重试"));
|
| 219 |
+
}, 12000);
|
| 220 |
+
|
| 221 |
peer.on("open", () => {
|
| 222 |
+
window.clearTimeout(timeout);
|
| 223 |
console.info("MonopolyHost开启成功");
|
| 224 |
resolve(peer);
|
| 225 |
});
|
| 226 |
+
peer.on("error", (err: PeerError) => {
|
| 227 |
+
window.clearTimeout(timeout);
|
| 228 |
+
peer.destroy();
|
| 229 |
+
reject(new Error(err?.message || "房主节点连接失败"));
|
| 230 |
+
});
|
| 231 |
});
|
| 232 |
const { roleList } = await getRoleList();
|
| 233 |
const room = new Room(roomId, roleList);
|