Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/tmp
/out-tsc
/dist

/node_modules
npm-debug.log*
Expand Down
16 changes: 8 additions & 8 deletions src/bridge/Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export class Bridge {

private readonly eventMap: BridgeEventListeners = {
CLUSTER_READY: undefined, CLUSTER_HEARTBEAT_FAILED: undefined,
CLUSTER_STOPPED: undefined, CLIENT_CONNECTED: undefined, CLIENT_DISCONNECTED: undefined,
CLUSTER_STOPPED: undefined, HOST_CONNECTED: undefined, HOST_DISCONNECTED: undefined,
CLUSTER_SPAWNED: undefined, CLUSTER_RECLUSTER: undefined, ERROR: undefined,
CLIENT_STOP: undefined
HOST_STOP: undefined
}

constructor(port: number, token: string, intents: GatewayIntentsString[], shardsPerCluster: number, clusterToStart: number, reclusteringTimeoutInMs: number) {
Expand Down Expand Up @@ -175,7 +175,7 @@ export class Bridge {
}

const bridgeConnection = new BridgeClientConnection(payload.id, connection, data, dev);
if(this.eventMap.CLIENT_CONNECTED) this.eventMap.CLIENT_CONNECTED(bridgeConnection);
if(this.eventMap.HOST_CONNECTED) this.eventMap.HOST_CONNECTED(bridgeConnection);

bridgeConnection.onMessage((m: any) => {
if (m.type == 'CLUSTER_SPAWNED') {
Expand Down Expand Up @@ -289,7 +289,7 @@ export class Bridge {
}

this.connectedClients.delete(connection.id);
if(this.eventMap.CLIENT_DISCONNECTED) this.eventMap.CLIENT_DISCONNECTED(closedConnection, reason);
if(this.eventMap.HOST_DISCONNECTED) this.eventMap.HOST_DISCONNECTED(closedConnection, reason);
});

this.server.on("message", (message, connection) => {
Expand Down Expand Up @@ -352,7 +352,7 @@ export class Bridge {
}

async stopInstance(instance: BridgeClientConnection, recluster = true) {
if(this.eventMap.CLIENT_STOP) this.eventMap.CLIENT_STOP(instance);
if(this.eventMap.HOST_STOP) this.eventMap.HOST_STOP(instance);
instance.connectionStatus = BridgeClientConnectionStatus.PENDING_STOP;

let clusterToSteal: BridgeClientCluster | undefined;
Expand Down Expand Up @@ -448,8 +448,8 @@ export type BridgeEventListeners = {
'CLUSTER_SPAWNED': ((cluster: BridgeClientCluster, connection: BridgeClientConnection) => void) | undefined,
'CLUSTER_RECLUSTER': ((cluster: BridgeClientCluster, newConnection: BridgeClientConnection, oldConnection: BridgeClientConnection) => void) | undefined,
'CLUSTER_HEARTBEAT_FAILED': ((cluster: BridgeClientCluster, error: unknown) => void) | undefined,
'CLIENT_CONNECTED': ((client: BridgeClientConnection) => void) | undefined,
'CLIENT_DISCONNECTED': ((client: BridgeClientConnection, reason: string) => void) | undefined,
'HOST_CONNECTED': ((client: BridgeClientConnection) => void) | undefined,
'HOST_DISCONNECTED': ((client: BridgeClientConnection, reason: string) => void) | undefined,
'ERROR': ((error: string) => void) | undefined,
'CLIENT_STOP': ((instance: BridgeClientConnection) => void) | undefined
'HOST_STOP': ((instance: BridgeClientConnection) => void) | undefined
};