Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/build-and-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 16.19.0
node-version: 22

- name: Set up Yarn
uses: actions/setup-node@v4
with:
node-version: 16.19.0
node-version: 22
cache: "yarn"

- name: Cache dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "16.19.0"
node-version: "22"

- name: Install Dependencies
run: yarn install
Expand All @@ -36,7 +36,7 @@ jobs:
- name: Setup Node.js for Docs
uses: actions/setup-node@v4
with:
node-version: "18.x"
node-version: "22"

- name: "Install dependencies for docs"
run: yarn install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "16.19.0"
node-version: "22"

- name: Install Dependencies
run: yarn install
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Setup Node.js for Docs
uses: actions/setup-node@v4
with:
node-version: "18.x"
node-version: "22"

- name: "Install dependencies for docs"
run: yarn install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 16.19.0
node-version: 22

- name: Cache dependencies
uses: actions/cache@v4
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.19.0
v22.16.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Ensure that the "Enable CORS" option is turned on in your Rocket.Chat server. Yo

#### Prerequisites

- **Node.js**: Version 16.19.0 is required. Use [Node Version Manager (NVM)](https://github.com/nvm-sh/nvm) for easy switching between Node.js versions.
- **Node.js**: Version 22 (LTS) is required. Use [Node Version Manager (NVM)](https://github.com/nvm-sh/nvm) for easy switching between Node.js versions.

To install and use the correct Node.js version, execute the following commands with the specific version number:

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@
"esbuild": "^0.17.19",
"husky": "^9.0.11",
"lerna": "^6.6.2",
"semver": "^7.6.0",
"typescript": "^5.1.3"
},
"dependencies": {
"dompurify": "^3.1.6",
"validator": "^13.15.15"
},
"resolutions": {
"react": "^19.0.0",
"react-dom": "^19.0.0"
}
}
17 changes: 14 additions & 3 deletions packages/api/src/EmbeddedChatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class EmbeddedChatApi {
onUiInteractionCallbacks: ((data: any) => void)[];
typingUsers: string[];
auth: RocketChatAuth;
private _connectPromise: Promise<void> | null = null;

constructor(
host: string,
Expand Down Expand Up @@ -186,6 +187,17 @@ export default class EmbeddedChatApi {
* TODO: Add logic to call thread message event listeners. To be done after thread implementation
*/
async connect() {
Comment thread
Spiral-Memory marked this conversation as resolved.
// Guard against concurrent connect() calls (e.g. React StrictMode double-invoke)
if (this._connectPromise) {
return this._connectPromise;
}
this._connectPromise = this._doConnect().finally(() => {
this._connectPromise = null;
});
return this._connectPromise;
}

private async _doConnect() {
try {
await this.close(); // before connection, all previous subscriptions should be cancelled
await this.rcClient.connect({});
Expand All @@ -198,7 +210,6 @@ export default class EmbeddedChatApi {
}
const message = JSON.parse(JSON.stringify(data));
if (message.ts?.$date) {
console.log(message.ts?.$date);
message.ts = message.ts.$date;
}
if (!message.ts) {
Expand Down Expand Up @@ -683,14 +694,14 @@ export default class EmbeddedChatApi {

async sendTypingStatus(username: string, typing: boolean) {
try {
this.rcClient.methodCall(
await this.rcClient.methodCall(
"stream-notify-room",
`${this.rid}/user-activity`,
username,
typing ? ["user-typing"] : []
);
} catch (err) {
console.error(err);
// DDP typing indicator fails when connection is temporarily down — expected, safe to ignore
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/auth/src/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export class Api {
if (!response.ok) {
throw new ApiError(response, "Failed Api Request for " + endpoint);
}
const jsonData = await response.json();
const text = await response.text();
const jsonData = text.length ? JSON.parse(text) : {};
return { data: jsonData };
}

Expand Down
11 changes: 8 additions & 3 deletions packages/auth/src/RocketChatAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class RocketChatAuth {
async onAuthChange(callback: (user: object | null) => void) {
this.authListeners.push(callback);
const user = await this.getCurrentUser();
callback(user);
if (this.authListeners.includes(callback)) {
callback(user);
}
}

async removeAuthListener(callback: (user: object | null) => void) {
Expand Down Expand Up @@ -72,6 +74,7 @@ class RocketChatAuth {
}
);
this.setUser(response.data);
this.notifyAuthListeners();
return this.currentUser;
}

Expand All @@ -92,6 +95,7 @@ class RocketChatAuth {
credentials
);
this.setUser(response.data);
this.notifyAuthListeners();
return this.currentUser;
}

Expand All @@ -107,6 +111,7 @@ class RocketChatAuth {
api: this.api,
});
this.setUser(response.data);
this.notifyAuthListeners();
return this.currentUser;
}

Expand Down Expand Up @@ -190,10 +195,10 @@ class RocketChatAuth {
try {
const token = await this.getToken();
if (token) {
const user = await this.loginWithResumeToken(token); // will notifyAuthListeners on successful login
const user = await this.loginWithResumeToken(token);
if (user) {
this.lastFetched = new Date();
await this.getCurrentUser(); // refresh the token if needed
await this.getCurrentUser();
}
}
} catch (e) {
Expand Down
8 changes: 4 additions & 4 deletions packages/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ This is the official documentation website of EmbeddedChat.

> **Node.js Version Requirement**
>
> The `docs/` folder requires **Node.js v18 or higher** to run correctly.
> If you’re using a lower version (e.g., v16.19.0 from other parts of the monorepo), you may encounter errors.
> The `docs/` folder requires **Node.js v22 or higher** to run correctly.
> If you’re using a lower version (e.g., v18), you may encounter errors.
>
> Use [NVM](https://github.com/nvm-sh/nvm) to install and switch to the correct version:
>
> ```bash
> nvm install 18
> nvm use 18
> nvm install 22
> nvm use 22
> ```

### Installation
Expand Down
9 changes: 6 additions & 3 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"@mdx-js/react": "^3.0.0",
"clsx": "^2.0.0",
"prism-react-renderer": "^2.3.0",
"react": "^18.0.0",
"react-dom": "^18.0.0"
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "3.5.1",
Expand All @@ -38,7 +38,10 @@
"last 5 safari version"
]
},
"resolutions": {
"webpack": "5.96.1"
},
"engines": {
"node": ">=18.0"
"node": ">=22.0"
}
}
Loading
Loading