@imam-inter/openim-sdk-js-wasm 3.8.2-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/LICENSE +661 -0
- package/README.md +166 -0
- package/assets/openIM.wasm +0 -0
- package/assets/sql-wasm.wasm +0 -0
- package/assets/wasm_exec.js +561 -0
- package/lib/api/database/alter.d.ts +2 -0
- package/lib/api/database/black.d.ts +7 -0
- package/lib/api/database/conversation.d.ts +31 -0
- package/lib/api/database/friend.d.ts +12 -0
- package/lib/api/database/friendRequest.d.ts +7 -0
- package/lib/api/database/groupMember.d.ts +22 -0
- package/lib/api/database/groupRequest.d.ts +8 -0
- package/lib/api/database/groups.d.ts +14 -0
- package/lib/api/database/index.d.ts +20 -0
- package/lib/api/database/init.d.ts +3 -0
- package/lib/api/database/instance.d.ts +3 -0
- package/lib/api/database/localAppSdkVersion.d.ts +2 -0
- package/lib/api/database/message.d.ts +31 -0
- package/lib/api/database/notification.d.ts +3 -0
- package/lib/api/database/sendingMessages.d.ts +3 -0
- package/lib/api/database/stranger.d.ts +4 -0
- package/lib/api/database/superGroup.d.ts +6 -0
- package/lib/api/database/tableMaster.d.ts +1 -0
- package/lib/api/database/tempCacheChatLogs.d.ts +2 -0
- package/lib/api/database/unreadMessage.d.ts +2 -0
- package/lib/api/database/upload.d.ts +4 -0
- package/lib/api/database/users.d.ts +3 -0
- package/lib/api/database/versionSync.d.ts +3 -0
- package/lib/api/index.d.ts +2 -0
- package/lib/api/upload.d.ts +5 -0
- package/lib/api/worker.d.ts +1 -0
- package/lib/constant/index.d.ts +71 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.es.js +2121 -0
- package/lib/index.js +2125 -0
- package/lib/index.umd.js +2131 -0
- package/lib/sdk/index.d.ts +173 -0
- package/lib/sdk/initialize.d.ts +5 -0
- package/lib/sqls/index.d.ts +20 -0
- package/lib/sqls/localAdminGroupRequests.d.ts +9 -0
- package/lib/sqls/localAppSdkVersion.d.ts +8 -0
- package/lib/sqls/localBlack.d.ts +12 -0
- package/lib/sqls/localChatLogsConversationID.d.ts +36 -0
- package/lib/sqls/localConversationUnreadMessages.d.ts +7 -0
- package/lib/sqls/localConversations.d.ts +34 -0
- package/lib/sqls/localFriend.d.ts +16 -0
- package/lib/sqls/localFriendRequest.d.ts +12 -0
- package/lib/sqls/localGroupMembers.d.ts +27 -0
- package/lib/sqls/localGroupRequests.d.ts +9 -0
- package/lib/sqls/localGroups.d.ts +16 -0
- package/lib/sqls/localNotification.d.ts +8 -0
- package/lib/sqls/localSendingMessages.d.ts +8 -0
- package/lib/sqls/localStranger.d.ts +8 -0
- package/lib/sqls/localSuperGroups.d.ts +10 -0
- package/lib/sqls/localTableMaster.d.ts +5 -0
- package/lib/sqls/localUpload.d.ts +10 -0
- package/lib/sqls/localUsers.d.ts +8 -0
- package/lib/sqls/localVersionSync.d.ts +9 -0
- package/lib/sqls/tempCacheLocalChatLogs.d.ts +6 -0
- package/lib/types/entity.d.ts +452 -0
- package/lib/types/enum.d.ts +134 -0
- package/lib/types/eventData.d.ts +51 -0
- package/lib/types/params.d.ts +390 -0
- package/lib/utils/emitter.d.ts +12 -0
- package/lib/utils/escape.d.ts +23 -0
- package/lib/utils/index.d.ts +7 -0
- package/lib/utils/is.d.ts +6 -0
- package/lib/utils/key.d.ts +3 -0
- package/lib/utils/logFormat.d.ts +1 -0
- package/lib/utils/response.d.ts +1 -0
- package/lib/utils/timer.d.ts +1 -0
- package/lib/utils/value.d.ts +6 -0
- package/lib/worker-legacy.js +1 -0
- package/lib/worker.js +1 -0
- package/package.json +94 -0
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# JavaScript/TypeScript Client SDK for OpenIM ๐จโ๐ป๐ฌ
|
|
2
|
+
|
|
3
|
+
Use this SDK to add instant messaging capabilities to your application. By connecting to a self-hosted [OpenIM](https://www.openim.online/) server, you can quickly integrate instant messaging capabilities into your app with just a few lines of code.
|
|
4
|
+
|
|
5
|
+
The underlying SDK core is implemented in [OpenIM SDK Core](https://github.com/openimsdk/openim-sdk-core). Using the [WebAssembly](https://webassembly.org/) support provided by Go language, it can be compiled into wasm for web integration. The web interacts with the [OpenIM SDK Core](https://github.com/openimsdk/openim-sdk-core) through JSON, and the SDK exposes a re-encapsulated API for easy usage. In terms of data storage, JavaScript handles the logic of the SQL layer by virtualizing SQLite and storing it in IndexedDB using [sql.js](https://sql.js.org/).
|
|
6
|
+
|
|
7
|
+
## Documentation ๐
|
|
8
|
+
|
|
9
|
+
Visit [https://docs.openim.io/](https://docs.openim.io/) for detailed documentation and guides.
|
|
10
|
+
|
|
11
|
+
For the SDK reference, see [https://docs.openim.io/sdks/quickstart/browser](https://docs.openim.io/sdks/quickstart/browser).
|
|
12
|
+
|
|
13
|
+
## Installation ๐ป
|
|
14
|
+
|
|
15
|
+
### Adding Dependencies
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
npm install @openim/wasm-client-sdk --save
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Obtaining Required Static Resources for WASM
|
|
22
|
+
|
|
23
|
+
Follow these steps to obtain the static resources required for WebAssembly (WASM):
|
|
24
|
+
|
|
25
|
+
1. Locate the `@openim/wasm-client-sdk` subdirectory in the `node_modules` directory of your project. Copy all the files in the `assets` folder to your project's public resource directory.
|
|
26
|
+
|
|
27
|
+
The files to be copied are:
|
|
28
|
+
|
|
29
|
+
- `openIM.wasm`
|
|
30
|
+
- `sql-wasm.wasm`
|
|
31
|
+
- `wasm_exec.js`
|
|
32
|
+
|
|
33
|
+
2. After copying the files, import the `wasm_exec.js` file in your `index.html` file using a `<script>` tag.
|
|
34
|
+
|
|
35
|
+
### Possible Issues โ
|
|
36
|
+
|
|
37
|
+
> if you are using webpack4, you may flow this issue [How to import @openim/wasm-client-sdk in webpack4.x](https://github.com/openimsdk/open-im-sdk-web-wasm/issues/73).
|
|
38
|
+
|
|
39
|
+
## Usage ๐
|
|
40
|
+
|
|
41
|
+
The following examples demonstrate how to use the SDK. TypeScript is used, providing complete type hints.
|
|
42
|
+
|
|
43
|
+
### Importing the SDK
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { getSDK } from '@openim/wasm-client-sdk';
|
|
47
|
+
|
|
48
|
+
const OpenIM = getSDK();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Logging In and Listening for Connection Status
|
|
52
|
+
|
|
53
|
+
> Note: You need to [deploy](https://github.com/openimsdk/open-im-server#rocket-quick-start) OpenIM Server first, the default port of OpenIM Server is 10001, 10002.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { CbEvents } from '@openim/wasm-client-sdk';
|
|
57
|
+
import type { WSEvent } from '@openim/wasm-client-sdk/lib/types/entity';
|
|
58
|
+
|
|
59
|
+
OpenIM.on(CbEvents.OnConnecting, handleConnecting);
|
|
60
|
+
OpenIM.on(CbEvents.OnConnectFailed, handleConnectFailed);
|
|
61
|
+
OpenIM.on(CbEvents.OnConnectSuccess, handleConnectSuccess);
|
|
62
|
+
|
|
63
|
+
OpenIM.login({
|
|
64
|
+
userID: 'IM user ID',
|
|
65
|
+
token: 'IM user token',
|
|
66
|
+
platformID: 5,
|
|
67
|
+
apiAddr: 'http://your-server-ip:10002',
|
|
68
|
+
wsAddr: 'ws://your-server-ip:10001',
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
function handleConnecting() {
|
|
72
|
+
// Connecting...
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function handleConnectFailed({ errCode, errMsg }: WSEvent) {
|
|
76
|
+
// Connection failed โ
|
|
77
|
+
console.log(errCode, errMsg);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function handleConnectSuccess() {
|
|
81
|
+
// Connection successful โ
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
To log into the IM server, you need to create an account and obtain a user ID and token. Refer to the [access token documentation](https://docs.openim.io/restapi/userManagement/userRegister) for details.
|
|
86
|
+
|
|
87
|
+
### Receiving and Sending Messages ๐ฌ
|
|
88
|
+
|
|
89
|
+
OpenIM makes it easy to send and receive messages. By default, there is no restriction on having a friend relationship to send messages (although you can configure other policies on the server). If you know the user ID of the recipient, you can conveniently send a message to them.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { CbEvents } from '@openim/wasm-client-sdk';
|
|
93
|
+
import type {
|
|
94
|
+
WSEvent,
|
|
95
|
+
MessageItem,
|
|
96
|
+
} from '@openim/wasm-client-sdk/lib/types/entity';
|
|
97
|
+
|
|
98
|
+
// Listenfor new messages ๐ฉ
|
|
99
|
+
OpenIM.on(CbEvents.OnRecvNewMessages, handleNewMessages);
|
|
100
|
+
|
|
101
|
+
const message = (await OpenIM.createTextMessage('hello openim')).data;
|
|
102
|
+
|
|
103
|
+
OpenIM.sendMessage({
|
|
104
|
+
recvID: 'recipient user ID',
|
|
105
|
+
groupID: '',
|
|
106
|
+
message,
|
|
107
|
+
})
|
|
108
|
+
.then(() => {
|
|
109
|
+
// Message sent successfully โ๏ธ
|
|
110
|
+
})
|
|
111
|
+
.catch(err => {
|
|
112
|
+
// Failed to send message โ
|
|
113
|
+
console.log(err);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
function handleNewMessages({ data }: WSEvent<MessageItem[]>) {
|
|
117
|
+
// New message list ๐จ
|
|
118
|
+
console.log(data);
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Examples ๐
|
|
123
|
+
|
|
124
|
+
You can find a demo web app that uses the SDK in the [openim-pc-web-demo](https://github.com/openimsdk/open-im-pc-web-demo) repository.
|
|
125
|
+
|
|
126
|
+
## Browser Support ๐
|
|
127
|
+
|
|
128
|
+
| Browser | Desktop OS | Mobile OS |
|
|
129
|
+
| ------------------- | --------------------- | --------- |
|
|
130
|
+
| Chrome (61+) | Windows, macOS, Linux | Android |
|
|
131
|
+
| Firefox (58+) | Windows, macOS, Linux | Android |
|
|
132
|
+
| Safari (15+) | macOS | iOS |
|
|
133
|
+
| Edge (Chromium 16+) | Windows, macOS | |
|
|
134
|
+
|
|
135
|
+
## Community :busts_in_silhouette:
|
|
136
|
+
|
|
137
|
+
- ๐ [OpenIM Community](https://github.com/OpenIMSDK/community)
|
|
138
|
+
- ๐ [OpenIM Interest Group](https://github.com/Openim-sigs)
|
|
139
|
+
- ๐ [Join our Slack community](https://join.slack.com/t/openimsdk/shared_invite/zt-2ijy1ys1f-O0aEDCr7ExRZ7mwsHAVg9A)
|
|
140
|
+
- :eyes: [Join our wechat (ๅพฎไฟก็พค)](https://openim-1253691595.cos.ap-nanjing.myqcloud.com/WechatIMG20.jpeg)
|
|
141
|
+
|
|
142
|
+
## Community Meetings :calendar:
|
|
143
|
+
|
|
144
|
+
We want anyone to get involved in our community and contributing code, we offer gifts and rewards, and we welcome you to join us every Thursday night.
|
|
145
|
+
|
|
146
|
+
Our conference is in the [OpenIM Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-2ijy1ys1f-O0aEDCr7ExRZ7mwsHAVg9A) ๐ฏ, then you can search the Open-IM-Server pipeline to join
|
|
147
|
+
|
|
148
|
+
We take notes of each [biweekly meeting](https://github.com/orgs/OpenIMSDK/discussions/categories/meeting) in [GitHub discussions](https://github.com/openimsdk/open-im-server/discussions/categories/meeting), Our historical meeting notes, as well as replays of the meetings are available at [Google Docs :bookmark_tabs:](https://docs.google.com/document/d/1nx8MDpuG74NASx081JcCpxPgDITNTpIIos0DS6Vr9GU/edit?usp=sharing).
|
|
149
|
+
|
|
150
|
+
## Who are using OpenIM :eyes:
|
|
151
|
+
|
|
152
|
+
Check out our [user case studies](https://github.com/OpenIMSDK/community/blob/main/ADOPTERS.md) page for a list of the project users. Don't hesitate to leave a [๐comment](https://github.com/openimsdk/open-im-server/issues/379) and share your use case.
|
|
153
|
+
|
|
154
|
+
## License :page_facing_up:
|
|
155
|
+
|
|
156
|
+
This software is licensed under a dual-license model:
|
|
157
|
+
|
|
158
|
+
- The GNU Affero General Public License (AGPL), Version 3 or later; **OR**
|
|
159
|
+
- Commercial license terms from OpenIMSDK.
|
|
160
|
+
|
|
161
|
+
If you wish to use this software under commercial terms, please contact us at: contact@openim.io
|
|
162
|
+
|
|
163
|
+
For more information, see: https://www.openim.io/en/licensing
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
Binary file
|
|
Binary file
|