agora-appbuilder-core 4.0.21 → 4.0.22-beta-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/src/components/chat/chatConfigure.native.tsx +23 -13
- package/template/src/components/chat/chatConfigure.tsx +52 -30
- package/template/src/subComponents/ChatInput.native.tsx +2 -4
- package/template/src/subComponents/ChatInput.tsx +2 -6
- package/template/src/subComponents/chat/ChatActionMenu.tsx +2 -8
- package/template/src/subComponents/chat/ChatAttachment.native.tsx +4 -10
- package/template/src/subComponents/chat/ChatSendButton.tsx +2 -4
- package/template/src/subComponents/chat/ImagePopup.tsx +2 -8
package/package.json
CHANGED
|
@@ -29,6 +29,7 @@ interface ChatMessageAttributes {
|
|
|
29
29
|
file_name?: string;
|
|
30
30
|
file_url?: string;
|
|
31
31
|
from_platform?: string;
|
|
32
|
+
channel?: string;
|
|
32
33
|
}
|
|
33
34
|
interface chatConfigureContextInterface {
|
|
34
35
|
open: boolean;
|
|
@@ -65,7 +66,7 @@ const ChatConfigure = ({children}) => {
|
|
|
65
66
|
const chatClient = ChatClient.getInstance();
|
|
66
67
|
const chatManager = chatClient.chatManager;
|
|
67
68
|
|
|
68
|
-
const localUid = data?.
|
|
69
|
+
const localUid = data?.uid?.toString();
|
|
69
70
|
const agoraToken = data?.chat?.user_token;
|
|
70
71
|
const {store} = React.useContext(StorageContext);
|
|
71
72
|
const {
|
|
@@ -119,11 +120,14 @@ const ChatConfigure = ({children}) => {
|
|
|
119
120
|
messages[0].chatType === ChatMessageChatType.PeerChat;
|
|
120
121
|
const {msgId, from, body, localTime} = messages[0];
|
|
121
122
|
const chatType = body.type;
|
|
122
|
-
const fromUser = from
|
|
123
|
-
const {file_ext, file_name, file_url, from_platform} =
|
|
124
|
-
.attributes as ChatMessageAttributes;
|
|
123
|
+
const fromUser = from;
|
|
124
|
+
const {file_ext, file_name, file_url, from_platform, channel} =
|
|
125
|
+
messages[0].attributes as ChatMessageAttributes;
|
|
125
126
|
|
|
126
|
-
|
|
127
|
+
// prevent cross channel msgs
|
|
128
|
+
if (channel !== data.channel) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
127
131
|
|
|
128
132
|
switch (chatType) {
|
|
129
133
|
case ChatMessageType.TXT:
|
|
@@ -277,7 +281,7 @@ const ChatConfigure = ({children}) => {
|
|
|
277
281
|
logger.log(
|
|
278
282
|
LogSource.Internals,
|
|
279
283
|
'CHAT',
|
|
280
|
-
`Logged in User ${localUid} to Agora Chat Server`,
|
|
284
|
+
`Logged in Native User ${localUid} to Agora Chat Server`,
|
|
281
285
|
);
|
|
282
286
|
setupMessageListener();
|
|
283
287
|
// adding chat connection event listeners
|
|
@@ -291,6 +295,11 @@ const ChatConfigure = ({children}) => {
|
|
|
291
295
|
onConnected() {
|
|
292
296
|
console.warn('onConnected');
|
|
293
297
|
// once sdk connects to chat server successfully , need to add message listeners
|
|
298
|
+
logger.log(
|
|
299
|
+
LogSource.Internals,
|
|
300
|
+
'CHAT',
|
|
301
|
+
`Native User ${localUid} to connected to Agora Chat Server`,
|
|
302
|
+
);
|
|
294
303
|
},
|
|
295
304
|
onDisconnected() {
|
|
296
305
|
console.warn('onDisconnected:');
|
|
@@ -305,7 +314,7 @@ const ChatConfigure = ({children}) => {
|
|
|
305
314
|
logger.error(
|
|
306
315
|
LogSource.Internals,
|
|
307
316
|
'CHAT',
|
|
308
|
-
`Failed
|
|
317
|
+
`Failed Logging Native User ${localUid} from Agora Chat Server`,
|
|
309
318
|
error,
|
|
310
319
|
);
|
|
311
320
|
}
|
|
@@ -334,6 +343,9 @@ const ChatConfigure = ({children}) => {
|
|
|
334
343
|
switch (type) {
|
|
335
344
|
case ChatMessageType.TXT:
|
|
336
345
|
chatMsg = ChatMessage.createTextMessage(to, msg, chatMsgChatType);
|
|
346
|
+
chatMsg.attributes = {
|
|
347
|
+
channel: data.channel,
|
|
348
|
+
};
|
|
337
349
|
break;
|
|
338
350
|
case ChatMessageType.IMAGE:
|
|
339
351
|
chatMsg = ChatMessage.createImageMessage(to, url, chatMsgChatType);
|
|
@@ -343,6 +355,7 @@ const ChatConfigure = ({children}) => {
|
|
|
343
355
|
file_name: option?.ext?.file_name,
|
|
344
356
|
file_url: option?.ext?.file_url, // this local url , when upload util is available for native then will use it
|
|
345
357
|
from_platform: 'native',
|
|
358
|
+
channel: data.channel,
|
|
346
359
|
};
|
|
347
360
|
|
|
348
361
|
console.warn('Image msg to be sent', chatMsg);
|
|
@@ -358,6 +371,7 @@ const ChatConfigure = ({children}) => {
|
|
|
358
371
|
file_name: option?.ext?.file_name,
|
|
359
372
|
file_url: option?.url, // this local url , when upload util is available for native then will use it
|
|
360
373
|
from_platform: 'native',
|
|
374
|
+
channel: data.channel,
|
|
361
375
|
};
|
|
362
376
|
console.warn('File msg to be sent', chatMsg);
|
|
363
377
|
break;
|
|
@@ -381,13 +395,9 @@ const ChatConfigure = ({children}) => {
|
|
|
381
395
|
|
|
382
396
|
// this is local user messages
|
|
383
397
|
if (option.chatType === SDKChatType.SINGLE_CHAT) {
|
|
384
|
-
addMessageToPrivateStore(
|
|
385
|
-
Number(option.to.split('_')[1]),
|
|
386
|
-
messageData,
|
|
387
|
-
true,
|
|
388
|
-
);
|
|
398
|
+
addMessageToPrivateStore(Number(option.to), messageData, true);
|
|
389
399
|
} else {
|
|
390
|
-
addMessageToStore(Number(option.from
|
|
400
|
+
addMessageToStore(Number(option.from), messageData);
|
|
391
401
|
}
|
|
392
402
|
}
|
|
393
403
|
})
|
|
@@ -77,6 +77,8 @@ const ChatConfigure = ({children}) => {
|
|
|
77
77
|
useEffect(() => {
|
|
78
78
|
const initializeChatSDK = async () => {
|
|
79
79
|
try {
|
|
80
|
+
// disable Chat SDK logs
|
|
81
|
+
AgoraChat.logger.disableAll();
|
|
80
82
|
const CHAT_APP_KEY = `${$config.CHAT_ORG_NAME}#${$config.CHAT_APP_NAME}`;
|
|
81
83
|
// Initializes the Web client.
|
|
82
84
|
newConn = new AgoraChat.connection({
|
|
@@ -84,10 +86,10 @@ const ChatConfigure = ({children}) => {
|
|
|
84
86
|
});
|
|
85
87
|
// Logs into Agora Chat.
|
|
86
88
|
const result = await newConn.open({
|
|
87
|
-
user: data?.
|
|
89
|
+
user: data?.uid?.toString(),
|
|
88
90
|
agoraToken: data.chat.user_token,
|
|
89
91
|
});
|
|
90
|
-
logger.
|
|
92
|
+
logger.log(
|
|
91
93
|
LogSource.Internals,
|
|
92
94
|
'CHAT',
|
|
93
95
|
`Logged in User ${data.uid} to Agora Chat Server`,
|
|
@@ -97,16 +99,29 @@ const ChatConfigure = ({children}) => {
|
|
|
97
99
|
newConn.addEventHandler('connection&message', {
|
|
98
100
|
// app is connected to chat server
|
|
99
101
|
onConnected: () => {
|
|
100
|
-
|
|
102
|
+
logger.log(
|
|
103
|
+
LogSource.Internals,
|
|
104
|
+
'CHAT',
|
|
105
|
+
`User ${data.uid} connected to Agora Chat Server`,
|
|
106
|
+
);
|
|
101
107
|
},
|
|
102
108
|
|
|
103
109
|
onFileMessage: message => {
|
|
110
|
+
if (message?.ext?.channel !== data?.channel) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
logger.debug(
|
|
114
|
+
LogSource.Internals,
|
|
115
|
+
'CHAT',
|
|
116
|
+
`Received File Message`,
|
|
117
|
+
message,
|
|
118
|
+
);
|
|
104
119
|
const fileUrl =
|
|
105
120
|
message.ext?.from_platform === 'native'
|
|
106
121
|
? message.url
|
|
107
122
|
: message.ext.file_url;
|
|
108
123
|
|
|
109
|
-
const fromUser = message?.from
|
|
124
|
+
const fromUser = message?.from;
|
|
110
125
|
|
|
111
126
|
if (message.chatType === SDKChatType.GROUP_CHAT) {
|
|
112
127
|
showMessageNotification(
|
|
@@ -151,12 +166,21 @@ const ChatConfigure = ({children}) => {
|
|
|
151
166
|
}
|
|
152
167
|
},
|
|
153
168
|
onImageMessage: message => {
|
|
169
|
+
if (message?.ext?.channel !== data?.channel) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
logger.debug(
|
|
173
|
+
LogSource.Internals,
|
|
174
|
+
'CHAT',
|
|
175
|
+
`Received Img Message`,
|
|
176
|
+
message,
|
|
177
|
+
);
|
|
154
178
|
const fileUrl =
|
|
155
179
|
message.ext?.from_platform === 'native'
|
|
156
180
|
? message.url
|
|
157
181
|
: message.ext.file_url;
|
|
158
182
|
|
|
159
|
-
const fromUser = message?.from
|
|
183
|
+
const fromUser = message?.from;
|
|
160
184
|
|
|
161
185
|
if (message.chatType === SDKChatType.GROUP_CHAT) {
|
|
162
186
|
showMessageNotification(
|
|
@@ -203,14 +227,17 @@ const ChatConfigure = ({children}) => {
|
|
|
203
227
|
},
|
|
204
228
|
// text message is recieved
|
|
205
229
|
onTextMessage: message => {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
230
|
+
if (message?.ext?.channel !== data?.channel) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
logger.debug(
|
|
234
|
+
LogSource.Internals,
|
|
235
|
+
'CHAT',
|
|
236
|
+
`Received Text Message`,
|
|
237
|
+
message,
|
|
211
238
|
);
|
|
212
239
|
|
|
213
|
-
const fromUser = message?.from
|
|
240
|
+
const fromUser = message?.from;
|
|
214
241
|
|
|
215
242
|
if (message.chatType === SDKChatType.GROUP_CHAT) {
|
|
216
243
|
// show to notifcation- group msg received
|
|
@@ -262,20 +289,14 @@ const ChatConfigure = ({children}) => {
|
|
|
262
289
|
},
|
|
263
290
|
// on token expired
|
|
264
291
|
onTokenExpired: () => {
|
|
265
|
-
|
|
292
|
+
logger.log(LogSource.Internals, 'CHAT', 'ChatSDK Token expired');
|
|
266
293
|
},
|
|
267
294
|
onError: error => {
|
|
268
|
-
|
|
295
|
+
logger.error(LogSource.Internals, 'CHAT', 'ChatSDK Error', error);
|
|
269
296
|
},
|
|
270
297
|
});
|
|
271
298
|
connRef.current = newConn;
|
|
272
|
-
logger.debug(LogSource.Internals, 'CHAT', 'Initialized Chat SDK');
|
|
273
299
|
} catch (error) {
|
|
274
|
-
console.log(
|
|
275
|
-
'%cChatSDK: initialization error: %s',
|
|
276
|
-
'color: red',
|
|
277
|
-
JSON.stringify(error, null, 2),
|
|
278
|
-
);
|
|
279
300
|
logger.error(
|
|
280
301
|
LogSource.Internals,
|
|
281
302
|
'CHAT',
|
|
@@ -289,7 +310,7 @@ const ChatConfigure = ({children}) => {
|
|
|
289
310
|
initializeChatSDK();
|
|
290
311
|
return () => {
|
|
291
312
|
newConn.close();
|
|
292
|
-
logger.
|
|
313
|
+
logger.log(
|
|
293
314
|
LogSource.Internals,
|
|
294
315
|
'CHAT',
|
|
295
316
|
`Logging out User ${data.uid} from Agora Chat Server`,
|
|
@@ -304,6 +325,9 @@ const ChatConfigure = ({children}) => {
|
|
|
304
325
|
if (connRef.current) {
|
|
305
326
|
//TODO thumb and url of actual image uploaded available in file upload complete
|
|
306
327
|
const localFileUrl = option?.ext?.file_url || '';
|
|
328
|
+
//add channel name so to prevent cross channel message mixup when same user joins two diff channels
|
|
329
|
+
// this is filtered on msgRecived event
|
|
330
|
+
option.ext = {...option?.ext, channel: data?.channel};
|
|
307
331
|
//@ts-ignore
|
|
308
332
|
const msg = AgoraChat.message.create(option);
|
|
309
333
|
connRef.current
|
|
@@ -331,13 +355,9 @@ const ChatConfigure = ({children}) => {
|
|
|
331
355
|
//todo chattype as per natue type
|
|
332
356
|
// this is local user messages
|
|
333
357
|
if (option.chatType === SDKChatType.SINGLE_CHAT) {
|
|
334
|
-
addMessageToPrivateStore(
|
|
335
|
-
Number(option?.to.split('_')[1]),
|
|
336
|
-
messageData,
|
|
337
|
-
true,
|
|
338
|
-
);
|
|
358
|
+
addMessageToPrivateStore(Number(option?.to), messageData, true);
|
|
339
359
|
} else {
|
|
340
|
-
addMessageToStore(Number(option?.from
|
|
360
|
+
addMessageToStore(Number(option?.from), messageData);
|
|
341
361
|
}
|
|
342
362
|
})
|
|
343
363
|
.catch(error => {
|
|
@@ -402,11 +422,9 @@ const ChatConfigure = ({children}) => {
|
|
|
402
422
|
const CHAT_APP_KEY = `${$config.CHAT_ORG_NAME}#${$config.CHAT_APP_NAME}`;
|
|
403
423
|
const uploadObj = {
|
|
404
424
|
onFileUploadProgress: (data: ProgressEvent) => {
|
|
405
|
-
console.log('Chat-SDK: upload inprogress', data);
|
|
406
425
|
setUploadStatus(UploadStatus.IN_PROGRESS);
|
|
407
426
|
},
|
|
408
427
|
onFileUploadComplete: (data: any) => {
|
|
409
|
-
console.log('Chat-SDK: upload success', data);
|
|
410
428
|
const url = `${data.uri}/${data.entities[0].uuid}?em-redirect=true&share-secret=${data.entities[0]['share-secret']}`;
|
|
411
429
|
//TODO: handle for multiple uploads
|
|
412
430
|
setUploadedFiles(prev => {
|
|
@@ -415,7 +433,6 @@ const ChatConfigure = ({children}) => {
|
|
|
415
433
|
setUploadStatus(UploadStatus.SUCCESS);
|
|
416
434
|
},
|
|
417
435
|
onFileUploadError: (error: any) => {
|
|
418
|
-
console.log('Chat-SDK: upload error', error);
|
|
419
436
|
logger.error(LogSource.Internals, 'CHAT', 'Attachment upload failed');
|
|
420
437
|
setUploadStatus(UploadStatus.FAILURE);
|
|
421
438
|
},
|
|
@@ -451,7 +468,12 @@ const ChatConfigure = ({children}) => {
|
|
|
451
468
|
connRef.current
|
|
452
469
|
.recallMessage(option)
|
|
453
470
|
.then(res => {
|
|
454
|
-
|
|
471
|
+
logger.debug(
|
|
472
|
+
LogSource.Internals,
|
|
473
|
+
'CHAT',
|
|
474
|
+
'Chat Message Reacalled Success',
|
|
475
|
+
res,
|
|
476
|
+
);
|
|
455
477
|
})
|
|
456
478
|
.catch(err => {
|
|
457
479
|
logger.debug(
|
|
@@ -150,10 +150,8 @@ export const ChatTextInput = (props: ChatTextInputProps) => {
|
|
|
150
150
|
? SDKChatType.SINGLE_CHAT
|
|
151
151
|
: SDKChatType.GROUP_CHAT,
|
|
152
152
|
type: ChatMessageType.TXT,
|
|
153
|
-
from: data.
|
|
154
|
-
to: privateChatUser
|
|
155
|
-
? data.channel + '_' + privateChatUser.toString()
|
|
156
|
-
: groupID,
|
|
153
|
+
from: data.uid.toString(),
|
|
154
|
+
to: privateChatUser ? privateChatUser.toString() : groupID,
|
|
157
155
|
msg: message,
|
|
158
156
|
};
|
|
159
157
|
sendChatSDKMessage(option);
|
|
@@ -145,17 +145,13 @@ export const ChatTextInput = (props: ChatTextInputProps) => {
|
|
|
145
145
|
return;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
debugger;
|
|
149
|
-
console.log(data);
|
|
150
148
|
const option = {
|
|
151
149
|
chatType: privateChatUser
|
|
152
150
|
? SDKChatType.SINGLE_CHAT
|
|
153
151
|
: SDKChatType.GROUP_CHAT,
|
|
154
152
|
type: ChatMessageType.TXT,
|
|
155
|
-
from: data.
|
|
156
|
-
to: privateChatUser
|
|
157
|
-
? data.channel + '_' + privateChatUser.toString()
|
|
158
|
-
: groupID,
|
|
153
|
+
from: data.uid.toString(),
|
|
154
|
+
to: privateChatUser ? privateChatUser.toString() : groupID,
|
|
159
155
|
msg: message,
|
|
160
156
|
};
|
|
161
157
|
sendChatSDKMessage(option);
|
|
@@ -62,7 +62,7 @@ export const ChatActionMenu = (props: CaptionsActionMenuProps) => {
|
|
|
62
62
|
const {defaultContent} = useContent();
|
|
63
63
|
|
|
64
64
|
const {
|
|
65
|
-
data: {isHost, chat
|
|
65
|
+
data: {isHost, chat},
|
|
66
66
|
} = useRoomInfo();
|
|
67
67
|
|
|
68
68
|
const groupID = chat.group_id;
|
|
@@ -167,13 +167,7 @@ export const ChatActionMenu = (props: CaptionsActionMenuProps) => {
|
|
|
167
167
|
confirmLabel={confirmLabel}
|
|
168
168
|
confirmLabelStyle={{color: $config.SEMANTIC_ERROR}}
|
|
169
169
|
onConfirmClick={() => {
|
|
170
|
-
deleteAttachment(
|
|
171
|
-
msgId,
|
|
172
|
-
privateChatUser
|
|
173
|
-
? channel + '_' + recallFromUser
|
|
174
|
-
: recallFromUser.toString(),
|
|
175
|
-
chatType,
|
|
176
|
-
);
|
|
170
|
+
deleteAttachment(msgId, recallFromUser.toString(), chatType);
|
|
177
171
|
if (chatType === SDKChatType.SINGLE_CHAT) {
|
|
178
172
|
removeMessageFromPrivateStore(msgId, isLocal);
|
|
179
173
|
}
|
|
@@ -128,13 +128,11 @@ export const ChatAttachmentButton = (props: ChatAttachmentButtonProps) => {
|
|
|
128
128
|
const option = {
|
|
129
129
|
type: isImageUploaded ? ChatMessageType.IMAGE : ChatMessageType.FILE,
|
|
130
130
|
url: filePath,
|
|
131
|
-
to: privateChatUser
|
|
132
|
-
? data.channel + '_' + privateChatUser.toString()
|
|
133
|
-
: groupID,
|
|
131
|
+
to: privateChatUser ? privateChatUser.toString() : groupID,
|
|
134
132
|
chatType: privateChatUser
|
|
135
133
|
? SDKChatType.SINGLE_CHAT
|
|
136
134
|
: SDKChatType.GROUP_CHAT,
|
|
137
|
-
from: data.
|
|
135
|
+
from: data.uid.toString(),
|
|
138
136
|
fileName: result[0].name,
|
|
139
137
|
ext: {
|
|
140
138
|
file_length: result[0].size,
|
|
@@ -173,13 +171,9 @@ export const ChatAttachmentButton = (props: ChatAttachmentButtonProps) => {
|
|
|
173
171
|
|
|
174
172
|
// this is local user messages
|
|
175
173
|
if (message.chatType === ChatMessageChatType.PeerChat) {
|
|
176
|
-
addMessageToPrivateStore(
|
|
177
|
-
Number(message.to.split('_')[1]),
|
|
178
|
-
messageData,
|
|
179
|
-
true,
|
|
180
|
-
);
|
|
174
|
+
addMessageToPrivateStore(Number(message.to), messageData, true);
|
|
181
175
|
} else {
|
|
182
|
-
addMessageToStore(Number(message.from
|
|
176
|
+
addMessageToStore(Number(message.from), messageData);
|
|
183
177
|
}
|
|
184
178
|
|
|
185
179
|
setUploadStatus(UploadStatus.SUCCESS);
|
|
@@ -80,10 +80,8 @@ const ChatSendButton = (props: ChatSendButtonProps) => {
|
|
|
80
80
|
: SDKChatType.GROUP_CHAT,
|
|
81
81
|
type: msgType as ChatMessageType,
|
|
82
82
|
msg: msgType === ChatMessageType.TXT ? message : '', // currenlt not supporting combinarion msg (file+txt)
|
|
83
|
-
from: data.
|
|
84
|
-
to: selectedUserId
|
|
85
|
-
? data.channel + '_' + selectedUserId.toString()
|
|
86
|
-
: groupID,
|
|
83
|
+
from: data.uid.toString(),
|
|
84
|
+
to: selectedUserId ? selectedUserId.toString() : groupID,
|
|
87
85
|
ext: {
|
|
88
86
|
file_length,
|
|
89
87
|
file_ext,
|
|
@@ -61,7 +61,7 @@ const ImagePopup = (props: ImagePopupProps) => {
|
|
|
61
61
|
React.useState(false);
|
|
62
62
|
const {privateChatUser} = useChatUIControls();
|
|
63
63
|
const {
|
|
64
|
-
data: {isHost, chat
|
|
64
|
+
data: {isHost, chat},
|
|
65
65
|
} = useRoomInfo();
|
|
66
66
|
const {downloadAttachment, deleteAttachment} = useChatConfigure();
|
|
67
67
|
const {removeMessageFromPrivateStore, removeMessageFromStore} =
|
|
@@ -284,13 +284,7 @@ const ImagePopup = (props: ImagePopupProps) => {
|
|
|
284
284
|
confirmLabel={confirmLabel}
|
|
285
285
|
confirmLabelStyle={{color: $config.SEMANTIC_ERROR}}
|
|
286
286
|
onConfirmClick={() => {
|
|
287
|
-
deleteAttachment(
|
|
288
|
-
msgId,
|
|
289
|
-
privateChatUser
|
|
290
|
-
? channel + '_' + recallFromUser
|
|
291
|
-
: recallFromUser.toString(),
|
|
292
|
-
chatType,
|
|
293
|
-
);
|
|
287
|
+
deleteAttachment(msgId, recallFromUser.toString(), chatType);
|
|
294
288
|
if (chatType === SDKChatType.SINGLE_CHAT) {
|
|
295
289
|
removeMessageFromPrivateStore(msgId, isLocal);
|
|
296
290
|
}
|