Skip to content

Commit 2accf3a

Browse files
authored
Merge pull request #6 from commt/crashlytics
Crashlytics
2 parents 50e833e + 1ac8b93 commit 2accf3a

File tree

9 files changed

+393
-87
lines changed

9 files changed

+393
-87
lines changed

src/components/Chat/index.tsx

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const Chat = ({
4747
rooms,
4848
messages,
4949
app: {
50-
configs: { indicators, tenantId },
50+
configs: { indicators, tenantId, apiKey, subscriptionKey, projectName },
5151
},
5252
},
5353
dispatch,
@@ -86,21 +86,39 @@ const Chat = ({
8686
activeRoom?.lastMessage?.user?._id !== selfUser?._id
8787
) {
8888
// Update the room's lastMessageReadToken field
89-
sendReadToken({
90-
token: dayjs().valueOf(),
91-
chatRoomAuthId: activeRoom.chatRoomAuthId,
92-
});
89+
sendReadToken(
90+
{
91+
token: dayjs().valueOf(),
92+
chatRoomAuthId: activeRoom.chatRoomAuthId,
93+
},
94+
//handle Log params
95+
{
96+
apiKey,
97+
subscriptionKey,
98+
projectName,
99+
chatAuthId: selfUser!.chatAuthId,
100+
},
101+
);
93102
}
94103
}, [indicators, activeRoom?.lastMessage]);
95104

96105
const typingStatus = (isTyping: boolean) => {
97106
selfUser &&
98107
activeRoom &&
99-
sendTypingStatus({
100-
isTyping,
101-
userId: selfUser._id,
102-
chatRoomAuthId: activeRoom.chatRoomAuthId,
103-
});
108+
sendTypingStatus(
109+
{
110+
isTyping,
111+
userId: selfUser._id,
112+
chatRoomAuthId: activeRoom.chatRoomAuthId,
113+
},
114+
//handle Log params
115+
{
116+
apiKey,
117+
subscriptionKey,
118+
projectName,
119+
chatAuthId: selfUser!.chatAuthId,
120+
},
121+
);
104122
isAlreadyTypingRef.current = isTyping;
105123
};
106124

@@ -180,11 +198,21 @@ const Chat = ({
180198
tenantId,
181199
};
182200
// Create new room with socket event
183-
createNewRoom(data, (room) => {
184-
setActiveRoom(room);
185-
addRoom(room)(dispatch);
186-
sendMessage(message, room);
187-
});
201+
createNewRoom(
202+
data,
203+
(room) => {
204+
setActiveRoom(room);
205+
addRoom(room)(dispatch);
206+
sendMessage(message, room);
207+
},
208+
//handle Log params
209+
{
210+
apiKey,
211+
subscriptionKey,
212+
projectName,
213+
chatAuthId: selfUser!.chatAuthId,
214+
},
215+
);
188216
}
189217
} else {
190218
// if room exist send message

src/context/reducers/appReducer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type ConfigsProps = {
1616
apiKey: string;
1717
subscriptionKey: string;
1818
secretKey: string;
19+
projectName: string;
1920
};
2021

2122
export type AppState = {
@@ -35,6 +36,7 @@ export const AppValues: AppState = {
3536
apiKey: "",
3637
subscriptionKey: "",
3738
secretKey: "",
39+
projectName: "",
3840
},
3941
};
4042

src/hooks/useSendMessage.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ interface onSendMessageProps {
1616
const useSendMessage = () => {
1717
const {
1818
state: {
19+
users: { selfUser },
1920
app: {
20-
configs: { secretKey },
21+
configs: { secretKey, apiKey, subscriptionKey, projectName },
2122
},
2223
},
2324
dispatch,
@@ -60,6 +61,14 @@ const useSendMessage = () => {
6061
})(dispatch);
6162
}
6263
},
64+
//handle Log params
65+
{
66+
apiKey,
67+
subscriptionKey,
68+
projectName,
69+
chatAuthId: selfUser!.chatAuthId,
70+
chatRoomAuthId,
71+
},
6372
);
6473
};
6574

