call-control-sdk 1.0.0 → 2.1.0

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 CHANGED
@@ -1,40 +1,29 @@
1
1
  {
2
2
  "name": "call-control-sdk",
3
3
  "description": "Call Control SDK",
4
- "version": "1.0.0",
5
- "type": "module",
4
+ "version": "2.1.0",
6
5
  "author": "Achala",
7
6
  "license": "MIT",
7
+ "main": "dist/index.cjs",
8
+ "module": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "files": [
11
+ "dist"
12
+ ],
8
13
  "scripts": {
9
14
  "dev": "vite",
10
15
  "start": "vite",
11
- "build": "tsc -b && vite build",
12
- "build:lib": "tsc --project tsconfig.lib.json && vite build --mode lib",
16
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
13
17
  "lint": "eslint .",
14
18
  "format": "prettier --write .",
15
- "preview": "vite preview",
16
- "prepublishOnly": "npm run build:lib"
19
+ "prepublishOnly": "npm run build"
17
20
  },
18
- "dependencies": {
21
+ "peerDependencies": {
19
22
  "@emotion/react": "^11.14.0",
20
23
  "@emotion/styled": "^11.14.1",
21
24
  "@mui/icons-material": "^7.3.1",
22
25
  "@mui/material": "^7.3.1",
23
26
  "react": "^19.1.1",
24
27
  "react-dom": "^19.1.1"
25
- },
26
- "devDependencies": {
27
- "@eslint/js": "^9.33.0",
28
- "@types/node": "^24.2.1",
29
- "@types/react": "^19.1.10",
30
- "@types/react-dom": "^19.1.7",
31
- "@vitejs/plugin-react-swc": "^4.0.0",
32
- "eslint": "^9.33.0",
33
- "eslint-plugin-react-hooks": "^5.2.0",
34
- "eslint-plugin-react-refresh": "^0.4.20",
35
- "globals": "^16.3.0",
36
- "typescript": "~5.8.3",
37
- "typescript-eslint": "^8.39.1",
38
- "vite": "^7.1.2"
39
28
  }
40
29
  }
package/eslint.config.js DELETED
@@ -1,23 +0,0 @@
1
- import js from '@eslint/js'
2
- import globals from 'globals'
3
- import reactHooks from 'eslint-plugin-react-hooks'
4
- import reactRefresh from 'eslint-plugin-react-refresh'
5
- import tseslint from 'typescript-eslint'
6
- import { globalIgnores } from 'eslint/config'
7
-
8
- export default tseslint.config([
9
- globalIgnores(['dist']),
10
- {
11
- files: ['**/*.{ts,tsx}'],
12
- extends: [
13
- js.configs.recommended,
14
- tseslint.configs.recommended,
15
- reactHooks.configs['recommended-latest'],
16
- reactRefresh.configs.vite,
17
- ],
18
- languageOptions: {
19
- ecmaVersion: 2020,
20
- globals: globals.browser,
21
- },
22
- },
23
- ])
package/index.html DELETED
@@ -1,13 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Call Control SDK</title>
8
- </head>
9
- <body>
10
- <div id="root"></div>
11
- <script type="module" src="/src/main.tsx"></script>
12
- </body>
13
- </html>
package/public/vite.svg DELETED
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
package/src/App.tsx DELETED
@@ -1,47 +0,0 @@
1
- import { useEffect } from "react";
2
- import { Box } from "@mui/material";
3
- import { CallControlPanel, initCallSDK, updateCallData } from "./lib";
4
-
5
- function App() {
6
- useEffect(() => {
7
- // Initialize the SDK with a test API key
8
- try {
9
- initCallSDK("test-api-key-12345");
10
- console.log("SDK initialized successfully");
11
-
12
- // Simulate some call data
13
- updateCallData({
14
- mobileNumber: "+1-234-567-8900",
15
- callReferenceId: "CALL-REF-001",
16
- agentLoginId: "AGENT-123",
17
- });
18
- } catch (error) {
19
- console.error("SDK initialization failed:", error);
20
- }
21
- }, []);
22
-
23
- const handleDataChange = (data: {
24
- mobileNumber: string;
25
- callReferenceId: string;
26
- agentLoginId: string;
27
- }) => {
28
- console.log("Call data changed:", data);
29
- };
30
-
31
- return (
32
- <Box>
33
- <h1
34
- style={{
35
- color: "#1976d2",
36
- marginBottom: "20px",
37
- }}
38
- >
39
- Call Control SDK Demo
40
- </h1>
41
-
42
- <CallControlPanel onDataChange={handleDataChange} />
43
- </Box>
44
- );
45
- }
46
-
47
- export default App;
package/src/index.css DELETED
@@ -1,23 +0,0 @@
1
- :root {
2
- font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
3
- line-height: 1.5;
4
- font-weight: 400;
5
- width: 100%;
6
- color-scheme: light dark;
7
- color: rgba(255, 255, 255, 0.87);
8
- background-color: #f3f3f3;
9
-
10
- font-synthesis: none;
11
- text-rendering: optimizeLegibility;
12
- -webkit-font-smoothing: antialiased;
13
- -moz-osx-font-smoothing: grayscale;
14
- }
15
-
16
-
17
- body {
18
- margin: 0;
19
- display: flex;
20
- width: 100%;
21
- min-height: 100vh;
22
- }
23
-
@@ -1,422 +0,0 @@
1
- import React, { useEffect, useState, useCallback } from "react";
2
- import {
3
- Paper,
4
- IconButton,
5
- Typography,
6
- Menu,
7
- MenuItem,
8
- Box,
9
- Tooltip,
10
- Fade,
11
- useTheme,
12
- Button,
13
- } from "@mui/material";
14
- import {
15
- PauseCircle,
16
- PlayCircle,
17
- Mic,
18
- MicOff,
19
- MoreVert,
20
- CallEnd,
21
- KeyboardArrowDown,
22
- Cached,
23
- FreeBreakfast,
24
- AirlineSeatIndividualSuite,
25
- TransferWithinAStation,
26
- Groups,
27
- Phone,
28
- DragIndicator,
29
- SpatialAudioOff,
30
- } from "@mui/icons-material";
31
- import { useSDKState } from "../hooks/useSDKState";
32
- import { useDraggable } from "../hooks/useDraggable";
33
- import { sdkStateManager } from "../sdk-state";
34
- import type { CallControlPanelProps, CallStatus } from "../types";
35
-
36
- export function CallControlPanel({ onDataChange }: CallControlPanelProps) {
37
- const theme = useTheme();
38
- const state = useSDKState();
39
- const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
40
- const [moreOptionsAnchorEl, setMoreOptionsAnchorEl] =
41
- useState<null | HTMLElement>(null);
42
- const [callDuration, setCallDuration] = useState(0);
43
-
44
- const { position, isDragging, dragRef, handleMouseDown, handleTouchStart } =
45
- useDraggable(state.position, (newPosition) =>
46
- sdkStateManager.setPosition(newPosition)
47
- );
48
-
49
- // Call duration timer
50
- useEffect(() => {
51
- let interval: NodeJS.Timeout;
52
-
53
- if (state.callStartTime) {
54
- interval = setInterval(() => {
55
- const elapsed = Math.floor((Date.now() - state.callStartTime!) / 1000);
56
- setCallDuration(elapsed);
57
- }, 1000);
58
- } else {
59
- setCallDuration(0);
60
- }
61
-
62
- return () => {
63
- if (interval) clearInterval(interval);
64
- };
65
- }, [state.callStartTime]);
66
-
67
- // Notify parent of data changes
68
- useEffect(() => {
69
- if (onDataChange) {
70
- onDataChange(state.callData);
71
- }
72
- }, [state.callData, onDataChange]);
73
-
74
- const formatDuration = useCallback((seconds: number): string => {
75
- const mins = Math.floor(seconds / 60);
76
- const secs = seconds % 60;
77
- return `${mins.toString().padStart(2, "0")}:${secs
78
- .toString()
79
- .padStart(2, "0")}`;
80
- }, []);
81
-
82
- const getStatusColor = useCallback((status: CallStatus) => {
83
- switch (status) {
84
- case "ready":
85
- return "success";
86
- case "break":
87
- return "warning";
88
- case "idle":
89
- return "default";
90
- default:
91
- return "default";
92
- }
93
- }, []);
94
-
95
- const handleHoldToggle = () => {
96
- sdkStateManager.setHolding(!state.isHolding);
97
- };
98
-
99
- const handleMuteToggle = () => {
100
- sdkStateManager.setMuted(!state.isMuted);
101
- };
102
-
103
- const handleStatusChange = (newStatus: CallStatus) => {
104
- sdkStateManager.setStatus(newStatus);
105
- setAnchorEl(null);
106
- };
107
-
108
- const handleEndCall = () => {
109
- sdkStateManager.endCall();
110
- };
111
-
112
- const handleStartCall = () => {
113
- sdkStateManager.startCall();
114
- };
115
-
116
- const handleMoreClick = (event: React.MouseEvent<HTMLElement>) => {
117
- setAnchorEl(event.currentTarget);
118
- };
119
- const handleMoreOptions = (event: React.MouseEvent<HTMLElement>) => {
120
- setMoreOptionsAnchorEl(event.currentTarget);
121
- };
122
- const handleMoreClose = () => {
123
- setAnchorEl(null);
124
- };
125
-
126
- const handleMoreOptionsClose = () => {
127
- setMoreOptionsAnchorEl(null);
128
- };
129
-
130
- // if (!state.isInitialized) {
131
- // return (
132
- // <Paper
133
- // elevation={2}
134
- // sx={{
135
- // position: "fixed",
136
- // top: "50%",
137
- // left: "50%",
138
- // transform: "translate(-50%, -50%)",
139
- // p: 2,
140
- // borderRadius: 2,
141
- // bgcolor: "error.light",
142
- // color: "error.contrastText",
143
- // zIndex: 9999,
144
- // }}
145
- // >
146
- // <Typography variant="h6" gutterBottom>
147
- // SDK Error
148
- // </Typography>
149
- // <Typography variant="body2">
150
- // Call SDK not initialized. Please call initCallSDK() first.
151
- // </Typography>
152
- // </Paper>
153
- // );
154
- // }
155
-
156
- return (
157
- <>
158
- <Fade in={true} timeout={300}>
159
- <Paper
160
- ref={dragRef}
161
- elevation={isDragging ? 2 : 1}
162
- sx={{
163
- position: "fixed",
164
- left: position.x,
165
- top: position.y,
166
- p: 1,
167
- borderRadius: 3,
168
- bgcolor: "background.paper",
169
- cursor: isDragging ? "grabbing" : "grab",
170
- transition: theme.transitions.create(["box-shadow", "transform"], {
171
- duration: theme.transitions.duration.short,
172
- }),
173
- transform: isDragging ? "scale(1.01)" : "scale(1)",
174
- minWidth: 320,
175
- userSelect: "none",
176
- }}
177
- onMouseDown={handleMouseDown}
178
- onTouchStart={handleTouchStart}
179
- >
180
- <Box
181
- sx={{
182
- display: "flex",
183
- alignItems: "center",
184
- }}
185
- >
186
- {/* Status and Timer Row */}
187
- <Box
188
- sx={{
189
- display: "flex",
190
- justifyContent: "space-between",
191
- alignItems: "center",
192
- }}
193
- >
194
- <Typography
195
- variant="h6"
196
- sx={{
197
- color: state.callStartTime
198
- ? "success.main"
199
- : "text.secondary",
200
- marginRight: "8px",
201
- display: "flex",
202
- justifyContent: "space-between",
203
- alignItems: "center",
204
- }}
205
- >
206
- <DragIndicator
207
- sx={{
208
- marginRight: "10px",
209
- }}
210
- />{" "}
211
- {formatDuration(callDuration)}
212
- </Typography>
213
-
214
- <Tooltip title="Status">
215
- <Button
216
- sx={{
217
- backgroundColor: getStatusColor(state.status),
218
- fontWeight: "bold",
219
- borderRadius: "16px",
220
- display: "flex",
221
- alignItems: "center",
222
- justifyContent: "space-between",
223
- marginRight: "8px",
224
- }}
225
- onClick={(e) => {
226
- e.stopPropagation();
227
- handleMoreClick(e);
228
- }}
229
- variant="outlined"
230
- >
231
- <Typography
232
- width={50}
233
- variant="body2"
234
- sx={{
235
- fontWeight: "bold",
236
- }}
237
- >
238
- {state.status.toUpperCase()}
239
- </Typography>
240
-
241
- <KeyboardArrowDown />
242
- </Button>
243
- </Tooltip>
244
- </Box>
245
-
246
- {/* Control Buttons */}
247
- <Box
248
- sx={{
249
- display: "flex",
250
- gap: 1,
251
- justifyContent: "center",
252
- alignItems: "center",
253
- }}
254
- >
255
- <Tooltip title={"Redial"}>
256
- <IconButton
257
- onClick={(e) => {
258
- e.stopPropagation();
259
- }}
260
- color={"default"}
261
- sx={{
262
- bgcolor: "action.hover",
263
- "&:hover": {
264
- bgcolor: "warning",
265
- },
266
- }}
267
- >
268
- <Cached />
269
- </IconButton>
270
- </Tooltip>
271
- {/* Hold Button */}
272
- <Tooltip title={state.isHolding ? "Resume" : "Hold"}>
273
- <IconButton
274
- onClick={(e) => {
275
- e.stopPropagation();
276
- handleHoldToggle();
277
- }}
278
- color={state.isHolding ? "warning" : "default"}
279
- sx={{
280
- bgcolor: state.isHolding ? "warning.info" : "action.hover",
281
- }}
282
- >
283
- {state.isHolding ? <PlayCircle /> : <PauseCircle />}
284
- </IconButton>
285
- </Tooltip>
286
-
287
- {/* Mute Button */}
288
- <Tooltip title={state.isMuted ? "Unmute" : "Mute"}>
289
- <IconButton
290
- onClick={(e) => {
291
- e.stopPropagation();
292
- handleMuteToggle();
293
- }}
294
- color={state.isMuted ? "error" : "default"}
295
- sx={{
296
- bgcolor: state.isMuted ? "error.info" : "action.hover",
297
- }}
298
- >
299
- {state.isMuted ? <MicOff /> : <Mic />}
300
- </IconButton>
301
- </Tooltip>
302
-
303
- {/* More Menu Button */}
304
- <Tooltip title="More Options">
305
- <IconButton
306
- onClick={(e) => {
307
- e.stopPropagation();
308
- handleMoreOptions(e);
309
- }}
310
- sx={{
311
- bgcolor: "action.hover",
312
- "&:hover": { bgcolor: "action.selected" },
313
- }}
314
- >
315
- <MoreVert />
316
- </IconButton>
317
- </Tooltip>
318
-
319
- {/* End Call Button */}
320
- <Tooltip title={state.callStartTime ? "End Call" : "Start Call"}>
321
- <IconButton
322
- onClick={(e) => {
323
- e.stopPropagation();
324
- (state.callStartTime ? handleEndCall : handleStartCall)();
325
- }}
326
- color="error"
327
- sx={{
328
- bgcolor: state.callStartTime
329
- ? "error.main"
330
- : "success.light",
331
- color: "white",
332
- "&:hover": {
333
- bgcolor: state.callStartTime
334
- ? "error.light"
335
- : "success.dark",
336
- },
337
- }}
338
- >
339
- <CallEnd />
340
- </IconButton>
341
- </Tooltip>
342
- </Box>
343
- </Box>
344
- </Paper>
345
- </Fade>
346
-
347
- {/* More Options Menu */}
348
- <Menu
349
- anchorEl={anchorEl}
350
- open={Boolean(anchorEl)}
351
- onClose={handleMoreClose}
352
- onClick={(e) => e.stopPropagation()}
353
- >
354
- <MenuItem
355
- onClick={() => handleStatusChange("ready")}
356
- sx={{
357
- backgroundColor: state.status === "ready" ? "#0038f01c" : "initial",
358
- }}
359
- >
360
- <Box
361
- sx={{
362
- display: "flex",
363
- alignItems: "center",
364
- gap: 1,
365
- }}
366
- >
367
- <Phone color="success" />
368
- <Typography>Ready</Typography>
369
- </Box>
370
- </MenuItem>
371
- <MenuItem
372
- onClick={() => handleStatusChange("break")}
373
- sx={{
374
- backgroundColor: state.status === "break" ? "#0038f01c" : "initial",
375
- }}
376
- >
377
- <Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
378
- <FreeBreakfast color="error" />
379
- <Typography>Break</Typography>
380
- </Box>
381
- </MenuItem>
382
- <MenuItem
383
- onClick={() => handleStatusChange("idle")}
384
- sx={{
385
- backgroundColor: state.status === "idle" ? "#0038f01c" : "initial",
386
- }}
387
- >
388
- <Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
389
- <AirlineSeatIndividualSuite color="warning" />
390
- <Typography>Idle</Typography>
391
- </Box>
392
- </MenuItem>
393
- </Menu>
394
-
395
- <Menu
396
- anchorEl={moreOptionsAnchorEl}
397
- open={Boolean(moreOptionsAnchorEl)}
398
- onClose={handleMoreOptionsClose}
399
- onClick={(e) => e.stopPropagation()}
400
- >
401
- <MenuItem onClick={() => setMoreOptionsAnchorEl(null)}>
402
- <Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
403
- <TransferWithinAStation color="secondary" />
404
- <Typography>Call Transfer</Typography>
405
- </Box>
406
- </MenuItem>
407
- <MenuItem onClick={() => setMoreOptionsAnchorEl(null)}>
408
- <Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
409
- <Groups color="secondary" />
410
- <Typography>Conference Call</Typography>
411
- </Box>
412
- </MenuItem>
413
- <MenuItem onClick={() => setMoreOptionsAnchorEl(null)}>
414
- <Box sx={{ display: "flex", alignItems: "center", gap: 1 }}>
415
- <SpatialAudioOff color="secondary" />
416
- <Typography>Queue Waiting</Typography>
417
- </Box>
418
- </MenuItem>
419
- </Menu>
420
- </>
421
- );
422
- }