cardoctor-call-chat 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cardoctor-call-chat",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -0,0 +1,18 @@
1
+ const myHeaders = new Headers();
2
+ myHeaders.append("accept", "application/json");
3
+ myHeaders.append("apikey", "07ffe79d29cf9a3596e5fe369125a48b829ea400");
4
+ myHeaders.append("content-type", "application/json");
5
+
6
+ const requestOptions = {
7
+ method: "POST",
8
+ headers: myHeaders
9
+ };
10
+
11
+ export const getAuthToken = async (userId: string) => {
12
+ const getToken = await fetch(
13
+ `https://2772864c1a441d73.api-in.cometchat.io/v3/users/${userId}/auth_tokens`,
14
+ requestOptions
15
+ )
16
+ const response = await getToken.json()
17
+ return response.data.authToken
18
+ }
@@ -0,0 +1,11 @@
1
+ import { CometChatMessageComposer } from "@cometchat/chat-uikit-react";
2
+
3
+ const CometChatCompose = ({group}: {group:any}) => {
4
+ return (
5
+ <>
6
+ <CometChatMessageComposer group={group}/>
7
+ </>
8
+ );
9
+ }
10
+
11
+ export default CometChatCompose;
@@ -0,0 +1,10 @@
1
+ import { CometChatMessageHeader } from "@cometchat/chat-uikit-react"
2
+
3
+ export default function CometChatHeader({group}: {
4
+ group: any
5
+ }) {
6
+
7
+ return(
8
+ <CometChatMessageHeader group={group}/>
9
+ )
10
+ }
@@ -0,0 +1,4 @@
1
+ export * from './compose'
2
+ export * from './header'
3
+ export * from './list'
4
+ export * from './message'
@@ -0,0 +1,25 @@
1
+ import { CometChatGroups } from "@cometchat/chat-uikit-react";
2
+ import { CometChat } from "@cometchat/chat-sdk-javascript";
3
+ import React from "react";
4
+
5
+ interface IListGroup {
6
+ tag?: string[]
7
+ limit?: number
8
+ setSelectGroup: any
9
+ }
10
+
11
+ const ListGroup = React.memo(({
12
+ tag = [],
13
+ limit = 20,
14
+ setSelectGroup
15
+ }: IListGroup) => {
16
+ return <CometChatGroups
17
+ groupsRequestBuilder={new CometChat.GroupsRequestBuilder()
18
+ .setLimit(limit)
19
+ .setTags(tag)
20
+ }
21
+ onItemClick={e => setSelectGroup(e)}
22
+ />
23
+ });
24
+
25
+ export default ListGroup;
@@ -0,0 +1,11 @@
1
+ import { CometChatMessageList } from "@cometchat/chat-uikit-react";
2
+
3
+ const CometChatMessage = ({group}: {group:any}) => {
4
+ return (
5
+ <div className="h-[800px] scroll-auto overflow-scroll">
6
+ <CometChatMessageList group={group} />
7
+ </div>
8
+ );
9
+ }
10
+
11
+ export default CometChatMessage;
@@ -0,0 +1,25 @@
1
+ import { CometChatUIKit } from "@cometchat/chat-uikit-react";
2
+ let isLoggingIn = false;
3
+ export const loginWithAuthToken = async (authToken: string) => {
4
+ try {
5
+ if (isLoggingIn) {
6
+ console.log("⚠️ Login request already in progress...");
7
+ return;
8
+ }
9
+
10
+ const existingUser = await CometChatUIKit.getLoggedinUser();
11
+ if (existingUser) {
12
+ console.log("🔹 Already logged in:", existingUser);
13
+ return existingUser;
14
+ }
15
+
16
+ isLoggingIn = true;
17
+ const user = await CometChatUIKit.loginWithAuthToken(authToken);
18
+ console.log("✅ Login successful:", user);
19
+ return user;
20
+ } catch (error) {
21
+ console.error("❌ Login failed:", error);
22
+ } finally {
23
+ isLoggingIn = false;
24
+ }
25
+ };
@@ -0,0 +1,57 @@
1
+ import { useState, useEffect } from "react";
2
+ import { UIKitSettingsBuilder, CometChatUIKit } from "@cometchat/chat-uikit-react";
3
+ import { getAuthToken } from "./api/get-auth-token";
4
+ import { loginWithAuthToken } from "./func/login-user";
5
+
6
+ interface ChatInitState {
7
+ user: any | null;
8
+ loading: boolean;
9
+ }
10
+
11
+ interface IPros {
12
+ appId: string;
13
+ region: string;
14
+ userId: string
15
+ }
16
+
17
+ export function useCallChatInit(props: IPros): ChatInitState {
18
+ const [user, setUser] = useState<any | null>(null);
19
+ const [loading, setLoading] = useState(true);
20
+
21
+ useEffect(() => {
22
+ let mounted = true;
23
+
24
+ const init = async () => {
25
+ try {
26
+ const UIKitSettings = new UIKitSettingsBuilder()
27
+ .setAppId(props.appId)
28
+ .setRegion(props.region)
29
+ .subscribePresenceForAllUsers()
30
+ .build();
31
+
32
+ await CometChatUIKit.init(UIKitSettings);
33
+ console.log("✅ CometChat UI Kit initialized successfully.");
34
+
35
+ const token = await getAuthToken(props.userId);
36
+ console.log("🚀 ~ init ~ token:", token)
37
+ const loggedInUser = await loginWithAuthToken(token);
38
+
39
+ if (mounted) {
40
+ setUser(loggedInUser);
41
+ setLoading(false);
42
+ }
43
+ } catch (error) {
44
+ console.error("❌ CometChat init failed:", error);
45
+ if (mounted) setLoading(false);
46
+ }
47
+ };
48
+
49
+ init();
50
+
51
+ return () => {
52
+ mounted = false;
53
+ };
54
+ }, []);
55
+
56
+ return { user, loading };
57
+ }
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
- export * from "./useCounter";
1
+ export * from "./cometchat/use-call-chat-init";
2
+ export * from "./cometchat/components"
File without changes
package/src/useCounter.ts DELETED
@@ -1,12 +0,0 @@
1
- import { useState, useEffect } from "react";
2
-
3
- export function useCounter(initial = 0) {
4
- const [count, setCount] = useState(initial);
5
-
6
- useEffect(() => {
7
- console.log("Counter mounted:", count);
8
- return () => console.log("Counter unmounted");
9
- }, []);
10
-
11
- return { count, setCount };
12
- }