@yinshan-tech/webrtc-react 0.1.1 → 0.8.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/README.md +78 -66
- package/dist/CallWidget.d.ts +41 -0
- package/dist/CallWidget.js +266 -0
- package/dist/CallWidget.js.map +1 -0
- package/dist/OutboundCallButton.d.ts +20 -20
- package/dist/OutboundCallButton.js +57 -45
- package/dist/OutboundCallButton.js.map +1 -1
- package/dist/OutboundModeShell.d.ts +59 -0
- package/dist/OutboundModeShell.js +270 -0
- package/dist/OutboundModeShell.js.map +1 -0
- package/dist/SoftphoneProvider.d.ts +13 -0
- package/dist/SoftphoneProvider.js +21 -0
- package/dist/SoftphoneProvider.js.map +1 -0
- package/dist/ensureCallWidgetHost.d.ts +7 -0
- package/dist/ensureCallWidgetHost.js +57 -0
- package/dist/ensureCallWidgetHost.js.map +1 -0
- package/dist/hooks.d.ts +19 -0
- package/dist/hooks.js +67 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +20 -12
- package/dist/index.js +14 -9
- package/dist/index.js.map +1 -1
- package/dist/injectSoftphoneStyles.d.ts +2 -0
- package/dist/injectSoftphoneStyles.js +15 -0
- package/dist/injectSoftphoneStyles.js.map +1 -0
- package/dist/styles.css +306 -5
- package/dist/stylesInject.d.ts +2 -0
- package/dist/stylesInject.js +3 -0
- package/dist/stylesInject.js.map +1 -0
- package/package.json +25 -15
- package/dist/OutboundCallModal.d.ts +0 -49
- package/dist/OutboundCallModal.js +0 -279
- package/dist/OutboundCallModal.js.map +0 -1
- package/dist/ensureCallModalHost.d.ts +0 -7
- package/dist/ensureCallModalHost.js +0 -104
- package/dist/ensureCallModalHost.js.map +0 -1
- package/dist/useWebRTCInitialization.d.ts +0 -6
- package/dist/useWebRTCInitialization.js +0 -17
- package/dist/useWebRTCInitialization.js.map +0 -1
|
@@ -1,48 +1,51 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
var _a;
|
|
6
|
-
return ((_a = tryGetActiveKit()) === null || _a === void 0 ? void 0 : _a.config.messages['webrtc.outbound']) || 'Call Center';
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Plugin call button (one per table row).
|
|
10
|
-
* Usage: createWebRTCKit(...) once, then just render this component —
|
|
11
|
-
* the global call modal is auto-mounted.
|
|
12
|
-
*/
|
|
13
|
-
export const OutboundCallButton = (props) => {
|
|
2
|
+
import { tryUseSoftphoneContext } from './SoftphoneProvider';
|
|
3
|
+
import { ensureCallWidgetHost } from './ensureCallWidgetHost';
|
|
4
|
+
const OutboundCallButtonInner = (props) => {
|
|
14
5
|
var _a, _b;
|
|
15
|
-
const { loading = false, disabled = false, children, className, style, buttonText,
|
|
6
|
+
const { phone, loading = false, disabled = false, children, className, style, buttonText, onResult, confirmBeforeCall, autoMountWidget = false, render, dialPayload, displayName, remoteNumber, uiContext, phoneNumber, extNo, projectId, adminId, } = props;
|
|
16
7
|
const [busy, setBusy] = useState(false);
|
|
17
8
|
useEffect(() => {
|
|
18
|
-
if (
|
|
19
|
-
|
|
9
|
+
if (autoMountWidget) {
|
|
10
|
+
ensureCallWidgetHost({ phone });
|
|
20
11
|
}
|
|
21
|
-
}, [
|
|
12
|
+
}, [autoMountWidget, phone]);
|
|
22
13
|
const start = useCallback(async () => {
|
|
23
14
|
if (disabled || busy || loading)
|
|
24
15
|
return;
|
|
25
16
|
if (confirmBeforeCall && !(await confirmBeforeCall()))
|
|
26
17
|
return;
|
|
27
|
-
if (
|
|
28
|
-
|
|
18
|
+
if (autoMountWidget) {
|
|
19
|
+
ensureCallWidgetHost({ phone });
|
|
20
|
+
}
|
|
21
|
+
// Unlock HTMLAudio in the same user-gesture tick before any await
|
|
22
|
+
try {
|
|
23
|
+
phone.unlockAudio();
|
|
24
|
+
}
|
|
25
|
+
catch (_a) {
|
|
26
|
+
// ignore if not connected yet — dial path will init tones after connect
|
|
29
27
|
}
|
|
30
28
|
setBusy(true);
|
|
31
29
|
try {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
if (phone.getRegistration() !== 'registered') {
|
|
31
|
+
await phone.connect();
|
|
32
|
+
try {
|
|
33
|
+
phone.unlockAudio();
|
|
34
|
+
}
|
|
35
|
+
catch (_b) {
|
|
36
|
+
// ignore
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const result = await phone.dial({
|
|
40
|
+
dialPayload,
|
|
41
|
+
displayName,
|
|
42
|
+
remoteNumber,
|
|
43
|
+
uiContext,
|
|
42
44
|
phoneNumber,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
extNo,
|
|
46
|
+
projectId,
|
|
47
|
+
adminId,
|
|
48
|
+
});
|
|
46
49
|
onResult === null || onResult === void 0 ? void 0 : onResult(result);
|
|
47
50
|
}
|
|
48
51
|
finally {
|
|
@@ -53,28 +56,37 @@ export const OutboundCallButton = (props) => {
|
|
|
53
56
|
busy,
|
|
54
57
|
loading,
|
|
55
58
|
confirmBeforeCall,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
contactMobile,
|
|
63
|
-
customerHistoryMobile,
|
|
64
|
-
providerType,
|
|
65
|
-
instanceId,
|
|
59
|
+
autoMountWidget,
|
|
60
|
+
phone,
|
|
61
|
+
dialPayload,
|
|
62
|
+
displayName,
|
|
63
|
+
remoteNumber,
|
|
64
|
+
uiContext,
|
|
66
65
|
phoneNumber,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
extNo,
|
|
67
|
+
projectId,
|
|
68
|
+
adminId,
|
|
70
69
|
onResult,
|
|
71
70
|
]);
|
|
72
71
|
const isLoading = loading || busy;
|
|
73
|
-
const text = (_b = (_a = (typeof children === 'string' ? children : undefined)) !== null && _a !== void 0 ? _a : buttonText) !== null && _b !== void 0 ? _b :
|
|
72
|
+
const text = (_b = (_a = (typeof children === 'string' ? children : undefined)) !== null && _a !== void 0 ? _a : buttonText) !== null && _b !== void 0 ? _b : 'Call Center';
|
|
74
73
|
if (render) {
|
|
75
74
|
return render({ start, busy: isLoading, disabled, text });
|
|
76
75
|
}
|
|
77
76
|
return (React.createElement("button", { type: "button", className: ['wro-btn', className].filter(Boolean).join(' '), style: style, disabled: disabled || isLoading, onClick: start, "aria-busy": isLoading }, children !== null && children !== void 0 ? children : text));
|
|
78
77
|
};
|
|
78
|
+
/**
|
|
79
|
+
* Dial trigger. Prefer SoftphoneProvider; or pass `phone` prop.
|
|
80
|
+
* Does not subscribe to global Softphone notify (avoids N× toast with table rows).
|
|
81
|
+
*/
|
|
82
|
+
export const OutboundCallButton = (props) => {
|
|
83
|
+
var _a;
|
|
84
|
+
const ctx = tryUseSoftphoneContext();
|
|
85
|
+
const phone = (_a = props.phone) !== null && _a !== void 0 ? _a : ctx;
|
|
86
|
+
if (!phone) {
|
|
87
|
+
throw new Error('[webrtc-react] OutboundCallButton needs SoftphoneProvider or a phone prop');
|
|
88
|
+
}
|
|
89
|
+
return React.createElement(OutboundCallButtonInner, Object.assign({}, props, { phone: phone }));
|
|
90
|
+
};
|
|
79
91
|
export default OutboundCallButton;
|
|
80
92
|
//# sourceMappingURL=OutboundCallButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OutboundCallButton.js","sourceRoot":"","sources":["../src/OutboundCallButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"OutboundCallButton.js","sourceRoot":"","sources":["../src/OutboundCallButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EA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,GAAI,IAAI,CACV,CACV,CAAC;AACJ,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAsC,CAAC,KAAK,EAAE,EAAE;;IAC7E,MAAM,GAAG,GAAG,sBAAsB,EAAE,CAAC;IACrC,MAAM,KAAK,GAAG,MAAA,KAAK,CAAC,KAAK,mCAAI,GAAG,CAAC;IACjC,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;KACH;IACD,OAAO,oBAAC,uBAAuB,oBAAK,KAAK,IAAE,KAAK,EAAE,KAAK,IAAI,CAAC;AAC9D,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { CallSnapshot, Softphone } from '@yinshan-tech/webrtc-sdk';
|
|
3
|
+
export type OutboundMode = 'manual' | 'predictive' | 'progressive';
|
|
4
|
+
export type OutboundModeSessionProps = {
|
|
5
|
+
agentStatusText?: string;
|
|
6
|
+
batchProgress?: {
|
|
7
|
+
done: number;
|
|
8
|
+
total: number;
|
|
9
|
+
connected: number;
|
|
10
|
+
missed: number;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type OutboundModeShellTexts = {
|
|
14
|
+
title?: string;
|
|
15
|
+
customer?: string;
|
|
16
|
+
calling?: string;
|
|
17
|
+
connected?: string;
|
|
18
|
+
ended?: string;
|
|
19
|
+
failed?: string;
|
|
20
|
+
hangup?: string;
|
|
21
|
+
close?: string;
|
|
22
|
+
mute?: string;
|
|
23
|
+
unmute?: string;
|
|
24
|
+
minimize?: string;
|
|
25
|
+
agentStatus?: string;
|
|
26
|
+
batchProgress?: string;
|
|
27
|
+
connectedCount?: string;
|
|
28
|
+
missedCount?: string;
|
|
29
|
+
};
|
|
30
|
+
export type OutboundModeShellRenderCtx = {
|
|
31
|
+
call: CallSnapshot | null;
|
|
32
|
+
uiContext: Record<string, unknown> | undefined;
|
|
33
|
+
};
|
|
34
|
+
export type OutboundModeShellProps = {
|
|
35
|
+
phone?: Softphone;
|
|
36
|
+
mode: OutboundMode;
|
|
37
|
+
modeSession?: OutboundModeSessionProps;
|
|
38
|
+
title?: string;
|
|
39
|
+
/** Default: mode !== 'manual' */
|
|
40
|
+
visibleWhenNoCall?: boolean;
|
|
41
|
+
renderModeActions?: () => React.ReactNode;
|
|
42
|
+
renderBusinessInfo?: (ctx: OutboundModeShellRenderCtx) => React.ReactNode;
|
|
43
|
+
renderStatusExtra?: (ctx: {
|
|
44
|
+
call: CallSnapshot | null;
|
|
45
|
+
}) => React.ReactNode;
|
|
46
|
+
className?: string;
|
|
47
|
+
style?: React.CSSProperties;
|
|
48
|
+
cssVars?: Record<string, string>;
|
|
49
|
+
zIndex?: number;
|
|
50
|
+
showMute?: boolean;
|
|
51
|
+
showMinimize?: boolean;
|
|
52
|
+
texts?: OutboundModeShellTexts;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Multi-mode outbound workbench shell.
|
|
56
|
+
* Hosts own mode-session actions and business info via slots.
|
|
57
|
+
*/
|
|
58
|
+
export declare const OutboundModeShell: React.FC<OutboundModeShellProps>;
|
|
59
|
+
export default OutboundModeShell;
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { tryUseSoftphoneContext } from './SoftphoneProvider';
|
|
3
|
+
import { injectSoftphoneStyles } from './injectSoftphoneStyles';
|
|
4
|
+
function IconMinus() {
|
|
5
|
+
return (React.createElement("svg", { width: "14", height: "14", viewBox: "0 0 14 14", "aria-hidden": true },
|
|
6
|
+
React.createElement("path", { d: "M2.5 7h9", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round" })));
|
|
7
|
+
}
|
|
8
|
+
function IconPhone() {
|
|
9
|
+
return (React.createElement("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": true },
|
|
10
|
+
React.createElement("path", { d: "M6.62 10.79a15.05 15.05 0 006.59 6.59l2.2-2.2a1 1 0 011.01-.24c1.12.37 2.33.57 3.58.57a1 1 0 011 1V20a1 1 0 01-1 1C10.4 21 3 13.6 3 4a1 1 0 011-1h3.5a1 1 0 011 1c0 1.25.2 2.46.57 3.58a1 1 0 01-.24 1.01l-2.21 2.2z" })));
|
|
11
|
+
}
|
|
12
|
+
function IconMic({ muted }) {
|
|
13
|
+
if (muted) {
|
|
14
|
+
return (React.createElement("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": true },
|
|
15
|
+
React.createElement("path", { d: "M19 11h-1.7a5.3 5.3 0 01-.5 2.1l1.3 1.3A7 7 0 0019 11zM12 4a3 3 0 013 3v.2l1.8 1.8V7a4.8 4.8 0 00-9.6 0v4c0 .3 0 .6.1.9l1.5 1.5.1-.4V7a3 3 0 013-3zM4.3 3L3 4.3 9.7 11v1a2.3 2.3 0 002.3 2.3h.2L16 18.5V19h-4v2h6.7L19.7 23 21 21.7 4.3 3z" })));
|
|
16
|
+
}
|
|
17
|
+
return (React.createElement("svg", { width: "22", height: "22", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": true },
|
|
18
|
+
React.createElement("path", { d: "M12 14a3 3 0 003-3V5a3 3 0 10-6 0v6a3 3 0 003 3zm5-3a5 5 0 01-10 0H5a7 7 0 006 6.9V21h2v-3.1A7 7 0 0019 11h-2z" })));
|
|
19
|
+
}
|
|
20
|
+
function pad2(n) {
|
|
21
|
+
return n.toString().padStart(2, '0');
|
|
22
|
+
}
|
|
23
|
+
function phaseUi(phase) {
|
|
24
|
+
switch (phase) {
|
|
25
|
+
case 'dialing':
|
|
26
|
+
case 'ringing':
|
|
27
|
+
case 'ending':
|
|
28
|
+
return 'calling';
|
|
29
|
+
case 'active':
|
|
30
|
+
return 'connected';
|
|
31
|
+
case 'ended':
|
|
32
|
+
return 'ended';
|
|
33
|
+
case 'failed':
|
|
34
|
+
return 'failed';
|
|
35
|
+
default:
|
|
36
|
+
return 'idle';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Multi-mode outbound workbench shell.
|
|
41
|
+
* Hosts own mode-session actions and business info via slots.
|
|
42
|
+
*/
|
|
43
|
+
export const OutboundModeShell = (props) => {
|
|
44
|
+
var _a;
|
|
45
|
+
const ctx = tryUseSoftphoneContext();
|
|
46
|
+
const phone = (_a = props.phone) !== null && _a !== void 0 ? _a : ctx;
|
|
47
|
+
if (!phone) {
|
|
48
|
+
throw new Error('[webrtc-react] OutboundModeShell needs SoftphoneProvider or a phone prop');
|
|
49
|
+
}
|
|
50
|
+
const { mode, modeSession, title, visibleWhenNoCall = mode !== 'manual', renderModeActions, renderBusinessInfo, renderStatusExtra, className, style, cssVars, zIndex, showMute = true, showMinimize = true, texts, } = props;
|
|
51
|
+
const [call, setCall] = useState(() => phone.getCall());
|
|
52
|
+
const [dismissedId, setDismissedId] = useState(null);
|
|
53
|
+
const [minimized, setMinimized] = useState(false);
|
|
54
|
+
const [duration, setDuration] = useState('00:00');
|
|
55
|
+
const [pos, setPos] = useState(null);
|
|
56
|
+
const startTimeRef = useRef(null);
|
|
57
|
+
const dragRef = useRef(null);
|
|
58
|
+
const t = useCallback((code, fallback) => { var _a; return (_a = texts === null || texts === void 0 ? void 0 : texts[code]) !== null && _a !== void 0 ? _a : fallback; }, [texts]);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
injectSoftphoneStyles();
|
|
61
|
+
}, []);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
setCall(phone.getCall());
|
|
64
|
+
return phone.subscribe((ev) => {
|
|
65
|
+
if (ev.type === 'call') {
|
|
66
|
+
setCall(ev.call);
|
|
67
|
+
if (ev.call.phase === 'dialing' || ev.call.phase === 'ringing') {
|
|
68
|
+
setDismissedId(null);
|
|
69
|
+
setMinimized(false);
|
|
70
|
+
}
|
|
71
|
+
if (ev.call.phase === 'ended' || ev.call.phase === 'failed') {
|
|
72
|
+
setDismissedId(ev.call.id);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}, [phone]);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
const timer = setInterval(() => {
|
|
79
|
+
if ((call === null || call === void 0 ? void 0 : call.phase) === 'active') {
|
|
80
|
+
if (!startTimeRef.current) {
|
|
81
|
+
startTimeRef.current = call.startedAt || Date.now();
|
|
82
|
+
}
|
|
83
|
+
const startedAt = startTimeRef.current;
|
|
84
|
+
const diff = Math.round((Date.now() - startedAt) / 1000);
|
|
85
|
+
setDuration(`${pad2(Math.floor(diff / 60))}:${pad2(diff % 60)}`);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
startTimeRef.current = null;
|
|
89
|
+
setDuration('00:00');
|
|
90
|
+
}
|
|
91
|
+
}, 1000);
|
|
92
|
+
return () => clearInterval(timer);
|
|
93
|
+
}, [call]);
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (!call)
|
|
96
|
+
return;
|
|
97
|
+
if (call.phase === 'ended' || call.phase === 'failed') {
|
|
98
|
+
setDismissedId(call.id);
|
|
99
|
+
}
|
|
100
|
+
}, [call]);
|
|
101
|
+
const ui = call ? phaseUi(call.phase) : 'idle';
|
|
102
|
+
const hasActiveSurface = !!call && ui !== 'idle' && dismissedId !== call.id;
|
|
103
|
+
const showShell = visibleWhenNoCall || hasActiveSurface;
|
|
104
|
+
const rootStyle = useMemo(() => {
|
|
105
|
+
const s = Object.assign({}, (cssVars || {}));
|
|
106
|
+
if (zIndex != null)
|
|
107
|
+
s['--wro-modal-z'] = String(zIndex);
|
|
108
|
+
return s;
|
|
109
|
+
}, [cssVars, zIndex]);
|
|
110
|
+
const stateText = useCallback((phase) => {
|
|
111
|
+
const u = phaseUi(phase);
|
|
112
|
+
if (u === 'calling')
|
|
113
|
+
return t('calling', 'Calling...');
|
|
114
|
+
if (u === 'connected')
|
|
115
|
+
return t('connected', 'In call');
|
|
116
|
+
if (u === 'ended')
|
|
117
|
+
return t('ended', 'Call ended');
|
|
118
|
+
if (u === 'failed')
|
|
119
|
+
return t('failed', 'Call failed');
|
|
120
|
+
return '';
|
|
121
|
+
}, [t]);
|
|
122
|
+
const hangup = useCallback(() => {
|
|
123
|
+
if (!call)
|
|
124
|
+
return;
|
|
125
|
+
if (call.phase === 'failed' || call.phase === 'ended') {
|
|
126
|
+
setDismissedId(call.id);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
phone.hangup();
|
|
130
|
+
setDismissedId(call.id);
|
|
131
|
+
}, [call, phone]);
|
|
132
|
+
const toggleMute = useCallback(() => {
|
|
133
|
+
if (!call || call.phase !== 'active')
|
|
134
|
+
return;
|
|
135
|
+
phone.setMuted(!phone.isMuted());
|
|
136
|
+
}, [call, phone]);
|
|
137
|
+
const onDragStart = useCallback((e, isMini = false) => {
|
|
138
|
+
const target = e.target;
|
|
139
|
+
if (target.closest('button') || target.closest('.wro-shell__mode-actions'))
|
|
140
|
+
return;
|
|
141
|
+
e.preventDefault();
|
|
142
|
+
const el = e.currentTarget;
|
|
143
|
+
const rect = el.getBoundingClientRect();
|
|
144
|
+
el.style.left = `${rect.left}px`;
|
|
145
|
+
el.style.top = `${rect.top}px`;
|
|
146
|
+
el.style.right = 'auto';
|
|
147
|
+
dragRef.current = {
|
|
148
|
+
el,
|
|
149
|
+
startClientX: e.clientX,
|
|
150
|
+
startClientY: e.clientY,
|
|
151
|
+
originX: rect.left,
|
|
152
|
+
originY: rect.top,
|
|
153
|
+
moved: false,
|
|
154
|
+
isMini,
|
|
155
|
+
};
|
|
156
|
+
const onMove = (ev) => {
|
|
157
|
+
const d = dragRef.current;
|
|
158
|
+
if (!d)
|
|
159
|
+
return;
|
|
160
|
+
const dx = ev.clientX - d.startClientX;
|
|
161
|
+
const dy = ev.clientY - d.startClientY;
|
|
162
|
+
if (!d.moved && Math.hypot(dx, dy) < 5)
|
|
163
|
+
return;
|
|
164
|
+
d.moved = true;
|
|
165
|
+
d.el.classList.add('is-dragging');
|
|
166
|
+
const maxX = Math.max(0, window.innerWidth - d.el.offsetWidth);
|
|
167
|
+
const maxY = Math.max(0, window.innerHeight - d.el.offsetHeight);
|
|
168
|
+
const x = Math.max(0, Math.min(d.originX + dx, maxX));
|
|
169
|
+
const y = Math.max(0, Math.min(d.originY + dy, maxY));
|
|
170
|
+
d.el.style.left = `${x}px`;
|
|
171
|
+
d.el.style.top = `${y}px`;
|
|
172
|
+
};
|
|
173
|
+
const onUp = () => {
|
|
174
|
+
const d = dragRef.current;
|
|
175
|
+
document.removeEventListener('mousemove', onMove);
|
|
176
|
+
document.removeEventListener('mouseup', onUp);
|
|
177
|
+
dragRef.current = null;
|
|
178
|
+
if (!d)
|
|
179
|
+
return;
|
|
180
|
+
d.el.classList.remove('is-dragging');
|
|
181
|
+
if (d.moved) {
|
|
182
|
+
setPos({
|
|
183
|
+
x: parseFloat(d.el.style.left) || d.originX,
|
|
184
|
+
y: parseFloat(d.el.style.top) || d.originY,
|
|
185
|
+
});
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (d.isMini)
|
|
189
|
+
setMinimized(false);
|
|
190
|
+
};
|
|
191
|
+
document.addEventListener('mousemove', onMove);
|
|
192
|
+
document.addEventListener('mouseup', onUp);
|
|
193
|
+
}, []);
|
|
194
|
+
if (!showShell)
|
|
195
|
+
return null;
|
|
196
|
+
const muted = !!((call === null || call === void 0 ? void 0 : call.muted) || (call && phone.isMuted()));
|
|
197
|
+
const canHangup = !!(call &&
|
|
198
|
+
(call.canHangup || call.phase === 'failed' || call.phase === 'ended'));
|
|
199
|
+
const name = (call === null || call === void 0 ? void 0 : call.displayName) || t('customer', 'Customer');
|
|
200
|
+
const number = call === null || call === void 0 ? void 0 : call.remoteNumber;
|
|
201
|
+
const shellTitle = title || t('title', 'Auto Agent Phone');
|
|
202
|
+
const floatStyle = pos
|
|
203
|
+
? { left: pos.x, top: pos.y, right: 'auto' }
|
|
204
|
+
: undefined;
|
|
205
|
+
const batch = modeSession === null || modeSession === void 0 ? void 0 : modeSession.batchProgress;
|
|
206
|
+
const batchPct = batch && batch.total > 0 ? Math.min(100, Math.round((batch.done / batch.total) * 100)) : 0;
|
|
207
|
+
const miniLabel = number || name;
|
|
208
|
+
if (minimized && hasActiveSurface) {
|
|
209
|
+
return (React.createElement("div", { className: "wro-root", style: rootStyle },
|
|
210
|
+
React.createElement("div", { className: "wro-shell-mini", style: floatStyle, onMouseDown: (e) => onDragStart(e, true), role: "button", tabIndex: 0 },
|
|
211
|
+
React.createElement("div", { className: "wro-shell-mini__name" }, miniLabel),
|
|
212
|
+
ui === 'connected' ? (React.createElement("div", { className: "wro-shell-mini__duration" }, duration)) : (React.createElement("div", { className: "wro-shell-mini__status" }, call ? stateText(call.phase) : '')))));
|
|
213
|
+
}
|
|
214
|
+
return (React.createElement("div", { className: "wro-root", style: rootStyle },
|
|
215
|
+
React.createElement("div", { className: ['wro-shell', `wro-shell--${mode}`, className].filter(Boolean).join(' '), style: Object.assign(Object.assign({}, style), floatStyle), role: "dialog", "aria-modal": "false", onMouseDown: (e) => onDragStart(e, false) },
|
|
216
|
+
React.createElement("div", { className: "wro-shell__header" },
|
|
217
|
+
React.createElement("div", { className: "wro-shell__title" },
|
|
218
|
+
React.createElement("span", { className: "wro-shell__title-icon", "aria-hidden": true },
|
|
219
|
+
React.createElement(IconPhone, null)),
|
|
220
|
+
React.createElement("span", null, shellTitle)),
|
|
221
|
+
showMinimize && hasActiveSurface && (React.createElement("button", { type: "button", className: "wro-shell__icon-btn", title: t('minimize', 'Minimize'), "aria-label": t('minimize', 'Minimize'), onClick: () => setMinimized(true) },
|
|
222
|
+
React.createElement(IconMinus, null)))),
|
|
223
|
+
(mode === 'predictive' || mode === 'progressive') && (React.createElement("div", { className: "wro-shell__mode-bar" },
|
|
224
|
+
mode === 'predictive' && (React.createElement("div", { className: "wro-shell__agent-status" },
|
|
225
|
+
React.createElement("span", null, t('agentStatus', 'Agent status')),
|
|
226
|
+
React.createElement("span", { className: "wro-shell__agent-status-value" }, (modeSession === null || modeSession === void 0 ? void 0 : modeSession.agentStatusText) || '—'))),
|
|
227
|
+
renderModeActions ? (React.createElement("div", { className: "wro-shell__mode-actions" }, renderModeActions())) : null)),
|
|
228
|
+
hasActiveSurface && call ? (React.createElement(React.Fragment, null,
|
|
229
|
+
React.createElement("div", { className: "wro-shell__call-status" },
|
|
230
|
+
React.createElement("span", { className: [
|
|
231
|
+
'wro-shell__state',
|
|
232
|
+
ui === 'calling' ? 'is-calling' : '',
|
|
233
|
+
ui === 'connected' ? 'is-connected' : '',
|
|
234
|
+
ui === 'failed' ? 'is-failed' : '',
|
|
235
|
+
]
|
|
236
|
+
.filter(Boolean)
|
|
237
|
+
.join(' ') }, stateText(call.phase)), renderStatusExtra === null || renderStatusExtra === void 0 ? void 0 :
|
|
238
|
+
renderStatusExtra({ call })),
|
|
239
|
+
number ? React.createElement("div", { className: "wro-shell__number" }, number) : null,
|
|
240
|
+
React.createElement("div", { className: "wro-shell__name", title: name }, name))) : (React.createElement("div", { className: "wro-shell__idle-hint" }, mode === 'manual' ? null : '—')), renderBusinessInfo === null || renderBusinessInfo === void 0 ? void 0 :
|
|
241
|
+
renderBusinessInfo({ call, uiContext: call === null || call === void 0 ? void 0 : call.uiContext }),
|
|
242
|
+
hasActiveSurface && call ? (React.createElement(React.Fragment, null,
|
|
243
|
+
React.createElement("div", { className: "wro-shell__duration" }, duration),
|
|
244
|
+
React.createElement("div", { className: "wro-shell__actions" },
|
|
245
|
+
showMute && ui === 'connected' && (React.createElement("button", { type: "button", className: ['wro-shell__circle', muted ? 'is-muted' : 'is-unmuted'].join(' '), onClick: toggleMute, title: muted ? t('unmute', 'Unmute') : t('mute', 'Mute') },
|
|
246
|
+
React.createElement(IconMic, { muted: muted }))),
|
|
247
|
+
React.createElement("button", { type: "button", className: "wro-shell__circle is-hangup", disabled: !canHangup && ui !== 'failed', onClick: hangup, title: ui === 'failed' || ui === 'ended' ? t('close', 'Close') : t('hangup', 'Hang up') },
|
|
248
|
+
React.createElement("span", { className: "wro-shell__hangup-icon" },
|
|
249
|
+
React.createElement(IconPhone, null)))))) : null,
|
|
250
|
+
mode === 'progressive' && batch ? (React.createElement("div", { className: "wro-shell__batch" },
|
|
251
|
+
React.createElement("div", { className: "wro-shell__batch-head" },
|
|
252
|
+
React.createElement("span", null, t('batchProgress', 'Batch progress')),
|
|
253
|
+
React.createElement("span", null,
|
|
254
|
+
batch.done,
|
|
255
|
+
"/",
|
|
256
|
+
batch.total)),
|
|
257
|
+
React.createElement("div", { className: "wro-shell__batch-bar", "aria-hidden": true },
|
|
258
|
+
React.createElement("div", { className: "wro-shell__batch-bar-fill", style: { width: `${batchPct}%` } })),
|
|
259
|
+
React.createElement("div", { className: "wro-shell__batch-stats" },
|
|
260
|
+
React.createElement("span", null,
|
|
261
|
+
t('connectedCount', 'Connected'),
|
|
262
|
+
": ",
|
|
263
|
+
batch.connected),
|
|
264
|
+
React.createElement("span", null,
|
|
265
|
+
t('missedCount', 'Not connected'),
|
|
266
|
+
": ",
|
|
267
|
+
batch.missed)))) : null)));
|
|
268
|
+
};
|
|
269
|
+
export default OutboundModeShell;
|
|
270
|
+
//# sourceMappingURL=OutboundModeShell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OutboundModeShell.js","sourceRoot":"","sources":["../src/OutboundModeShell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAwDhE,SAAS,SAAS;IAChB,OAAO,CACL,6BAAK,KAAK,EAAC,IAAI,EAAC,MAAM,EAAC,IAAI,EAAC,OAAO,EAAC,WAAW;QA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AAa,EAAE,eAAe,CAAC;;wBAAI,KAAK,CAAC,MAAM,CAC7C,CACH,CACF,CACP,CAAC,CAAC,CAAC,IAAI,CACJ,CACF,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Softphone } from '@yinshan-tech/webrtc-sdk';
|
|
3
|
+
export interface SoftphoneProviderProps {
|
|
4
|
+
phone: Softphone;
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Inject a Softphone instance for descendants (button / widget / hooks).
|
|
9
|
+
* Host creates phone via createSoftphone() and owns its lifecycle.
|
|
10
|
+
*/
|
|
11
|
+
export declare const SoftphoneProvider: React.FC<SoftphoneProviderProps>;
|
|
12
|
+
export declare function useSoftphoneContext(): Softphone;
|
|
13
|
+
export declare function tryUseSoftphoneContext(): Softphone | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React, { createContext, useContext, useMemo } from 'react';
|
|
2
|
+
const SoftphoneContext = createContext(null);
|
|
3
|
+
/**
|
|
4
|
+
* Inject a Softphone instance for descendants (button / widget / hooks).
|
|
5
|
+
* Host creates phone via createSoftphone() and owns its lifecycle.
|
|
6
|
+
*/
|
|
7
|
+
export const SoftphoneProvider = ({ phone, children }) => {
|
|
8
|
+
const value = useMemo(() => phone, [phone]);
|
|
9
|
+
return React.createElement(SoftphoneContext.Provider, { value: value }, children);
|
|
10
|
+
};
|
|
11
|
+
export function useSoftphoneContext() {
|
|
12
|
+
const phone = useContext(SoftphoneContext);
|
|
13
|
+
if (!phone) {
|
|
14
|
+
throw new Error('[webrtc-react] SoftphoneProvider is missing. Wrap your tree with <SoftphoneProvider phone={phone}>.');
|
|
15
|
+
}
|
|
16
|
+
return phone;
|
|
17
|
+
}
|
|
18
|
+
export function tryUseSoftphoneContext() {
|
|
19
|
+
return useContext(SoftphoneContext);
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=SoftphoneProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SoftphoneProvider.js","sourceRoot":"","sources":["../src/SoftphoneProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAGlE,MAAM,gBAAgB,GAAG,aAAa,CAAmB,IAAI,CAAC,CAAC;AAO/D;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAqC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;IACzF,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5C,OAAO,oBAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAAG,QAAQ,CAA6B,CAAC;AACzF,CAAC,CAAC;AAEF,MAAM,UAAU,mBAAmB;IACjC,MAAM,KAAK,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC3C,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,KAAK,CACb,qGAAqG,CACtG,CAAC;KACH;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,UAAU,CAAC,gBAAgB,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Softphone } from '@yinshan-tech/webrtc-sdk';
|
|
2
|
+
import type { CallWidgetProps } from './CallWidget';
|
|
3
|
+
export type EnsureCallWidgetHostOptions = CallWidgetProps & {
|
|
4
|
+
phone: Softphone;
|
|
5
|
+
};
|
|
6
|
+
export declare function ensureCallWidgetHost(options: EnsureCallWidgetHostOptions): void;
|
|
7
|
+
export declare function destroyCallWidgetHost(): void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Lazily mount a single global CallWidget.
|
|
14
|
+
* CSS comes from styles.css (embedded via stylesInject) — single source of truth.
|
|
15
|
+
*/
|
|
16
|
+
import React from 'react';
|
|
17
|
+
import { createRoot } from 'react-dom/client';
|
|
18
|
+
import { CallWidget } from './CallWidget';
|
|
19
|
+
import { SoftphoneProvider } from './SoftphoneProvider';
|
|
20
|
+
import { injectSoftphoneStyles } from './injectSoftphoneStyles';
|
|
21
|
+
const HOST_ID = 'wro-react-call-widget-host';
|
|
22
|
+
let mounted = false;
|
|
23
|
+
let root = null;
|
|
24
|
+
let mountedPhone = null;
|
|
25
|
+
export function ensureCallWidgetHost(options) {
|
|
26
|
+
if (typeof document === 'undefined')
|
|
27
|
+
return;
|
|
28
|
+
const { phone } = options, widgetProps = __rest(options, ["phone"]);
|
|
29
|
+
injectSoftphoneStyles();
|
|
30
|
+
if (mounted && mountedPhone === phone && root) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
let host = document.getElementById(HOST_ID);
|
|
34
|
+
if (!host) {
|
|
35
|
+
host = document.createElement('div');
|
|
36
|
+
host.id = HOST_ID;
|
|
37
|
+
document.body.appendChild(host);
|
|
38
|
+
}
|
|
39
|
+
if (!root) {
|
|
40
|
+
root = createRoot(host);
|
|
41
|
+
}
|
|
42
|
+
root.render(React.createElement(SoftphoneProvider, { phone: phone },
|
|
43
|
+
React.createElement(CallWidget, Object.assign({}, widgetProps, { phone: phone }))));
|
|
44
|
+
mounted = true;
|
|
45
|
+
mountedPhone = phone;
|
|
46
|
+
}
|
|
47
|
+
export function destroyCallWidgetHost() {
|
|
48
|
+
if (root) {
|
|
49
|
+
root.unmount();
|
|
50
|
+
root = null;
|
|
51
|
+
}
|
|
52
|
+
mounted = false;
|
|
53
|
+
mountedPhone = null;
|
|
54
|
+
const host = document.getElementById(HOST_ID);
|
|
55
|
+
host === null || host === void 0 ? void 0 : host.remove();
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=ensureCallWidgetHost.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensureCallWidgetHost.js","sourceRoot":"","sources":["../src/ensureCallWidgetHost.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA;;;GAGG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAa,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,MAAM,OAAO,GAAG,4BAA4B,CAAC;AAC7C,IAAI,OAAO,GAAG,KAAK,CAAC;AACpB,IAAI,IAAI,GAAgB,IAAI,CAAC;AAC7B,IAAI,YAAY,GAAqB,IAAI,CAAC;AAM1C,MAAM,UAAU,oBAAoB,CAAC,OAAoC;IACvE,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAO;IAC5C,MAAM,EAAE,KAAK,KAAqB,OAAO,EAAvB,WAAW,UAAK,OAAO,EAAnC,SAAyB,CAAU,CAAC;IAC1C,qBAAqB,EAAE,CAAC;IAExB,IAAI,OAAO,IAAI,YAAY,KAAK,KAAK,IAAI,IAAI,EAAE;QAC7C,OAAO;KACR;IAED,IAAI,IAAI,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,CAAC,IAAI,EAAE;QACT,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC;QAClB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;KACjC;IAED,IAAI,CAAC,IAAI,EAAE;QACT,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;KACzB;IAED,IAAI,CAAC,MAAM,CACT,oBAAC,iBAAiB,IAAC,KAAK,EAAE,KAAK;QAC7B,oBAAC,UAAU,oBAAK,WAAW,IAAE,KAAK,EAAE,KAAK,IAAI,CAC3B,CACrB,CAAC;IACF,OAAO,GAAG,IAAI,CAAC;IACf,YAAY,GAAG,KAAK,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,qBAAqB;IACnC,IAAI,IAAI,EAAE;QACR,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAI,GAAG,IAAI,CAAC;KACb;IACD,OAAO,GAAG,KAAK,CAAC;IAChB,YAAY,GAAG,IAAI,CAAC;IACpB,MAAM,IAAI,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAC9C,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,EAAE,CAAC;AACjB,CAAC"}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CallSnapshot, RegistrationStatus } from '@yinshan-tech/webrtc-sdk';
|
|
2
|
+
import type { SoftphoneNotify } from './OutboundCallButton';
|
|
3
|
+
export declare function useSoftphone(): import("@yinshan-tech/webrtc-sdk").Softphone;
|
|
4
|
+
/**
|
|
5
|
+
* Single subscriber for Softphone `notify` events.
|
|
6
|
+
* Mount once under SoftphoneProvider (e.g. SoftphoneRoot) — never per dial button.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useSoftphoneNotify(handler: (notify: SoftphoneNotify) => void): void;
|
|
9
|
+
export declare function useCallSnapshot(): CallSnapshot | null;
|
|
10
|
+
export declare function useRegistration(): RegistrationStatus;
|
|
11
|
+
export interface UseSoftphoneConnectOptions {
|
|
12
|
+
/** Auto connect on mount. Default true */
|
|
13
|
+
autoConnect?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Connect softphone once on mount (optional). */
|
|
16
|
+
export declare function useSoftphoneConnect(options?: UseSoftphoneConnectOptions): {
|
|
17
|
+
status: RegistrationStatus;
|
|
18
|
+
error: string | null;
|
|
19
|
+
};
|