@zjw-jszn/shared-imsdk 1.0.3 → 1.0.4
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 +90 -26
- package/index.js +5 -0
- package/package.json +7 -12
package/README.md
CHANGED
|
@@ -1,45 +1,109 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zjw-jszn/shared-imsdk
|
|
2
2
|
|
|
3
|
-
`@zjw-jszn/shared-imsdk`
|
|
3
|
+
`@zjw-jszn/shared-imsdk` 是 IM Web SDK 的共享内核,提供鉴权、会话、消息、未读、WebSocket 与通用聊天 UI。
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
-
|
|
7
|
-
- 通用 UI 组件与状态管理
|
|
8
|
-
- 可配置的 API 前缀与 WebSocket controller
|
|
9
|
-
- 基于 API 前缀自动识别平台/门店能力差异
|
|
5
|
+
适用场景:你需要自定义模式(非标准平台/门店)或需要直接复用底层能力。
|
|
6
|
+
如果你是标准平台/门店接入,优先使用 `@zjw-jszn/platform-imsdk` 或 `@zjw-jszn/store-imsdk`。
|
|
10
7
|
|
|
11
|
-
|
|
8
|
+
## 安装
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
```bash
|
|
11
|
+
pnpm add @zjw-jszn/shared-imsdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 导入
|
|
14
15
|
|
|
15
16
|
```ts
|
|
16
17
|
import { IMSDK } from '@zjw-jszn/shared-imsdk'
|
|
18
|
+
import type { IMSDKConfig, UserInfo } from '@zjw-jszn/shared-imsdk'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
默认导出也可用:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import IMSDK from '@zjw-jszn/shared-imsdk'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 初始化
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
type Controls = {
|
|
31
|
+
show: () => void
|
|
32
|
+
hide: () => void
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare function init(config?: IMSDKConfig): Promise<Controls>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 最小可运行配置(自定义模式)
|
|
39
|
+
|
|
40
|
+
> `shared` 不会自动注入平台/门店模式默认值,以下字段必须由接入方提供。
|
|
17
41
|
|
|
18
|
-
|
|
19
|
-
|
|
42
|
+
```ts
|
|
43
|
+
import { IMSDK } from '@zjw-jszn/shared-imsdk'
|
|
44
|
+
import type { IMSDKConfig } from '@zjw-jszn/shared-imsdk'
|
|
45
|
+
|
|
46
|
+
const config: IMSDKConfig = {
|
|
47
|
+
phone: '18888888888',
|
|
20
48
|
api: {
|
|
21
49
|
baseURL: 'https://aox.api.orchiport.asia',
|
|
22
|
-
prefix: '/site/IM',
|
|
50
|
+
prefix: '/site/IM',
|
|
51
|
+
siteId: '6',
|
|
23
52
|
},
|
|
24
53
|
ws: {
|
|
25
|
-
controller: 'Site',
|
|
26
|
-
platform: 'site',
|
|
27
|
-
},
|
|
28
|
-
auth: {
|
|
29
|
-
// 仅当业务端有扩展鉴权参数时使用(如门店 username/avatar)
|
|
30
|
-
authorizationPayload: {},
|
|
54
|
+
controller: 'Site',
|
|
55
|
+
platform: 'site',
|
|
31
56
|
},
|
|
32
|
-
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const controls = await IMSDK.init(config)
|
|
60
|
+
controls.show()
|
|
33
61
|
```
|
|
34
62
|
|
|
35
|
-
##
|
|
63
|
+
## `IMSDKConfig` 关键字段
|
|
36
64
|
|
|
37
|
-
|
|
38
|
-
|
|
65
|
+
| 字段 | 说明 |
|
|
66
|
+
| --- | --- |
|
|
67
|
+
| `phone` | 首次鉴权必填(无 token 场景) |
|
|
68
|
+
| `api.baseURL` | HTTP 基础地址(默认 `https://aox.api.orchiport.asia`) |
|
|
69
|
+
| `api.prefix` | API 前缀,`shared` 模式下必须显式传入 |
|
|
70
|
+
| `api.siteId` | 站点 ID,用于鉴权后 WS 连接 |
|
|
71
|
+
| `ws.controller` | WebSocket 控制器,必须显式传入 |
|
|
72
|
+
| `ws.platform` | 平台标识,必须为小写,且等于 `controller.toLowerCase()` |
|
|
73
|
+
| `sound` | 消息提示音开关与地址 |
|
|
74
|
+
| `auth.authorizationPayload` | 鉴权扩展参数透传 |
|
|
75
|
+
| `runtimeApi` | 运行时扩展接口(`getChatConfig/closeSession/getCustomerChatList`) |
|
|
39
76
|
|
|
40
|
-
|
|
77
|
+
## 常用导出
|
|
41
78
|
|
|
42
|
-
|
|
79
|
+
```ts
|
|
80
|
+
import {
|
|
81
|
+
IMSDK,
|
|
82
|
+
getUserInfo,
|
|
83
|
+
isInitialized,
|
|
84
|
+
getConfig,
|
|
85
|
+
updateConfig,
|
|
86
|
+
resetConfig,
|
|
87
|
+
buildApiPath,
|
|
88
|
+
hasApiCapability,
|
|
89
|
+
http,
|
|
90
|
+
wsClient,
|
|
91
|
+
} from '@zjw-jszn/shared-imsdk'
|
|
92
|
+
```
|
|
43
93
|
|
|
44
|
-
|
|
45
|
-
|
|
94
|
+
## 初始化约束与错误
|
|
95
|
+
|
|
96
|
+
- 缺少 `api.prefix` 会抛错。
|
|
97
|
+
- 缺少 `ws.controller` 或 `ws.platform` 会抛错。
|
|
98
|
+
- `ws.platform` 必须小写,且需与 `ws.controller.toLowerCase()` 一致。
|
|
99
|
+
- 首次初始化且无 token 时,必须传 `phone`。
|
|
100
|
+
- 已以某模式初始化后,不允许在同页面切换到另一模式。
|
|
101
|
+
|
|
102
|
+
## 样式
|
|
103
|
+
|
|
104
|
+
包入口会自动注入样式;通常无需手动引入。
|
|
105
|
+
如需手动控制加载时机:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import '@zjw-jszn/shared-imsdk/style.css'
|
|
109
|
+
```
|
package/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zjw-jszn/shared-imsdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
5
|
-
"main": "./dist/shared-imsdk.umd.js",
|
|
6
|
-
"module": "./dist/shared-imsdk.es.js",
|
|
4
|
+
"version": "1.0.4",
|
|
7
5
|
"exports": {
|
|
8
6
|
".": {
|
|
9
|
-
"types":
|
|
10
|
-
|
|
11
|
-
"default": "./dist/index.d.ts"
|
|
12
|
-
},
|
|
13
|
-
"import": {
|
|
14
|
-
"development": "./src/index.ts",
|
|
15
|
-
"default": "./dist/shared-imsdk.es.js"
|
|
16
|
-
}
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./index.js"
|
|
17
9
|
},
|
|
18
10
|
"./style.css": "./dist/shared-imsdk.css"
|
|
19
11
|
},
|
|
12
|
+
"main": "./dist/shared-imsdk.umd.js",
|
|
13
|
+
"module": "./index.js",
|
|
20
14
|
"types": "./dist/index.d.ts",
|
|
21
15
|
"files": [
|
|
22
|
-
"dist"
|
|
16
|
+
"dist",
|
|
17
|
+
"index.js"
|
|
23
18
|
],
|
|
24
19
|
"publishConfig": {
|
|
25
20
|
"access": "public",
|