src/hooks/useSetRooms.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import { IndicatorProps } from "../context/reducers/appReducer";
88
const useSetRooms = () => {
99
const {
1010
state: {
11+
users: { selfUser },
1112
app: {
12-
configs: { apiKey, subscriptionKey, indicators },
13+
configs: { apiKey, subscriptionKey, indicators, projectName },
1314
},
1415
},
1516
dispatch,
@@ -21,6 +22,8 @@ const useSetRooms = () => {
2122
roomIds: rooms.map((room) => room.chatRoomAuthId).join(","),
2223
apiKey,
2324
subscriptionKey,
25+
projectName,
26+
chatAuthId: selfUser!.chatAuthId,
2427
});
2528

2629
// Match the 'lastMessageReadToken' field for active rooms from the service data

src/hooks/useSetUsers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const useSetUsers = () => {
1010
state: {
1111
users: { selfUser },
1212
app: {
13-
configs: { apiKey, subscriptionKey, indicators },
13+
configs: { apiKey, subscriptionKey, indicators, projectName },
1414
},
1515
},
1616
dispatch,
@@ -27,6 +27,8 @@ const useSetUsers = () => {
2727
userIds,
2828
apiKey,
2929
subscriptionKey,
30+
projectName,
31+
chatAuthId: selfUser!.chatAuthId,
3032
});
3133

3234
// Match the 'online' field for active users from the service data

src/service/index.ts

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import axios from "./Axios";
33
import { ConfigsProps } from "../context/reducers/appReducer";
44
import { RoomProps } from "../context/reducers/roomsReducer";
55
import PackageJson from "../../package.json";
6+
import * as events from "../utils/events";
67

78
export interface InitiateProps {
89
apiKey: string;
910
subscriptionKey: string;
11+
projectName: string;
1012
}
1113

1214
interface OnlineInfoProps extends InitiateProps {
1315
userIds: string;
16+
chatAuthId: string; // for selfUser's chatAuthId
1417
}
1518

1619
type OnlineInfoReturnProps = Pick<
@@ -20,20 +23,30 @@ type OnlineInfoReturnProps = Pick<
2023

2124
interface ReadTokenProps extends InitiateProps {
2225
roomIds: string;
26+
chatAuthId: string; //selfUser's chatAuthId
2327
}
2428

2529
type ReadTokenReturnProps = Pick<
2630
RoomProps,
2731
"chatRoomAuthId" | "lastMessageReadToken"
2832
>;
2933

34+
interface HandleLoggerProps extends InitiateProps {
35+
error: {
36+
error: Error | string | { [key: string]: any } | unknown;
37+
event: string;
38+
};
39+
chatAuthId?: string;
40+
chatRoomAuthId?: string;
41+
}
42+
3043
const project = {
3144
name: "React Native SDK",
3245
version: PackageJson.version,
3346
};
3447

3548
export const initiate = async (props: InitiateProps) => {
36-
const { apiKey, subscriptionKey } = props;
49+
const { apiKey, subscriptionKey, projectName } = props;
3750

3851
try {
3952
const response = await axios.get<ConfigsProps>(`/api/v1/tenant/config/`, {
@@ -53,14 +66,22 @@ export const initiate = async (props: InitiateProps) => {
5366
}
5467

5568
return;
56-
} catch {
57-
// TODO: Log error
58-
/* empty */
69+
} catch (error) {
70+
// Log error to service
71+
handleLogger({
72+
apiKey,
73+
subscriptionKey,
74+
projectName,
75+
error: {
76+
error,
77+
event: events.INITIATE_TENANT_CONFIGS,
78+
},
79+
});
5980
}
6081
};
6182

6283
export const getUsersOnlineInfo = async (props: OnlineInfoProps) => {
63-
const { userIds, apiKey, subscriptionKey } = props;
84+
const { userIds, apiKey, subscriptionKey, projectName, chatAuthId } = props;
6485

6586
try {
6687
const response = await axios.get<OnlineInfoReturnProps[]>(
@@ -77,14 +98,23 @@ export const getUsersOnlineInfo = async (props: OnlineInfoProps) => {
7798
);
7899

79100
return response.data;
80-
} catch {
81-
// TODO: Log error
82-
/* empty */
101+
} catch (error) {
102+
// Log error to service
103+
handleLogger({
104+
apiKey,
105+
subscriptionKey,
106+
projectName,
107+
error: {
108+
error,
109+
event: events.GET_USERS_ONLINE_INFO,
110+
},
111+
chatAuthId,
112+
});
83113
}
84114
};
85115

86116
export const getRoomsReadToken = async (props: ReadTokenProps) => {
87-
const { roomIds, apiKey, subscriptionKey } = props;
117+
const { roomIds, apiKey, subscriptionKey, projectName, chatAuthId } = props;
88118

89119
try {
90120
const response = await axios.get<ReadTokenReturnProps[]>(
@@ -100,8 +130,49 @@ export const getRoomsReadToken = async (props: ReadTokenProps) => {
100130
},
101131
);
102132
return response.data;
103-
} catch {
133+
} catch (error) {
104134
// TODO: Log error
105-
/* empty */
135+
handleLogger({
136+
apiKey,
137+
subscriptionKey,
138+
projectName,
139+
error: {
140+
error,
141+
event: events.GET_ROOMS_READ_TOKEN,
142+
},
143+
chatAuthId,
144+
});
145+
}
146+
};
147+
148+
export const handleLogger = async (props: HandleLoggerProps) => {
149+
const {
150+
apiKey,
151+
subscriptionKey,
152+
projectName,
153+
error,
154+
chatAuthId,
155+
chatRoomAuthId,
156+
} = props;
157+
158+
const logObject = {
159+
projectName,
160+
SDK: project.name,
161+
version: project.version,
162+
error,
163+
...(chatAuthId && { chatAuthId }),
164+
...(chatRoomAuthId && { chatRoomAuthId }),
165+
};
166+
167+
try {
168+
axios.post("/system/logger", logObject, {
169+
headers: {
170+
apiKey,
171+
subscriptionKey,
172+
},
173+
});
174+
} catch (error_) {
175+
// Log error
176+
console.log("handle Logger failed", error_);
106177
}
107178
};

0 commit comments

Comments
 (0)