@yinshan-tech/webrtc-react 0.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.
Files changed (2) hide show
  1. package/README.md +89 -0
  2. package/package.json +34 -0
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # @yinshan-tech/webrtc-react
2
+
3
+ `@yinshan-tech/webrtc-sdk` 的 React UI 层:`OutboundCallButton`、`OutboundCallModal`、hooks。**不依赖 antd**,样式基于 CSS 变量,可完全自定义或换成自己的组件。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm i @yinshan-tech/webrtc-sdk @yinshan-tech/webrtc-react
9
+ # peer: @yinshan-tech/webrtc-sdk, react >= 16.8, react-dom >= 16.8
10
+ ```
11
+
12
+ 包自带独立 `tsconfig.json`,`yarn build` 输出 `dist/`(CommonJS + `.d.ts` + `styles.css`)。
13
+
14
+ ## 最简用法:初始化一次 + 直接放按钮
15
+
16
+ ```tsx
17
+ // 1. 应用启动时(如 app.tsx)
18
+ import { createWebRTCKit } from '@yinshan-tech/webrtc-sdk';
19
+ createWebRTCKit({ endpoints, adapters /* ... */ });
20
+
21
+ // 2. 任意页面 / 表格行内直接放按钮,全局通话弹窗自动挂载
22
+ import { OutboundCallButton } from '@yinshan-tech/webrtc-react';
23
+
24
+ <OutboundCallButton
25
+ providerType="CALL_CENTER"
26
+ casePoolId={record.loanId}
27
+ role={record.contactType}
28
+ outboundDialPhoneType="CONTACT"
29
+ customerName={record.contactName}
30
+ contactMobile={record.contact}
31
+ onNotify={({ level, message: msg }) => message[level]?.(msg)}
32
+ onCallSuccess={(callId) => saveCallId(callId)}
33
+ />
34
+ ```
35
+
36
+ ## OutboundCallButton 可配置项
37
+
38
+ | Prop | 类型 | 说明 |
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,逻辑复用 |
49
+
50
+ `render` 示例(用 antd 按钮):
51
+
52
+ ```tsx
53
+ <OutboundCallButton
54
+ {...callParams}
55
+ render={({ start, busy, text }) => (
56
+ <Button type="primary" danger loading={busy} onClick={start}>{text}</Button>
57
+ )}
58
+ />
59
+ ```
60
+
61
+ ## OutboundCallModal 可配置项
62
+
63
+ 弹窗默认由按钮自动挂载;需要自定义时手动渲染一次(全局一个)并给按钮传 `autoMountModal={false}`。
64
+
65
+ | Prop | 类型 | 说明 |
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` | 通话状态变化回调(埋点 / 宿主联动) |
75
+
76
+ 全局默认样式也可以在初始化时统一配置:
77
+
78
+ ```ts
79
+ createWebRTCKit({
80
+ // ...
81
+ ui: { modal: { cssVars: { '--wro-modal-z': '2000' }, zIndex: 2000 } },
82
+ });
83
+ ```
84
+
85
+ ## 其他导出
86
+
87
+ - `useWebRTCInitialization(options)`:进入页面时预注册 provider 的 hook
88
+ - `ensureOutboundCallModalHost()` / `destroyOutboundCallModalHost()`:手动控制全局弹窗宿主
89
+ - 便捷 re-export:`startOutboundCall`、`subscribeCallState`、`getAllCallInfo` 及相关类型
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@yinshan-tech/webrtc-react",
3
+ "version": "0.1.0",
4
+ "description": "React UI for @yinshan-tech/webrtc-sdk: OutboundCallButton, OutboundCallModal, hooks (no antd)",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "sideEffects": [
8
+ "./dist/styles.css"
9
+ ],
10
+ "files": [
11
+ "dist",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "build": "rm -rf dist && tsc -p tsconfig.json && cp src/styles.css dist/styles.css"
16
+ },
17
+ "peerDependencies": {
18
+ "@yinshan-tech/webrtc-sdk": "^0.1.0",
19
+ "react": ">=16.8.0",
20
+ "react-dom": ">=16.8.0"
21
+ },
22
+ "devDependencies": {
23
+ "@types/react": "^17.0.0",
24
+ "@types/react-dom": "^17.0.0",
25
+ "typescript": "^4.8.3"
26
+ },
27
+ "keywords": [
28
+ "webrtc",
29
+ "outbound",
30
+ "react",
31
+ "call-center"
32
+ ],
33
+ "license": "UNLICENSED"
34
+ }