@samparkchat/sampark-web-chat 0.0.1

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.
Files changed (92) hide show
  1. package/README.md +93 -0
  2. package/package.json +72 -0
  3. package/sampark/sampark-chat/App.d.ts +4 -0
  4. package/sampark/sampark-chat/App.js +123 -0
  5. package/sampark/sampark-chat/App.test.d.ts +1 -0
  6. package/sampark/sampark-chat/App.test.js +8 -0
  7. package/sampark/sampark-chat/components/Headers/ChatHeader.d.ts +12 -0
  8. package/sampark/sampark-chat/components/Headers/ChatHeader.js +142 -0
  9. package/sampark/sampark-chat/components/Headers/GroupChatHeader.d.ts +17 -0
  10. package/sampark/sampark-chat/components/Headers/GroupChatHeader.js +227 -0
  11. package/sampark/sampark-chat/components/Headers/ParticipantHeader.d.ts +9 -0
  12. package/sampark/sampark-chat/components/Headers/ParticipantHeader.js +71 -0
  13. package/sampark/sampark-chat/components/Headers/SamparkHeader.d.ts +11 -0
  14. package/sampark/sampark-chat/components/Headers/SamparkHeader.js +162 -0
  15. package/sampark/sampark-chat/components/MessageActions.d.ts +19 -0
  16. package/sampark/sampark-chat/components/MessageActions.js +177 -0
  17. package/sampark/sampark-chat/components/bottomsheets/GroupBottomSheet.d.ts +11 -0
  18. package/sampark/sampark-chat/components/bottomsheets/GroupBottomSheet.js +276 -0
  19. package/sampark/sampark-chat/components/bottomsheets/GroupOptionBottomSheet.d.ts +12 -0
  20. package/sampark/sampark-chat/components/bottomsheets/GroupOptionBottomSheet.js +239 -0
  21. package/sampark/sampark-chat/components/lists/ParticipantList.d.ts +12 -0
  22. package/sampark/sampark-chat/components/lists/ParticipantList.js +207 -0
  23. package/sampark/sampark-chat/components/lists/ViewParticipents.d.ts +36 -0
  24. package/sampark/sampark-chat/components/lists/ViewParticipents.js +452 -0
  25. package/sampark/sampark-chat/index.d.ts +5 -0
  26. package/sampark/sampark-chat/index.js +17 -0
  27. package/sampark/sampark-chat/models/deleteModel.d.ts +8 -0
  28. package/sampark/sampark-chat/models/deleteModel.js +63 -0
  29. package/sampark/sampark-chat/models/infoModal.d.ts +8 -0
  30. package/sampark/sampark-chat/models/infoModal.js +75 -0
  31. package/sampark/sampark-chat/reportWebVitals.d.ts +3 -0
  32. package/sampark/sampark-chat/reportWebVitals.js +13 -0
  33. package/sampark/sampark-chat/screens/PeerChatScreen.d.ts +20 -0
  34. package/sampark/sampark-chat/screens/PeerChatScreen.js +467 -0
  35. package/sampark/sampark-chat/screens/SamparkChatContext.d.ts +6 -0
  36. package/sampark/sampark-chat/screens/SamparkChatContext.js +9 -0
  37. package/sampark/sampark-chat/screens/SamparkChatProvider.d.ts +7 -0
  38. package/sampark/sampark-chat/screens/SamparkChatProvider.js +69 -0
  39. package/sampark/sampark-chat/screens/SamparkchatScreen.d.ts +16 -0
  40. package/sampark/sampark-chat/screens/SamparkchatScreen.js +1317 -0
  41. package/sampark/sampark-chat/screens/groupChatScreen.d.ts +24 -0
  42. package/sampark/sampark-chat/screens/groupChatScreen.js +375 -0
  43. package/sampark/sampark-chat/sdk/client/Groupchat.d.ts +53 -0
  44. package/sampark/sampark-chat/sdk/client/Groupchat.js +457 -0
  45. package/sampark/sampark-chat/sdk/client/PeerChat.d.ts +34 -0
  46. package/sampark/sampark-chat/sdk/client/PeerChat.js +227 -0
  47. package/sampark/sampark-chat/sdk/client/SamparkChat.d.ts +12 -0
  48. package/sampark/sampark-chat/sdk/client/SamparkChat.js +101 -0
  49. package/sampark/sampark-chat/sdk/enum/ActionTypes.d.ts +15 -0
  50. package/sampark/sampark-chat/sdk/enum/ActionTypes.js +16 -0
  51. package/sampark/sampark-chat/sdk/enum/constant.d.ts +1 -0
  52. package/sampark/sampark-chat/sdk/enum/constant.js +3 -0
  53. package/sampark/sampark-chat/sdk/interface/SamparkChatservice.d.ts +3 -0
  54. package/sampark/sampark-chat/sdk/interface/SamparkChatservice.js +1 -0
  55. package/sampark/sampark-chat/sdk/interface/SamparkGroupChatService.d.ts +26 -0
  56. package/sampark/sampark-chat/sdk/interface/SamparkGroupChatService.js +1 -0
  57. package/sampark/sampark-chat/sdk/interface/SamparkPeerChatService.d.ts +9 -0
  58. package/sampark/sampark-chat/sdk/interface/SamparkPeerChatService.js +1 -0
  59. package/sampark/sampark-chat/sdk/types/AddParticipentRequest.d.ts +16 -0
  60. package/sampark/sampark-chat/sdk/types/AddParticipentRequest.js +14 -0
  61. package/sampark/sampark-chat/sdk/types/ChatHistoryRequest.d.ts +10 -0
  62. package/sampark/sampark-chat/sdk/types/ChatHistoryRequest.js +14 -0
  63. package/sampark/sampark-chat/sdk/types/CreateChatSession.d.ts +11 -0
  64. package/sampark/sampark-chat/sdk/types/CreateChatSession.js +15 -0
  65. package/sampark/sampark-chat/sdk/types/CreateChatUser.d.ts +9 -0
  66. package/sampark/sampark-chat/sdk/types/CreateChatUser.js +13 -0
  67. package/sampark/sampark-chat/sdk/types/CreateGroupChatRequest.d.ts +18 -0
  68. package/sampark/sampark-chat/sdk/types/CreateGroupChatRequest.js +16 -0
  69. package/sampark/sampark-chat/sdk/types/DeleteGroupRequest.d.ts +15 -0
  70. package/sampark/sampark-chat/sdk/types/DeleteGroupRequest.js +13 -0
  71. package/sampark/sampark-chat/sdk/types/GenerateTokenRequest.d.ts +10 -0
  72. package/sampark/sampark-chat/sdk/types/GenerateTokenRequest.js +14 -0
  73. package/sampark/sampark-chat/sdk/types/GetGroupsRequest.d.ts +8 -0
  74. package/sampark/sampark-chat/sdk/types/GetGroupsRequest.js +12 -0
  75. package/sampark/sampark-chat/sdk/types/GetParticipentRequest.d.ts +8 -0
  76. package/sampark/sampark-chat/sdk/types/GetParticipentRequest.js +12 -0
  77. package/sampark/sampark-chat/sdk/types/GetRegisteredUserDetailsRequest.d.ts +8 -0
  78. package/sampark/sampark-chat/sdk/types/GetRegisteredUserDetailsRequest.js +12 -0
  79. package/sampark/sampark-chat/sdk/types/GroupChatHistoryRequest.d.ts +12 -0
  80. package/sampark/sampark-chat/sdk/types/GroupChatHistoryRequest.js +16 -0
  81. package/sampark/sampark-chat/sdk/types/RemoveParticipentRequest.d.ts +14 -0
  82. package/sampark/sampark-chat/sdk/types/RemoveParticipentRequest.js +12 -0
  83. package/sampark/sampark-chat/sdk/types/UpdateGroupAdminRequest.d.ts +10 -0
  84. package/sampark/sampark-chat/sdk/types/UpdateGroupAdminRequest.js +14 -0
  85. package/sampark/sampark-chat/sdk/types/UpdateGroupStatus.d.ts +10 -0
  86. package/sampark/sampark-chat/sdk/types/UpdateGroupStatus.js +14 -0
  87. package/sampark/sampark-chat/services/Common.d.ts +12 -0
  88. package/sampark/sampark-chat/services/Common.js +18 -0
  89. package/sampark/sampark-chat/services/DateFormat.d.ts +2 -0
  90. package/sampark/sampark-chat/services/DateFormat.js +14 -0
  91. package/sampark/sampark-chat/setupTests.d.ts +1 -0
  92. package/sampark/sampark-chat/setupTests.js +5 -0
