@rtsee/messenger 0.0.74 → 0.0.78

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 (44) hide show
  1. package/dist/messenger/src/helpers/ChatMemberPermissionsManager.js +32 -34
  2. package/dist/messenger/src/helpers/ChatMemberPermissionsManager.js.map +1 -1
  3. package/dist/messenger/src/index.js +3 -19
  4. package/dist/messenger/src/index.js.map +1 -1
  5. package/dist/messenger/src/interfaces/ChatEvents.js +2 -5
  6. package/dist/messenger/src/interfaces/ChatEvents.js.map +1 -1
  7. package/dist/messenger/src/interfaces/ChatMemberRolePermissions.js +2 -5
  8. package/dist/messenger/src/interfaces/ChatMemberRolePermissions.js.map +1 -1
  9. package/dist/messenger/src/interfaces/Component.js +0 -2
  10. package/dist/messenger/src/interfaces/Messages.js +0 -2
  11. package/dist/messenger/src/interfaces/MessengerOptions.js +0 -2
  12. package/dist/messenger/src/interfaces/SearchQueryOptions.js +0 -2
  13. package/dist/messenger/src/interfaces/index.d.ts +0 -1
  14. package/dist/messenger/src/interfaces/index.d.ts.map +1 -1
  15. package/dist/messenger/src/interfaces/index.js +6 -23
  16. package/dist/messenger/src/interfaces/index.js.map +1 -1
  17. package/dist/messenger/src/models/RTSeeChat.d.ts +1 -1
  18. package/dist/messenger/src/models/RTSeeChat.d.ts.map +1 -1
  19. package/dist/messenger/src/models/RTSeeChat.js +172 -176
  20. package/dist/messenger/src/models/RTSeeChat.js.map +1 -1
  21. package/dist/messenger/src/models/RTSeeChatMember.js +12 -10
  22. package/dist/messenger/src/models/RTSeeChatMember.js.map +1 -1
  23. package/dist/messenger/src/models/RTSeeMessage.js +32 -24
  24. package/dist/messenger/src/models/RTSeeMessage.js.map +1 -1
  25. package/dist/messenger/src/models/RTSeeMessenger.d.ts +14 -3
  26. package/dist/messenger/src/models/RTSeeMessenger.d.ts.map +1 -1
  27. package/dist/messenger/src/models/RTSeeMessenger.js +243 -294
  28. package/dist/messenger/src/models/RTSeeMessenger.js.map +1 -1
  29. package/dist/messenger/src/models/RTSeeMessengerSearch.d.ts.map +1 -1
  30. package/dist/messenger/src/models/RTSeeMessengerSearch.js +48 -45
  31. package/dist/messenger/src/models/RTSeeMessengerSearch.js.map +1 -1
  32. package/dist/messenger/src/models/index.d.ts +1 -0
  33. package/dist/messenger/src/models/index.d.ts.map +1 -1
  34. package/dist/messenger/src/models/index.js +6 -21
  35. package/dist/messenger/src/models/index.js.map +1 -1
  36. package/dist/messenger/src/models/remote-actions/MessengerRemoteActions.d.ts +6 -0
  37. package/dist/messenger/src/models/remote-actions/MessengerRemoteActions.d.ts.map +1 -0
  38. package/dist/messenger/src/models/remote-actions/MessengerRemoteActions.js +11 -0
  39. package/dist/messenger/src/models/remote-actions/MessengerRemoteActions.js.map +1 -0
  40. package/package.json +2 -2
  41. package/dist/messenger/src/interfaces/RTSeeMessengerEvents.d.ts +0 -20
  42. package/dist/messenger/src/interfaces/RTSeeMessengerEvents.d.ts.map +0 -1
  43. package/dist/messenger/src/interfaces/RTSeeMessengerEvents.js +0 -24
  44. package/dist/messenger/src/interfaces/RTSeeMessengerEvents.js.map +0 -1
