From efea624c8e04e34dd4168a90b50c252dc18ee11d Mon Sep 17 00:00:00 2001 From: vivek Date: Fri, 20 Feb 2026 15:16:02 +0530 Subject: [PATCH 1/2] fix(api): remove blocking loop in handleTypingEvent and fix credentials typo --- packages/api/src/EmbeddedChatApi.ts | 44 ++++++++++++++++------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/packages/api/src/EmbeddedChatApi.ts b/packages/api/src/EmbeddedChatApi.ts index 72e25a046..676f5a51e 100644 --- a/packages/api/src/EmbeddedChatApi.ts +++ b/packages/api/src/EmbeddedChatApi.ts @@ -120,7 +120,7 @@ export default class EmbeddedChatApi { async login(userOrEmail: string, password: string, code: string) { let credentials; if (!code) { - credentials = credentials = { + credentials = { user: userOrEmail.trim(), password, }; @@ -351,33 +351,37 @@ export default class EmbeddedChatApi { ); } - handleTypingEvent({ + async handleTypingEvent({ typingUser, isTyping, }: { typingUser: string; isTyping: boolean; }) { - // don't wait for more than 2 seconds. Though in practical, the waiting time is insignificant. - setTimeout(() => { - typingHandlerLock = 0; - }, 2000); - // eslint-disable-next-line no-empty - while (typingHandlerLock) {} - typingHandlerLock = 1; - // move user to front if typing else remove it. - const idx = this.typingUsers.indexOf(typingUser); - if (idx !== -1) { - this.typingUsers.splice(idx, 1); + // wait for lock to release + while (typingHandlerLock) { + await new Promise((resolve) => setTimeout(resolve, 100)); } - if (isTyping) { - this.typingUsers.unshift(typingUser); + + typingHandlerLock = 1; + + try { + // move user to front if typing else remove it. + const idx = this.typingUsers.indexOf(typingUser); + if (idx !== -1) { + this.typingUsers.splice(idx, 1); + } + if (isTyping) { + this.typingUsers.unshift(typingUser); + } + + const newTypingStatus = cloneArray(this.typingUsers); + this.onTypingStatusCallbacks.forEach((callback) => + callback(newTypingStatus) + ); + } finally { + typingHandlerLock = 0; } - typingHandlerLock = 0; - const newTypingStatus = cloneArray(this.typingUsers); - this.onTypingStatusCallbacks.forEach((callback) => - callback(newTypingStatus) - ); } async getRCAppInfo() { From 62369d6afbe2fcd88a5bc3b3f32fdf03214a535a Mon Sep 17 00:00:00 2001 From: vivek Date: Sat, 21 Feb 2026 23:44:50 +0530 Subject: [PATCH 2/2] fix(api): add error handling to handleTypingEvent per review feedback --- packages/api/src/EmbeddedChatApi.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/api/src/EmbeddedChatApi.ts b/packages/api/src/EmbeddedChatApi.ts index 676f5a51e..cba06c2ae 100644 --- a/packages/api/src/EmbeddedChatApi.ts +++ b/packages/api/src/EmbeddedChatApi.ts @@ -374,11 +374,13 @@ export default class EmbeddedChatApi { if (isTyping) { this.typingUsers.unshift(typingUser); } - + const newTypingStatus = cloneArray(this.typingUsers); this.onTypingStatusCallbacks.forEach((callback) => callback(newTypingStatus) ); + } catch (error) { + console.error("Error in handleTypingEvent:", error); } finally { typingHandlerLock = 0; }