Skip to content

Commit 386b8c3

Browse files
committed
fix(gateway): send online count directly to connecting socket
The online count was always 0 because VISITOR_ONLINE events relied solely on Redis emitter broadcasts, which may not reach clients if the emitter-adapter chain has any issues. Now also send the count directly via socket.emit on connection to guarantee delivery.
1 parent 7fba2fd commit 386b8c3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

apps/core/src/processors/gateway/web/events.gateway.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,17 @@ export class WebEventsGateway
205205
this.whenUserOnline()
206206
super.handleConnect(socket)
207207
this.hooks.onConnected.forEach((fn) => fn(socket))
208+
209+
// Send current online count directly to the connecting socket,
210+
// bypassing Redis emitter to ensure delivery
211+
this.sendOnlineNumber()
212+
.then((data) => {
213+
socket.emit(
214+
'message',
215+
this.gatewayMessageFormat(BusinessEvents.VISITOR_ONLINE, data),
216+
)
217+
})
218+
.catch(() => {})
208219
}
209220

210221
private async updateSocketLang(socket: SocketIO.Socket, lang: string) {

0 commit comments

Comments
 (0)