@@ -1,140 +1,121 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
- return new (P || (P = Promise))(function (resolve, reject) {
31
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
- step((generator = generator.apply(thisArg, _arguments || [])).next());
35
- });
36
- };
37
- var __generator = (this && this.__generator) || function (thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
39
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
- function verb(n) { return function (v) { return step([n, v]); }; }
41
- function step(op) {
42
- if (f) throw new TypeError("Generator is already executing.");
43
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
44
- 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;
45
- if (y = 0, t) op = [op[0] & 2, t.value];
46
- switch (op[0]) {
47
- case 0: case 1: t = op; break;
48
- case 4: _.label++; return { value: op[1], done: false };
49
- case 5: _.label++; y = op[1]; op = [0]; continue;
50
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
- default:
52
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
- if (t[2]) _.ops.pop();
57
- _.trys.pop(); continue;
58
- }
59
- op = body.call(thisArg, _);
60
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
- }
63
- };
64
- Object.defineProperty(exports, "__esModule", { value: true });
65
- exports.RTSeeMessenger = void 0;
66
- var RTSeeChat_1 = require("./RTSeeChat");
67
- var messenger_1 = require("@rtsee/messenger");
68
- var core_1 = require("@rtsee/core");
69
- var common_1 = require("@rtsee/common");
70
- var DEFAULT_CHATS_FETCH_STEP = 20;
71
- var RTSeeMessenger = /** @class */ (function (_super) {
72
- __extends(RTSeeMessenger, _super);
73
- function RTSeeMessenger(options) {
74
- var _this = _super.call(this, options) || this;
75
- _this.chats = [];
76
- _this.loadingChatsInProgress = false;
77
- _this.unreadMessagesCount = 0;
78
- _this.isInFocus = true;
79
- _this.mainMenuOpened = false;
80
- _this.folded = false;
81
- _this.search = new messenger_1.RTSeeMessengerSearch({
82
- signalingClient: _this.signalingClient,
1
+ import { RTSeeChat } from "./RTSeeChat";
2
+ import { getMessengerRemoteActions, RTSeeChatMember, RTSeeMessengerSearch } from "@rtsee/messenger";
3
+ import { RTSeeCore } from "@rtsee/core";
4
+ import { MessengerClientEvents, RTSeeChatMemberRoles, RTSeeChatTypes, RTSeeMessageStatus, RTSeeMessengerEvents } from "@rtsee/common";
5
+ const DEFAULT_CHATS_FETCH_STEP = 20;
6
+ export class RTSeeMessenger extends RTSeeCore {
7
+ chats = [];
8
+ openedChat;
9
+ openedProfile = null;
10
+ ownProfileOpened = false;
11
+ openedChatDetails = false;
12
+ search;
13
+ getHistoricalChats;
14
+ videoChat;
15
+ loadingChatsInProgress = false;
16
+ unreadMessagesCount = 0;
17
+ isInFocus = true;
18
+ folded = false;
19
+ remoteActions;
20
+ // ui
21
+ peerLoadInProgress = false;
22
+ chatLoadInProgress = false;
23
+ chatInputHeight = 35 + 16;
24
+ constructor(options) {
25
+ super(options);
26
+ this.search = new RTSeeMessengerSearch({
27
+ signalingClient: this.signalingClient,
83
28
  });
84
29
  if (options.getHistoricalChats) {
85
- _this.getHistoricalChats = options.getHistoricalChats;
30
+ this.getHistoricalChats = options.getHistoricalChats;
86
31
  }
87
32
  if (options.videoChat) {
88
- _this.attachVideoChat(options.videoChat);
33
+ this.attachVideoChat(options.videoChat);
89
34
  }
90
- _this.signalingClient.connect({
91
- messenger: _this,
35
+ this.signalingClient.connect({
36
+ messenger: this,
92
37
  });
93
- _this.attachWindowEvents();
94
- return _this;
38
+ this.remoteActions = getMessengerRemoteActions(this.signalingClient);
39
+ this.attachWindowEvents();
40
+ }
41
+ async openProfile(id) {
42
+ this.collapseInfo();
43
+ try {
44
+ const peer = await this.remoteActions.getPeer.send(id);
45
+ this.openedProfile = peer;
46
+ if (this.openedProfile.clientId === this.myPeer.clientId) {
47
+ this.ownProfileOpened = true;
48
+ }
49
+ if (!peer) {
50
+ return null;
51
+ }
52
+ }
53
+ catch (e) {
54
+ console.log(e);
55
+ }
56
+ }
57
+ setChatInputHeight(value) {
58
+ this.chatInputHeight = value;
59
+ }
60
+ collapseInfo() {
61
+ this.closeProfile();
62
+ this.closeChatInfo();
95
63
  }
96
- RTSeeMessenger.prototype.openMainMenu = function (open) {
97
- this.mainMenuOpened = open;
98
- };
99
- RTSeeMessenger.prototype.changeChatFoldState = function (state) {
64
+ closeProfile() {
65
+ if (this.ownProfileOpened) {
66
+ this.ownProfileOpened = false;
67
+ this.emit(RTSeeMessengerEvents.OWN_PROFILE_CLOSED);
68
+ }
69
+ this.openedProfile = null;
70
+ }
71
+ openChatInfo() {
72
+ this.collapseInfo();
73
+ if (!this.openedChat) {
74
+ return;
75
+ }
76
+ this.openedChatDetails = true;
77
+ }
78
+ closeChatInfo() {
79
+ this.openedChatDetails = false;
80
+ }
81
+ changeChatFoldState(state) {
100
82
  this.folded = state;
101
- };
102
- RTSeeMessenger.prototype.attachWindowEvents = function () {
103
- var _this = this;
104
- window.addEventListener("focus", function () {
105
- _this.onFocus();
83
+ }
84
+ attachWindowEvents() {
85
+ window.addEventListener("focus", () => {
86
+ this.onFocus();
106
87
  });
107
- window.addEventListener("blur", function () {
108
- _this.onOnBlur();
88
+ window.addEventListener("blur", () => {
89
+ this.onOnBlur();
109
90
  });
110
- };
111
- RTSeeMessenger.prototype.onFocus = function () {
91
+ }
92
+ onFocus() {
112
93
  this.isInFocus = true;
113
94
  if (this.openedChat) {
114
- var unseenMessage = this.openedChat.getLastUnseenMessage();
95
+ const unseenMessage = this.openedChat.getLastUnseenMessage();
115
96
  if (unseenMessage) {
116
97
  this.emitMessagesSeen([unseenMessage]);
117
98
  }
118
99
  }
119
- };
120
- RTSeeMessenger.prototype.onOnBlur = function () {
100
+ }
101
+ onOnBlur() {
121
102
  this.isInFocus = false;
122
- };
123
- RTSeeMessenger.prototype.attachVideoChat = function (videoChat) {
103
+ }
104
+ attachVideoChat(videoChat) {
124
105
  this.videoChat = videoChat;
125
- };
126
- RTSeeMessenger.prototype.onReady = function () {
106
+ }
107
+ onReady() {
127
108
  if (this.getHistoricalChats) {
128
109
  this.loadChats();
129
110
  }
130
- };
131
- RTSeeMessenger.prototype.openChatByPeer = function (peer) {
132
- var chat = this.getChatByReceiverId(peer.clientId);
111
+ }
112
+ openChatByPeer(peer) {
113
+ let chat = this.getChatByReceiverId(peer.clientId);
133
114
  if (!chat) {
134
- var temporaryChatId = core_1.RTSeeCore.uuidv4();
135
- var chatData = {
115
+ const temporaryChatId = RTSeeCore.uuidv4();
116
+ const chatData = {
136
117
  id: temporaryChatId,
137
- type: common_1.RTSeeChatTypes.INDIVIDUAL,
118
+ type: RTSeeChatTypes.INDIVIDUAL,
138
119
  isPreset: true,
139
120
  clientId: this.signalingClient.getMyPeerId(),
140
121
  name: peer.name || peer.clientId,
@@ -145,43 +126,43 @@ var RTSeeMessenger = /** @class */ (function (_super) {
145
126
  unreadMessagesCount: 0,
146
127
  members: [
147
128
  this.getMeAsChatMember(temporaryChatId),
148
- new messenger_1.RTSeeChatMember({
129
+ new RTSeeChatMember({
149
130
  chatId: temporaryChatId,
150
131
  id: peer.clientId,
151
132
  name: peer.name,
152
133
  imageUrl: peer.imageUrl,
153
134
  url: peer.url,
154
- role: common_1.RTSeeChatMemberRoles.MEMBER,
135
+ role: RTSeeChatMemberRoles.MEMBER,
155
136
  }),
156
137
  ],
157
138
  };
158
139
  chat = this.addChat(chatData);
159
140
  }
160
141
  this.openChat(chat);
161
- };
162
- RTSeeMessenger.prototype.openChat = function (chat) {
142
+ }
143
+ openChat(chat) {
163
144
  console.log('Open Chat: ', chat);
164
145
  this.folded = false;
165
146
  this.openedChat = chat;
166
147
  this.openedChat.onOpened();
167
148
  this.emitMessagesSeen(this.openedChat.getUnseenMessages());
168
- this.emit(common_1.MessengerClientEvents.CHAT_OPENED);
169
- };
170
- RTSeeMessenger.prototype.openChatById = function (id) {
171
- var chat = this.getChatById(id) || this.getChatByTemporaryId(id);
149
+ this.emit(MessengerClientEvents.CHAT_OPENED);
150
+ }
151
+ openChatById(id) {
152
+ const chat = this.getChatById(id) || this.getChatByTemporaryId(id);
172
153
  if (!chat) {
173
154
  return;
174
155
  }
175
156
  this.openChat(chat);
176
- };
177
- RTSeeMessenger.prototype.closeChat = function () {
157
+ }
158
+ closeChat() {
178
159
  this.openedChat = null;
179
- };
180
- RTSeeMessenger.prototype.handleIncomingMessage = function (messageData) {
181
- var chat = this.getChatById(messageData.chatId);
182
- var message;
160
+ }
161
+ handleIncomingMessage(messageData) {
162
+ let chat = this.getChatById(messageData.chatId);
163
+ let message;
183
164
  if (chat) {
184
- message = chat.addMessage(messageData);
165
+ message = chat.addMessage(messageData, false);
185
166
  }
186
167
  else {
187
168
  chat = this.joinChatByIncomingMessage(messageData);
@@ -190,12 +171,11 @@ var RTSeeMessenger = /** @class */ (function (_super) {
190
171
  this.emitMessagesSeen([message]);
191
172
  }
192
173
  this.emitMessagesReceived([messageData]);
193
- };
194
- RTSeeMessenger.prototype.emitMessagesReceived = function (messages) {
195
- var _this = this;
196
- messages.forEach(function (message) {
174
+ }
175
+ emitMessagesReceived(messages) {
176
+ messages.forEach((message) => {
197
177
  if (message.chatId) {
198
- var messageReceivedData = {
178
+ const messageReceivedData = {
199
179
  messages: [
200
180
  {
201
181
  chatId: message.chatId,
@@ -204,8 +184,8 @@ var RTSeeMessenger = /** @class */ (function (_super) {
204
184
  },
205
185
  ],
206
186
  };
207
- _this.signalingClient.emitEvent({
208
- name: messenger_1.RTSeeMessengerEvents.MESSAGE_RECEIVED,
187
+ this.signalingClient.emitEvent({
188
+ name: RTSeeMessengerEvents.MESSAGE_RECEIVED,
209
189
  data: messageReceivedData,
210
190
  });
211
191
  }
@@ -213,13 +193,13 @@ var RTSeeMessenger = /** @class */ (function (_super) {
213
193
  console.log("Error, chat without id!");
214
194
  }
215
195
  });
216
- };
217
- RTSeeMessenger.prototype.emitMessagesSeen = function (messages) {
196
+ }
197
+ emitMessagesSeen(messages) {
218
198
  if (!messages.length) {
219
199
  return;
220
200
  }
221
- var messageSeenData = {
222
- messages: messages.map(function (e) {
201
+ const messageSeenData = {
202
+ messages: messages.map((e) => {
223
203
  return {
224
204
  chatId: e.chatId,
225
205
  id: e.id,
@@ -228,77 +208,80 @@ var RTSeeMessenger = /** @class */ (function (_super) {
228
208
  }),
229
209
  };
230
210
  this.signalingClient.emitEvent({
231
- name: messenger_1.RTSeeMessengerEvents.INCOMING_MESSAGES_SEEN,
211
+ name: RTSeeMessengerEvents.INCOMING_MESSAGES_SEEN,
232
212
  data: messageSeenData,
233
213
  });
234
- messages.forEach(function (e) {
235
- e.setStatus(common_1.RTSeeMessageStatus.SEEN);
214
+ messages.forEach((e) => {
215
+ e.setStatus(RTSeeMessageStatus.SEEN);
236
216
  });
237
- };
238
- RTSeeMessenger.prototype.handleMessageReceivedEvent = function (options) {
239
- var chat = this.getChatById(options.chatId);
217
+ }
218
+ handleMessageReceivedEvent(options) {
219
+ const chat = this.getChatById(options.chatId);
240
220
  if (!chat) {
241
221
  return;
242
222
  }
243
- options.messagesIds.forEach(function (e) {
244
- var message = chat.getMessageById(e);
223
+ options.messagesIds.forEach((e) => {
224
+ const message = chat.getMessageById(e);
245
225
  if (message) {
246
- message.setStatus(common_1.RTSeeMessageStatus.DELIVERED);
226
+ message.setStatus(RTSeeMessageStatus.DELIVERED);
247
227
  }
248
228
  });
249
- };
250
- RTSeeMessenger.prototype.handleIncomingMessagesSeen = function (options) {
251
- var chat = this.getChatById(options.chatId);
229
+ }
230
+ handleIncomingMessagesSeen(options) {
231
+ const chat = this.getChatById(options.chatId);
252
232
  if (!chat) {
253
233
  return;
254
234
  }
255
235
  chat.markMessagesAsSeen(options.messagesIds);
256
- };
257
- RTSeeMessenger.prototype.handleMessageSendFailed = function (toId) {
258
- var chat = this.getChatByReceiverId(toId);
236
+ }
237
+ handleMessageSendFailed(toId) {
238
+ const chat = this.getChatByReceiverId(toId);
259
239
  if (!chat) {
260
240
  return;
261
241
  }
262
242
  console.log(chat.id, "failed to send message!");
263
- };
264
- RTSeeMessenger.prototype.onRemoteChatCreated = function (chat, temporaryId) {
265
- var existing = this.getChatById(temporaryId);
243
+ }
244
+ onRemoteChatCreated(chat, temporaryId) {
245
+ const existing = this.getChatById(temporaryId);
266
246
  if (existing) {
267
247
  existing.init(chat);
268
248
  }
269
249
  else {
270
250
  this.addChat(chat);
271
251
  }
272
- };
273
- RTSeeMessenger.prototype.getRemoteChat = function (chatId) {
252
+ }
253
+ getRemoteChat(chatId) {
274
254
  this.signalingClient.emitEvent({
275
- name: messenger_1.RTSeeMessengerEvents.GET_CHAT,
255
+ name: RTSeeMessengerEvents.GET_CHAT,
276
256
  data: {
277
257
  id: chatId,
278
258
  },
279
259
  });
280
- };
281
- RTSeeMessenger.prototype.getChatByReceiverId = function (id) {
282
- return (this.chats.find(function (e) {
260
+ }
261
+ getChatByReceiverId(id) {
262
+ return (this.chats.find((e) => {
283
263
  return e.type === "individual" && e.receiverId === id;
284
264
  }) || null);
285
- };
286
- RTSeeMessenger.prototype.getChatByTemporaryId = function (id) {
287
- return (this.chats.find(function (e) {
265
+ }
266
+ getChatByTemporaryId(id) {
267
+ return (this.chats.find((e) => {
288
268
  return e.id === id && e.isPreset === true;
289
269
  }) || null);
290
- };
291
- RTSeeMessenger.prototype.getChatById = function (id) {
292
- return this.chats.find(function (e) { return e.id === id; }) || null;
293
- };
294
- RTSeeMessenger.prototype.populateChats = function (chats) {
295
- var _this = this;
296
- chats.forEach(function (elem) {
297
- _this.addChat(elem, true);
270
+ }
271
+ getChatById(id) {
272
+ return this.chats.find((e) => e.id === id) || null;
273
+ }
274
+ populateChats(chats) {
275
+ chats.forEach((elem) => {
276
+ this.addChat(elem, true);
277
+ });
278
+ }
279
+ addChat(chatData, append) {
280
+ const chat = new RTSeeChat({
281
+ ...chatData,
282
+ clientId: this.signalingClient.getMyPeerId(),
283
+ signalingClient: this.signalingClient,
298
284
  });
299
- };
300
- RTSeeMessenger.prototype.addChat = function (chatData, append) {
301
- var chat = new RTSeeChat_1.RTSeeChat(__assign(__assign({}, chatData), { clientId: this.signalingClient.getMyPeerId(), signalingClient: this.signalingClient }));
302
285
  if (append) {
303
286
  this.chats.push(chat);
304
287
  }
@@ -307,45 +290,44 @@ var RTSeeMessenger = /** @class */ (function (_super) {
307
290
  }
308
291
  this.subscribeToChatEvents(chat);
309
292
  return chat;
310
- };
311
- RTSeeMessenger.prototype.subscribeToChatEvents = function (chat) {
312
- var _this = this;
313
- chat.on(messenger_1.RTSeeMessengerEvents.GET_MESSAGES, function (options) {
314
- _this.signalingClient.emitEvent({
315
- name: messenger_1.RTSeeMessengerEvents.GET_MESSAGES,
293
+ }
294
+ subscribeToChatEvents(chat) {
295
+ chat.on(RTSeeMessengerEvents.GET_MESSAGES, (options) => {
296
+ this.signalingClient.emitEvent({
297
+ name: RTSeeMessengerEvents.GET_MESSAGES,
316
298
  data: options,
317
299
  });
318
300
  });
319
- };
320
- RTSeeMessenger.prototype.getMeAsChatMember = function (chatId) {
301
+ }
302
+ getMeAsChatMember(chatId) {
321
303
  if (!this.signalingClient) {
322
304
  throw new Error("Can not add chats before signalingClient is initialized.");
323
305
  }
324
- var myPeer = this.signalingClient.getMyPeer();
306
+ const myPeer = this.signalingClient.getMyPeer();
325
307
  console.log('getMeAsChatMember My Peer here, ', myPeer);
326
- return new messenger_1.RTSeeChatMember({
308
+ return new RTSeeChatMember({
327
309
  id: this.clientId,
328
- chatId: chatId,
310
+ chatId,
329
311
  name: myPeer.name,
330
312
  url: myPeer.url,
331
313
  imageUrl: myPeer.imageUrl,
332
- role: common_1.RTSeeChatMemberRoles.MEMBER,
314
+ role: RTSeeChatMemberRoles.MEMBER,
333
315
  });
334
- };
335
- RTSeeMessenger.prototype.joinChatByIncomingMessage = function (messageData) {
336
- var addedChat = this.getChatById(messageData.chatId);
316
+ }
317
+ joinChatByIncomingMessage(messageData) {
318
+ const addedChat = this.getChatById(messageData.chatId);
337
319
  if (!addedChat) {
338
320
  this.getRemoteChat(messageData.chatId);
339
321
  return null;
340
322
  }
341
323
  addedChat.addMessage(messageData);
342
324
  return addedChat;
343
- };
344
- RTSeeMessenger.prototype.onCallCreated = function (call, options) {
325
+ }
326
+ onCallCreated(call, options) {
345
327
  if (!options.chatId) {
346
328
  return;
347
329
  }
348
- var chat = this.getExistingChat({
330
+ const chat = this.getExistingChat({
349
331
  chatId: options.chatId,
350
332
  });
351
333
  if (!chat) {
@@ -358,28 +340,27 @@ var RTSeeMessenger = /** @class */ (function (_super) {
358
340
  data: call,
359
341
  chatId: chat.id,
360
342
  });
361
- };
362
- RTSeeMessenger.prototype.onChatsLoaded = function (result) {
343
+ }
344
+ onChatsLoaded(result) {
363
345
  this.loadingChatsInProgress = false;
364
346
  this.unreadMessagesCount = result.unreadCount;
365
347
  this.populateChats(result.chats);
366
- };
367
- RTSeeMessenger.prototype.onMessagesLoaded = function (result) {
368
- var chat = this.getChatById(result.chatId);
348
+ }
349
+ onMessagesLoaded(result) {
350
+ const chat = this.getChatById(result.chatId);
369
351
  if (!chat) {
370
352
  return;
371
353
  }
372
354
  this.emitMessagesSeen(chat.getUnseenMessages());
373
355
  chat.addMessages(result.messages, result.direction);
374
356
  chat.unreadMessagesCount = result.unreadCount;
375
- };
376
- RTSeeMessenger.prototype.markMessagesAsSeen = function (messages) {
377
- var _this = this;
378
- var messagesSeenOptions = {
357
+ }
358
+ markMessagesAsSeen(messages) {
359
+ const messagesSeenOptions = {
379
360
  messages: [],
380
361
  };
381
- messages.forEach(function (e) {
382
- if (e.status !== common_1.RTSeeMessageStatus.SEEN && e.from !== _this.clientId) {
362
+ messages.forEach((e) => {
363
+ if (e.status !== RTSeeMessageStatus.SEEN && e.from !== this.clientId) {
383
364
  messagesSeenOptions.messages.push({
384
365
  id: e.id,
385
366
  from: e.from,
@@ -388,31 +369,32 @@ var RTSeeMessenger = /** @class */ (function (_super) {
388
369
  }
389
370
  });
390
371
  this.signalingClient.emitEvent({
391
- name: messenger_1.RTSeeMessengerEvents.INCOMING_MESSAGES_SEEN,
372
+ name: RTSeeMessengerEvents.INCOMING_MESSAGES_SEEN,
392
373
  data: messagesSeenOptions,
393
374
  });
394
- };
395
- RTSeeMessenger.prototype.onMessageSendSuccess = function (messageData) {
396
- var chat = this.getChatById(messageData.chatId);
397
- var tempChat = this.getChatByTemporaryId(messageData.temporaryChatId);
375
+ }
376
+ onMessageSendSuccess(messageData) {
377
+ const chat = this.getChatById(messageData.chatId);
378
+ const tempChat = this.getChatByTemporaryId(messageData.temporaryChatId);
398
379
  if (chat) {
399
- var message = chat.getMessageByTemporaryId(messageData.temporaryId);
380
+ const message = chat.getMessageByTemporaryId(messageData.temporaryId);
400
381
  if (message) {
401
382
  message.onSendSuccess(messageData);
402
383
  }
403
384
  else {
404
- var addedMessage = chat.addMessage(messageData);
385
+ const addedMessage = chat.addMessage(messageData);
405
386
  addedMessage.temporaryId = null;
406
387
  }
407
388
  }
408
389
  else if (tempChat) {
409
390
  tempChat.id = messageData.chatId;
410
- var message = chat.getMessageByTemporaryId(messageData.temporaryId);
391
+ tempChat.isPreset = false;
392
+ const message = chat.getMessageByTemporaryId(messageData.temporaryId);
411
393
  if (message) {
412
394
  message.onSendSuccess(messageData);
413
395
  }
414
396
  else {
415
- var addedMessage = chat.addMessage(messageData);
397
+ const addedMessage = chat.addMessage(messageData);
416
398
  addedMessage.temporaryId = null;
417
399
  }
418
400
  }
@@ -420,63 +402,43 @@ var RTSeeMessenger = /** @class */ (function (_super) {
420
402
  messageData.temporaryId = null;
421
403
  this.getRemoteChat(messageData.chatId);
422
404
  }
423
- };
424
- RTSeeMessenger.prototype.joinCall = function (roomId) {
425
- return __awaiter(this, void 0, void 0, function () {
426
- return __generator(this, function (_a) {
427
- switch (_a.label) {
428
- case 0:
429
- if (!this.videoChat || !this.signalingClient) {
430
- console.log("ERROR! Signaling Client is not initialized or Video Chat is not connected!");
431
- return [2 /*return*/];
432
- }
433
- return [4 /*yield*/, this.videoChat.connect(roomId, this.signalingClient.getMyPeer())];
434
- case 1:
435
- _a.sent();
436
- return [2 /*return*/];
437
- }
438
- });
439
- });
440
- };
441
- RTSeeMessenger.prototype.initializeVideoCall = function (chat) {
442
- return __awaiter(this, void 0, void 0, function () {
443
- return __generator(this, function (_a) {
444
- switch (_a.label) {
445
- case 0:
446
- if (!this.videoChat) {
447
- console.log("Video chat not connected!");
448
- return [2 /*return*/];
449
- }
450
- if (!chat.conferenceRoom) {
451
- this.videoChat.createRoom({ chatId: chat.id });
452
- return [2 /*return*/];
453
- }
454
- return [4 /*yield*/, this.videoChat.call(chat.conferenceRoom.id, {
455
- callerId: this.myPeer.clientId,
456
- chatId: this.openedChat.id
457
- })];
458
- case 1:
459
- _a.sent();
460
- return [2 /*return*/];
461
- }
462
- });
405
+ }
406
+ async joinCall(roomId) {
407
+ if (!this.videoChat || !this.signalingClient) {
408
+ console.log("ERROR! Signaling Client is not initialized or Video Chat is not connected!");
409
+ return;
410
+ }
411
+ await this.videoChat.connect(roomId, this.signalingClient.getMyPeer());
412
+ }
413
+ async initializeVideoCall(chat) {
414
+ if (!this.videoChat) {
415
+ console.log("Video chat not connected!");
416
+ return;
417
+ }
418
+ if (!chat.conferenceRoom) {
419
+ this.videoChat.createRoom({ chatId: chat.id });
420
+ return;
421
+ }
422
+ await this.videoChat.call(chat.conferenceRoom.id, {
423
+ callerId: this.myPeer.clientId,
424
+ chatId: this.openedChat.id
463
425
  });
464
- };
465
- RTSeeMessenger.prototype.loadChats = function () {
426
+ }
427
+ loadChats() {
466
428
  this.loadingChatsInProgress = true;
467
429
  this.signalingClient.emitEvent({
468
- name: messenger_1.RTSeeMessengerEvents.GET_CHATS,
430
+ name: RTSeeMessengerEvents.GET_CHATS,
469
431
  data: {
470
432
  limit: DEFAULT_CHATS_FETCH_STEP,
471
433
  offset: this.chats.length,
472
434
  },
473
435
  });
474
- };
475
- RTSeeMessenger.prototype.createGroup = function (options) {
476
- var temporaryChatId = core_1.RTSeeCore.uuidv4();
477
- var chatData = {
436
+ }
437
+ createGroup(options) {
438
+ const temporaryChatId = RTSeeCore.uuidv4();
439
+ const chatData = {
478
440
  id: temporaryChatId,
479
- type: common_1.RTSeeChatTypes.GROUP,
441
+ type: RTSeeChatTypes.GROUP,
480
442
  clientId: this.signalingClient.getMyPeerId(),
481
443
  name: options.name,
482
444
  imageUrl: options.imageUrl,
@@ -488,12 +450,12 @@ var RTSeeMessenger = /** @class */ (function (_super) {
488
450
  unreadMessagesCount: 0,
489
451
  };
490
452
  this.addChat(chatData);
491
- };
492
- RTSeeMessenger.prototype.createChannel = function (options) {
493
- var temporaryChatId = core_1.RTSeeCore.uuidv4();
494
- var chatData = {
453
+ }
454
+ createChannel(options) {
455
+ const temporaryChatId = RTSeeCore.uuidv4();
456
+ const chatData = {
495
457
  id: temporaryChatId,
496
- type: common_1.RTSeeChatTypes.CHANNEL,
458
+ type: RTSeeChatTypes.CHANNEL,
497
459
  clientId: this.signalingClient.getMyPeerId(),
498
460
  name: options.name,
499
461
  imageUrl: options.imageUrl,
@@ -505,27 +467,16 @@ var RTSeeMessenger = /** @class */ (function (_super) {
505
467
  unreadMessagesCount: 0,
506
468
  };
507
469
  this.addChat(chatData);
508
- };
509
- RTSeeMessenger.prototype.onRoomCreated = function (room) {
510
- return __awaiter(this, void 0, void 0, function () {
511
- var chat;
512
- return __generator(this, function (_a) {
513
- switch (_a.label) {
514
- case 0:
515
- chat = this.getChatById(room.chatId);
516
- if (!chat) {
517
- return [2 /*return*/];
518
- }
519
- chat.setConferenceRoom(room);
520
- return [4 /*yield*/, this.initializeVideoCall(chat)];
521
- case 1:
522
- _a.sent();
523
- return [2 /*return*/];
524
- }
525
- });
526
- });
527
- };
528
- RTSeeMessenger.prototype.getExistingChat = function (options) {
470
+ }
471
+ async onRoomCreated(room) {
472
+ const chat = this.getChatById(room.chatId);
473
+ if (!chat) {
474
+ return;
475
+ }
476
+ chat.setConferenceRoom(room);
477
+ await this.initializeVideoCall(chat);
478
+ }
479
+ getExistingChat(options) {
529
480
  if (options.chatId) {
530
481
  return this.getChatById(options.chatId);
531
482
  }
@@ -535,8 +486,6 @@ var RTSeeMessenger = /** @class */ (function (_super) {
535
486
  }
536
487
  return this.getChatByReceiverId(options.receiverId);
537
488
  }
538
- };
539
- return RTSeeMessenger;
540
- }(core_1.RTSeeCore));
541
- exports.RTSeeMessenger = RTSeeMessenger;
489
+ }
490
+ }
542
491
  //# sourceMappingURL=RTSeeMessenger.js.map