@@ -0,0 +1,457 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { io } from "socket.io-client";
38
+ import axios from "axios";
39
+ import { apiUrl } from "../enum/constant";
40
+ import { CreateGroupChatRequest } from "../types/CreateGroupChatRequest";
41
+ import { AddParticipantRequest } from "../types/AddParticipentRequest";
42
+ import { RemoveParticipantRequest } from "../types/RemoveParticipentRequest";
43
+ import { DeleteGroupRequest } from "../types/DeleteGroupRequest";
44
+ import { GetParticipantsRequest } from "../types/GetParticipentRequest";
45
+ import { GetGroupsRequest } from "../types/GetGroupsRequest";
46
+ import { GroupChatHistoryRequest } from "../types/GroupChatHistoryRequest";
47
+ import { UpdateGroupStatusRequest } from "../types/UpdateGroupStatus";
48
+ import { GetRegisteredUserDetailsRequest } from "../types/GetRegisteredUserDetailsRequest";
49
+ import { UpdateGroupAdminRequest } from "../types/UpdateGroupAdminRequest";
50
+ var GroupChat = /** @class */ (function () {
51
+ function GroupChat(organizationId, applicationId) {
52
+ this.socket = io(apiUrl);
53
+ this.organizationId = organizationId;
54
+ this.applicationId = applicationId;
55
+ }
56
+ GroupChat.prototype.test = function () {
57
+ console.log("Test function calling ....");
58
+ };
59
+ GroupChat.prototype.sendOnlineStatus = function (userId) {
60
+ if (this.socket && this.organizationId) {
61
+ this.socket.emit('userOnline', { userId: userId, organizationId: this.organizationId });
62
+ console.log("User ".concat(userId, " is online in org: ").concat(this.organizationId));
63
+ }
64
+ else {
65
+ console.log('Socket not initialized or organization ID missing');
66
+ }
67
+ };
68
+ GroupChat.prototype.connectUser = function (OnStatusUpdate) {
69
+ var _a;
70
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.on('userStatusChanged', function (organizationId, userId, status) {
71
+ console.log("".concat(organizationId, " in the ").concat(userId, " has the ").concat(status));
72
+ if (OnStatusUpdate) {
73
+ console.log("".concat(userId, " has online ").concat(organizationId));
74
+ OnStatusUpdate({ organizationId: organizationId, userId: userId, status: status });
75
+ }
76
+ });
77
+ };
78
+ GroupChat.prototype.sendTyping = function (roomId, userId, userName) {
79
+ if (this.socket) {
80
+ // console.log(`${userId} starts typing in this ${roomId}`),
81
+ this.socket.emit('typing', { roomId: roomId, userId: userId, userName: userName });
82
+ }
83
+ else {
84
+ console.error('Socket not initialized');
85
+ }
86
+ };
87
+ GroupChat.prototype.sendStopTyping = function (roomId, userId, userName) {
88
+ if (this.socket) {
89
+ // console.log(`${userId} stop typing in this ${roomId}`),
90
+ this.socket.emit('stopTyping', { roomId: roomId, userId: userId, userName: userName });
91
+ }
92
+ else {
93
+ console.error('Socket not initialized');
94
+ }
95
+ };
96
+ GroupChat.prototype.connectTyping = function (onTyping) {
97
+ var _a;
98
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.on('userTyping', function (_a) {
99
+ var userId = _a.userId, userName = _a.userName, roomId = _a.roomId, isTyping = _a.isTyping;
100
+ // console.log('Received userTyping event:', { userId, userName, roomId, isTyping });
101
+ if (onTyping) {
102
+ // console.log(`${userId} with ${userName} is typing in this ${roomId} with status ${isTyping}`);
103
+ onTyping({ userId: userId, userName: userName, roomId: roomId, isTyping: isTyping });
104
+ }
105
+ });
106
+ };
107
+ GroupChat.prototype.createGroupChat = function (adminId, roomType, groupName, participants) {
108
+ return __awaiter(this, void 0, void 0, function () {
109
+ var payload, response, error_1;
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0:
113
+ _a.trys.push([0, 2, , 3]);
114
+ payload = new CreateGroupChatRequest(adminId, this.organizationId, roomType = roomType, groupName = groupName, participants = participants, this.applicationId);
115
+ return [4 /*yield*/, axios.post("".concat(apiUrl, "/chat/createGroupChat"), payload)];
116
+ case 1:
117
+ response = _a.sent();
118
+ if (response.data && response.data.status === 200) {
119
+ return [2 /*return*/, response.data.data.room_id];
120
+ }
121
+ else {
122
+ return [2 /*return*/, ''];
123
+ }
124
+ return [3 /*break*/, 3];
125
+ case 2:
126
+ error_1 = _a.sent();
127
+ console.error("Error creating group chat:", error_1);
128
+ return [2 /*return*/, ''];
129
+ case 3: return [2 /*return*/];
130
+ }
131
+ });
132
+ });
133
+ };
134
+ GroupChat.prototype.JoinGroupRoom = function (roomId, userId, userName) {
135
+ if (this.socket) {
136
+ this.socket.emit('joinGroup', { roomId: roomId, userId: userId, userName: userName });
137
+ }
138
+ else {
139
+ console.error('socket not initilized');
140
+ }
141
+ };
142
+ GroupChat.prototype.addParticipantToGroup = function (roomId, groupName, participants) {
143
+ return __awaiter(this, void 0, void 0, function () {
144
+ var payload, response, error_2;
145
+ return __generator(this, function (_a) {
146
+ switch (_a.label) {
147
+ case 0:
148
+ _a.trys.push([0, 2, , 3]);
149
+ payload = new AddParticipantRequest(roomId = roomId, groupName = groupName, this.organizationId, participants = participants);
150
+ return [4 /*yield*/, axios.post("".concat(apiUrl, "/chat/addParticipants"), payload)];
151
+ case 1:
152
+ response = _a.sent();
153
+ if (response.data && response.data.status === 200) {
154
+ return [2 /*return*/, response.data.data.room_id];
155
+ }
156
+ else {
157
+ return [2 /*return*/, ''];
158
+ }
159
+ return [3 /*break*/, 3];
160
+ case 2:
161
+ error_2 = _a.sent();
162
+ return [2 /*return*/, ''];
163
+ case 3: return [2 /*return*/];
164
+ }
165
+ });
166
+ });
167
+ };
168
+ GroupChat.prototype.removeParticipentFromGroup = function (roomId, participants) {
169
+ return __awaiter(this, void 0, void 0, function () {
170
+ var payload, response, error_3;
171
+ return __generator(this, function (_a) {
172
+ switch (_a.label) {
173
+ case 0:
174
+ _a.trys.push([0, 2, , 3]);
175
+ payload = new RemoveParticipantRequest(roomId = roomId, participants = participants);
176
+ return [4 /*yield*/, axios.post("".concat(apiUrl, "/chat/removeParticipent"), payload)];
177
+ case 1:
178
+ response = _a.sent();
179
+ if (response.data && response.data.status === 200) {
180
+ return [2 /*return*/, response.data.data.room_id];
181
+ }
182
+ else {
183
+ return [2 /*return*/, ''];
184
+ }
185
+ return [3 /*break*/, 3];
186
+ case 2:
187
+ error_3 = _a.sent();
188
+ console.error("Error adding participant:", error_3);
189
+ return [2 /*return*/, ''];
190
+ case 3: return [2 /*return*/];
191
+ }
192
+ });
193
+ });
194
+ };
195
+ GroupChat.prototype.deleteGroupByUser = function (roomId, participants) {
196
+ return __awaiter(this, void 0, void 0, function () {
197
+ var payload, response, error_4;
198
+ return __generator(this, function (_a) {
199
+ switch (_a.label) {
200
+ case 0:
201
+ _a.trys.push([0, 2, , 3]);
202
+ payload = new DeleteGroupRequest(this.organizationId, roomId = roomId, participants = participants);
203
+ return [4 /*yield*/, axios.post("".concat(apiUrl, "/chat/deleteGroupByUser"), payload)];
204
+ case 1:
205
+ response = _a.sent();
206
+ if (response.data && response.data.status === 200) {
207
+ return [2 /*return*/, response.data.message];
208
+ }
209
+ else {
210
+ return [2 /*return*/, ''];
211
+ }
212
+ return [3 /*break*/, 3];
213
+ case 2:
214
+ error_4 = _a.sent();
215
+ console.error("Error adding participant:", error_4);
216
+ return [2 /*return*/, ''];
217
+ case 3: return [2 /*return*/];
218
+ }
219
+ });
220
+ });
221
+ };
222
+ GroupChat.prototype.getParticipant = function (roomId) {
223
+ return __awaiter(this, void 0, void 0, function () {
224
+ var payload, response, error_5;
225
+ return __generator(this, function (_a) {
226
+ switch (_a.label) {
227
+ case 0:
228
+ _a.trys.push([0, 2, , 3]);
229
+ payload = new GetParticipantsRequest(roomId = roomId, this.organizationId);
230
+ return [4 /*yield*/, axios.post("".concat(apiUrl, "/chat/getParticipents"), payload)];
231
+ case 1:
232
+ response = _a.sent();
233
+ if (response.data && response.data.status === 200) {
234
+ return [2 /*return*/, response.data.data.participants];
235
+ }
236
+ else {
237
+ return [2 /*return*/, null];
238
+ }
239
+ return [3 /*break*/, 3];
240
+ case 2:
241
+ error_5 = _a.sent();
242
+ console.error("Error retrieving participents", error_5);
243
+ return [2 /*return*/, null];
244
+ case 3: return [2 /*return*/];
245
+ }
246
+ });
247
+ });
248
+ };
249
+ GroupChat.prototype.sendGroupMessage = function (roomId, message, userId, userName) {
250
+ if (this.socket) {
251
+ this.socket.emit('sendGroupMessage', { organizationId: this.organizationId, roomId: roomId, message: message, userId: userId, userName: userName, applicationId: this.applicationId });
252
+ }
253
+ else {
254
+ console.error('Socket not initialized');
255
+ }
256
+ };
257
+ // connectUser(OnStatusUpdate: OnStatusUpdateCallback
258
+ // ): void {
259
+ // this.socket?.on('userStatusChanged',(organizationId:string,userId:string,status:boolean)=>{
260
+ // console.log(`${organizationId} in the ${userId} has the ${status}`)
261
+ // if(OnStatusUpdate){
262
+ // console.log(`${userId} has online ${organizationId}`)
263
+ // OnStatusUpdate({organizationId,userId,status});
264
+ // }
265
+ // })
266
+ // }
267
+ GroupChat.prototype.connect = function (onGroupMessageReceived) {
268
+ var _this = this;
269
+ var _a, _b, _c, _d, _e, _f;
270
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.off('receiveGroupMessage');
271
+ (_b = this.socket) === null || _b === void 0 ? void 0 : _b.on('connect', function () {
272
+ onGroupMessageReceived({ msg: 'connected' });
273
+ });
274
+ (_c = this.socket) === null || _c === void 0 ? void 0 : _c.on('receiveGroupMessage', function (message, userId, userName, roomId, time) {
275
+ if (onGroupMessageReceived) {
276
+ onGroupMessageReceived({ message: message, userId: userId, userName: userName, roomId: roomId, userRemoved: false, time: time });
277
+ }
278
+ });
279
+ (_d = this.socket) === null || _d === void 0 ? void 0 : _d.on('userRemovedFromGroup', function (userId, removedRoomId) {
280
+ if (onGroupMessageReceived) {
281
+ onGroupMessageReceived({ userId: userId, userRemoved: true, removedRoomId: removedRoomId });
282
+ }
283
+ });
284
+ (_e = this.socket) === null || _e === void 0 ? void 0 : _e.on('userStatusChanged', function (_a) {
285
+ var userId = _a.userId, status = _a.status, organizationId = _a.organizationId;
286
+ console.log("User ".concat(userId, " status updated to"), status ? "online" : "offline");
287
+ if (organizationId === _this.organizationId) {
288
+ console.log("User ".concat(userId, " status updated to"), status ? "online" : "offline");
289
+ }
290
+ });
291
+ (_f = this.socket) === null || _f === void 0 ? void 0 : _f.on('disconnect', function () {
292
+ console.log('Disconnected from group chat server');
293
+ });
294
+ };
295
+ GroupChat.prototype.getRoomsByUserId = function (userId) {
296
+ return __awaiter(this, void 0, void 0, function () {
297
+ var payload, response, error_6;
298
+ return __generator(this, function (_a) {
299
+ switch (_a.label) {
300
+ case 0:
301
+ _a.trys.push([0, 2, , 3]);
302
+ payload = new GetGroupsRequest(userId = userId, this.organizationId);
303
+ return [4 /*yield*/, axios.post("".concat(apiUrl, "/chat/getRoomsById"), payload)];
304
+ case 1:
305
+ response = _a.sent();
306
+ if (response.data && response.data.status === 200) {
307
+ return [2 /*return*/, response.data.data.rooms];
308
+ }
309
+ else {
310
+ return [2 /*return*/, null];
311
+ }
312
+ return [3 /*break*/, 3];
313
+ case 2:
314
+ error_6 = _a.sent();
315
+ console.error("Error retrieving rooms:", error_6);
316
+ return [2 /*return*/, null];
317
+ case 3: return [2 /*return*/];
318
+ }
319
+ });
320
+ });
321
+ };
322
+ GroupChat.prototype.getGroupChatHistory = function (roomId, userGroupStatus, userGroupUpdatedAt, page, limit) {
323
+ return __awaiter(this, void 0, void 0, function () {
324
+ var payload, response, error_7;
325
+ return __generator(this, function (_a) {
326
+ switch (_a.label) {
327
+ case 0:
328
+ _a.trys.push([0, 2, , 3]);
329
+ payload = new GroupChatHistoryRequest(roomId = roomId, this.organizationId, userGroupStatus, userGroupUpdatedAt, page = page, limit = limit);
330
+ return [4 /*yield*/, axios.post("".concat(apiUrl, "/chat/getPaginatedGroupChat"), payload)];
331
+ case 1:
332
+ response = _a.sent();
333
+ if (response.data && response.data.status == 200) {
334
+ return [2 /*return*/, response.data.data];
335
+ }
336
+ else {
337
+ return [2 /*return*/, null];
338
+ }
339
+ return [3 /*break*/, 3];
340
+ case 2:
341
+ error_7 = _a.sent();
342
+ console.error("Error validating credentials:", error_7);
343
+ return [2 /*return*/, null];
344
+ case 3: return [2 /*return*/];
345
+ }
346
+ });
347
+ });
348
+ };
349
+ GroupChat.prototype.leaveGroup = function (roomId, userId) {
350
+ if (this.socket) {
351
+ this.socket.emit('leaveGroup', { roomId: roomId, userId: userId });
352
+ this.socket.on('userRemoved', function (removedUserId) {
353
+ if (removedUserId === userId) {
354
+ // console.log(`You (${userId}) have successfully left the group.`);
355
+ }
356
+ else {
357
+ // console.log(`User ${removedUserId} has left the group.`);
358
+ }
359
+ });
360
+ this.socket.on('error', function (errorMessage) {
361
+ console.error("Error: ".concat(errorMessage));
362
+ });
363
+ }
364
+ else {
365
+ console.error('Socket not initialized');
366
+ }
367
+ };
368
+ GroupChat.prototype.updateGroupStatusByParticipant = function (participantId, groupId, groupStatus) {
369
+ return __awaiter(this, void 0, void 0, function () {
370
+ var payload, response, error_8;
371
+ return __generator(this, function (_a) {
372
+ switch (_a.label) {
373
+ case 0:
374
+ _a.trys.push([0, 2, , 3]);
375
+ payload = new UpdateGroupStatusRequest(this.organizationId, participantId, groupId, groupStatus);
376
+ return [4 /*yield*/, axios.post("".concat(apiUrl, "/chat/updateGroupStatusByParticipant"), payload)];
377
+ case 1:
378
+ response = _a.sent();
379
+ if (response.data && response.data.status == 200) {
380
+ return [2 /*return*/, response.data];
381
+ }
382
+ else {
383
+ return [2 /*return*/, null];
384
+ }
385
+ return [3 /*break*/, 3];
386
+ case 2:
387
+ error_8 = _a.sent();
388
+ console.error("Error validating credentials:", error_8);
389
+ return [2 /*return*/, null];
390
+ case 3: return [2 /*return*/];
391
+ }
392
+ });
393
+ });
394
+ };
395
+ GroupChat.prototype.getRegisteredParticipantDetails = function (participantId) {
396
+ return __awaiter(this, void 0, void 0, function () {
397
+ var payload, response, error_9;
398
+ return __generator(this, function (_a) {
399
+ switch (_a.label) {
400
+ case 0:
401
+ _a.trys.push([0, 2, , 3]);
402
+ payload = new GetRegisteredUserDetailsRequest(this.organizationId, participantId);
403
+ return [4 /*yield*/, axios.post("".concat(apiUrl, "/chat/getRegisteredUserDetails"), payload)];
404
+ case 1:
405
+ response = _a.sent();
406
+ if (response.data && response.data.status == 200) {
407
+ return [2 /*return*/, response.data];
408
+ }
409
+ else {
410
+ return [2 /*return*/, null];
411
+ }
412
+ return [3 /*break*/, 3];
413
+ case 2:
414
+ error_9 = _a.sent();
415
+ console.error("Error validating credentials:", error_9);
416
+ return [2 /*return*/, null];
417
+ case 3: return [2 /*return*/];
418
+ }
419
+ });
420
+ });
421
+ };
422
+ GroupChat.prototype.updateGroupAdmin = function (room_id, organizationId, current_admin_id, new_admin_id) {
423
+ return __awaiter(this, void 0, void 0, function () {
424
+ var payload, response, error_10;
425
+ return __generator(this, function (_a) {
426
+ switch (_a.label) {
427
+ case 0:
428
+ _a.trys.push([0, 2, , 3]);
429
+ payload = new UpdateGroupAdminRequest(room_id, organizationId, current_admin_id, new_admin_id);
430
+ return [4 /*yield*/, axios.post("".concat(apiUrl, "/chat/updateGroupAdmin"), payload)];
431
+ case 1:
432
+ response = _a.sent();
433
+ if (response.data && response.data.status == 200) {
434
+ return [2 /*return*/, response.data];
435
+ }
436
+ else {
437
+ return [2 /*return*/, null];
438
+ }
439
+ return [3 /*break*/, 3];
440
+ case 2:
441
+ error_10 = _a.sent();
442
+ console.error("Error validating credentials:", error_10);
443
+ return [2 /*return*/, null];
444
+ case 3: return [2 /*return*/];
445
+ }
446
+ });
447
+ });
448
+ };
449
+ GroupChat.prototype.disconnect = function () {
450
+ if (this.socket) {
451
+ this.socket.disconnect();
452
+ }
453
+ };
454
+ return GroupChat;
455
+ }());
456
+ export { GroupChat };
457
+ export default GroupChat;
@@ -0,0 +1,34 @@
1
+ import { ISamparkPeerChatService } from '../interface/SamparkPeerChatService';
2
+ type OnMessageReceivedCallback = (message: any) => void;
3
+ type OnTypingCallback = (typingData: {
4
+ userId: string;
5
+ userName: string;
6
+ room_id: string;
7
+ isTyping: boolean;
8
+ }) => void;
9
+ export declare class PeerChat implements ISamparkPeerChatService {
10
+ private socket?;
11
+ private isSocketConnected?;
12
+ private organizationId;
13
+ private applicationId;
14
+ constructor(orgId: string, appId: string);
15
+ test(): void;
16
+ getOrganizationId(): string;
17
+ sendOnlineStatus(userId: string, userName: string): void;
18
+ peerConnectUser(onUserStatusUpdate: (data: {
19
+ organizationId: string;
20
+ userId: string;
21
+ status: string;
22
+ }) => void, onInitialOnlineUsers: (onlineUsers: string[]) => void): void;
23
+ getChatHistory(roomId: string, page: number, limit: number): Promise<any>;
24
+ registerUser(participantId: string, participantName: string): Promise<string>;
25
+ connect(onMessageReceived: OnMessageReceivedCallback): void;
26
+ joinChatSession(room_id: string): void;
27
+ sendPeerTyping(room_id: string, userId: string, userName: string): void;
28
+ sendStopPeerTyping(room_id: string, userId: string, userName: string): void;
29
+ peerConnectTyping(onTyping: OnTypingCallback): void;
30
+ getChatRoomId(userId: string, userName: string, peerId: string, peerName: string): Promise<string>;
31
+ sendMessage(room_id: string, message: string, userId: string, userName: string, peerId: string, peerName: string): void;
32
+ disconnect(): void;
33
+ }
34
+ export default PeerChat;