Support different socket.io for client and server

This commit is contained in:
Mimi 2022-11-12 20:13:41 +08:00
parent fbf7ff07d4
commit 7044b67cb0
3 changed files with 4 additions and 4 deletions

View File

@ -8,7 +8,7 @@ const $ = jquery;
function run(flag) {
client.setRenderer(flag ? godRenderer : playerRenderer);
client.connectGame("//" + location.host, $("#name").val(), (success, msg) => {
client.connectGame(io, "//" + location.host, $("#name").val(), (success, msg) => {
if (success) {
$("#main-ui").fadeIn(1000);
$("#begin, #wasted").fadeOut(1000);

View File

@ -3,6 +3,7 @@ if (process.argv.length < 3) {
process.exit(1);
}
import io from "socket.io-client";
import * as client from "./src/game-client.js";
import { consts } from "./config.js";
@ -26,7 +27,7 @@ function connect() {
const prefixes = consts.PREFIXES.split(" ");
const names = consts.NAMES.split(" ");
const name = process.argv[3] || [prefixes[Math.floor(Math.random() * prefixes.length)], names[Math.floor(Math.random() * names.length)]].join(" ");
client.connectGame(process.argv[2], "[BOT] " + name, function(success, msg) {
client.connectGame(io, process.argv[2], "[BOT] " + name, function(success, msg) {
if (!success) {
console.error(msg);
setTimeout(connect, 1000);

View File

@ -1,4 +1,3 @@
import io from "socket.io-client";
import { Grid, Player, initPlayer, updateFrame } from "./core/index.js";
import { consts } from "../config.js";
let running = false;
@ -24,7 +23,7 @@ try {
}
//Public API
function connectGame(url, name, callback, flag) {
function connectGame(io, url, name, callback, flag) {
if (running) return; //Prevent multiple runs
running = true;
user = null;