@yinshan-tech/webrtc-react 0.1.1 → 0.8.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 +78 -66
- package/dist/CallWidget.d.ts +43 -0
- package/dist/CallWidget.js +275 -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 +60 -0
- package/dist/OutboundModeShell.js +279 -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
package/README.md
CHANGED
|
@@ -1,89 +1,101 @@
|
|
|
1
1
|
# @yinshan-tech/webrtc-react
|
|
2
2
|
|
|
3
|
-
`@yinshan-tech/webrtc-sdk`
|
|
3
|
+
React UI for [`@yinshan-tech/webrtc-sdk`](../webrtc-sdk/README.md) Softphone — button + floating call widget. **No antd.**
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm i @yinshan-tech/webrtc-
|
|
9
|
-
# peer: @yinshan-tech/webrtc-sdk, react >= 16.8, react-dom >= 16.8
|
|
8
|
+
npm i @yinshan-tech/webrtc-react@^0.8 @yinshan-tech/webrtc-sdk@^0.8
|
|
10
9
|
```
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
Optional (if you mount neither CallWidget nor ensureCallWidgetHost):
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
```ts
|
|
14
|
+
import '@yinshan-tech/webrtc-react/styles.css';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`CallWidget` and `ensureCallWidgetHost` inject the **same** `styles.css` content (single source).
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
15
20
|
|
|
16
21
|
```tsx
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
customerName={record.contactName}
|
|
30
|
-
contactMobile={record.contact}
|
|
31
|
-
onNotify={({ level, message: msg }) => message[level]?.(msg)}
|
|
32
|
-
onCallSuccess={(callId) => saveCallId(callId)}
|
|
33
|
-
/>
|
|
34
|
-
```
|
|
22
|
+
import { createSoftphone } from '@yinshan-tech/webrtc-sdk';
|
|
23
|
+
import {
|
|
24
|
+
SoftphoneProvider,
|
|
25
|
+
OutboundCallButton,
|
|
26
|
+
CallWidget,
|
|
27
|
+
useSoftphoneConnect,
|
|
28
|
+
} from '@yinshan-tech/webrtc-react';
|
|
29
|
+
|
|
30
|
+
const phone = createSoftphone({
|
|
31
|
+
endpoints: { /* ... */ },
|
|
32
|
+
adapters: { /* ... */ },
|
|
33
|
+
});
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
function SoftphoneBoot({ children }: { children: React.ReactNode }) {
|
|
36
|
+
useSoftphoneConnect(); // phone.connect() on mount
|
|
37
|
+
return <>{children}</>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function App() {
|
|
41
|
+
return (
|
|
42
|
+
<SoftphoneProvider phone={phone}>
|
|
43
|
+
<SoftphoneBoot>
|
|
44
|
+
<OutboundCallButton
|
|
45
|
+
dialPayload={{ phoneNumber: '6281...' }}
|
|
46
|
+
displayName="Customer"
|
|
47
|
+
/>
|
|
48
|
+
{/* Simple floating card — or use OutboundModeShell for multi-mode workbench */}
|
|
49
|
+
<CallWidget />
|
|
50
|
+
</SoftphoneBoot>
|
|
51
|
+
</SoftphoneProvider>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
37
55
|
|
|
38
|
-
|
|
39
|
-
| --- | --- | --- |
|
|
40
|
-
| `...OutboundCallParams` | - | casePoolId / role / outboundDialPhoneType / customerName / contactMobile / providerType / onCallStart / onCallSuccess 等 |
|
|
41
|
-
| `buttonText` / `children` | string / node | 按钮内容,默认取 kit messages `webrtc.outbound` |
|
|
42
|
-
| `loading` / `disabled` | boolean | 外部 loading / 禁用 |
|
|
43
|
-
| `className` / `style` | - | 样式(默认类名 `wro-btn`) |
|
|
44
|
-
| `onNotify` | `(notify) => void` | 注册 / 拨号过程提示,桥接宿主 toast |
|
|
45
|
-
| `onResult` | `(result) => void` | 拨号流程最终结果(ok / errorCode) |
|
|
46
|
-
| `confirmBeforeCall` | `() => boolean \| Promise<boolean>` | 拨号前拦截(如灰名单二次确认),返回 false 取消 |
|
|
47
|
-
| `autoMountModal` | boolean,默认 `true` | 自动挂载全局通话弹窗;自渲染弹窗时设为 false |
|
|
48
|
-
| `render` | `({ start, busy, disabled, text }) => element` | headless 模式:完全自定义按钮 UI,逻辑复用 |
|
|
56
|
+
### OutboundModeShell (multi-mode workbench)
|
|
49
57
|
|
|
50
|
-
`
|
|
58
|
+
Shared chrome for `manual` | `predictive` | `progressive`. Hosts own mode-session actions and business content via slots. Opaque `uiContext` comes from `dial({ uiContext })` or `phone.patchCallUiContext(...)`.
|
|
51
59
|
|
|
52
60
|
```tsx
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
import { OutboundModeShell } from '@yinshan-tech/webrtc-react';
|
|
62
|
+
|
|
63
|
+
<OutboundModeShell
|
|
64
|
+
mode="manual"
|
|
65
|
+
renderBusinessInfo={({ uiContext }) => (
|
|
66
|
+
<div>{String(uiContext?.contactRole ?? '')}</div>
|
|
57
67
|
)}
|
|
58
68
|
/>
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## OutboundCallModal 可配置项
|
|
62
69
|
|
|
63
|
-
|
|
70
|
+
{/* Predictive / progressive: visible without an active call by default */}
|
|
71
|
+
<OutboundModeShell
|
|
72
|
+
mode="progressive"
|
|
73
|
+
modeSession={{
|
|
74
|
+
batchProgress: { done: 0, total: 10, connected: 0, missed: 0 },
|
|
75
|
+
}}
|
|
76
|
+
renderModeActions={() => (
|
|
77
|
+
<>
|
|
78
|
+
<button type="button">Pause</button>
|
|
79
|
+
<button type="button">Cancel</button>
|
|
80
|
+
</>
|
|
81
|
+
)}
|
|
82
|
+
renderBusinessInfo={({ call, uiContext }) => /* host fields */ null}
|
|
83
|
+
/>
|
|
84
|
+
```
|
|
64
85
|
|
|
65
|
-
|
|
66
|
-
| --- | --- | --- |
|
|
67
|
-
| `className` / `overlayClassName` / `style` | - | 弹窗 / 遮罩样式 |
|
|
68
|
-
| `cssVars` | `Record<string, string>` | 覆盖 CSS 变量,如 `{ '--wro-btn-bg': '#1677ff' }` |
|
|
69
|
-
| `zIndex` | number | 弹窗层级 |
|
|
70
|
-
| `showMute` | boolean,默认 true | 是否显示静音按钮 |
|
|
71
|
-
| `texts` | `{ hangup, mute, unmute, calling, connected, ... }` | 文案覆盖(优先级高于 kit messages) |
|
|
72
|
-
| `filterInfo` | `(info) => boolean` | 多实例时过滤要展示的通话 |
|
|
73
|
-
| `renderContent` | `({ info, muted, canHangup, hangup, toggleMute, stateText }) => node` | 完全自定义弹窗内容,保留遮罩与状态订阅 |
|
|
74
|
-
| `onStateChange` | `(info) => void` | 通话状态变化回调(埋点 / 宿主联动) |
|
|
86
|
+
Do not mount both `CallWidget` and `OutboundModeShell` for the same Softphone — pick one call surface.
|
|
75
87
|
|
|
76
|
-
|
|
88
|
+
`OutboundCallButton` `autoMountWidget` defaults to **false**. Set `autoMountWidget` only when you do **not** mount a tree call surface (portal via `ensureCallWidgetHost`). Do not combine portal + tree surface — duplicate UI.
|
|
77
89
|
|
|
78
|
-
|
|
79
|
-
createWebRTCKit({
|
|
80
|
-
// ...
|
|
81
|
-
ui: { modal: { cssVars: { '--wro-modal-z': '2000' }, zIndex: 2000 } },
|
|
82
|
-
});
|
|
83
|
-
```
|
|
90
|
+
Headless / Vue / plain JS hosts should use **sdk only** — this package is optional.
|
|
84
91
|
|
|
85
|
-
##
|
|
92
|
+
## Migration from 0.2
|
|
86
93
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
94
|
+
| 0.2 | 0.8 |
|
|
95
|
+
|-----|-----|
|
|
96
|
+
| `createWebRTCKit` + global kit | `createSoftphone` + `SoftphoneProvider` |
|
|
97
|
+
| `OutboundCallModal` | `CallWidget` |
|
|
98
|
+
| `ensureOutboundCallModalHost` | `ensureCallWidgetHost({ phone })` |
|
|
99
|
+
| `useWebRTCInitialization` | `useSoftphoneConnect` |
|
|
100
|
+
| `startOutboundCall` | `phone.dial` / button |
|
|
101
|
+
| `customerName` | `displayName` |
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { CallSnapshot, Softphone } from '@yinshan-tech/webrtc-sdk';
|
|
3
|
+
export interface CallWidgetTexts {
|
|
4
|
+
customer?: string;
|
|
5
|
+
calling?: string;
|
|
6
|
+
connected?: string;
|
|
7
|
+
ending?: string;
|
|
8
|
+
hangingUp?: string;
|
|
9
|
+
ended?: string;
|
|
10
|
+
failed?: string;
|
|
11
|
+
hangup?: string;
|
|
12
|
+
close?: string;
|
|
13
|
+
mute?: string;
|
|
14
|
+
unmute?: string;
|
|
15
|
+
minimize?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface CallWidgetRenderProps {
|
|
18
|
+
call: CallSnapshot;
|
|
19
|
+
muted: boolean;
|
|
20
|
+
canHangup: boolean;
|
|
21
|
+
hangup: () => void;
|
|
22
|
+
toggleMute: () => void;
|
|
23
|
+
stateText: string;
|
|
24
|
+
}
|
|
25
|
+
export interface CallWidgetProps {
|
|
26
|
+
phone?: Softphone;
|
|
27
|
+
className?: string;
|
|
28
|
+
style?: React.CSSProperties;
|
|
29
|
+
cssVars?: Record<string, string>;
|
|
30
|
+
zIndex?: number;
|
|
31
|
+
showMute?: boolean;
|
|
32
|
+
showMinimize?: boolean;
|
|
33
|
+
texts?: CallWidgetTexts;
|
|
34
|
+
/** Hide widget when phase is idle/ended (after close). Default true */
|
|
35
|
+
hideWhenIdle?: boolean;
|
|
36
|
+
renderContent?: (props: CallWidgetRenderProps) => React.ReactNode;
|
|
37
|
+
onStateChange?: (call: CallSnapshot | null) => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Floating call card bound to a Softphone instance.
|
|
41
|
+
*/
|
|
42
|
+
export declare const CallWidget: React.FC<CallWidgetProps>;
|
|
43
|
+
export default CallWidget;
|
|
@@ -0,0 +1,275 @@
|
|
|
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
|
+
return 'calling';
|
|
28
|
+
case 'ending':
|
|
29
|
+
return 'ending';
|
|
30
|
+
case 'active':
|
|
31
|
+
return 'connected';
|
|
32
|
+
case 'ended':
|
|
33
|
+
return 'ended';
|
|
34
|
+
case 'failed':
|
|
35
|
+
return 'failed';
|
|
36
|
+
default:
|
|
37
|
+
return 'idle';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Floating call card bound to a Softphone instance.
|
|
42
|
+
*/
|
|
43
|
+
export const CallWidget = (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] CallWidget needs SoftphoneProvider or a phone prop');
|
|
49
|
+
}
|
|
50
|
+
const { className, style, cssVars, zIndex, showMute = true, showMinimize = true, texts, hideWhenIdle = true, renderContent, onStateChange, } = 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
|
+
onStateChange === null || onStateChange === void 0 ? void 0 : onStateChange(ev.call);
|
|
68
|
+
if (ev.call.phase === 'dialing' || ev.call.phase === 'ringing') {
|
|
69
|
+
setDismissedId(null);
|
|
70
|
+
setMinimized(false);
|
|
71
|
+
}
|
|
72
|
+
// Align ap-admin manual outbound: close widget as soon as call ends/fails
|
|
73
|
+
if (ev.call.phase === 'ended' || ev.call.phase === 'failed') {
|
|
74
|
+
setDismissedId(ev.call.id);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}, [phone, onStateChange]);
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
const timer = setInterval(() => {
|
|
81
|
+
if ((call === null || call === void 0 ? void 0 : call.phase) === 'active') {
|
|
82
|
+
if (!startTimeRef.current) {
|
|
83
|
+
startTimeRef.current = call.startedAt || Date.now();
|
|
84
|
+
}
|
|
85
|
+
const startedAt = startTimeRef.current;
|
|
86
|
+
const diff = Math.round((Date.now() - startedAt) / 1000);
|
|
87
|
+
setDuration(`${pad2(Math.floor(diff / 60))}:${pad2(diff % 60)}`);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
startTimeRef.current = null;
|
|
91
|
+
setDuration('00:00');
|
|
92
|
+
}
|
|
93
|
+
}, 1000);
|
|
94
|
+
return () => clearInterval(timer);
|
|
95
|
+
}, [call]);
|
|
96
|
+
// Safety net if phase flips without a fresh subscribe delivery
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (!call)
|
|
99
|
+
return;
|
|
100
|
+
if (call.phase === 'ended' || call.phase === 'failed') {
|
|
101
|
+
setDismissedId(call.id);
|
|
102
|
+
}
|
|
103
|
+
}, [call]);
|
|
104
|
+
const ui = call ? phaseUi(call.phase) : 'idle';
|
|
105
|
+
// hideWhenIdle: hide after dismiss (auto on ended/failed, or Close)
|
|
106
|
+
const showCard = !!call &&
|
|
107
|
+
ui !== 'idle' &&
|
|
108
|
+
dismissedId !== call.id &&
|
|
109
|
+
!(hideWhenIdle && dismissedId === call.id);
|
|
110
|
+
const rootStyle = useMemo(() => {
|
|
111
|
+
const s = Object.assign({}, (cssVars || {}));
|
|
112
|
+
if (zIndex != null)
|
|
113
|
+
s['--wro-modal-z'] = String(zIndex);
|
|
114
|
+
return s;
|
|
115
|
+
}, [cssVars, zIndex]);
|
|
116
|
+
const stateText = useCallback((phase) => {
|
|
117
|
+
const u = phaseUi(phase);
|
|
118
|
+
if (u === 'calling')
|
|
119
|
+
return t('calling', 'Calling...');
|
|
120
|
+
if (u === 'ending')
|
|
121
|
+
return t('hangingUp', 'Hanging up...');
|
|
122
|
+
if (u === 'connected')
|
|
123
|
+
return t('connected', 'In call');
|
|
124
|
+
if (u === 'ended')
|
|
125
|
+
return t('ended', 'Call ended');
|
|
126
|
+
if (u === 'failed')
|
|
127
|
+
return t('failed', 'Call failed');
|
|
128
|
+
return '';
|
|
129
|
+
}, [t]);
|
|
130
|
+
const hangup = useCallback(() => {
|
|
131
|
+
if (!call)
|
|
132
|
+
return;
|
|
133
|
+
if (call.phase === 'failed' || call.phase === 'ended') {
|
|
134
|
+
setDismissedId(call.id);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (call.phase === 'ending')
|
|
138
|
+
return;
|
|
139
|
+
// Wait for ended/failed — do not dismiss early so hangup_failed can retry
|
|
140
|
+
void phone.hangup();
|
|
141
|
+
}, [call, phone]);
|
|
142
|
+
const toggleMute = useCallback(() => {
|
|
143
|
+
if (!call || call.phase !== 'active')
|
|
144
|
+
return;
|
|
145
|
+
phone.setMuted(!phone.isMuted());
|
|
146
|
+
}, [call, phone]);
|
|
147
|
+
const onDragStart = useCallback((e, isMini = false) => {
|
|
148
|
+
const target = e.target;
|
|
149
|
+
if (target.closest('button'))
|
|
150
|
+
return;
|
|
151
|
+
e.preventDefault();
|
|
152
|
+
const el = e.currentTarget;
|
|
153
|
+
const rect = el.getBoundingClientRect();
|
|
154
|
+
el.style.left = `${rect.left}px`;
|
|
155
|
+
el.style.top = `${rect.top}px`;
|
|
156
|
+
el.style.right = 'auto';
|
|
157
|
+
dragRef.current = {
|
|
158
|
+
el,
|
|
159
|
+
startClientX: e.clientX,
|
|
160
|
+
startClientY: e.clientY,
|
|
161
|
+
originX: rect.left,
|
|
162
|
+
originY: rect.top,
|
|
163
|
+
moved: false,
|
|
164
|
+
isMini,
|
|
165
|
+
};
|
|
166
|
+
const onMove = (ev) => {
|
|
167
|
+
const d = dragRef.current;
|
|
168
|
+
if (!d)
|
|
169
|
+
return;
|
|
170
|
+
const dx = ev.clientX - d.startClientX;
|
|
171
|
+
const dy = ev.clientY - d.startClientY;
|
|
172
|
+
if (!d.moved && Math.hypot(dx, dy) < 5)
|
|
173
|
+
return;
|
|
174
|
+
d.moved = true;
|
|
175
|
+
d.el.classList.add('is-dragging');
|
|
176
|
+
const maxX = Math.max(0, window.innerWidth - d.el.offsetWidth);
|
|
177
|
+
const maxY = Math.max(0, window.innerHeight - d.el.offsetHeight);
|
|
178
|
+
const x = Math.max(0, Math.min(d.originX + dx, maxX));
|
|
179
|
+
const y = Math.max(0, Math.min(d.originY + dy, maxY));
|
|
180
|
+
d.el.style.left = `${x}px`;
|
|
181
|
+
d.el.style.top = `${y}px`;
|
|
182
|
+
};
|
|
183
|
+
const onUp = () => {
|
|
184
|
+
const d = dragRef.current;
|
|
185
|
+
document.removeEventListener('mousemove', onMove);
|
|
186
|
+
document.removeEventListener('mouseup', onUp);
|
|
187
|
+
dragRef.current = null;
|
|
188
|
+
if (!d)
|
|
189
|
+
return;
|
|
190
|
+
d.el.classList.remove('is-dragging');
|
|
191
|
+
if (d.moved) {
|
|
192
|
+
setPos({
|
|
193
|
+
x: parseFloat(d.el.style.left) || d.originX,
|
|
194
|
+
y: parseFloat(d.el.style.top) || d.originY,
|
|
195
|
+
});
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (d.isMini)
|
|
199
|
+
setMinimized(false);
|
|
200
|
+
};
|
|
201
|
+
document.addEventListener('mousemove', onMove);
|
|
202
|
+
document.addEventListener('mouseup', onUp);
|
|
203
|
+
}, []);
|
|
204
|
+
if (!showCard || !call)
|
|
205
|
+
return null;
|
|
206
|
+
const muted = call.muted || phone.isMuted();
|
|
207
|
+
const canHangup = call.phase !== 'ending' &&
|
|
208
|
+
(call.canHangup || call.phase === 'failed' || call.phase === 'ended');
|
|
209
|
+
const name = call.displayName || t('customer', 'Customer');
|
|
210
|
+
const avatar = name.trim().charAt(0).toUpperCase() || '?';
|
|
211
|
+
const floatStyle = pos
|
|
212
|
+
? { left: pos.x, top: pos.y, right: 'auto' }
|
|
213
|
+
: undefined;
|
|
214
|
+
if (renderContent) {
|
|
215
|
+
return (React.createElement("div", { className: "wro-root", style: rootStyle }, renderContent({
|
|
216
|
+
call,
|
|
217
|
+
muted,
|
|
218
|
+
canHangup,
|
|
219
|
+
hangup,
|
|
220
|
+
toggleMute,
|
|
221
|
+
stateText: stateText(call.phase),
|
|
222
|
+
})));
|
|
223
|
+
}
|
|
224
|
+
if (minimized) {
|
|
225
|
+
return (React.createElement("div", { className: "wro-root", style: rootStyle },
|
|
226
|
+
React.createElement("div", { className: "wro-call-mini", style: floatStyle, onMouseDown: (e) => onDragStart(e, true), role: "button", tabIndex: 0 },
|
|
227
|
+
React.createElement("div", { className: "wro-call-mini__name" }, name),
|
|
228
|
+
ui === 'connected' ? (React.createElement("div", { className: "wro-call-mini__duration" }, duration)) : (React.createElement("div", { className: "wro-call-mini__status" }, stateText(call.phase))))));
|
|
229
|
+
}
|
|
230
|
+
const avatarClass = [
|
|
231
|
+
'wro-call__avatar',
|
|
232
|
+
ui === 'calling' ? 'is-calling' : '',
|
|
233
|
+
ui === 'connected' ? 'is-connected' : '',
|
|
234
|
+
ui === 'failed' ? 'is-failed' : '',
|
|
235
|
+
ui === 'ended' ? 'is-ended' : '',
|
|
236
|
+
]
|
|
237
|
+
.filter(Boolean)
|
|
238
|
+
.join(' ');
|
|
239
|
+
return (React.createElement("div", { className: "wro-root", style: rootStyle },
|
|
240
|
+
React.createElement("div", { className: ['wro-call', className].filter(Boolean).join(' '), style: Object.assign(Object.assign({}, style), floatStyle), role: "dialog", "aria-modal": "false", onMouseDown: (e) => onDragStart(e, false) },
|
|
241
|
+
showMinimize && (React.createElement("button", { type: "button", className: "wro-call__minimize", title: t('minimize', 'Minimize'), "aria-label": t('minimize', 'Minimize'), onClick: () => setMinimized(true) },
|
|
242
|
+
React.createElement(IconMinus, null))),
|
|
243
|
+
React.createElement("div", { className: avatarClass, "aria-hidden": true }, avatar),
|
|
244
|
+
React.createElement("div", { className: "wro-call__name", title: name }, name),
|
|
245
|
+
React.createElement("div", { className: "wro-call__status" }, ui === 'connected' ? (React.createElement("span", { className: "wro-call__duration" }, duration)) : (React.createElement("span", { className: [
|
|
246
|
+
'wro-call__state',
|
|
247
|
+
ui === 'calling' ? 'is-calling' : '',
|
|
248
|
+
ui === 'failed' ? 'is-failed' : '',
|
|
249
|
+
ui === 'ended' ? 'is-ended' : '',
|
|
250
|
+
]
|
|
251
|
+
.filter(Boolean)
|
|
252
|
+
.join(' ') }, stateText(call.phase)))),
|
|
253
|
+
ui !== 'ended' && (React.createElement("div", { className: "wro-call__actions" },
|
|
254
|
+
showMute && ui === 'connected' && (React.createElement("div", { className: "wro-call__action" },
|
|
255
|
+
React.createElement("button", { type: "button", className: ['wro-call__circle', muted ? 'is-muted' : 'is-unmuted'].join(' '), onClick: toggleMute },
|
|
256
|
+
React.createElement(IconMic, { muted: muted })),
|
|
257
|
+
React.createElement("span", { className: "wro-call__label" }, muted ? t('unmute', 'Unmute') : t('mute', 'Mute')))),
|
|
258
|
+
React.createElement("div", { className: "wro-call__action" },
|
|
259
|
+
React.createElement("button", { type: "button", className: "wro-call__circle is-hangup", disabled: !canHangup && ui !== 'failed', onClick: hangup },
|
|
260
|
+
React.createElement("span", { className: "wro-call__hangup-icon" },
|
|
261
|
+
React.createElement(IconPhone, null))),
|
|
262
|
+
React.createElement("span", { className: "wro-call__label" }, ui === 'failed'
|
|
263
|
+
? t('close', 'Close')
|
|
264
|
+
: ui === 'ending'
|
|
265
|
+
? t('hangingUp', 'Hanging up...')
|
|
266
|
+
: t('hangup', 'Hang up'))))),
|
|
267
|
+
ui === 'ended' && (React.createElement("div", { className: "wro-call__actions" },
|
|
268
|
+
React.createElement("div", { className: "wro-call__action" },
|
|
269
|
+
React.createElement("button", { type: "button", className: "wro-call__circle is-hangup", onClick: hangup },
|
|
270
|
+
React.createElement("span", { className: "wro-call__hangup-icon" },
|
|
271
|
+
React.createElement(IconPhone, null))),
|
|
272
|
+
React.createElement("span", { className: "wro-call__label" }, t('close', 'Close'))))))));
|
|
273
|
+
};
|
|
274
|
+
export default CallWidget;
|
|
275
|
+
//# sourceMappingURL=CallWidget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CallWidget.js","sourceRoot":"","sources":["../src/CallWidget.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;AAyChE,SAAS,SAAS;IAChB,OAAO,CACL,6BAAK,KAAK,EAAC,IAAI,EAAC,MAAM,EAAC,IAAI,EAAC,OAAO,EAAC,WAAW;QAC7C,8BAAM,CAAC,EAAC,UAAU,EAAC,MAAM,EAAC,cAAc,EAAC,WAAW,EAAC,KAAK,EAAC,aAAa,EAAC,OAAO,GAAG,CAC/E,CACP,CAAC;AACJ,CAAC;AAED,SAAS,SAAS;IAChB,OAAO,CACL,6BAAK,KAAK,EAAC,IAAI,EAAC,MAAM,EAAC,IAAI,EAAC,OAAO,EAAC,WAAW,EAAC,IAAI,EAAC,cAAc;QACjE,8BAAM,CAAC,EAAC,sNAAsN,GAAG,CAC7N,CACP,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CAC1D,CACF,CACP,CACG,CACF,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { DialParams, DialResult, Softphone } from '@yinshan-tech/webrtc-sdk';
|
|
3
|
+
export interface SoftphoneNotify {
|
|
4
|
+
level: 'info' | 'success' | 'warning' | 'error';
|
|
5
|
+
code: string;
|
|
6
|
+
message: string;
|
|
7
|
+
}
|
|
3
8
|
export interface OutboundCallButtonRenderProps {
|
|
4
|
-
/** Trigger the call (already guards busy/disabled) */
|
|
5
9
|
start: () => Promise<void>;
|
|
6
|
-
/** True while dialing flow is running */
|
|
7
10
|
busy: boolean;
|
|
8
11
|
disabled: boolean;
|
|
9
12
|
text: string;
|
|
10
13
|
}
|
|
11
|
-
export
|
|
12
|
-
/**
|
|
14
|
+
export type OutboundCallButtonProps = DialParams & {
|
|
15
|
+
/** Softphone instance — required if not under SoftphoneProvider */
|
|
16
|
+
phone?: Softphone;
|
|
13
17
|
loading?: boolean;
|
|
14
18
|
disabled?: boolean;
|
|
15
19
|
children?: React.ReactNode;
|
|
16
20
|
className?: string;
|
|
17
21
|
style?: React.CSSProperties;
|
|
18
|
-
/** Fallback text when children omitted; default from kit messages `webrtc.outbound` */
|
|
19
22
|
buttonText?: string;
|
|
20
|
-
/** Bridge register/dial notifications to host toast (antd message, ElMessage, ...) */
|
|
21
|
-
onNotify?: (notify: OutboundCallNotify) => void;
|
|
22
|
-
/** Called with the final result of the dial flow (ok / errorCode) */
|
|
23
|
-
onResult?: (result: StartOutboundCallResult) => void;
|
|
24
|
-
/** Optional gate before dialing, e.g. graylist confirm. Return false to abort. */
|
|
25
|
-
confirmBeforeCall?: () => boolean | Promise<boolean>;
|
|
26
23
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
24
|
+
* @deprecated Global phone.notify fan-out — do not use on N table rows.
|
|
25
|
+
* Prefer `useSoftphoneNotify` once under SoftphoneProvider, and/or `onResult`.
|
|
29
26
|
*/
|
|
30
|
-
|
|
27
|
+
onNotify?: (notify: SoftphoneNotify) => void;
|
|
28
|
+
onResult?: (result: DialResult) => void;
|
|
29
|
+
confirmBeforeCall?: () => boolean | Promise<boolean>;
|
|
31
30
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* Auto-mount portal CallWidget via ensureCallWidgetHost.
|
|
32
|
+
* Default false — prefer a single <CallWidget /> under SoftphoneProvider
|
|
33
|
+
* (portal + tree CallWidget = duplicate UI).
|
|
34
34
|
*/
|
|
35
|
+
autoMountWidget?: boolean;
|
|
35
36
|
render?: (renderProps: OutboundCallButtonRenderProps) => React.ReactElement;
|
|
36
37
|
};
|
|
37
38
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* the global call modal is auto-mounted.
|
|
39
|
+
* Dial trigger. Prefer SoftphoneProvider; or pass `phone` prop.
|
|
40
|
+
* Does not subscribe to global Softphone notify (avoids N× toast with table rows).
|
|
41
41
|
*/
|
|
42
42
|
export declare const OutboundCallButton: React.FC<OutboundCallButtonProps>;
|
|
43
43
|
export default OutboundCallButton;
|