Skip to content

Commit

Permalink
✔ Fix User Socket Disconnect Dangling ~
Browse files Browse the repository at this point in the history
  • Loading branch information
bifeldy committed Oct 14, 2023
1 parent 512be19 commit dff418f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
2 changes: 1 addition & 1 deletion dist/fansubid/browser/ngsw.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"configVersion": 1,
"timestamp": 1697257534887,
"timestamp": 1697259411691,
"index": "/index.html",
"assetGroups": [
{
Expand Down
2 changes: 1 addition & 1 deletion dist/fansubid/server/main.js

Large diffs are not rendered by default.

24 changes: 6 additions & 18 deletions src/api/gateways/socket-io.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import { UserService } from '../repository/user.service';
@WebSocketGateway()
export class SocketIoGateway implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect {

timeOutVisitor = null;

constructor(
private cms: ClusterMasterSlaveService,
private cfg: ConfigService,
Expand All @@ -57,29 +55,19 @@ export class SocketIoGateway implements OnGatewayInit, OnGatewayConnection, OnGa
handleConnection(client: Socket, ...args: any[]) {
this.gs.log('[SOCKET_IO_GATEWAY-CLIENT_CONNECTED] 🌟', client.id);
this.sis.checkNewNotification(client);
if (this.timeOutVisitor) {
clearTimeout(this.timeOutVisitor);
}
this.timeOutVisitor = setTimeout(async () => {
this.timeOutVisitor = null;
setTimeout(async () => {
const totalSockets = (await this.sis.getAllClientsSocket()).length;
this.ts.updateVisitor(`🏃‍♂️ ${totalSockets} Pengunjung`);
this.sis.emitToBroadcast('visitor', totalSockets);
}, 5 * 1000);
}

handleDisconnect(client: Socket, ...args: any[]) {
async handleDisconnect(client: Socket, ...args: any[]) {
this.gs.log('[SOCKET_IO_GATEWAY-CLIENT_DISCONNECTED] 🌟', client.id);
if (this.timeOutVisitor) {
clearTimeout(this.timeOutVisitor);
}
this.timeOutVisitor = setTimeout(async () => {
this.timeOutVisitor = null;
await this.sis.disconnectRoom(client);
const totalSockets = (await this.sis.getAllClientsSocket()).length;
this.sis.emitToBroadcast('visitor', totalSockets);
this.ts.updateVisitor(`🏃‍♂️ ${totalSockets} Pengunjung`);
}, 5 * 1000);
await this.sis.disconnectRoom(client);
const totalSockets = (await this.sis.getAllClientsSocket()).length;
this.sis.emitToBroadcast('visitor', totalSockets);
this.ts.updateVisitor(`🏃‍♂️ ${totalSockets} Pengunjung`);
}

/** */
Expand Down

0 comments on commit dff418f

Please sign in to comment.