@phonghq/go-chat 1.0.56 → 1.0.58
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/assets/icons/call/IconClock.vue.d.ts +2 -0
- package/dist/assets/icons/call/IconClock.vue.js +22 -0
- package/dist/chat/App.vue.js +30 -9
- package/dist/chat/page/home/ChatList.vue.d.ts +4 -0
- package/dist/chat/page/home/ChatList.vue.js +4 -2
- package/dist/chat/page/home/ChatMessage.vue.d.ts +1 -0
- package/dist/chat/page/home/ChatMessage.vue.js +27 -7
- package/dist/chat/page/home/ChatMessageItem.vue.js +31 -16
- package/dist/chat/page/home/DropZone.vue.d.ts +13 -0
- package/dist/chat/page/home/DropZone.vue.js +130 -0
- package/dist/chat/page/home/Home.vue.d.ts +1 -0
- package/dist/chat/page/home/Home.vue.js +71 -20
- package/dist/chat/page/home/HomeHeader.vue.js +7 -5
- package/dist/chat/page/home/InputChat.vue.js +139 -70
- package/dist/chat/page/home/PhoneNumpad.vue.js +2 -0
- package/dist/components/chat/call/Calling.vue.js +82 -73
- package/dist/components/chat/call/TimeLeft.vue.d.ts +5 -0
- package/dist/components/chat/call/TimeLeft.vue.js +59 -0
- package/dist/composable/useInitData.js +2 -2
- package/dist/composable/useListConversations.d.ts +2 -0
- package/dist/composable/useListConversations.js +54 -11
- package/dist/composable/usePlivo.d.ts +1 -0
- package/dist/composable/usePlivo.js +31 -9
- package/dist/constant/mqtt.d.ts +1 -0
- package/dist/constant/mqtt.js +3 -0
- package/dist/go-chat.es.js +40729 -40475
- package/dist/go-chat.umd.js +23 -23
- package/dist/plugins/mqtt.js +5 -7
- package/dist/style.css +1 -1
- package/dist/types/chat/auth.d.ts +0 -1
- package/dist/types/chat/call.d.ts +1 -0
- package/dist/types/chat/call.js +1 -0
- package/dist/types/chat/global.d.ts +3 -1
- package/dist/types/message.d.ts +1 -0
- package/dist/utils/chat/store/auth.d.ts +0 -2
- package/dist/utils/chat/store/auth.js +7 -7
- package/dist/utils/chat/store/conversation.js +1 -1
- package/dist/utils/chat/store/message.d.ts +4 -0
- package/dist/utils/chat/store/message.js +4 -0
- package/dist/views/home/phone-numpad/PhoneNumpad.vue.js +3 -0
- package/package.json +1 -1
|
@@ -16,35 +16,37 @@ import IconMic from '../../../assets/icons/call/IconMic.vue';
|
|
|
16
16
|
import { useDebounce } from '../../../utils/debounce';
|
|
17
17
|
import { phoneNumberFormat } from '../../../utils/string-helper';
|
|
18
18
|
import { handleMedialPermissionError, showPageError } from '../../../utils/chat/page-error';
|
|
19
|
+
import RingAudio from '../../../assets/sound/telephone-2.mp3';
|
|
20
|
+
import TimeLeft from '../../../components/chat/call/TimeLeft.vue';
|
|
19
21
|
const props = withDefaults(defineProps(), {
|
|
20
22
|
responsive: 'window'
|
|
21
23
|
});
|
|
22
24
|
const emit = defineEmits();
|
|
23
25
|
const handlePlivoCallBack = (status, data) => {
|
|
26
|
+
callStatus.value = status;
|
|
24
27
|
if (status == PLIVO_CALL_STATUS.RINGING) {
|
|
28
|
+
handleInComingCall(data);
|
|
29
|
+
}
|
|
30
|
+
else if (status == PLIVO_CALL_STATUS.CHECK_USER_OFFER) {
|
|
25
31
|
getUserOffer(data?.phone ?? '');
|
|
26
|
-
callStatus.value = PLIVO_CALL_STATUS.RINGING;
|
|
27
|
-
open();
|
|
28
32
|
}
|
|
29
33
|
else if (status == PLIVO_CALL_STATUS.CONNECT_FAILED || status == PLIVO_CALL_STATUS.NO_ANSWER) {
|
|
30
34
|
endCall();
|
|
31
|
-
callStatus.value = status;
|
|
32
35
|
}
|
|
33
36
|
else if (status == PLIVO_CALL_STATUS.CALL_END) {
|
|
34
37
|
errorMessage.value = data?.message ?? '';
|
|
35
38
|
const closeModal = data?.reason == 'ORIGINATOR_CANCEL';
|
|
36
39
|
endCall({ closeModal });
|
|
37
|
-
callStatus.value = status;
|
|
38
40
|
}
|
|
39
41
|
else if (status == PLIVO_CALL_STATUS.CALL_START) {
|
|
40
|
-
|
|
42
|
+
audioRef.value?.pause();
|
|
41
43
|
startTimer();
|
|
42
44
|
}
|
|
43
45
|
else if (status == PLIVO_CALL_STATUS.MEDIA_PERMISSION_FAIL) {
|
|
44
46
|
handleMedialPermissionError();
|
|
45
47
|
}
|
|
46
48
|
};
|
|
47
|
-
const { plivoLogin, plivoCallAnswer, plivoCall, plivoEndCall, plivoCallSwishMute, plivoCallSwishSpeaker } = usePlivo(handlePlivoCallBack);
|
|
49
|
+
const { plivoLogin, plivoCallAnswer, plivoCall, plivoEndCall, plivoCallSwishMute, plivoCallSwishSpeaker, checkTimeLimit } = usePlivo(handlePlivoCallBack);
|
|
48
50
|
const STATUS_LABEL = computed(() => {
|
|
49
51
|
return {
|
|
50
52
|
[PLIVO_CALL_STATUS.CONNECTING]: 'Connecting...',
|
|
@@ -57,7 +59,8 @@ const STATUS_LABEL = computed(() => {
|
|
|
57
59
|
[PLIVO_CALL_STATUS.CANCEL]: '',
|
|
58
60
|
[PLIVO_CALL_STATUS.TIME_OUT]: '',
|
|
59
61
|
[PLIVO_CALL_STATUS.BUSY]: '',
|
|
60
|
-
[PLIVO_CALL_STATUS.MEDIA_PERMISSION_FAIL]: ''
|
|
62
|
+
[PLIVO_CALL_STATUS.MEDIA_PERMISSION_FAIL]: '',
|
|
63
|
+
[PLIVO_CALL_STATUS.CHECK_USER_OFFER]: ''
|
|
61
64
|
};
|
|
62
65
|
});
|
|
63
66
|
const label = computed(() => STATUS_LABEL.value[callStatus.value] ?? '');
|
|
@@ -68,8 +71,10 @@ const disable = ref(false);
|
|
|
68
71
|
const errorMessage = ref('');
|
|
69
72
|
const record_link = ref('');
|
|
70
73
|
const drawerVisibleRef = ref(null);
|
|
74
|
+
const audioRef = ref(null);
|
|
71
75
|
const userRemoter = ref(null);
|
|
72
76
|
const isMute = ref(false);
|
|
77
|
+
const limitTime = ref(0);
|
|
73
78
|
let timer = null;
|
|
74
79
|
let timeOut = null;
|
|
75
80
|
let refreshTokenTimeOut = null;
|
|
@@ -78,7 +83,7 @@ let callType = 'call';
|
|
|
78
83
|
let uuidEnd = '';
|
|
79
84
|
onMounted(async () => {
|
|
80
85
|
try {
|
|
81
|
-
if (dataProfile.value?.
|
|
86
|
+
if (dataProfile.value?.phone) {
|
|
82
87
|
const token = await getPlivoAccessToken();
|
|
83
88
|
await plivoLogin({ token });
|
|
84
89
|
setTimeout(refreshToken, 15 * 60 * 1000);
|
|
@@ -101,16 +106,20 @@ function startTimer() {
|
|
|
101
106
|
let sec = 0;
|
|
102
107
|
timer = setInterval(() => {
|
|
103
108
|
sec++;
|
|
109
|
+
limitTime.value = limitTime.value - 1;
|
|
104
110
|
const m = String(Math.floor(sec / 60)).padStart(2, '0');
|
|
105
111
|
const s = String(sec % 60).padStart(2, '0');
|
|
106
112
|
duration.value = `${m}:${s}`;
|
|
113
|
+
if (!limitTime.value || limitTime.value <= 0) {
|
|
114
|
+
handleTimeLimitError();
|
|
115
|
+
}
|
|
107
116
|
}, 1000);
|
|
108
117
|
}
|
|
109
118
|
function endCall(option) {
|
|
110
119
|
if (option?.closeModal) {
|
|
111
|
-
|
|
112
|
-
drawerVisibleRef.value?.close();
|
|
120
|
+
closeModal();
|
|
113
121
|
}
|
|
122
|
+
audioRef.value?.pause();
|
|
114
123
|
handleEmitEndCall(userRemoter.value, callType);
|
|
115
124
|
plivoEndCall(callStatus.value);
|
|
116
125
|
callStatus.value = PLIVO_CALL_STATUS.CALL_END;
|
|
@@ -124,6 +133,10 @@ function endCall(option) {
|
|
|
124
133
|
clearTimeout(timeOut);
|
|
125
134
|
callType = '';
|
|
126
135
|
}
|
|
136
|
+
const closeModal = () => {
|
|
137
|
+
drawerVisible.value = false;
|
|
138
|
+
drawerVisibleRef.value?.close();
|
|
139
|
+
};
|
|
127
140
|
const handleEmitEndCall = useDebounce((data, type) => {
|
|
128
141
|
emit('endCall', data, type);
|
|
129
142
|
}, 500);
|
|
@@ -150,6 +163,16 @@ const refreshToken = async () => {
|
|
|
150
163
|
console.log(e);
|
|
151
164
|
}
|
|
152
165
|
};
|
|
166
|
+
const handleInComingCall = (data) => {
|
|
167
|
+
limitTime.value = data?.limit_time ?? 0;
|
|
168
|
+
if (limitTime.value <= 0) {
|
|
169
|
+
handleTimeLimitError();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
emit('userCalling', userRemoter.value);
|
|
173
|
+
audioRef.value?.play();
|
|
174
|
+
open();
|
|
175
|
+
};
|
|
153
176
|
const open = () => {
|
|
154
177
|
drawerVisible.value = true;
|
|
155
178
|
disable.value = true;
|
|
@@ -169,6 +192,11 @@ const startCall = async (data) => {
|
|
|
169
192
|
callStatus.value = PLIVO_CALL_STATUS.CONNECTING;
|
|
170
193
|
userRemoter.value = data;
|
|
171
194
|
open();
|
|
195
|
+
limitTime.value = await checkTimeLimit();
|
|
196
|
+
if (!limitTime.value || limitTime.value <= 0) {
|
|
197
|
+
handleTimeLimitError();
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
172
200
|
callType = 'call';
|
|
173
201
|
await plivoCall(data.phone);
|
|
174
202
|
callStatus.value = PLIVO_CALL_STATUS.CALLING;
|
|
@@ -194,7 +222,6 @@ const getUserOffer = async (phone) => {
|
|
|
194
222
|
let res = null;
|
|
195
223
|
try {
|
|
196
224
|
userRemoter.value = { phone, username: '' };
|
|
197
|
-
emit('userCalling', userRemoter.value);
|
|
198
225
|
let data = {
|
|
199
226
|
phone: formatPhone10number(phone, '1'),
|
|
200
227
|
client_id: dataProfile.value?.tenant_id ?? ''
|
|
@@ -209,56 +236,14 @@ const getUserOffer = async (phone) => {
|
|
|
209
236
|
phone: res?.phone ? '1' + res?.phone : phone
|
|
210
237
|
};
|
|
211
238
|
userRemoter.value = user;
|
|
212
|
-
if (callStatus.value !== PLIVO_CALL_STATUS.CALL_END) {
|
|
239
|
+
if (callStatus.value !== PLIVO_CALL_STATUS.CALL_END && callStatus.value !== PLIVO_CALL_STATUS.CHECK_USER_OFFER) {
|
|
213
240
|
emit('userCalling', userRemoter.value);
|
|
214
241
|
}
|
|
215
242
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
// if (message?.data?.status == PLIVO_CALL_STATUS.RINGING) {
|
|
221
|
-
// if (message?.data?.to_number == dataProfile.value?.phone) {
|
|
222
|
-
// callStatus.value = PLIVO_CALL_STATUS.RINGING
|
|
223
|
-
// dataWebSK = {
|
|
224
|
-
// from: message.data.from_number,
|
|
225
|
-
// to: message.data.to_number
|
|
226
|
-
// }
|
|
227
|
-
// getUserOffer(message.data.from_number)
|
|
228
|
-
// handleCallAnswer(message)
|
|
229
|
-
// open()
|
|
230
|
-
// }
|
|
231
|
-
// } else if (message?.data?.status == PLIVO_CALL_STATUS.CALL_START) {
|
|
232
|
-
// try {
|
|
233
|
-
// await startIncomingCall(message?.data?.call_uuid)
|
|
234
|
-
// startTimer()
|
|
235
|
-
// callStatus.value = PLIVO_CALL_STATUS.CALL_START
|
|
236
|
-
// } catch (e) {
|
|
237
|
-
// console.log(e)
|
|
238
|
-
// endCall()
|
|
239
|
-
// }
|
|
240
|
-
// } else if (message?.data?.status == PLIVO_CALL_STATUS.CALL_END) {
|
|
241
|
-
// endCall()
|
|
242
|
-
// } else if (
|
|
243
|
-
// message?.data?.status == PLIVO_CALL_STATUS.CONNECT_FAILED ||
|
|
244
|
-
// message?.data?.status == PLIVO_CALL_STATUS.NO_ANSWER
|
|
245
|
-
// ) {
|
|
246
|
-
// endCall()
|
|
247
|
-
// callStatus.value = message?.data?.status
|
|
248
|
-
// } else {
|
|
249
|
-
// // console.log(message)
|
|
250
|
-
// da = false
|
|
251
|
-
// // handleMedia(message)
|
|
252
|
-
// }
|
|
253
|
-
// } else if (message?.event == 'record_uploaded') {
|
|
254
|
-
// if (uuidEnd == message?.data?.call_uuid) {
|
|
255
|
-
// record_link.value = message?.data?.recording_url
|
|
256
|
-
// }
|
|
257
|
-
// }
|
|
258
|
-
//
|
|
259
|
-
// // if (da){
|
|
260
|
-
// // } else console.log('-----------------', message)
|
|
261
|
-
// }
|
|
243
|
+
const handleTimeLimitError = () => {
|
|
244
|
+
errorMessage.value = 'Call time limit reached. This call has ended.';
|
|
245
|
+
endCall();
|
|
246
|
+
};
|
|
262
247
|
const exportRecordFile = async () => {
|
|
263
248
|
downloadRecord(record_link.value);
|
|
264
249
|
};
|
|
@@ -267,7 +252,7 @@ const handleAfterClose = () => {
|
|
|
267
252
|
uuidEnd = '';
|
|
268
253
|
};
|
|
269
254
|
let __VLS_exposed;
|
|
270
|
-
defineExpose({ startCall, endCall, userRemoter, callStatus, answer, label });
|
|
255
|
+
defineExpose({ startCall, endCall, userRemoter, callStatus, answer, label, closeModal });
|
|
271
256
|
debugger; /* PartiallyEnd: #3632/scriptSetup.vue */
|
|
272
257
|
const __VLS_defaults = {
|
|
273
258
|
responsive: 'window'
|
|
@@ -321,6 +306,16 @@ const { default: __VLS_8 } = __VLS_2.slots;
|
|
|
321
306
|
...{ class: "flex flex-col items-center justify-center h-full relative bg-white" },
|
|
322
307
|
...{ style: {} },
|
|
323
308
|
});
|
|
309
|
+
/** @type {[typeof TimeLeft, ]} */ ;
|
|
310
|
+
// @ts-ignore
|
|
311
|
+
const __VLS_10 = __VLS_asFunctionalComponent(TimeLeft, new TimeLeft({
|
|
312
|
+
time: (__VLS_ctx.limitTime),
|
|
313
|
+
}));
|
|
314
|
+
const __VLS_11 = __VLS_10({
|
|
315
|
+
time: (__VLS_ctx.limitTime),
|
|
316
|
+
}, ...__VLS_functionalComponentArgsRest(__VLS_10));
|
|
317
|
+
// @ts-ignore
|
|
318
|
+
[limitTime,];
|
|
324
319
|
__VLS_asFunctionalElement(__VLS_elements.div, __VLS_elements.div)({
|
|
325
320
|
...{ class: "h-40 w-40 call-avatar mb-8" },
|
|
326
321
|
});
|
|
@@ -329,7 +324,7 @@ const { default: __VLS_8 } = __VLS_2.slots;
|
|
|
329
324
|
});
|
|
330
325
|
/** @type {[typeof Avatar, ]} */ ;
|
|
331
326
|
// @ts-ignore
|
|
332
|
-
const
|
|
327
|
+
const __VLS_14 = __VLS_asFunctionalComponent(Avatar, new Avatar({
|
|
333
328
|
...{ class: "bg-white z-[2]" },
|
|
334
329
|
src: (__VLS_ctx.userRemoter?.avatar ?? ''),
|
|
335
330
|
id: (__VLS_ctx.userRemoter?.id ?? ''),
|
|
@@ -337,14 +332,14 @@ const { default: __VLS_8 } = __VLS_2.slots;
|
|
|
337
332
|
name: (__VLS_ctx.userRemoter?.username),
|
|
338
333
|
size: "xxl",
|
|
339
334
|
}));
|
|
340
|
-
const
|
|
335
|
+
const __VLS_15 = __VLS_14({
|
|
341
336
|
...{ class: "bg-white z-[2]" },
|
|
342
337
|
src: (__VLS_ctx.userRemoter?.avatar ?? ''),
|
|
343
338
|
id: (__VLS_ctx.userRemoter?.id ?? ''),
|
|
344
339
|
color: (__VLS_ctx.userRemoter?.color),
|
|
345
340
|
name: (__VLS_ctx.userRemoter?.username),
|
|
346
341
|
size: "xxl",
|
|
347
|
-
}, ...__VLS_functionalComponentArgsRest(
|
|
342
|
+
}, ...__VLS_functionalComponentArgsRest(__VLS_14));
|
|
348
343
|
// @ts-ignore
|
|
349
344
|
[userRemoter, userRemoter, userRemoter, userRemoter,];
|
|
350
345
|
if (__VLS_ctx.callStatus == __VLS_ctx.PLIVO_CALL_STATUS.RINGING || __VLS_ctx.callStatus == __VLS_ctx.PLIVO_CALL_STATUS.CALLING) {
|
|
@@ -371,7 +366,10 @@ const { default: __VLS_8 } = __VLS_2.slots;
|
|
|
371
366
|
[userRemoter, userRemoter, phoneNumberFormat,];
|
|
372
367
|
__VLS_asFunctionalElement(__VLS_elements.p, __VLS_elements.p)({
|
|
373
368
|
...{ class: "text-gray-400 mt-1" },
|
|
369
|
+
...{ class: ({ 'text-2xl font-semibold': __VLS_ctx.callStatus == __VLS_ctx.PLIVO_CALL_STATUS.CALL_START }) },
|
|
374
370
|
});
|
|
371
|
+
// @ts-ignore
|
|
372
|
+
[callStatus, PLIVO_CALL_STATUS,];
|
|
375
373
|
(__VLS_ctx.callStatus == __VLS_ctx.PLIVO_CALL_STATUS.CALL_START ? __VLS_ctx.duration : __VLS_ctx.STATUS_LABEL[__VLS_ctx.callStatus]);
|
|
376
374
|
// @ts-ignore
|
|
377
375
|
[callStatus, callStatus, PLIVO_CALL_STATUS, duration, STATUS_LABEL,];
|
|
@@ -391,8 +389,8 @@ const { default: __VLS_8 } = __VLS_2.slots;
|
|
|
391
389
|
[record_link, exportRecordFile,];
|
|
392
390
|
/** @type {[typeof IconSoundDownload, ]} */ ;
|
|
393
391
|
// @ts-ignore
|
|
394
|
-
const
|
|
395
|
-
const
|
|
392
|
+
const __VLS_18 = __VLS_asFunctionalComponent(IconSoundDownload, new IconSoundDownload({}));
|
|
393
|
+
const __VLS_19 = __VLS_18({}, ...__VLS_functionalComponentArgsRest(__VLS_18));
|
|
396
394
|
}
|
|
397
395
|
if (__VLS_ctx.callStatus == __VLS_ctx.PLIVO_CALL_STATUS.CALL_START) {
|
|
398
396
|
// @ts-ignore
|
|
@@ -409,12 +407,12 @@ const { default: __VLS_8 } = __VLS_2.slots;
|
|
|
409
407
|
});
|
|
410
408
|
/** @type {[typeof IconMic, ]} */ ;
|
|
411
409
|
// @ts-ignore
|
|
412
|
-
const
|
|
410
|
+
const __VLS_22 = __VLS_asFunctionalComponent(IconMic, new IconMic({
|
|
413
411
|
mute: (__VLS_ctx.isMute),
|
|
414
412
|
}));
|
|
415
|
-
const
|
|
413
|
+
const __VLS_23 = __VLS_22({
|
|
416
414
|
mute: (__VLS_ctx.isMute),
|
|
417
|
-
}, ...__VLS_functionalComponentArgsRest(
|
|
415
|
+
}, ...__VLS_functionalComponentArgsRest(__VLS_22));
|
|
418
416
|
// @ts-ignore
|
|
419
417
|
[isMute,];
|
|
420
418
|
}
|
|
@@ -433,8 +431,8 @@ const { default: __VLS_8 } = __VLS_2.slots;
|
|
|
433
431
|
});
|
|
434
432
|
/** @type {[typeof IconClose, ]} */ ;
|
|
435
433
|
// @ts-ignore
|
|
436
|
-
const
|
|
437
|
-
const
|
|
434
|
+
const __VLS_26 = __VLS_asFunctionalComponent(IconClose, new IconClose({}));
|
|
435
|
+
const __VLS_27 = __VLS_26({}, ...__VLS_functionalComponentArgsRest(__VLS_26));
|
|
438
436
|
}
|
|
439
437
|
if (__VLS_ctx.callStatus != __VLS_ctx.PLIVO_CALL_STATUS.CALL_END) {
|
|
440
438
|
// @ts-ignore
|
|
@@ -451,8 +449,8 @@ const { default: __VLS_8 } = __VLS_2.slots;
|
|
|
451
449
|
});
|
|
452
450
|
/** @type {[typeof IconPhoneCancel, ]} */ ;
|
|
453
451
|
// @ts-ignore
|
|
454
|
-
const
|
|
455
|
-
const
|
|
452
|
+
const __VLS_30 = __VLS_asFunctionalComponent(IconPhoneCancel, new IconPhoneCancel({}));
|
|
453
|
+
const __VLS_31 = __VLS_30({}, ...__VLS_functionalComponentArgsRest(__VLS_30));
|
|
456
454
|
}
|
|
457
455
|
if (__VLS_ctx.callStatus == __VLS_ctx.PLIVO_CALL_STATUS.RINGING) {
|
|
458
456
|
// @ts-ignore
|
|
@@ -465,14 +463,23 @@ const { default: __VLS_8 } = __VLS_2.slots;
|
|
|
465
463
|
[answer,];
|
|
466
464
|
/** @type {[typeof IconPhone, ]} */ ;
|
|
467
465
|
// @ts-ignore
|
|
468
|
-
const
|
|
469
|
-
const
|
|
466
|
+
const __VLS_34 = __VLS_asFunctionalComponent(IconPhone, new IconPhone({}));
|
|
467
|
+
const __VLS_35 = __VLS_34({}, ...__VLS_functionalComponentArgsRest(__VLS_34));
|
|
470
468
|
}
|
|
471
469
|
__VLS_asFunctionalElement(__VLS_elements.div, __VLS_elements.div)({
|
|
472
470
|
...{ class: "flex items-center justify-center gap-8 mt-10" },
|
|
473
471
|
});
|
|
474
472
|
}
|
|
475
473
|
var __VLS_2;
|
|
474
|
+
__VLS_asFunctionalElement(__VLS_elements.audio, __VLS_elements.audio)({
|
|
475
|
+
ref: "audioRef",
|
|
476
|
+
src: (__VLS_ctx.RingAudio),
|
|
477
|
+
loop: true,
|
|
478
|
+
preload: "auto",
|
|
479
|
+
});
|
|
480
|
+
/** @type {typeof __VLS_ctx.audioRef} */ ;
|
|
481
|
+
// @ts-ignore
|
|
482
|
+
[RingAudio, audioRef,];
|
|
476
483
|
/** @type {__VLS_StyleScopedClasses['flex']} */ ;
|
|
477
484
|
/** @type {__VLS_StyleScopedClasses['flex-col']} */ ;
|
|
478
485
|
/** @type {__VLS_StyleScopedClasses['items-center']} */ ;
|
|
@@ -505,6 +512,8 @@ var __VLS_2;
|
|
|
505
512
|
/** @type {__VLS_StyleScopedClasses['font-semibold']} */ ;
|
|
506
513
|
/** @type {__VLS_StyleScopedClasses['text-gray-400']} */ ;
|
|
507
514
|
/** @type {__VLS_StyleScopedClasses['mt-1']} */ ;
|
|
515
|
+
/** @type {__VLS_StyleScopedClasses['text-2xl']} */ ;
|
|
516
|
+
/** @type {__VLS_StyleScopedClasses['font-semibold']} */ ;
|
|
508
517
|
/** @type {__VLS_StyleScopedClasses['flex']} */ ;
|
|
509
518
|
/** @type {__VLS_StyleScopedClasses['items-center']} */ ;
|
|
510
519
|
/** @type {__VLS_StyleScopedClasses['justify-center']} */ ;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
time: number;
|
|
3
|
+
};
|
|
4
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
5
|
+
export default _default;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/// <reference types="C:/phonghq/go-chat-v2/node_modules/.vue-global-types/vue_3.5_0.d.ts" />
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import IconClock from '../../../assets/icons/call/IconClock.vue';
|
|
4
|
+
const props = withDefaults(defineProps(), {});
|
|
5
|
+
const emit = defineEmits();
|
|
6
|
+
const limitTimeLabel = computed(() => {
|
|
7
|
+
const m2 = Math.floor(props.time / 60);
|
|
8
|
+
const s2 = props.time % 60;
|
|
9
|
+
return `${m2.toString().padStart(2, '0')}:${s2.toString().padStart(2, '0')}`;
|
|
10
|
+
});
|
|
11
|
+
debugger; /* PartiallyEnd: #3632/scriptSetup.vue */
|
|
12
|
+
const __VLS_defaults = {};
|
|
13
|
+
const __VLS_ctx = {
|
|
14
|
+
...{},
|
|
15
|
+
...{},
|
|
16
|
+
...{},
|
|
17
|
+
...{},
|
|
18
|
+
...{},
|
|
19
|
+
};
|
|
20
|
+
let __VLS_elements;
|
|
21
|
+
let __VLS_components;
|
|
22
|
+
let __VLS_directives;
|
|
23
|
+
__VLS_asFunctionalElement(__VLS_elements.div, __VLS_elements.div)({
|
|
24
|
+
...{ class: "text-sm rounded-lg px-3 py-1.5 border border-chat-primary border-[2px] bg-[#eff6ff] absolute top-6 left-6 text-chat-primary flex items-center gap-1" },
|
|
25
|
+
});
|
|
26
|
+
/** @type {[typeof IconClock, ]} */ ;
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
const __VLS_0 = __VLS_asFunctionalComponent(IconClock, new IconClock({
|
|
29
|
+
...{ class: "w-4 h-4" },
|
|
30
|
+
}));
|
|
31
|
+
const __VLS_1 = __VLS_0({
|
|
32
|
+
...{ class: "w-4 h-4" },
|
|
33
|
+
}, ...__VLS_functionalComponentArgsRest(__VLS_0));
|
|
34
|
+
(__VLS_ctx.limitTimeLabel);
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
[limitTimeLabel,];
|
|
37
|
+
/** @type {__VLS_StyleScopedClasses['text-sm']} */ ;
|
|
38
|
+
/** @type {__VLS_StyleScopedClasses['rounded-lg']} */ ;
|
|
39
|
+
/** @type {__VLS_StyleScopedClasses['px-3']} */ ;
|
|
40
|
+
/** @type {__VLS_StyleScopedClasses['py-1.5']} */ ;
|
|
41
|
+
/** @type {__VLS_StyleScopedClasses['border']} */ ;
|
|
42
|
+
/** @type {__VLS_StyleScopedClasses['border-chat-primary']} */ ;
|
|
43
|
+
/** @type {__VLS_StyleScopedClasses['border-[2px]']} */ ;
|
|
44
|
+
/** @type {__VLS_StyleScopedClasses['bg-[#eff6ff]']} */ ;
|
|
45
|
+
/** @type {__VLS_StyleScopedClasses['absolute']} */ ;
|
|
46
|
+
/** @type {__VLS_StyleScopedClasses['top-6']} */ ;
|
|
47
|
+
/** @type {__VLS_StyleScopedClasses['left-6']} */ ;
|
|
48
|
+
/** @type {__VLS_StyleScopedClasses['text-chat-primary']} */ ;
|
|
49
|
+
/** @type {__VLS_StyleScopedClasses['flex']} */ ;
|
|
50
|
+
/** @type {__VLS_StyleScopedClasses['items-center']} */ ;
|
|
51
|
+
/** @type {__VLS_StyleScopedClasses['gap-1']} */ ;
|
|
52
|
+
/** @type {__VLS_StyleScopedClasses['w-4']} */ ;
|
|
53
|
+
/** @type {__VLS_StyleScopedClasses['h-4']} */ ;
|
|
54
|
+
const __VLS_export = (await import('vue')).defineComponent({
|
|
55
|
+
__typeEmits: {},
|
|
56
|
+
__typeProps: {},
|
|
57
|
+
props: {},
|
|
58
|
+
});
|
|
59
|
+
export default {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ref } from 'vue';
|
|
2
2
|
import { sdkInit } from '../plugins/sdk';
|
|
3
|
-
import {
|
|
3
|
+
import { dataProfile, getProfile, loginLink } from '../utils/chat/store/auth';
|
|
4
4
|
import { routerPush } from '../utils/chat/chat-router';
|
|
5
5
|
import { PAGE } from '../constant/general';
|
|
6
6
|
import { connectMqtt, subscribeToTopic, unsubscribeFromTopic } from '../plugins/mqtt';
|
|
@@ -36,7 +36,7 @@ export function useInitData() {
|
|
|
36
36
|
const initData = async (props, responsive) => {
|
|
37
37
|
await getProfile();
|
|
38
38
|
if (dataProfile.value?.user_type == 'tenant') {
|
|
39
|
-
await checkTenantPhoneOnGapInsight()
|
|
39
|
+
// await checkTenantPhoneOnGapInsight()
|
|
40
40
|
}
|
|
41
41
|
unsubscribeFromTopic(TOPIC_DETAIL_CALL + dataProfile.value?.id);
|
|
42
42
|
subscribeToTopic(TOPIC_DETAIL_CALL + dataProfile.value?.id);
|
|
@@ -47,6 +47,8 @@ export declare const useListConversations: (is_unknown: number, is_tenant: boole
|
|
|
47
47
|
getData: (data?: IParamGetConversation, option?: {
|
|
48
48
|
reset?: boolean;
|
|
49
49
|
hideLoading?: boolean;
|
|
50
|
+
page?: number;
|
|
51
|
+
is_mqtt?: boolean;
|
|
50
52
|
}) => Promise<void>;
|
|
51
53
|
handleReadMessage: (receiver_id: any) => void;
|
|
52
54
|
getDataCache: () => boolean;
|
|
@@ -5,6 +5,7 @@ import { dataProfile } from '../utils/chat/store/auth';
|
|
|
5
5
|
import { useDebounce } from '../utils/debounce';
|
|
6
6
|
import { getConversation } from '../utils/chat/store/conversation';
|
|
7
7
|
import { readMessages } from '../utils/chat/store/message';
|
|
8
|
+
import dayjs from 'dayjs';
|
|
8
9
|
import { useDigibot } from '../composable/useDigibot';
|
|
9
10
|
import { getCache, setCache } from '../utils/chat/cache';
|
|
10
11
|
const { digibotData, digibotId } = useDigibot();
|
|
@@ -19,10 +20,17 @@ export const useListConversations = (is_unknown, is_tenant) => {
|
|
|
19
20
|
const isLoadingSearch = ref(false);
|
|
20
21
|
onMounted(() => {
|
|
21
22
|
handleConnectMqtt();
|
|
23
|
+
document.addEventListener('visibilitychange', handleVisibilitychange);
|
|
22
24
|
});
|
|
23
25
|
onUnmounted(() => {
|
|
26
|
+
document.removeEventListener('visibilitychange', handleVisibilitychange);
|
|
24
27
|
handleDisconnectMqtt;
|
|
25
28
|
});
|
|
29
|
+
const handleVisibilitychange = () => {
|
|
30
|
+
if (document.visibilityState === 'visible') {
|
|
31
|
+
getDataMqtt();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
26
34
|
const handleDisconnectMqtt = () => {
|
|
27
35
|
TOPIC_HOME.forEach((item) => {
|
|
28
36
|
unsubscribeFromTopic(item + dataProfile.value?.id);
|
|
@@ -56,26 +64,33 @@ export const useListConversations = (is_unknown, is_tenant) => {
|
|
|
56
64
|
}
|
|
57
65
|
};
|
|
58
66
|
const mqttMessageHandler = (topic, data) => {
|
|
67
|
+
if (topic == TOPIC_HOME[3] + dataProfile.value?.id) {
|
|
68
|
+
getData({}, { reset: true });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
59
71
|
if ((data.is_unknown ?? 0) == is_unknown || (!is_tenant && is_unknown == 0)) {
|
|
60
|
-
|
|
72
|
+
getDataMqttDebounce();
|
|
61
73
|
if (topic ===
|
|
62
74
|
TOPIC_HOME[0] + dataProfile.value?.id
|
|
63
|
-
|
|
64
|
-
) {
|
|
75
|
+
|| topic === TOPIC_HOME[1] + dataProfile.value?.id) {
|
|
65
76
|
const index = listConversations.value.findIndex((item) => item.id === data.id);
|
|
66
77
|
const hasChatBox = listConversations.value.findIndex((item) => item.id === digibotId);
|
|
67
78
|
if (index != -1) {
|
|
68
79
|
data.username = listConversations.value[index].username ?? '';
|
|
80
|
+
data.color = listConversations.value[index].color ?? '';
|
|
81
|
+
data.avatar = listConversations.value[index].avatar ?? '';
|
|
82
|
+
data.receiver_id = listConversations.value[index].receiver_id;
|
|
69
83
|
listConversations.value.splice(index, 1);
|
|
70
84
|
}
|
|
71
85
|
if (hasChatBox > -1) {
|
|
72
86
|
listConversations.value.splice(1, 0, data);
|
|
73
87
|
}
|
|
74
88
|
else {
|
|
89
|
+
data.receiver_id = data.receiver_id != dataProfile.value?.id ? data.receiver_id : data.sender_id;
|
|
75
90
|
listConversations.value.unshift(data);
|
|
76
91
|
}
|
|
77
92
|
}
|
|
78
|
-
if (topic === TOPIC_HOME[
|
|
93
|
+
if (topic === TOPIC_HOME[2] + dataProfile.value?.id) {
|
|
79
94
|
if (data.is_unknown == is_unknown) {
|
|
80
95
|
const index = listConversations.value.findIndex((item) => item.id === data.id);
|
|
81
96
|
if (index != -1) {
|
|
@@ -96,19 +111,31 @@ export const useListConversations = (is_unknown, is_tenant) => {
|
|
|
96
111
|
// }
|
|
97
112
|
}
|
|
98
113
|
};
|
|
99
|
-
const
|
|
100
|
-
|
|
114
|
+
const getDataMqttDebounce = useDebounce(() => {
|
|
115
|
+
getDataMqtt();
|
|
101
116
|
}, 5000);
|
|
102
117
|
const getData = async (data, option) => {
|
|
103
118
|
try {
|
|
104
119
|
if (!is_tenant && is_unknown == 1)
|
|
105
120
|
return;
|
|
106
121
|
params.value = { ...params.value, ...(data ?? {}) };
|
|
107
|
-
const is_unknown_value = is_tenant ? is_unknown : undefined;
|
|
108
122
|
if (option?.reset) {
|
|
109
123
|
params.value.page = 1;
|
|
110
124
|
}
|
|
111
|
-
const
|
|
125
|
+
const is_unknown_value = is_tenant ? is_unknown : undefined;
|
|
126
|
+
const page_request = option?.page ?? params.value.page;
|
|
127
|
+
const res = await getConversation({
|
|
128
|
+
...params.value,
|
|
129
|
+
is_unknown: is_unknown_value,
|
|
130
|
+
page: page_request
|
|
131
|
+
});
|
|
132
|
+
if (page_request <= 1 && !params.value?.search) {
|
|
133
|
+
setCache(STORAGE_KEY + is_unknown, res.items);
|
|
134
|
+
}
|
|
135
|
+
if (option?.is_mqtt) {
|
|
136
|
+
mergeChats(res?.items);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
112
139
|
if (option?.reset) {
|
|
113
140
|
listConversations.value = [];
|
|
114
141
|
if (is_unknown == 0 && dataProfile.value?.user_type == 'tenant')
|
|
@@ -118,9 +145,6 @@ export const useListConversations = (is_unknown, is_tenant) => {
|
|
|
118
145
|
listConversations.value.push(...(res?.items ?? []));
|
|
119
146
|
params.value.page = res?._meta?.currentPage || 1;
|
|
120
147
|
pageCount.value = res?._meta?.pageCount || 1;
|
|
121
|
-
if (params.value.page <= 1) {
|
|
122
|
-
setCache(STORAGE_KEY + is_unknown, listConversations.value);
|
|
123
|
-
}
|
|
124
148
|
}
|
|
125
149
|
catch (error) {
|
|
126
150
|
console.error(error);
|
|
@@ -128,6 +152,25 @@ export const useListConversations = (is_unknown, is_tenant) => {
|
|
|
128
152
|
finally {
|
|
129
153
|
}
|
|
130
154
|
};
|
|
155
|
+
const mergeChats = (newChats) => {
|
|
156
|
+
const map = new Map();
|
|
157
|
+
listConversations.value.forEach((c) => {
|
|
158
|
+
map.set(c.id, c);
|
|
159
|
+
});
|
|
160
|
+
newChats.forEach((c) => {
|
|
161
|
+
map.set(c.id, {
|
|
162
|
+
...(map.get(c.id) ?? {}),
|
|
163
|
+
...c
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
listConversations.value = Array.from(map.values()).sort((a, b) => dayjs(b.updated_at).valueOf() - dayjs(a.updated_at).valueOf());
|
|
167
|
+
};
|
|
168
|
+
const getDataMqtt = async () => {
|
|
169
|
+
let page = params.value.page;
|
|
170
|
+
for (let i = 1; i <= page; i++) {
|
|
171
|
+
await getData(undefined, { page: i, is_mqtt: true });
|
|
172
|
+
}
|
|
173
|
+
};
|
|
131
174
|
const getDataCache = () => {
|
|
132
175
|
const cache_data = getCache(STORAGE_KEY + is_unknown);
|
|
133
176
|
if (cache_data.data) {
|
|
@@ -10,4 +10,5 @@ export declare function usePlivo(callback: (status: PlivoCallStatusType, data?:
|
|
|
10
10
|
plivoEndCall: (status: PlivoCallStatusType) => void;
|
|
11
11
|
plivoCallSwishMute: (isMute: boolean) => void;
|
|
12
12
|
plivoCallSwishSpeaker: (id: any) => void;
|
|
13
|
+
checkTimeLimit: () => Promise<number>;
|
|
13
14
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PLIVO_CALL_STATUS } from '../types/chat/call';
|
|
2
2
|
import { createSipAccount } from '../utils/chat/store/call';
|
|
3
3
|
import { dataProfile } from '../utils/chat/store/auth';
|
|
4
|
+
import { getPhoneTimeLimit } from '../utils/chat/store/message';
|
|
4
5
|
export function usePlivo(callback) {
|
|
5
6
|
var options = {
|
|
6
7
|
debug: 'ALL',
|
|
@@ -40,13 +41,14 @@ export function usePlivo(callback) {
|
|
|
40
41
|
const payload = JSON.parse(atob(data.token.split('.')[1]));
|
|
41
42
|
await createSipAccount({
|
|
42
43
|
sip_username: `${payload.sub}_${payload.iss}`,
|
|
43
|
-
did_number: dataProfile.value?.
|
|
44
|
+
did_number: dataProfile.value?.phone ?? ''
|
|
44
45
|
});
|
|
45
46
|
}
|
|
46
47
|
// await plivoBrowserSdk?.client?.tokenLogin(payload.sub ?? '', token)
|
|
47
48
|
// await plivoBrowserSdk?.client?.login('webcall003079673454891827', '123456abcA!')
|
|
48
49
|
// await plivoBrowserSdk?.client?.login(payload.sub , null, token)
|
|
49
50
|
await plivoBrowserSdk?.client?.loginWithAccessToken(data.token);
|
|
51
|
+
plivoBrowserSdk?.client?.setRingTone(false);
|
|
50
52
|
// await plivoBrowserSdk?.client?.on?.(payload)
|
|
51
53
|
// console.log('Registered with token')
|
|
52
54
|
}
|
|
@@ -57,13 +59,20 @@ export function usePlivo(callback) {
|
|
|
57
59
|
const handleLoginFailed = (e) => {
|
|
58
60
|
console.log('Login failed', e);
|
|
59
61
|
};
|
|
60
|
-
const handleIncomingCall = (call) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
const handleIncomingCall = async (call) => {
|
|
63
|
+
try {
|
|
64
|
+
const data = {
|
|
65
|
+
phone: _getPhone(call.src)
|
|
66
|
+
};
|
|
67
|
+
callback(PLIVO_CALL_STATUS.CHECK_USER_OFFER, data);
|
|
68
|
+
const limit_time = await checkTimeLimit();
|
|
69
|
+
plivoBrowserSdk?.client?.setRingTone(true);
|
|
70
|
+
callback(PLIVO_CALL_STATUS.RINGING, { ...data, limit_time });
|
|
71
|
+
CallUuid = call?.callUUID;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
callback(PLIVO_CALL_STATUS.CALL_END);
|
|
75
|
+
}
|
|
67
76
|
};
|
|
68
77
|
const handleCallRemoteRinging = (callInfo) => {
|
|
69
78
|
CallUuid = callInfo.callUUID;
|
|
@@ -125,7 +134,7 @@ export function usePlivo(callback) {
|
|
|
125
134
|
plivoBrowserSdk?.client?.unmute?.();
|
|
126
135
|
};
|
|
127
136
|
const plivoCall = async (phone) => {
|
|
128
|
-
plivoBrowserSdk
|
|
137
|
+
plivoBrowserSdk?.client?.call('+' + phone, { number_phone: phone });
|
|
129
138
|
await _waitEventOrTimeout(5000);
|
|
130
139
|
};
|
|
131
140
|
const plivoEndCall = (status) => {
|
|
@@ -135,6 +144,7 @@ export function usePlivo(callback) {
|
|
|
135
144
|
else if (status == PLIVO_CALL_STATUS.CALL_START || status == PLIVO_CALL_STATUS.CALLING) {
|
|
136
145
|
plivoBrowserSdk?.client?.hangup?.();
|
|
137
146
|
}
|
|
147
|
+
plivoBrowserSdk?.client?.setRingTone(false);
|
|
138
148
|
};
|
|
139
149
|
const handleCallFailed = (data, callInfo) => {
|
|
140
150
|
console.log('handleCallFailed', data);
|
|
@@ -158,6 +168,17 @@ export function usePlivo(callback) {
|
|
|
158
168
|
alert(id);
|
|
159
169
|
plivoBrowserSdk?.client?.audio?.set?.(id);
|
|
160
170
|
};
|
|
171
|
+
const checkTimeLimit = async () => {
|
|
172
|
+
// await sleep()
|
|
173
|
+
const res = await getPhoneTimeLimit({
|
|
174
|
+
tenant_id: dataProfile.value?.tenant_id ?? '',
|
|
175
|
+
phone: dataProfile.value?.phone ?? ''
|
|
176
|
+
});
|
|
177
|
+
return res;
|
|
178
|
+
};
|
|
179
|
+
const sleep = () => {
|
|
180
|
+
return new Promise(resolve => setTimeout(resolve, 2000));
|
|
181
|
+
};
|
|
161
182
|
return {
|
|
162
183
|
plivoLogin,
|
|
163
184
|
plivoCallAnswer,
|
|
@@ -166,5 +187,6 @@ export function usePlivo(callback) {
|
|
|
166
187
|
plivoEndCall,
|
|
167
188
|
plivoCallSwishMute,
|
|
168
189
|
plivoCallSwishSpeaker,
|
|
190
|
+
checkTimeLimit
|
|
169
191
|
};
|
|
170
192
|
}
|