@rtsee/messenger 0.0.75 → 0.0.79
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/dist/messenger/src/helpers/ChatMemberPermissionsManager.js +32 -34
- package/dist/messenger/src/helpers/ChatMemberPermissionsManager.js.map +1 -1
- package/dist/messenger/src/index.js +3 -19
- package/dist/messenger/src/index.js.map +1 -1
- package/dist/messenger/src/interfaces/ChatEvents.js +2 -5
- package/dist/messenger/src/interfaces/ChatEvents.js.map +1 -1
- package/dist/messenger/src/interfaces/ChatMemberRolePermissions.js +2 -5
- package/dist/messenger/src/interfaces/ChatMemberRolePermissions.js.map +1 -1
- package/dist/messenger/src/interfaces/Component.js +0 -2
- package/dist/messenger/src/interfaces/Messages.js +0 -2
- package/dist/messenger/src/interfaces/MessengerOptions.js +0 -2
- package/dist/messenger/src/interfaces/SearchQueryOptions.js +0 -2
- package/dist/messenger/src/interfaces/index.d.ts +0 -1
- package/dist/messenger/src/interfaces/index.d.ts.map +1 -1
- package/dist/messenger/src/interfaces/index.js +6 -23
- package/dist/messenger/src/interfaces/index.js.map +1 -1
- package/dist/messenger/src/models/RTSeeChat.d.ts +1 -1
- package/dist/messenger/src/models/RTSeeChat.d.ts.map +1 -1
- package/dist/messenger/src/models/RTSeeChat.js +172 -176
- package/dist/messenger/src/models/RTSeeChat.js.map +1 -1
- package/dist/messenger/src/models/RTSeeChatMember.js +12 -10
- package/dist/messenger/src/models/RTSeeChatMember.js.map +1 -1
- package/dist/messenger/src/models/RTSeeMessage.js +32 -24
- package/dist/messenger/src/models/RTSeeMessage.js.map +1 -1
- package/dist/messenger/src/models/RTSeeMessenger.d.ts +14 -3
- package/dist/messenger/src/models/RTSeeMessenger.d.ts.map +1 -1
- package/dist/messenger/src/models/RTSeeMessenger.js +243 -294
- package/dist/messenger/src/models/RTSeeMessenger.js.map +1 -1
- package/dist/messenger/src/models/RTSeeMessengerSearch.d.ts.map +1 -1
- package/dist/messenger/src/models/RTSeeMessengerSearch.js +48 -45
- package/dist/messenger/src/models/RTSeeMessengerSearch.js.map +1 -1
- package/dist/messenger/src/models/index.d.ts +1 -0
- package/dist/messenger/src/models/index.d.ts.map +1 -1
- package/dist/messenger/src/models/index.js +6 -21
- package/dist/messenger/src/models/index.js.map +1 -1
- package/dist/messenger/src/models/remote-actions/MessengerRemoteActions.d.ts +6 -0
- package/dist/messenger/src/models/remote-actions/MessengerRemoteActions.d.ts.map +1 -0
- package/dist/messenger/src/models/remote-actions/MessengerRemoteActions.js +11 -0
- package/dist/messenger/src/models/remote-actions/MessengerRemoteActions.js.map +1 -0
- package/package.json +2 -2
- package/dist/messenger/src/interfaces/RTSeeMessengerEvents.d.ts +0 -20
- package/dist/messenger/src/interfaces/RTSeeMessengerEvents.d.ts.map +0 -1
- package/dist/messenger/src/interfaces/RTSeeMessengerEvents.js +0 -24
- package/dist/messenger/src/interfaces/RTSeeMessengerEvents.js.map +0 -1
|
@@ -1,140 +1,121 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
30
|
+
this.getHistoricalChats = options.getHistoricalChats;
|
|
86
31
|
}
|
|
87
32
|
if (options.videoChat) {
|
|
88
|
-
|
|
33
|
+
this.attachVideoChat(options.videoChat);
|
|
89
34
|
}
|
|
90
|
-
|
|
91
|
-
messenger:
|
|
35
|
+
this.signalingClient.connect({
|
|
36
|
+
messenger: this,
|
|
92
37
|
});
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
97
|
-
this.
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
_this.onFocus();
|
|
83
|
+
}
|
|
84
|
+
attachWindowEvents() {
|
|
85
|
+
window.addEventListener("focus", () => {
|
|
86
|
+
this.onFocus();
|
|
106
87
|
});
|
|
107
|
-
window.addEventListener("blur",
|
|
108
|
-
|
|
88
|
+
window.addEventListener("blur", () => {
|
|
89
|
+
this.onOnBlur();
|
|
109
90
|
});
|
|
110
|
-
}
|
|
111
|
-
|
|
91
|
+
}
|
|
92
|
+
onFocus() {
|
|
112
93
|
this.isInFocus = true;
|
|
113
94
|
if (this.openedChat) {
|
|
114
|
-
|
|
95
|
+
const unseenMessage = this.openedChat.getLastUnseenMessage();
|
|
115
96
|
if (unseenMessage) {
|
|
116
97
|
this.emitMessagesSeen([unseenMessage]);
|
|
117
98
|
}
|
|
118
99
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
100
|
+
}
|
|
101
|
+
onOnBlur() {
|
|
121
102
|
this.isInFocus = false;
|
|
122
|
-
}
|
|
123
|
-
|
|
103
|
+
}
|
|
104
|
+
attachVideoChat(videoChat) {
|
|
124
105
|
this.videoChat = videoChat;
|
|
125
|
-
}
|
|
126
|
-
|
|
106
|
+
}
|
|
107
|
+
onReady() {
|
|
127
108
|
if (this.getHistoricalChats) {
|
|
128
109
|
this.loadChats();
|
|
129
110
|
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
111
|
+
}
|
|
112
|
+
openChatByPeer(peer) {
|
|
113
|
+
let chat = this.getChatByReceiverId(peer.clientId);
|
|
133
114
|
if (!chat) {
|
|
134
|
-
|
|
135
|
-
|
|
115
|
+
const temporaryChatId = RTSeeCore.uuidv4();
|
|
116
|
+
const chatData = {
|
|
136
117
|
id: temporaryChatId,
|
|
137
|
-
type:
|
|
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
|
|
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:
|
|
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
|
-
|
|
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(
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
157
|
+
}
|
|
158
|
+
closeChat() {
|
|
178
159
|
this.openedChat = null;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
messages.forEach(function (message) {
|
|
174
|
+
}
|
|
175
|
+
emitMessagesReceived(messages) {
|
|
176
|
+
messages.forEach((message) => {
|
|
197
177
|
if (message.chatId) {
|
|
198
|
-
|
|
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
|
-
|
|
208
|
-
name:
|
|
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
|
-
|
|
196
|
+
}
|
|
197
|
+
emitMessagesSeen(messages) {
|
|
218
198
|
if (!messages.length) {
|
|
219
199
|
return;
|
|
220
200
|
}
|
|
221
|
-
|
|
222
|
-
messages: messages.map(
|
|
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:
|
|
211
|
+
name: RTSeeMessengerEvents.INCOMING_MESSAGES_SEEN,
|
|
232
212
|
data: messageSeenData,
|
|
233
213
|
});
|
|
234
|
-
messages.forEach(
|
|
235
|
-
e.setStatus(
|
|
214
|
+
messages.forEach((e) => {
|
|
215
|
+
e.setStatus(RTSeeMessageStatus.SEEN);
|
|
236
216
|
});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
217
|
+
}
|
|
218
|
+
handleMessageReceivedEvent(options) {
|
|
219
|
+
const chat = this.getChatById(options.chatId);
|
|
240
220
|
if (!chat) {
|
|
241
221
|
return;
|
|
242
222
|
}
|
|
243
|
-
options.messagesIds.forEach(
|
|
244
|
-
|
|
223
|
+
options.messagesIds.forEach((e) => {
|
|
224
|
+
const message = chat.getMessageById(e);
|
|
245
225
|
if (message) {
|
|
246
|
-
message.setStatus(
|
|
226
|
+
message.setStatus(RTSeeMessageStatus.DELIVERED);
|
|
247
227
|
}
|
|
248
228
|
});
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
|
|
258
|
-
|
|
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
|
-
|
|
265
|
-
|
|
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
|
-
|
|
252
|
+
}
|
|
253
|
+
getRemoteChat(chatId) {
|
|
274
254
|
this.signalingClient.emitEvent({
|
|
275
|
-
name:
|
|
255
|
+
name: RTSeeMessengerEvents.GET_CHAT,
|
|
276
256
|
data: {
|
|
277
257
|
id: chatId,
|
|
278
258
|
},
|
|
279
259
|
});
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return (this.chats.find(
|
|
260
|
+
}
|
|
261
|
+
getChatByReceiverId(id) {
|
|
262
|
+
return (this.chats.find((e) => {
|
|
283
263
|
return e.type === "individual" && e.receiverId === id;
|
|
284
264
|
}) || null);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return (this.chats.find(
|
|
265
|
+
}
|
|
266
|
+
getChatByTemporaryId(id) {
|
|
267
|
+
return (this.chats.find((e) => {
|
|
288
268
|
return e.id === id && e.isPreset === true;
|
|
289
269
|
}) || null);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
return this.chats.find(
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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
|
-
|
|
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
|
-
|
|
306
|
+
const myPeer = this.signalingClient.getMyPeer();
|
|
325
307
|
console.log('getMeAsChatMember My Peer here, ', myPeer);
|
|
326
|
-
return new
|
|
308
|
+
return new RTSeeChatMember({
|
|
327
309
|
id: this.clientId,
|
|
328
|
-
chatId
|
|
310
|
+
chatId,
|
|
329
311
|
name: myPeer.name,
|
|
330
312
|
url: myPeer.url,
|
|
331
313
|
imageUrl: myPeer.imageUrl,
|
|
332
|
-
role:
|
|
314
|
+
role: RTSeeChatMemberRoles.MEMBER,
|
|
333
315
|
});
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
|
|
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
|
-
|
|
325
|
+
}
|
|
326
|
+
onCallCreated(call, options) {
|
|
345
327
|
if (!options.chatId) {
|
|
346
328
|
return;
|
|
347
329
|
}
|
|
348
|
-
|
|
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
|
-
|
|
343
|
+
}
|
|
344
|
+
onChatsLoaded(result) {
|
|
363
345
|
this.loadingChatsInProgress = false;
|
|
364
346
|
this.unreadMessagesCount = result.unreadCount;
|
|
365
347
|
this.populateChats(result.chats);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
|
|
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
|
-
|
|
377
|
-
|
|
378
|
-
var messagesSeenOptions = {
|
|
357
|
+
}
|
|
358
|
+
markMessagesAsSeen(messages) {
|
|
359
|
+
const messagesSeenOptions = {
|
|
379
360
|
messages: [],
|
|
380
361
|
};
|
|
381
|
-
messages.forEach(
|
|
382
|
-
if (e.status !==
|
|
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:
|
|
372
|
+
name: RTSeeMessengerEvents.INCOMING_MESSAGES_SEEN,
|
|
392
373
|
data: messagesSeenOptions,
|
|
393
374
|
});
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
375
|
+
}
|
|
376
|
+
onMessageSendSuccess(messageData) {
|
|
377
|
+
const chat = this.getChatById(messageData.chatId);
|
|
378
|
+
const tempChat = this.getChatByTemporaryId(messageData.temporaryChatId);
|
|
398
379
|
if (chat) {
|
|
399
|
-
|
|
380
|
+
const message = chat.getMessageByTemporaryId(messageData.temporaryId);
|
|
400
381
|
if (message) {
|
|
401
382
|
message.onSendSuccess(messageData);
|
|
402
383
|
}
|
|
403
384
|
else {
|
|
404
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
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
|
-
|
|
426
|
+
}
|
|
427
|
+
loadChats() {
|
|
466
428
|
this.loadingChatsInProgress = true;
|
|
467
429
|
this.signalingClient.emitEvent({
|
|
468
|
-
name:
|
|
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
|
-
|
|
476
|
-
|
|
477
|
-
|
|
436
|
+
}
|
|
437
|
+
createGroup(options) {
|
|
438
|
+
const temporaryChatId = RTSeeCore.uuidv4();
|
|
439
|
+
const chatData = {
|
|
478
440
|
id: temporaryChatId,
|
|
479
|
-
type:
|
|
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
|
-
|
|
493
|
-
|
|
494
|
-
|
|
453
|
+
}
|
|
454
|
+
createChannel(options) {
|
|
455
|
+
const temporaryChatId = RTSeeCore.uuidv4();
|
|
456
|
+
const chatData = {
|
|
495
457
|
id: temporaryChatId,
|
|
496
|
-
type:
|
|
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
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
return
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
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
|
-
|
|
540
|
-
}(core_1.RTSeeCore));
|
|
541
|
-
exports.RTSeeMessenger = RTSeeMessenger;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
542
491
|
//# sourceMappingURL=RTSeeMessenger.js.map
|