ajaxter-chat 2.0.1 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -128
- package/dist/components/BlockList/index.d.ts +10 -0
- package/dist/components/BlockList/index.js +33 -0
- package/dist/components/CallScreen/index.d.ts +13 -0
- package/dist/components/CallScreen/index.js +48 -0
- package/dist/components/ChatScreen/index.d.ts +10 -3
- package/dist/components/ChatScreen/index.js +142 -57
- package/dist/components/ChatWidget.js +192 -98
- package/dist/components/EmojiPicker/index.d.ts +8 -0
- package/dist/components/EmojiPicker/index.js +18 -0
- package/dist/components/HomeScreen/index.d.ts +2 -3
- package/dist/components/HomeScreen/index.js +25 -41
- package/dist/components/MaintenanceView/index.d.ts +0 -1
- package/dist/components/MaintenanceView/index.js +4 -6
- package/dist/components/RecentChatsScreen/index.d.ts +4 -3
- package/dist/components/RecentChatsScreen/index.js +7 -37
- package/dist/components/Tabs/BottomTabs.d.ts +1 -1
- package/dist/components/Tabs/BottomTabs.js +25 -20
- package/dist/components/TicketScreen/index.d.ts +3 -3
- package/dist/components/TicketScreen/index.js +39 -56
- package/dist/components/UserListScreen/index.d.ts +2 -4
- package/dist/components/UserListScreen/index.js +33 -62
- package/dist/config/index.d.ts +3 -3
- package/dist/config/index.js +18 -26
- package/dist/hooks/useChat.d.ts +8 -3
- package/dist/hooks/useChat.js +22 -18
- package/dist/hooks/useRemoteConfig.d.ts +6 -0
- package/dist/hooks/useRemoteConfig.js +22 -0
- package/dist/hooks/useWebRTC.d.ts +11 -0
- package/dist/hooks/useWebRTC.js +112 -0
- package/dist/index.d.ts +9 -5
- package/dist/index.js +8 -4
- package/dist/types/index.d.ts +62 -21
- package/dist/utils/chat.d.ts +13 -0
- package/dist/utils/chat.js +62 -0
- package/dist/utils/theme.d.ts +3 -1
- package/dist/utils/theme.js +14 -7
- package/package.json +4 -4
- package/public/chatData.json +162 -0
- package/src/components/BlockList/index.tsx +94 -0
- package/src/components/CallScreen/index.tsx +144 -0
- package/src/components/ChatScreen/index.tsx +403 -139
- package/src/components/ChatWidget.tsx +394 -250
- package/src/components/EmojiPicker/index.tsx +48 -0
- package/src/components/HomeScreen/index.tsx +58 -82
- package/src/components/MaintenanceView/index.tsx +6 -9
- package/src/components/RecentChatsScreen/index.tsx +51 -96
- package/src/components/Tabs/BottomTabs.tsx +45 -37
- package/src/components/TicketScreen/index.tsx +87 -133
- package/src/components/UserListScreen/index.tsx +75 -153
- package/src/config/index.ts +22 -28
- package/src/hooks/useChat.ts +31 -14
- package/src/hooks/useRemoteConfig.ts +20 -0
- package/src/hooks/useWebRTC.ts +130 -0
- package/src/index.ts +26 -15
- package/src/types/index.ts +85 -40
- package/src/utils/chat.ts +70 -0
- package/src/utils/theme.ts +18 -7
- package/dist/hooks/useUsers.d.ts +0 -7
- package/dist/hooks/useUsers.js +0 -26
- package/dist/services/userService.d.ts +0 -2
- package/dist/services/userService.js +0 -9
- package/dist/src/components/ChatScreen/index.d.ts +0 -12
- package/dist/src/components/ChatScreen/index.js +0 -83
- package/dist/src/components/ChatWidget.d.ts +0 -4
- package/dist/src/components/ChatWidget.js +0 -141
- package/dist/src/components/HomeScreen/index.d.ts +0 -9
- package/dist/src/components/HomeScreen/index.js +0 -71
- package/dist/src/components/MaintenanceView/index.d.ts +0 -7
- package/dist/src/components/MaintenanceView/index.js +0 -16
- package/dist/src/components/RecentChatsScreen/index.d.ts +0 -16
- package/dist/src/components/RecentChatsScreen/index.js +0 -38
- package/dist/src/components/Tabs/BottomTabs.d.ts +0 -10
- package/dist/src/components/Tabs/BottomTabs.js +0 -29
- package/dist/src/components/TicketScreen/index.d.ts +0 -9
- package/dist/src/components/TicketScreen/index.js +0 -71
- package/dist/src/components/UserListScreen/index.d.ts +0 -13
- package/dist/src/components/UserListScreen/index.js +0 -64
- package/dist/src/config/index.d.ts +0 -3
- package/dist/src/config/index.js +0 -38
- package/dist/src/hooks/useChat.d.ts +0 -8
- package/dist/src/hooks/useChat.js +0 -26
- package/dist/src/hooks/useUsers.d.ts +0 -7
- package/dist/src/hooks/useUsers.js +0 -26
- package/dist/src/index.d.ts +0 -14
- package/dist/src/index.js +0 -13
- package/dist/src/services/userService.d.ts +0 -2
- package/dist/src/services/userService.js +0 -9
- package/dist/src/types/index.d.ts +0 -59
- package/dist/src/types/index.js +0 -1
- package/dist/src/utils/theme.d.ts +0 -3
- package/dist/src/utils/theme.js +0 -13
- package/src/hooks/useUsers.ts +0 -27
- package/src/services/userService.ts +0 -9
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { CallSession, ChatUser } from '../../types';
|
|
3
|
+
import { avatarColor, initials } from '../../utils/chat';
|
|
4
|
+
|
|
5
|
+
interface CallScreenProps {
|
|
6
|
+
session: CallSession;
|
|
7
|
+
localVideoRef: React.RefObject<HTMLVideoElement | null>;
|
|
8
|
+
remoteVideoRef: React.RefObject<HTMLVideoElement | null>;
|
|
9
|
+
onEnd: () => void;
|
|
10
|
+
onToggleMute: () => void;
|
|
11
|
+
onToggleCamera: () => void;
|
|
12
|
+
primaryColor: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const CallScreen: React.FC<CallScreenProps> = ({
|
|
16
|
+
session, localVideoRef, remoteVideoRef,
|
|
17
|
+
onEnd, onToggleMute, onToggleCamera, primaryColor,
|
|
18
|
+
}) => {
|
|
19
|
+
const [duration, setDuration] = useState(0);
|
|
20
|
+
const peer = session.peer as ChatUser;
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (session.state !== 'connected' || !session.startedAt) return;
|
|
24
|
+
const t = setInterval(() => {
|
|
25
|
+
setDuration(Math.floor((Date.now() - session.startedAt!.getTime()) / 1000));
|
|
26
|
+
}, 1000);
|
|
27
|
+
return () => clearInterval(t);
|
|
28
|
+
}, [session.state, session.startedAt]);
|
|
29
|
+
|
|
30
|
+
const mins = String(Math.floor(duration / 60)).padStart(2, '0');
|
|
31
|
+
const secs = String(duration % 60).padStart(2, '0');
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div style={{
|
|
35
|
+
display:'flex', flexDirection:'column', height:'100%',
|
|
36
|
+
background: session.isCameraOn ? '#000' : `linear-gradient(145deg,${primaryColor}dd,#0f172a)`,
|
|
37
|
+
color:'#fff', animation:'cw-slideIn 0.22s ease',
|
|
38
|
+
position:'relative', overflow:'hidden',
|
|
39
|
+
}}>
|
|
40
|
+
{/* Remote video (background) */}
|
|
41
|
+
<video ref={remoteVideoRef} autoPlay playsInline
|
|
42
|
+
style={{ position:'absolute', inset:0, width:'100%', height:'100%', objectFit:'cover', opacity: session.state==='connected'?1:0 }}
|
|
43
|
+
/>
|
|
44
|
+
|
|
45
|
+
{/* Local video (PiP) */}
|
|
46
|
+
<video ref={localVideoRef} autoPlay playsInline muted
|
|
47
|
+
style={{
|
|
48
|
+
position:'absolute', bottom:120, right:14,
|
|
49
|
+
width:90, height:120, borderRadius:10,
|
|
50
|
+
objectFit:'cover', border:'2px solid rgba(255,255,255,0.3)',
|
|
51
|
+
display: session.isCameraOn ? 'block' : 'none',
|
|
52
|
+
zIndex:10,
|
|
53
|
+
}}
|
|
54
|
+
/>
|
|
55
|
+
|
|
56
|
+
{/* Overlay */}
|
|
57
|
+
<div style={{ position:'relative', zIndex:5, display:'flex', flexDirection:'column', height:'100%', background:'rgba(0,0,0,0.35)' }}>
|
|
58
|
+
{/* Top bar */}
|
|
59
|
+
<div style={{ padding:'16px 18px', display:'flex', alignItems:'center', gap:10 }}>
|
|
60
|
+
<div style={{ flex:1 }}>
|
|
61
|
+
<div style={{ fontWeight:700, fontSize:15, color:'#fff' }}>
|
|
62
|
+
{session.state === 'calling' && 'Calling...'}
|
|
63
|
+
{session.state === 'connected' && 'Connected'}
|
|
64
|
+
{session.state === 'ended' && 'Call Ended'}
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
{/* Center: avatar + name */}
|
|
70
|
+
<div style={{ flex:1, display:'flex', flexDirection:'column', alignItems:'center', justifyContent:'center', gap:16 }}>
|
|
71
|
+
{peer && (
|
|
72
|
+
<>
|
|
73
|
+
<div style={{
|
|
74
|
+
width:90, height:90, borderRadius:'50%',
|
|
75
|
+
backgroundColor: avatarColor(peer.name),
|
|
76
|
+
display:'flex', alignItems:'center', justifyContent:'center',
|
|
77
|
+
fontSize:28, fontWeight:700, color:'#fff',
|
|
78
|
+
boxShadow:'0 0 0 4px rgba(255,255,255,0.2)',
|
|
79
|
+
animation: session.state==='calling' ? 'cw-pulse 1.5s ease infinite' : 'none',
|
|
80
|
+
}}>
|
|
81
|
+
{initials(peer.name)}
|
|
82
|
+
</div>
|
|
83
|
+
<div style={{ textAlign:'center' }}>
|
|
84
|
+
<div style={{ fontSize:20, fontWeight:800 }}>{peer.name}</div>
|
|
85
|
+
<div style={{ fontSize:13, opacity:0.8, marginTop:4 }}>
|
|
86
|
+
{session.state === 'calling' && 'Ringing...'}
|
|
87
|
+
{session.state === 'connected' && `${mins}:${secs}`}
|
|
88
|
+
{session.state === 'ended' && 'Call ended'}
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
</>
|
|
92
|
+
)}
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
{/* Controls */}
|
|
96
|
+
<div style={{ padding:'24px', display:'flex', justifyContent:'center', alignItems:'center', gap:20 }}>
|
|
97
|
+
{/* Mute */}
|
|
98
|
+
<CallBtn
|
|
99
|
+
active={session.isMuted}
|
|
100
|
+
activeColor="#374151"
|
|
101
|
+
onClick={onToggleMute}
|
|
102
|
+
title={session.isMuted ? 'Unmute' : 'Mute'}
|
|
103
|
+
>
|
|
104
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none">
|
|
105
|
+
{session.isMuted
|
|
106
|
+
? <><path d="M12 1a3 3 0 00-3 3v8a3 3 0 006 0V4a3 3 0 00-3-3z" stroke="#fff" strokeWidth="2"/><line x1="1" y1="1" x2="23" y2="23" stroke="#ef4444" strokeWidth="2"/></>
|
|
107
|
+
: <><path d="M12 1a3 3 0 00-3 3v8a3 3 0 006 0V4a3 3 0 00-3-3z" stroke="#fff" strokeWidth="2" strokeLinecap="round"/><path d="M19 10v2a7 7 0 01-14 0v-2M12 19v4" stroke="#fff" strokeWidth="2" strokeLinecap="round"/></>
|
|
108
|
+
}
|
|
109
|
+
</svg>
|
|
110
|
+
</CallBtn>
|
|
111
|
+
|
|
112
|
+
{/* End call */}
|
|
113
|
+
<button onClick={onEnd} style={{
|
|
114
|
+
width:60, height:60, borderRadius:'50%', backgroundColor:'#ef4444',
|
|
115
|
+
border:'none', cursor:'pointer', display:'flex', alignItems:'center', justifyContent:'center',
|
|
116
|
+
boxShadow:'0 4px 16px rgba(239,68,68,0.5)', flexShrink:0,
|
|
117
|
+
}}>
|
|
118
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none">
|
|
119
|
+
<path d="M22 16.92v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07A19.5 19.5 0 013.07 10.8a19.79 19.79 0 01-3.07-8.68A2 2 0 012 0h3a2 2 0 012 1.72c.127.96.361 1.903.7 2.81a2 2 0 01-.45 2.11L6.09 7.91a16 16 0 006 6l1.27-1.27a2 2 0 012.11-.45c.907.339 1.85.573 2.81.7A2 2 0 0122 14.92v2z" fill="#fff" transform="rotate(135 12 12)"/>
|
|
120
|
+
</svg>
|
|
121
|
+
</button>
|
|
122
|
+
|
|
123
|
+
{/* Camera */}
|
|
124
|
+
<CallBtn active={session.isCameraOn} activeColor={primaryColor} onClick={onToggleCamera} title="Camera">
|
|
125
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none">
|
|
126
|
+
<path d="M23 7l-7 5 7 5V7zM1 5h13a2 2 0 012 2v10a2 2 0 01-2 2H1a2 2 0 01-2-2V7a2 2 0 012-2z" stroke="#fff" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
|
|
127
|
+
</svg>
|
|
128
|
+
</CallBtn>
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const CallBtn: React.FC<{ active: boolean; activeColor: string; onClick: () => void; title: string; children: React.ReactNode }> = ({
|
|
136
|
+
active, activeColor, onClick, title, children,
|
|
137
|
+
}) => (
|
|
138
|
+
<button onClick={onClick} title={title} style={{
|
|
139
|
+
width:50, height:50, borderRadius:'50%',
|
|
140
|
+
backgroundColor: active ? activeColor : 'rgba(255,255,255,0.2)',
|
|
141
|
+
border:'none', cursor:'pointer',
|
|
142
|
+
display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0,
|
|
143
|
+
}}>{children}</button>
|
|
144
|
+
);
|