geckos.io
geckos.io copied to clipboard
Client does not connect if server is Dockerized in a WSL Environment
Describe the bug
Hey guys! First of all, thank you for this library. It's being super useful for my online RPG engine.
Main issue: So, I tried to connect here our client to our dockerized API running on WSL and it simply doesn't connect, no matter what I do. I spent 2 days trying to debug the issue and realised that it does connect, if the server is outside docker.
I don't think it's a docker issue, since I have all required ports exposed and the exact same code works on a Linux machine without WSL.
Relevant code:
SERVER:
rpg-api:
container_name: rpg-api
restart: always
build: .
logging:
options:
max-size: "10m"
max-file: "3"
env_file: .env
ports:
- "$SERVER_PORT:$SERVER_PORT"
- "9229:9229" # debugging port
- "$SOCKET_PORT:$SOCKET_PORT"
- "$SOCKET_UDP_RANGE"
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
environment:
FORCE_COLOR: "true"
CHOKIDAR_USEPOLLING: "true" # enables hot-reloading on windows host
links:
- rpg-db
depends_on:
- rpg-db
networks:
- rpg-network
.env
# Server
ENV=Development
SERVER_PORT=5002
SOCKET_TYPE=TCP
API_CONTAINER=rpg-api
SOCKET_SERVER_PORT=5100
SOCKET_PORT=5101
SOCKET_UDP_RANGE="20000-20005:20000-20005/udp"
Server connection code:
const { geckos } = await import("@geckos.io/server");
this.socket = geckos(GECKOS_CONFIG);
this.socket.listen(appEnv.socket.port.SOCKET);
Server constants:
export const GECKOS_CONFIG = {
iceServers: [],
portRange: {
min: 20000,
max: appEnv.general.ENV === EnvType.Development ? 20005 : 20100,
},
authorization: GeckosAuthMiddleware,
cors: {
origin: "*",
allowAuthorization: true,
}, // required if the client and server are on separate domains
};
Client connection code:
public async init() {
return await new Promise<SocketClient>((resolve, reject) => {
try {
this.socket = geckos({
authorization: `Bearer ${authStore.token}`,
port: Number(appEnv.sockets.port)!,
url: `${appEnv.server.host}`,
});
this.socket.onConnect((error) => {
if (error) {
console.error(error);
connectionStore.setIsConnected(false);
reject(error);
}
this.channelId = this.socket.id;
if (!this.channelId) {
reject('Error while trying to stablish Geckos.IO connection: ChannelID not found');
} else {
console.log('🔌 Geckos.IO (UDP): Connected to the server!');
connectionStore.setIsConnected(true);
resolve(this.socket);
}
this.socket.on('disconnect', () => {
connectionStore.setIsConnected(false);
this.socket.close();
});
});
} catch (error) {
reject(error);
}
});
}
PS: It works normally on Linux. Socket.IO works fine also, so my temporary workaround is to use Socket.IO for development on WSL environments.
Have a question? Join the discussions instead.
I was also never able to run it on WSL.
It can work in Docker WSL, but only expose TCP (HTTP or WebSocket) ports, don't expose UDP ports, and do not use --net host
(instead use -p <port>:<port>
for your exposed TCP ports)
For some strange reason, I don't need to expose UDP ports, yet the WebRTC connection seems to work fine locally
This issue is stale because it has been open 300 days with no activity. Remove stale label or comment or this will be closed in 10 days.
This issue was closed because it has been stalled for 10 days with no activity.
It can work in Docker WSL, but only expose TCP (HTTP or WebSocket) ports, don't expose UDP ports, and do not use
--net host
(instead use-p <port>:<port>
for your exposed TCP ports)For some strange reason, I don't need to expose UDP ports, yet the WebRTC connection seems to work fine locally
BTW, this no longer works. Docker WebRTC seems busted on Windows in general, including WSL