feat: initial
This commit is contained in:
4
.eslintignore
Normal file
4
.eslintignore
Normal file
@@ -0,0 +1,4 @@
|
||||
src/types/global.d.ts
|
||||
assets/
|
||||
lib/
|
||||
wasm_exec.js
|
||||
39
.eslintrc.js
Normal file
39
.eslintrc.js
Normal file
@@ -0,0 +1,39 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: ['@typescript-eslint', 'node', 'prettier'],
|
||||
parserOptions: {
|
||||
tsconfigRootDir: __dirname,
|
||||
project: ['./tsconfig.json'],
|
||||
},
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:node/recommended',
|
||||
'plugin:@typescript-eslint/eslint-recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
||||
'plugin:prettier/recommended',
|
||||
],
|
||||
rules: {
|
||||
'prettier/prettier': 'warn',
|
||||
'node/no-missing-import': 'off',
|
||||
'node/no-empty-function': 'off',
|
||||
'node/no-unsupported-features/es-syntax': 'off',
|
||||
'node/no-missing-require': 'off',
|
||||
'node/shebang': 'off',
|
||||
'@typescript-eslint/no-use-before-define': 'off',
|
||||
quotes: ['warn', 'single', { avoidEscape: true }],
|
||||
'node/no-unpublished-import': 'off',
|
||||
'@typescript-eslint/no-unsafe-assignment': 'off',
|
||||
'@typescript-eslint/no-var-requires': 'off',
|
||||
'@typescript-eslint/ban-ts-comment': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/restrict-template-expressions': 'off',
|
||||
'@typescript-eslint/no-unsafe-return': 'off',
|
||||
'@typescript-eslint/no-floating-promises': 'off',
|
||||
'@typescript-eslint/no-empty-function': 'off',
|
||||
'@typescript-eslint/no-misused-promises': 'off',
|
||||
'no-async-promise-executor': 'off',
|
||||
},
|
||||
};
|
||||
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# Set the repository to show as TypeScript rather than JS in GitHub
|
||||
*.js linguist-detectable=false
|
||||
120
.gitignore
vendored
Normal file
120
.gitignore
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
demo
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env.test
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
# Compiled code
|
||||
lib/
|
||||
1
.husky/.gitignore
vendored
Normal file
1
.husky/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
_
|
||||
4
.husky/pre-commit
Executable file
4
.husky/pre-commit
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npx lint-staged
|
||||
4
.husky/prepare-commit-msg
Executable file
4
.husky/prepare-commit-msg
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
exec </dev/tty && node_modules/.bin/cz --hook || true
|
||||
6
.prettierrc
Normal file
6
.prettierrc
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "es5",
|
||||
"arrowParens": "avoid",
|
||||
"printWidth": 80
|
||||
}
|
||||
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"editor.formatOnSave": true,
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
}
|
||||
}
|
||||
201
LICENSE
Executable file
201
LICENSE
Executable file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
207
README.md
Normal file
207
README.md
Normal file
@@ -0,0 +1,207 @@
|
||||
# JavaScript/TypeScript Client SDK for OpenIM 👨💻💬
|
||||
|
||||
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.
|
||||
|
||||
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/).
|
||||
|
||||
|
||||
|
||||
|
||||
## Documentation 📚
|
||||
|
||||
Visit [https://doc.rentsoft.cn/](https://doc.rentsoft.cn/) for detailed documentation and guides.
|
||||
|
||||
For the SDK reference, see [https://doc.rentsoft.cn/sdks/quickstart/browser](https://doc.rentsoft.cn/sdks/quickstart/browser).
|
||||
|
||||
## Installation 💻
|
||||
|
||||
### Adding Dependencies
|
||||
|
||||
```shell
|
||||
npm install open-im-sdk-wasm --save
|
||||
```
|
||||
|
||||
### Obtaining Required Static Resources for WASM
|
||||
|
||||
Follow these steps to obtain the static resources required for WebAssembly (WASM):
|
||||
|
||||
1. Locate the `open-im-sdk-wasm` subdirectory in the `node_modules` directory of your project. Copy all the files in the `assets` folder to your project's public resource directory.
|
||||
|
||||
The files to be copied are:
|
||||
|
||||
- `openIM.wasm`
|
||||
- `sql-wasm.wasm`
|
||||
- `wasm_exec.js`
|
||||
|
||||
2. After copying the files, import the `wasm_exec.js` file in your `index.html` file using a `<script>` tag.
|
||||
|
||||
### Possible Issues ❗
|
||||
|
||||
#### For Webpack 5+
|
||||
|
||||
Add the following configuration to your Webpack configuration:
|
||||
|
||||
```js
|
||||
resolve: {
|
||||
fallback: {
|
||||
fs: false,
|
||||
path: false,
|
||||
crypto: false,
|
||||
},
|
||||
},
|
||||
```
|
||||
|
||||
#### For Webpack 4 or Vite
|
||||
|
||||
**Note:**
|
||||
If you are using `Webpack 4`, you will also need to install the worker loader.
|
||||
|
||||
```shell
|
||||
npm install worker-loader worker-plugin -D
|
||||
```
|
||||
|
||||
Add the following configuration to your Webpack configuration:
|
||||
|
||||
```js
|
||||
const WorkerPlugin = require("worker-plugin");
|
||||
|
||||
// ...
|
||||
|
||||
plugins: [new WorkerPlugin()],
|
||||
|
||||
// ...
|
||||
```
|
||||
|
||||
Follow these steps:
|
||||
|
||||
1. Copy the `lib` directory from the npm package to your project (e.g., `src/utils/lib`).
|
||||
|
||||
2. Modify the import method of the web worker in the `lib/api/index.js` file.
|
||||
|
||||
```js
|
||||
// For Webpack 4:
|
||||
+ import IMWorker from 'worker-loader!./worker.js';
|
||||
// For Vite:
|
||||
+ import IMWorker from './worker?worker';
|
||||
|
||||
- worker = new Worker(new URL('./worker.js', import.meta.url));
|
||||
+ worker = new IMWorker();
|
||||
```
|
||||
|
||||
## Usage 🚀
|
||||
|
||||
The following examples demonstrate how to use the SDK. TypeScript is used, providing complete type hints.
|
||||
|
||||
### Importing the SDK
|
||||
|
||||
```typescript
|
||||
import { getSDK } from 'open-im-sdk-wasm';
|
||||
// or your own path after copying
|
||||
// import { getSDK } from '@/utils/lib';
|
||||
|
||||
const OpenIM = getSDK();
|
||||
```
|
||||
|
||||
### Logging In and Listening for Connection Status
|
||||
|
||||
> 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.
|
||||
|
||||
```typescript
|
||||
import { CbEvents } from 'open-im-sdk-wasm';
|
||||
import type { WSEvent } from 'open-im-sdk-wasm';
|
||||
|
||||
OpenIM.on(CbEvents.OnConnecting, handleConnecting);
|
||||
OpenIM.on(CbEvents.OnConnectFailed, handleConnectFailed);
|
||||
OpenIM.on(CbEvents.OnConnectSuccess, handleConnectSuccess);
|
||||
|
||||
OpenIM.login({
|
||||
userID: 'IM user ID',
|
||||
token: 'IM user token',
|
||||
platformID: 5,
|
||||
apiAddr: 'http://your-server-ip:10002',
|
||||
wsAddr: 'ws://your-server-ip:10001',
|
||||
});
|
||||
|
||||
function handleConnecting() {
|
||||
// Connecting...
|
||||
}
|
||||
|
||||
function handleConnectFailed({ errCode, errMsg }: WSEvent) {
|
||||
// Connection failed ❌
|
||||
console.log(errCode, errMsg);
|
||||
}
|
||||
|
||||
function handleConnectSuccess() {
|
||||
// Connection successful ✅
|
||||
}
|
||||
```
|
||||
|
||||
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://doc.rentsoft.cn/restapi/userManagement/userRegister) for details.
|
||||
|
||||
### Receiving and Sending Messages 💬
|
||||
|
||||
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.
|
||||
|
||||
```typescript
|
||||
import { CbEvents } from 'open-im-sdk-wasm';
|
||||
import type { WSEvent, MessageItem } from 'open-im-sdk-wasm';
|
||||
|
||||
// Listenfor new messages 📩
|
||||
OpenIM.on(CbEvents.OnRecvNewMessages, handleNewMessages);
|
||||
|
||||
const message = (await OpenIM.createTextMessage('hello openim')).data;
|
||||
|
||||
OpenIM.sendMessage({
|
||||
recvID: 'recipient user ID',
|
||||
groupID: '',
|
||||
message,
|
||||
})
|
||||
.then(() => {
|
||||
// Message sent successfully ✉️
|
||||
})
|
||||
.catch(err => {
|
||||
// Failed to send message ❌
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
function handleNewMessages({ data }: WSEvent<MessageItem[]>) {
|
||||
// New message list 📨
|
||||
console.log(data);
|
||||
}
|
||||
```
|
||||
|
||||
## Examples 🌟
|
||||
|
||||
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.
|
||||
|
||||
## Browser Support 🌐
|
||||
|
||||
| Browser | Desktop OS | Mobile OS |
|
||||
| ------------------- | --------------------- | --------- |
|
||||
| Chrome (61+) | Windows, macOS, Linux | Android |
|
||||
| Firefox (58+) | Windows, macOS, Linux | Android |
|
||||
| Safari (15+) | macOS | iOS |
|
||||
| Edge (Chromium 16+) | Windows, macOS | |
|
||||
|
||||
## Community :busts_in_silhouette:
|
||||
|
||||
- 📚 [OpenIM Community](https://github.com/OpenIMSDK/community)
|
||||
- 💕 [OpenIM Interest Group](https://github.com/Openim-sigs)
|
||||
- 🚀 [Join our Slack community](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q)
|
||||
- :eyes: [Join our wechat (微信群)](https://openim-1253691595.cos.ap-nanjing.myqcloud.com/WechatIMG20.jpeg)
|
||||
|
||||
## Community Meetings :calendar:
|
||||
|
||||
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.
|
||||
|
||||
Our conference is in the [OpenIM Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q) 🎯, then you can search the Open-IM-Server pipeline to join
|
||||
|
||||
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).
|
||||
|
||||
## Who are using OpenIM :eyes:
|
||||
|
||||
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.
|
||||
|
||||
## License :page_facing_up:
|
||||
|
||||
OpenIM is licensed under the Apache 2.0 license. See [LICENSE](https://github.com/openimsdk/open-im-server/tree/main/LICENSE) for the full license text.
|
||||
12187
package-lock.json
generated
Normal file
12187
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
80
package.json
Normal file
80
package.json
Normal file
@@ -0,0 +1,80 @@
|
||||
{
|
||||
"name": "open-im-sdk-node",
|
||||
"version": "1.0.0",
|
||||
"description": "open im sdk for node",
|
||||
"source": "src/index.ts",
|
||||
"main": "lib/index.js",
|
||||
"module": "lib/index.es.js",
|
||||
"types": "lib/index.d.ts",
|
||||
"files": [
|
||||
"lib/**/*",
|
||||
"assets/**/*"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "rimraf lib && rollup -c && tsc-alias",
|
||||
"cm": "cz",
|
||||
"lint": "eslint ./src/ --fix",
|
||||
"prepare": "husky install",
|
||||
"semantic-release": "semantic-release",
|
||||
"test:watch": "jest --watch",
|
||||
"test": "jest --coverage",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/OpenIMSDK/open-im-sdk-node.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "blooming",
|
||||
"email": "blooming2477@gmail.com",
|
||||
"url": "https://github.com/Bloomingg"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0"
|
||||
},
|
||||
"keywords": [
|
||||
"openim"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/OpenIMSDK/open-im-sdk-node/issues"
|
||||
},
|
||||
"homepage": "https://github.com/OpenIMSDK/open-im-sdk-node#readme",
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^16.2.4",
|
||||
"@commitlint/config-conventional": "^16.2.4",
|
||||
"@rollup/plugin-alias": "^5.1.0",
|
||||
"@rollup/plugin-terser": "^0.4.4",
|
||||
"@types/ffi-napi": "^4.0.10",
|
||||
"@types/node": "^12.20.55",
|
||||
"@types/uuid": "^8.3.4",
|
||||
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
||||
"@typescript-eslint/parser": "^4.22.0",
|
||||
"conventional-changelog-conventionalcommits": "^5.0.0",
|
||||
"eslint": "^7.25.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-prettier": "^3.4.0",
|
||||
"husky": "^6.0.0",
|
||||
"jest": "^27.2.0",
|
||||
"lint-staged": "^10.5.4",
|
||||
"prettier": "^2.2.1",
|
||||
"rollup": "^2.79.1",
|
||||
"rollup-plugin-typescript2": "^0.36.0",
|
||||
"semantic-release": "^19.0.2",
|
||||
"tsc-alias": "^1.7.0",
|
||||
"typescript": "^4.2.4"
|
||||
},
|
||||
"config": {
|
||||
"commitizen": {
|
||||
"path": "./node_modules/@commitlint/cz-conventional-changelog"
|
||||
}
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.ts": "eslint --cache --cache-location .eslintcache --fix"
|
||||
},
|
||||
"dependencies": {
|
||||
"uuid": "^9.0.0",
|
||||
"ffi-napi": "^4.0.3"
|
||||
}
|
||||
}
|
||||
25
rollup.config.js
Normal file
25
rollup.config.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import typescript from 'rollup-plugin-typescript2';
|
||||
import alias from '@rollup/plugin-alias';
|
||||
|
||||
export default [
|
||||
{
|
||||
input: 'src/index.ts',
|
||||
output: [
|
||||
{
|
||||
file: 'lib/index.js',
|
||||
format: 'cjs',
|
||||
exports: 'auto',
|
||||
sourcemap: false
|
||||
},
|
||||
{
|
||||
file: 'lib/index.es.js',
|
||||
format: 'esm',
|
||||
sourcemap: false
|
||||
}
|
||||
],
|
||||
plugins: [
|
||||
alias(),
|
||||
typescript(),
|
||||
]
|
||||
}
|
||||
];
|
||||
3
src/constant/api.ts
Normal file
3
src/constant/api.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export enum ErrorCode {
|
||||
UnknownError = 10005,
|
||||
}
|
||||
182
src/constant/callback.ts
Normal file
182
src/constant/callback.ts
Normal file
@@ -0,0 +1,182 @@
|
||||
export enum NativeEvent {
|
||||
CONNECTING,
|
||||
CONNECT_SUCCESS,
|
||||
CONNECT_FAILED,
|
||||
KICKED_OFFLINE,
|
||||
USER_TOKEN_EXPIRED,
|
||||
JOINED_GROUP_ADDED,
|
||||
JOINED_GROUP_DELETED,
|
||||
GROUP_MEMBER_ADDED,
|
||||
GROUP_MEMBER_DELETED,
|
||||
GROUP_APPLICATION_ADDED,
|
||||
GROUP_APPLICATION_DELETED,
|
||||
GROUP_INFO_CHANGED,
|
||||
GROUP_DISMISSED,
|
||||
GROUP_MEMBER_INFO_CHANGED,
|
||||
GROUP_APPLICATION_ACCEPTED,
|
||||
GROUP_APPLICATION_REJECTED,
|
||||
FRIEND_APPLICATION_ADDED,
|
||||
FRIEND_APPLICATION_DELETED,
|
||||
FRIEND_APPLICATION_ACCEPTED,
|
||||
FRIEND_APPLICATION_REJECTED,
|
||||
FRIEND_ADDED,
|
||||
FRIEND_DELETED,
|
||||
FRIEND_INFO_CHANGED,
|
||||
BLACK_ADDED,
|
||||
BLACK_DELETED,
|
||||
SYNC_SERVER_START,
|
||||
SYNC_SERVER_FINISH,
|
||||
SYNC_SERVER_PROGRESS,
|
||||
SYNC_SERVER_FAILED,
|
||||
NEW_CONVERSATION,
|
||||
CONVERSATION_CHANGED,
|
||||
TOTAL_UNREAD_MESSAGE_COUNT_CHANGED,
|
||||
RECV_NEW_MESSAGE,
|
||||
RECV_C2C_READ_RECEIPT,
|
||||
RECV_GROUP_READ_RECEIPT,
|
||||
NEW_RECV_MESSAGE_REVOKED,
|
||||
RECV_MESSAGE_EXTENSIONS_CHANGED,
|
||||
RECV_MESSAGE_EXTENSIONS_DELETED,
|
||||
RECV_MESSAGE_EXTENSIONS_ADDED,
|
||||
RECV_OFFLINE_NEW_MESSAGE,
|
||||
MSG_DELETED,
|
||||
RECV_NEW_MESSAGES,
|
||||
RECV_OFFLINE_NEW_MESSAGES,
|
||||
SELF_INFO_UPDATED,
|
||||
USER_STATUS_CHANGED,
|
||||
RECV_CUSTOM_BUSINESS_MESSAGE,
|
||||
MESSAGE_KV_INFO_CHANGED,
|
||||
UPLOAD_FILE_CALLBACK_OPEN,
|
||||
UPLOAD_FILE_CALLBACK_PART_SIZE,
|
||||
UPLOAD_FILE_CALLBACK_HASH_PART_PROGRESS,
|
||||
UPLOAD_FILE_CALLBACK_HASH_PART_COMPLETE,
|
||||
UPLOAD_FILE_CALLBACK_UPLOAD_ID,
|
||||
UPLOAD_FILE_CALLBACK_UPLOAD_PART_COMPLETE,
|
||||
UPLOAD_FILE_CALLBACK_UPLOAD_COMPLETE,
|
||||
UPLOAD_FILE_CALLBACK_COMPLETE,
|
||||
}
|
||||
|
||||
export enum CbEvents {
|
||||
OnConnectFailed = 'OnConnectFailed',
|
||||
OnConnectSuccess = 'OnConnectSuccess',
|
||||
OnConnecting = 'OnConnecting',
|
||||
OnKickedOffline = 'OnKickedOffline',
|
||||
OnSelfInfoUpdated = 'OnSelfInfoUpdated',
|
||||
OnUserTokenExpired = 'OnUserTokenExpired',
|
||||
OnProgress = 'OnProgress',
|
||||
OnRecvNewMessage = 'OnRecvNewMessage',
|
||||
OnRecvNewMessages = 'OnRecvNewMessages',
|
||||
OnRecvMessageRevoked = 'OnRecvMessageRevoked',
|
||||
OnNewRecvMessageRevoked = 'OnNewRecvMessageRevoked',
|
||||
OnRecvC2CReadReceipt = 'OnRecvC2CReadReceipt',
|
||||
OnRecvGroupReadReceipt = 'OnRecvGroupReadReceipt',
|
||||
OnConversationChanged = 'OnConversationChanged',
|
||||
OnNewConversation = 'OnNewConversation',
|
||||
OnSyncServerFailed = 'OnSyncServerFailed',
|
||||
OnSyncServerFinish = 'OnSyncServerFinish',
|
||||
OnSyncServerStart = 'OnSyncServerStart',
|
||||
OnTotalUnreadMessageCountChanged = 'OnTotalUnreadMessageCountChanged',
|
||||
OnBlackAdded = 'OnBlackAdded',
|
||||
OnBlackDeleted = 'OnBlackDeleted',
|
||||
OnFriendApplicationAccepted = 'OnFriendApplicationAccepted',
|
||||
OnFriendApplicationAdded = 'OnFriendApplicationAdded',
|
||||
OnFriendApplicationDeleted = 'OnFriendApplicationDeleted',
|
||||
OnFriendApplicationRejected = 'OnFriendApplicationRejected',
|
||||
OnFriendInfoChanged = 'OnFriendInfoChanged',
|
||||
OnFriendAdded = 'OnFriendAdded',
|
||||
OnFriendDeleted = 'OnFriendDeleted',
|
||||
OnJoinedGroupAdded = 'OnJoinedGroupAdded',
|
||||
OnJoinedGroupDeleted = 'OnJoinedGroupDeleted',
|
||||
OnGroupDismissed = 'OnGroupDismissed',
|
||||
OnGroupMemberAdded = 'OnGroupMemberAdded',
|
||||
OnGroupMemberDeleted = 'OnGroupMemberDeleted',
|
||||
OnGroupApplicationAdded = 'OnGroupApplicationAdded',
|
||||
OnGroupApplicationDeleted = 'OnGroupApplicationDeleted',
|
||||
OnGroupInfoChanged = 'OnGroupInfoChanged',
|
||||
OnGroupMemberInfoChanged = 'OnGroupMemberInfoChanged',
|
||||
OnGroupApplicationAccepted = 'OnGroupApplicationAccepted',
|
||||
OnGroupApplicationRejected = 'OnGroupApplicationRejected',
|
||||
|
||||
UploadComplete = 'UploadComplete',
|
||||
OnRecvCustomBusinessMessage = 'OnRecvCustomBusinessMessage',
|
||||
OnUserStatusChanged = 'OnUserStatusChanged',
|
||||
UnUsedEvent = 'UnUsedEvent',
|
||||
|
||||
// rtc
|
||||
OnReceiveNewInvitation = 'OnReceiveNewInvitation',
|
||||
OnInviteeAccepted = 'OnInviteeAccepted',
|
||||
OnInviteeRejected = 'OnInviteeRejected',
|
||||
OnInvitationCancelled = 'OnInvitationCancelled',
|
||||
OnHangUp = 'OnHangUp',
|
||||
OnInvitationTimeout = 'OnInvitationTimeout',
|
||||
OnInviteeAcceptedByOtherDevice = 'OnInviteeAcceptedByOtherDevice',
|
||||
OnInviteeRejectedByOtherDevice = 'OnInviteeRejectedByOtherDevice',
|
||||
|
||||
// meeting
|
||||
OnStreamChange = 'OnStreamChange',
|
||||
OnRoomParticipantConnected = 'OnRoomParticipantConnected',
|
||||
OnRoomParticipantDisconnected = 'OnRoomParticipantDisconnected',
|
||||
OnReceiveCustomSignal = 'OnReceiveCustomSignal',
|
||||
}
|
||||
|
||||
export const eventMapping: Record<NativeEvent, CbEvents> = {
|
||||
[NativeEvent.CONNECTING]: CbEvents.OnConnecting,
|
||||
[NativeEvent.CONNECT_SUCCESS]: CbEvents.OnConnectSuccess,
|
||||
[NativeEvent.CONNECT_FAILED]: CbEvents.OnConnectFailed,
|
||||
[NativeEvent.KICKED_OFFLINE]: CbEvents.OnKickedOffline,
|
||||
[NativeEvent.USER_TOKEN_EXPIRED]: CbEvents.OnUserTokenExpired,
|
||||
[NativeEvent.JOINED_GROUP_ADDED]: CbEvents.OnJoinedGroupAdded,
|
||||
[NativeEvent.JOINED_GROUP_DELETED]: CbEvents.OnJoinedGroupDeleted,
|
||||
[NativeEvent.GROUP_MEMBER_ADDED]: CbEvents.OnGroupMemberAdded,
|
||||
[NativeEvent.GROUP_MEMBER_DELETED]: CbEvents.OnGroupMemberDeleted,
|
||||
[NativeEvent.GROUP_APPLICATION_ADDED]: CbEvents.OnGroupApplicationAdded,
|
||||
[NativeEvent.GROUP_APPLICATION_DELETED]: CbEvents.OnGroupApplicationDeleted,
|
||||
[NativeEvent.GROUP_INFO_CHANGED]: CbEvents.OnGroupInfoChanged,
|
||||
[NativeEvent.GROUP_DISMISSED]: CbEvents.OnGroupDismissed,
|
||||
[NativeEvent.GROUP_MEMBER_INFO_CHANGED]: CbEvents.OnGroupMemberInfoChanged,
|
||||
[NativeEvent.GROUP_APPLICATION_ACCEPTED]: CbEvents.OnGroupApplicationAccepted,
|
||||
[NativeEvent.GROUP_APPLICATION_REJECTED]: CbEvents.OnGroupApplicationRejected,
|
||||
[NativeEvent.FRIEND_APPLICATION_ADDED]: CbEvents.OnFriendApplicationAdded,
|
||||
[NativeEvent.FRIEND_APPLICATION_DELETED]: CbEvents.OnFriendApplicationDeleted,
|
||||
[NativeEvent.FRIEND_APPLICATION_ACCEPTED]:
|
||||
CbEvents.OnFriendApplicationAccepted,
|
||||
[NativeEvent.FRIEND_APPLICATION_REJECTED]:
|
||||
CbEvents.OnFriendApplicationRejected,
|
||||
[NativeEvent.FRIEND_ADDED]: CbEvents.OnFriendAdded,
|
||||
[NativeEvent.FRIEND_DELETED]: CbEvents.OnFriendDeleted,
|
||||
[NativeEvent.FRIEND_INFO_CHANGED]: CbEvents.OnFriendInfoChanged,
|
||||
[NativeEvent.BLACK_ADDED]: CbEvents.OnBlackAdded,
|
||||
[NativeEvent.BLACK_DELETED]: CbEvents.OnBlackDeleted,
|
||||
[NativeEvent.SYNC_SERVER_START]: CbEvents.OnSyncServerStart,
|
||||
[NativeEvent.SYNC_SERVER_FINISH]: CbEvents.OnSyncServerFinish,
|
||||
[NativeEvent.SYNC_SERVER_PROGRESS]: CbEvents.OnProgress,
|
||||
[NativeEvent.SYNC_SERVER_FAILED]: CbEvents.OnSyncServerFailed,
|
||||
[NativeEvent.NEW_CONVERSATION]: CbEvents.OnNewConversation,
|
||||
[NativeEvent.CONVERSATION_CHANGED]: CbEvents.OnConversationChanged,
|
||||
[NativeEvent.TOTAL_UNREAD_MESSAGE_COUNT_CHANGED]:
|
||||
CbEvents.OnTotalUnreadMessageCountChanged,
|
||||
[NativeEvent.RECV_NEW_MESSAGE]: CbEvents.OnRecvNewMessage,
|
||||
[NativeEvent.RECV_C2C_READ_RECEIPT]: CbEvents.OnRecvC2CReadReceipt,
|
||||
[NativeEvent.RECV_GROUP_READ_RECEIPT]: CbEvents.OnRecvGroupReadReceipt,
|
||||
[NativeEvent.NEW_RECV_MESSAGE_REVOKED]: CbEvents.OnNewRecvMessageRevoked,
|
||||
[NativeEvent.RECV_NEW_MESSAGES]: CbEvents.OnRecvNewMessages,
|
||||
[NativeEvent.SELF_INFO_UPDATED]: CbEvents.OnSelfInfoUpdated,
|
||||
[NativeEvent.USER_STATUS_CHANGED]: CbEvents.OnUserStatusChanged,
|
||||
[NativeEvent.RECV_CUSTOM_BUSINESS_MESSAGE]:
|
||||
CbEvents.OnRecvCustomBusinessMessage,
|
||||
[NativeEvent.UPLOAD_FILE_CALLBACK_COMPLETE]: CbEvents.UploadComplete,
|
||||
[NativeEvent.RECV_MESSAGE_EXTENSIONS_CHANGED]: CbEvents.UnUsedEvent,
|
||||
[NativeEvent.RECV_MESSAGE_EXTENSIONS_DELETED]: CbEvents.UnUsedEvent,
|
||||
[NativeEvent.RECV_MESSAGE_EXTENSIONS_ADDED]: CbEvents.UnUsedEvent,
|
||||
[NativeEvent.RECV_OFFLINE_NEW_MESSAGE]: CbEvents.UnUsedEvent,
|
||||
[NativeEvent.MSG_DELETED]: CbEvents.UnUsedEvent,
|
||||
[NativeEvent.RECV_OFFLINE_NEW_MESSAGES]: CbEvents.UnUsedEvent,
|
||||
[NativeEvent.MESSAGE_KV_INFO_CHANGED]: CbEvents.UnUsedEvent,
|
||||
[NativeEvent.UPLOAD_FILE_CALLBACK_OPEN]: CbEvents.UnUsedEvent,
|
||||
[NativeEvent.UPLOAD_FILE_CALLBACK_PART_SIZE]: CbEvents.UnUsedEvent,
|
||||
[NativeEvent.UPLOAD_FILE_CALLBACK_HASH_PART_PROGRESS]: CbEvents.UnUsedEvent,
|
||||
[NativeEvent.UPLOAD_FILE_CALLBACK_HASH_PART_COMPLETE]: CbEvents.UnUsedEvent,
|
||||
[NativeEvent.UPLOAD_FILE_CALLBACK_UPLOAD_ID]: CbEvents.UnUsedEvent,
|
||||
[NativeEvent.UPLOAD_FILE_CALLBACK_UPLOAD_PART_COMPLETE]: CbEvents.UnUsedEvent,
|
||||
[NativeEvent.UPLOAD_FILE_CALLBACK_UPLOAD_COMPLETE]: CbEvents.UnUsedEvent,
|
||||
};
|
||||
434
src/core/index.ts
Normal file
434
src/core/index.ts
Normal file
@@ -0,0 +1,434 @@
|
||||
import ffi from 'ffi-napi';
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import type { LibOpenIMSDK } from 'libOpenIMSDK';
|
||||
import { UserModuleApi, setupUserModule } from './modules/user';
|
||||
import { InitConfig, LoginParams } from '@/types/params';
|
||||
import { BaseResponse, SelfUserInfo } from '@/types/entity';
|
||||
import { ErrorCode } from '@/constant/api';
|
||||
import { LoginStatus } from '@/types/enum';
|
||||
import { NativeEvent, eventMapping } from '@/constant/callback';
|
||||
import Emitter from '@/utils/emitter';
|
||||
import { type FriendModuleApi, setupFriendModule } from './modules/friend';
|
||||
import { type GroupModuleApi, setupGroupModule } from './modules/group';
|
||||
import {
|
||||
type ConversationModuleApi,
|
||||
setupConversationModule,
|
||||
} from './modules/conversation';
|
||||
import { type MessageModuleApi, setupMessageModule } from './modules/message';
|
||||
|
||||
const CB_I_S = ffi.Function('void', ['int', 'string']);
|
||||
const CB_S_I_S_S = ffi.Function('void', ['string', 'int', 'string', 'string']);
|
||||
const CB_S_I_S_S_I = ffi.Function('void', [
|
||||
'string',
|
||||
'int',
|
||||
'string',
|
||||
'string',
|
||||
'int',
|
||||
]);
|
||||
|
||||
class OpenIMSDK
|
||||
extends Emitter
|
||||
implements
|
||||
UserModuleApi,
|
||||
FriendModuleApi,
|
||||
GroupModuleApi,
|
||||
ConversationModuleApi,
|
||||
MessageModuleApi
|
||||
{
|
||||
libOpenIMSDK: LibOpenIMSDK;
|
||||
listenerCallback: Buffer;
|
||||
|
||||
constructor(libPath: string) {
|
||||
super();
|
||||
this.libOpenIMSDK = ffi.Library(libPath, {
|
||||
set_group_listener: ['void', [CB_I_S]],
|
||||
set_conversation_listener: ['void', [CB_I_S]],
|
||||
set_advanced_msg_listener: ['void', [CB_I_S]],
|
||||
set_batch_msg_listener: ['void', [CB_I_S]],
|
||||
set_user_listener: ['void', [CB_I_S]],
|
||||
set_friend_listener: ['void', [CB_I_S]],
|
||||
set_custom_business_listener: ['void', [CB_I_S]],
|
||||
init_sdk: ['uint8', [CB_I_S, 'string', 'string']],
|
||||
un_init_sdk: ['void', ['string']],
|
||||
login: ['void', [CB_S_I_S_S, 'string', 'string', 'string']],
|
||||
logout: ['void', [CB_S_I_S_S, 'string']],
|
||||
network_status_changed: ['void', [CB_S_I_S_S, 'string']],
|
||||
get_login_status: ['int', ['string']],
|
||||
get_login_user: ['string', []],
|
||||
create_text_message: ['string', ['string', 'string']],
|
||||
create_advanced_text_message: ['string', ['string', 'string', 'string']],
|
||||
create_text_at_message: [
|
||||
'string',
|
||||
['string', 'string', 'string', 'string', 'string'],
|
||||
],
|
||||
create_location_message: [
|
||||
'string',
|
||||
['string', 'string', 'double', 'double'],
|
||||
],
|
||||
create_custom_message: [
|
||||
'string',
|
||||
['string', 'string', 'string', 'string'],
|
||||
],
|
||||
create_quote_message: ['string', ['string', 'string', 'string']],
|
||||
create_advanced_quote_message: [
|
||||
'string',
|
||||
['string', 'string', 'string', 'string'],
|
||||
],
|
||||
create_card_message: ['string', ['string', 'string']],
|
||||
create_video_message_from_full_path: [
|
||||
'string',
|
||||
['string', 'string', 'string', 'long long', 'string'],
|
||||
],
|
||||
create_image_message_from_full_path: ['string', ['string', 'string']],
|
||||
create_sound_message_from_full_path: [
|
||||
'string',
|
||||
['string', 'string', 'long long'],
|
||||
],
|
||||
create_file_message_from_full_path: [
|
||||
'string',
|
||||
['string', 'string', 'string'],
|
||||
],
|
||||
create_image_message: ['string', ['string', 'string']],
|
||||
create_image_message_by_url: [
|
||||
'string',
|
||||
['string', 'string', 'string', 'string'],
|
||||
],
|
||||
create_sound_message_by_url: ['string', ['string', 'string']],
|
||||
create_sound_message: ['string', ['string', 'string', 'long long']],
|
||||
create_video_message_by_url: ['string', ['string', 'string']],
|
||||
create_video_message: [
|
||||
'string',
|
||||
['string', 'string', 'string', 'long long', 'string'],
|
||||
],
|
||||
create_file_message_by_url: ['string', ['string', 'string']],
|
||||
create_file_message: ['string', ['string', 'string', 'string']],
|
||||
create_merger_message: [
|
||||
'string',
|
||||
['string', 'string', 'string', 'string'],
|
||||
],
|
||||
create_face_message: ['string', ['string', 'int', 'string']],
|
||||
create_forward_message: ['string', ['string', 'string']],
|
||||
get_all_conversation_list: ['void', [CB_S_I_S_S, 'string']],
|
||||
get_advanced_history_message_list: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string'],
|
||||
],
|
||||
send_message: [
|
||||
'void',
|
||||
[CB_S_I_S_S_I, 'string', 'string', 'string', 'string', 'string'],
|
||||
],
|
||||
|
||||
// User related functions
|
||||
get_users_info: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
get_users_info_from_srv: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
set_self_info: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
get_self_user_info: ['void', [CB_S_I_S_S, 'string']],
|
||||
update_msg_sender_info: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string'],
|
||||
],
|
||||
subscribe_users_status: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
unsubscribe_users_status: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
get_subscribe_users_status: ['void', [CB_S_I_S_S, 'string']],
|
||||
get_user_status: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
|
||||
// Friend related functions
|
||||
get_specified_friends_info: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
get_friend_list: ['void', [CB_S_I_S_S, 'string']],
|
||||
get_friend_list_page: ['void', [CB_S_I_S_S, 'string', 'int', 'int']],
|
||||
search_friends: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
check_friend: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
add_friend: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
set_friend_remark: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
delete_friend: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
get_friend_application_list_as_recipient: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string'],
|
||||
],
|
||||
get_friend_application_list_as_applicant: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string'],
|
||||
],
|
||||
accept_friend_application: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
refuse_friend_application: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
add_black: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
get_black_list: ['void', [CB_S_I_S_S, 'string']],
|
||||
remove_black: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
|
||||
// Group related functions
|
||||
create_group: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
join_group: ['void', [CB_S_I_S_S, 'string', 'string', 'string', 'int']],
|
||||
quit_group: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
dismiss_group: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
change_group_mute: ['void', [CB_S_I_S_S, 'string', 'string', 'int']],
|
||||
change_group_member_mute: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string', 'int'],
|
||||
],
|
||||
set_group_member_role_level: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string', 'int'],
|
||||
],
|
||||
set_group_member_info: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
get_joined_group_list: ['void', [CB_S_I_S_S, 'string']],
|
||||
get_specified_groups_info: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
search_groups: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
set_group_info: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
set_group_verification: ['void', [CB_S_I_S_S, 'string', 'string', 'int']],
|
||||
set_group_look_member_info: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'int'],
|
||||
],
|
||||
set_group_apply_member_friend: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'int'],
|
||||
],
|
||||
get_group_member_list: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'int', 'int', 'int'],
|
||||
],
|
||||
get_group_member_owner_and_admin: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string'],
|
||||
],
|
||||
get_group_member_list_by_join_time_filter: [
|
||||
'void',
|
||||
[
|
||||
CB_S_I_S_S,
|
||||
'string',
|
||||
'string',
|
||||
'int',
|
||||
'int',
|
||||
'long long',
|
||||
'long long',
|
||||
'string',
|
||||
],
|
||||
],
|
||||
get_specified_group_members_info: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string'],
|
||||
],
|
||||
kick_group_member: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string', 'string'],
|
||||
],
|
||||
transfer_group_owner: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string'],
|
||||
],
|
||||
invite_user_to_group: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string', 'string'],
|
||||
],
|
||||
get_group_application_list_as_recipient: ['void', [CB_S_I_S_S, 'string']],
|
||||
get_group_application_list_as_applicant: ['void', [CB_S_I_S_S, 'string']],
|
||||
accept_group_application: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string', 'string'],
|
||||
],
|
||||
refuse_group_application: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string', 'string'],
|
||||
],
|
||||
set_group_member_nickname: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string', 'string'],
|
||||
],
|
||||
search_group_members: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
is_join_group: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
}) as LibOpenIMSDK;
|
||||
|
||||
this.listenerCallback = ffi.Callback(
|
||||
'void',
|
||||
['int', 'string'],
|
||||
(event: NativeEvent, data) => {
|
||||
const cbEvent = eventMapping[event];
|
||||
this.emit(cbEvent, data);
|
||||
console.log(`listener callback - Event: ${cbEvent}, Data: ${data}`);
|
||||
}
|
||||
);
|
||||
|
||||
Object.assign(this, setupUserModule(this));
|
||||
Object.assign(this, setupFriendModule(this));
|
||||
Object.assign(this, setupGroupModule(this));
|
||||
Object.assign(this, setupConversationModule(this));
|
||||
Object.assign(this, setupMessageModule(this));
|
||||
}
|
||||
|
||||
baseCallbackWrap = <T>(
|
||||
resolve: (response: BaseResponse<T>) => void,
|
||||
reject: (response: BaseResponse<T>) => void
|
||||
) =>
|
||||
ffi.Callback(
|
||||
'void',
|
||||
['string', 'int', 'string', 'string'],
|
||||
(operationID, errCode: number, errMsg, data) => {
|
||||
let realData;
|
||||
try {
|
||||
realData = JSON.parse(data);
|
||||
} catch (error) {
|
||||
realData = data;
|
||||
}
|
||||
const response: BaseResponse<T> = {
|
||||
errCode,
|
||||
errMsg,
|
||||
data: realData,
|
||||
operationID,
|
||||
};
|
||||
if (errCode === 0) {
|
||||
resolve(response);
|
||||
} else {
|
||||
reject(response);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
asyncRetunWrap = <T>(operationID: string, data: unknown) =>
|
||||
new Promise<BaseResponse<T>>((resolve, reject) => {
|
||||
const hasError = !data && !operationID.includes('unInitSDK');
|
||||
if (data && typeof data === 'string') {
|
||||
try {
|
||||
data = JSON.parse(data);
|
||||
} catch (error) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
const response = {
|
||||
errCode: hasError ? ErrorCode.UnknownError : 0,
|
||||
errMsg: '',
|
||||
data: data as T,
|
||||
operationID,
|
||||
};
|
||||
if (response.errCode === 0) {
|
||||
resolve(response);
|
||||
} else {
|
||||
reject(response);
|
||||
}
|
||||
});
|
||||
|
||||
setListener = () => {
|
||||
this.libOpenIMSDK.set_user_listener(this.listenerCallback);
|
||||
this.libOpenIMSDK.set_friend_listener(this.listenerCallback);
|
||||
this.libOpenIMSDK.set_group_listener(this.listenerCallback);
|
||||
this.libOpenIMSDK.set_conversation_listener(this.listenerCallback);
|
||||
this.libOpenIMSDK.set_advanced_msg_listener(this.listenerCallback);
|
||||
this.libOpenIMSDK.set_batch_msg_listener(this.listenerCallback);
|
||||
this.libOpenIMSDK.set_custom_business_listener(this.listenerCallback);
|
||||
};
|
||||
|
||||
initSDK = (param: InitConfig, opid = uuidV4()) =>
|
||||
new Promise<boolean>((resolve, reject) => {
|
||||
const flag = this.libOpenIMSDK.init_sdk(
|
||||
this.listenerCallback,
|
||||
opid,
|
||||
JSON.stringify(param)
|
||||
);
|
||||
if (!flag) {
|
||||
reject(!!flag);
|
||||
return;
|
||||
}
|
||||
this.setListener();
|
||||
resolve(!!flag);
|
||||
});
|
||||
|
||||
login = (param: LoginParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse>((resolve, reject) => {
|
||||
const loginCallback = this.baseCallbackWrap(resolve, reject);
|
||||
this.libOpenIMSDK.login(loginCallback, opid, param.userID, param.token);
|
||||
});
|
||||
|
||||
getLoginStatus = (opid = uuidV4()) =>
|
||||
this.asyncRetunWrap<LoginStatus>(
|
||||
opid,
|
||||
this.libOpenIMSDK.get_login_status(opid)
|
||||
);
|
||||
|
||||
getLoginUser = (opid = uuidV4()) =>
|
||||
this.asyncRetunWrap<SelfUserInfo>(opid, this.libOpenIMSDK.get_login_user());
|
||||
|
||||
logout = (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse>((resolve, reject) => {
|
||||
const logoutCallback = this.baseCallbackWrap(resolve, reject);
|
||||
this.libOpenIMSDK.logout(logoutCallback, opid);
|
||||
});
|
||||
|
||||
unInitSDK = (opid = uuidV4()) =>
|
||||
this.asyncRetunWrap(
|
||||
opid,
|
||||
this.libOpenIMSDK.un_init_sdk(`unInitSDK-${opid}`)
|
||||
);
|
||||
|
||||
// implements user api
|
||||
getSelfUserInfo!: UserModuleApi['getSelfUserInfo'];
|
||||
|
||||
// implements friend api
|
||||
acceptFriendApplication!: FriendModuleApi['acceptFriendApplication'];
|
||||
addBlack!: FriendModuleApi['addBlack'];
|
||||
addFriend!: FriendModuleApi['addFriend'];
|
||||
checkFriend!: FriendModuleApi['checkFriend'];
|
||||
deleteFriend!: FriendModuleApi['deleteFriend'];
|
||||
getBlackList!: FriendModuleApi['getBlackList'];
|
||||
getFriendApplicationListAsApplicant!: FriendModuleApi['getFriendApplicationListAsApplicant'];
|
||||
getFriendApplicationListAsRecipient!: FriendModuleApi['getFriendApplicationListAsRecipient'];
|
||||
getFriendList!: FriendModuleApi['getFriendList'];
|
||||
getSpecifiedFriendsInfo!: FriendModuleApi['getSpecifiedFriendsInfo'];
|
||||
refuseFriendApplication!: FriendModuleApi['refuseFriendApplication'];
|
||||
removeBlack!: FriendModuleApi['removeBlack'];
|
||||
searchFriends!: FriendModuleApi['searchFriends'];
|
||||
setFriendRemark!: FriendModuleApi['setFriendRemark'];
|
||||
|
||||
// implements group api
|
||||
createGroup!: GroupModuleApi['createGroup'];
|
||||
joinGroup!: GroupModuleApi['joinGroup'];
|
||||
inviteUserToGroup!: GroupModuleApi['inviteUserToGroup'];
|
||||
getJoinedGroupList!: GroupModuleApi['getJoinedGroupList'];
|
||||
searchGroups!: GroupModuleApi['searchGroups'];
|
||||
getSpecifiedGroupsInfo!: GroupModuleApi['getSpecifiedGroupsInfo'];
|
||||
setGroupInfo!: GroupModuleApi['setGroupInfo'];
|
||||
getGroupApplicationListAsRecipient!: GroupModuleApi['getGroupApplicationListAsRecipient'];
|
||||
getGroupApplicationListAsApplicant!: GroupModuleApi['getGroupApplicationListAsApplicant'];
|
||||
acceptGroupApplication!: GroupModuleApi['acceptGroupApplication'];
|
||||
refuseGroupApplication!: GroupModuleApi['refuseGroupApplication'];
|
||||
getGroupMemberList!: GroupModuleApi['getGroupMemberList'];
|
||||
getSpecifiedGroupMembersInfo!: GroupModuleApi['getSpecifiedGroupMembersInfo'];
|
||||
searchGroupMembers!: GroupModuleApi['searchGroupMembers'];
|
||||
setGroupMemberInfo!: GroupModuleApi['setGroupMemberInfo'];
|
||||
getGroupMemberOwnerAndAdmin!: GroupModuleApi['getGroupMemberOwnerAndAdmin'];
|
||||
getGroupMemberListByJoinTimeFilter!: GroupModuleApi['getGroupMemberListByJoinTimeFilter'];
|
||||
kickGroupMember!: GroupModuleApi['kickGroupMember'];
|
||||
changeGroupMemberMute!: GroupModuleApi['changeGroupMemberMute'];
|
||||
changeGroupMute!: GroupModuleApi['changeGroupMute'];
|
||||
transferGroupOwner!: GroupModuleApi['transferGroupOwner'];
|
||||
dismissGroup!: GroupModuleApi['dismissGroup'];
|
||||
quitGroup!: GroupModuleApi['quitGroup'];
|
||||
|
||||
// implements conversation api
|
||||
getAllConversationList!: ConversationModuleApi['getAllConversationList'];
|
||||
|
||||
// implements message api
|
||||
createTextMessage!: MessageModuleApi['createTextMessage'];
|
||||
createTextAtMessage!: MessageModuleApi['createTextAtMessage'];
|
||||
createLocationMessage!: MessageModuleApi['createLocationMessage'];
|
||||
createCustomMessage!: MessageModuleApi['createCustomMessage'];
|
||||
createQuoteMessage!: MessageModuleApi['createQuoteMessage'];
|
||||
createCardMessage!: MessageModuleApi['createCardMessage'];
|
||||
createMergerMessage!: MessageModuleApi['createMergerMessage'];
|
||||
createFaceMessage!: MessageModuleApi['createFaceMessage'];
|
||||
createForwardMessage!: MessageModuleApi['createForwardMessage'];
|
||||
createImageMessage!: MessageModuleApi['createImageMessage'];
|
||||
createImageMessageFromFullPath!: MessageModuleApi['createImageMessageFromFullPath'];
|
||||
createImageMessageByUrl!: MessageModuleApi['createImageMessageByUrl'];
|
||||
createVideoMessage!: MessageModuleApi['createVideoMessage'];
|
||||
createVideoMessageFromFullPath!: MessageModuleApi['createVideoMessageFromFullPath'];
|
||||
createVideoMessageByUrl!: MessageModuleApi['createVideoMessageByUrl'];
|
||||
createSoundMessage!: MessageModuleApi['createSoundMessage'];
|
||||
createSoundMessageFromFullPath!: MessageModuleApi['createSoundMessageFromFullPath'];
|
||||
createSoundMessageByUrl!: MessageModuleApi['createSoundMessageByUrl'];
|
||||
createFileMessage!: MessageModuleApi['createFileMessage'];
|
||||
createFileMessageFromFullPath!: MessageModuleApi['createFileMessageFromFullPath'];
|
||||
createFileMessageByUrl!: MessageModuleApi['createFileMessageByUrl'];
|
||||
getAdvancedHistoryMessageList!: MessageModuleApi['getAdvancedHistoryMessageList'];
|
||||
sendMessage!: MessageModuleApi['sendMessage'];
|
||||
}
|
||||
|
||||
export default OpenIMSDK;
|
||||
179
src/core/modules/conversation.ts
Normal file
179
src/core/modules/conversation.ts
Normal file
@@ -0,0 +1,179 @@
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import { BaseResponse, ConversationItem } from '@/types/entity';
|
||||
import OpenIMSDK from '..';
|
||||
|
||||
export function setupConversationModule(openIMSDK: OpenIMSDK) {
|
||||
return {
|
||||
// getAllConversationList: (opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<ConversationItem[]>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_all_conversation_list(
|
||||
// openIMSDK.baseCallbackWrap<ConversationItem[]>(resolve, reject),
|
||||
// opid
|
||||
// );
|
||||
// }),
|
||||
// getConversationListSplit: (
|
||||
// params: SplitConversationParams,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<ConversationItem[]>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_conversation_list_split(
|
||||
// openIMSDK.baseCallbackWrap<ConversationItem[]>(resolve, reject),
|
||||
// opid,
|
||||
// params.offset,
|
||||
// params.count
|
||||
// );
|
||||
// }),
|
||||
// getOneConversation: (params: GetOneConversationParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<ConversationItem>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_one_conversation(
|
||||
// openIMSDK.baseCallbackWrap<ConversationItem>(resolve, reject),
|
||||
// opid,
|
||||
// params.sessionType,
|
||||
// params.sourceID
|
||||
// );
|
||||
// }),
|
||||
// getMultipleConversation: (conversationIDList: string, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<ConversationItem[]>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_multiple_conversation(
|
||||
// openIMSDK.baseCallbackWrap<ConversationItem[]>(resolve, reject),
|
||||
// opid,
|
||||
// conversationIDList
|
||||
// );
|
||||
// }),
|
||||
// getConversationIDBySessionType: (
|
||||
// params: GetOneConversationParams,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<ConversationItem>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_conversation_id_by_session_type(
|
||||
// openIMSDK.baseCallbackWrap<ConversationItem>(resolve, reject),
|
||||
// opid,
|
||||
// params.sourceID,
|
||||
// params.sessionType
|
||||
// );
|
||||
// }),
|
||||
// getTotalUnreadMsgCount: (opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<number>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_total_unread_msg_count(
|
||||
// openIMSDK.baseCallbackWrap<number>(resolve, reject),
|
||||
// opid
|
||||
// );
|
||||
// }),
|
||||
// markConversationMessageAsRead: (conversationID: string, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.mark_conversation_message_as_read(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// conversationID
|
||||
// );
|
||||
// }),
|
||||
// setConversationDraft: (
|
||||
// params: SetConversationDraftParams,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.set_conversation_draft(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.draftText
|
||||
// );
|
||||
// }),
|
||||
// pinConversation: (params: PinConversationParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.pin_conversation(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.isPinned ? 1 : 0
|
||||
// );
|
||||
// }),
|
||||
// setConversationRecvMessageOpt: (
|
||||
// params: SetConversationRecvOptParams,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.set_conversation_recv_message_opt(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.opt
|
||||
// );
|
||||
// }),
|
||||
// setConversationPrivateChat: (
|
||||
// params: SetConversationPrivateParams,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.set_conversation_private_chat(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.isPrivate
|
||||
// );
|
||||
// }),
|
||||
// setConversationBurnDuration: (
|
||||
// params: SetBurnDurationParams,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.set_conversation_burn_duration(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.burnDuration
|
||||
// );
|
||||
// }),
|
||||
// resetConversationGroupAtType: (groupID: string, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.reset_conversation_group_at_type(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// groupID
|
||||
// );
|
||||
// }),
|
||||
// hideConversation: (conversationID: string, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.hide_conversation(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// conversationID
|
||||
// );
|
||||
// }),
|
||||
// hideAllConversation: (opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.hide_all_conversation(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid
|
||||
// );
|
||||
// }),
|
||||
// clearConversationAndDeleteAllMsg: (
|
||||
// conversationID: string,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.clear_conversation_and_delete_all_msg(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// conversationID
|
||||
// );
|
||||
// }),
|
||||
// deleteConversationAndDeleteAllMsg: (
|
||||
// conversationID: string,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.delete_conversation_and_delete_all_msg(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// conversationID
|
||||
// );
|
||||
// }),
|
||||
};
|
||||
}
|
||||
|
||||
export interface ConversationModuleApi {
|
||||
getAllConversationList: (
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<ConversationItem[]>>;
|
||||
}
|
||||
181
src/core/modules/friend.ts
Normal file
181
src/core/modules/friend.ts
Normal file
@@ -0,0 +1,181 @@
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import OpenIMSDK from '..';
|
||||
import {
|
||||
AccessFriendParams,
|
||||
SearchFriendParams,
|
||||
RemarkFriendParams,
|
||||
} from '@/types/params';
|
||||
|
||||
import {
|
||||
BaseResponse,
|
||||
BlackUserItem,
|
||||
FriendApplicationItem,
|
||||
FriendshipInfo,
|
||||
FullUserItem,
|
||||
SearchedFriendsInfo,
|
||||
} from '@/types/entity';
|
||||
|
||||
export function setupFriendModule(openIMSDK: OpenIMSDK) {
|
||||
return {
|
||||
acceptFriendApplication: (params: AccessFriendParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.accept_friend_application(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
addBlack: (userID: string, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.add_black(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
userID
|
||||
);
|
||||
}),
|
||||
|
||||
addFriend: (userID: string, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.add_friend(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
userID
|
||||
);
|
||||
}),
|
||||
|
||||
checkFriend: (userIDList: string[], opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<FriendshipInfo[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.check_friend(
|
||||
openIMSDK.baseCallbackWrap<FriendshipInfo[]>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(userIDList)
|
||||
);
|
||||
}),
|
||||
|
||||
deleteFriend: (userID: string, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.delete_friend(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
userID
|
||||
);
|
||||
}),
|
||||
|
||||
getBlackList: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<BlackUserItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_black_list(
|
||||
openIMSDK.baseCallbackWrap<BlackUserItem[]>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
getFriendApplicationListAsApplicant: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<FriendApplicationItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_friend_application_list_as_applicant(
|
||||
openIMSDK.baseCallbackWrap<FriendApplicationItem[]>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
getFriendApplicationListAsRecipient: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<FriendApplicationItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_friend_application_list_as_recipient(
|
||||
openIMSDK.baseCallbackWrap<FriendApplicationItem[]>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
getFriendList: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<FullUserItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_friend_list(
|
||||
openIMSDK.baseCallbackWrap<FullUserItem[]>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
getSpecifiedFriendsInfo: (userIDList: string[], opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<FullUserItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_specified_friends_info(
|
||||
openIMSDK.baseCallbackWrap<FullUserItem[]>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(userIDList)
|
||||
);
|
||||
}),
|
||||
|
||||
refuseFriendApplication: (params: AccessFriendParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.refuse_friend_application(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
removeBlack: (userID: string, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.remove_black(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
userID
|
||||
);
|
||||
}),
|
||||
|
||||
searchFriends: (params: SearchFriendParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<SearchedFriendsInfo[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.search_friends(
|
||||
openIMSDK.baseCallbackWrap<SearchedFriendsInfo[]>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
setFriendRemark: (params: RemarkFriendParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.set_friend_remark(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export interface FriendModuleApi {
|
||||
acceptFriendApplication: (
|
||||
params: AccessFriendParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
addBlack: (userID: string, opid?: string) => Promise<BaseResponse<void>>;
|
||||
addFriend: (userID: string, opid?: string) => Promise<BaseResponse<void>>;
|
||||
checkFriend: (
|
||||
userIDList: string[],
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<FriendshipInfo[]>>;
|
||||
deleteFriend: (userID: string, opid?: string) => Promise<BaseResponse<void>>;
|
||||
getBlackList: (opid?: string) => Promise<BaseResponse<BlackUserItem[]>>;
|
||||
getFriendApplicationListAsApplicant: (
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<FriendApplicationItem[]>>;
|
||||
getFriendApplicationListAsRecipient: (
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<FriendApplicationItem[]>>;
|
||||
getFriendList: (opid?: string) => Promise<BaseResponse<FullUserItem[]>>;
|
||||
getSpecifiedFriendsInfo: (
|
||||
userIDList: string[],
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<FullUserItem[]>>;
|
||||
refuseFriendApplication: (
|
||||
params: AccessFriendParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
removeBlack: (userID: string, opid?: string) => Promise<BaseResponse<void>>;
|
||||
searchFriends: (
|
||||
params: SearchFriendParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<SearchedFriendsInfo[]>>;
|
||||
setFriendRemark: (
|
||||
params: RemarkFriendParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
}
|
||||
348
src/core/modules/group.ts
Normal file
348
src/core/modules/group.ts
Normal file
@@ -0,0 +1,348 @@
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import {
|
||||
BaseResponse,
|
||||
GroupApplicationItem,
|
||||
GroupItem,
|
||||
GroupMemberItem,
|
||||
} from '@/types/entity';
|
||||
import OpenIMSDK from '..';
|
||||
import {
|
||||
CreateGroupParams,
|
||||
JoinGroupParams,
|
||||
OpreateGroupParams,
|
||||
SearchGroupParams,
|
||||
SetGroupinfoParams,
|
||||
AccessGroupParams,
|
||||
GetGroupMemberParams,
|
||||
getGroupMembersInfoParams,
|
||||
SearchGroupMemberParams,
|
||||
UpdateMemberInfoParams,
|
||||
GetGroupMemberByTimeParams,
|
||||
ChangeGroupMemberMuteParams,
|
||||
ChangeGroupMuteParams,
|
||||
TransferGroupParams,
|
||||
} from '@/types/params';
|
||||
|
||||
export function setupGroupModule(openIMSDK: OpenIMSDK) {
|
||||
return {
|
||||
createGroup: (params: CreateGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupItem>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.create_group(
|
||||
openIMSDK.baseCallbackWrap<GroupItem>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
joinGroup: (params: JoinGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.join_group(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.reqMsg,
|
||||
params.joinSource
|
||||
);
|
||||
}),
|
||||
|
||||
inviteUserToGroup: (params: OpreateGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.invite_user_to_group(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.reason,
|
||||
JSON.stringify(params.userIDList)
|
||||
);
|
||||
}),
|
||||
|
||||
getJoinedGroupList: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_joined_group_list(
|
||||
openIMSDK.baseCallbackWrap<GroupItem[]>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
searchGroups: (params: SearchGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.search_groups(
|
||||
openIMSDK.baseCallbackWrap<GroupItem[]>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
getSpecifiedGroupsInfo: (groupIDList: string[], opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_specified_groups_info(
|
||||
openIMSDK.baseCallbackWrap<GroupItem[]>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(groupIDList)
|
||||
);
|
||||
}),
|
||||
|
||||
setGroupInfo: (params: SetGroupinfoParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.set_group_info(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
getGroupApplicationListAsRecipient: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupApplicationItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_group_application_list_as_recipient(
|
||||
openIMSDK.baseCallbackWrap<GroupApplicationItem[]>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
getGroupApplicationListAsApplicant: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupApplicationItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_group_application_list_as_applicant(
|
||||
openIMSDK.baseCallbackWrap<GroupApplicationItem[]>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
acceptGroupApplication: (params: AccessGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.accept_group_application(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.fromUserID,
|
||||
params.handleMsg
|
||||
);
|
||||
}),
|
||||
|
||||
refuseGroupApplication: (params: AccessGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.refuse_group_application(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.fromUserID,
|
||||
params.handleMsg
|
||||
);
|
||||
}),
|
||||
|
||||
getGroupMemberList: (params: GetGroupMemberParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupMemberItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_group_member_list(
|
||||
openIMSDK.baseCallbackWrap<GroupMemberItem[]>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.filter,
|
||||
params.offset,
|
||||
params.count
|
||||
);
|
||||
}),
|
||||
|
||||
getSpecifiedGroupMembersInfo: (
|
||||
params: getGroupMembersInfoParams,
|
||||
opid = uuidV4()
|
||||
) =>
|
||||
new Promise<BaseResponse<GroupMemberItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_specified_group_members_info(
|
||||
openIMSDK.baseCallbackWrap<GroupMemberItem[]>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
JSON.stringify(params.userIDList)
|
||||
);
|
||||
}),
|
||||
|
||||
searchGroupMembers: (params: SearchGroupMemberParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupMemberItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.search_group_members(
|
||||
openIMSDK.baseCallbackWrap<GroupMemberItem[]>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
setGroupMemberInfo: (params: UpdateMemberInfoParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.set_group_member_info(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
getGroupMemberOwnerAndAdmin: (groupID: string, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupMemberItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_group_member_owner_and_admin(
|
||||
openIMSDK.baseCallbackWrap<GroupMemberItem[]>(resolve, reject),
|
||||
opid,
|
||||
groupID
|
||||
);
|
||||
}),
|
||||
|
||||
getGroupMemberListByJoinTimeFilter: (
|
||||
params: GetGroupMemberByTimeParams,
|
||||
opid = uuidV4()
|
||||
) =>
|
||||
new Promise<BaseResponse<GroupMemberItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_group_member_list_by_join_time_filter(
|
||||
openIMSDK.baseCallbackWrap<GroupMemberItem[]>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.offset,
|
||||
params.count,
|
||||
params.joinTimeBegin,
|
||||
params.joinTimeEnd,
|
||||
JSON.stringify(params.filterUserIDList)
|
||||
);
|
||||
}),
|
||||
|
||||
kickGroupMember: (params: OpreateGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.kick_group_member(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.reason,
|
||||
JSON.stringify(params.userIDList)
|
||||
);
|
||||
}),
|
||||
|
||||
changeGroupMemberMute: (
|
||||
params: ChangeGroupMemberMuteParams,
|
||||
opid = uuidV4()
|
||||
) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.change_group_member_mute(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.userID,
|
||||
params.mutedSeconds
|
||||
);
|
||||
}),
|
||||
|
||||
changeGroupMute: (params: ChangeGroupMuteParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.change_group_mute(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.isMute ? 1 : 0
|
||||
);
|
||||
}),
|
||||
|
||||
transferGroupOwner: (params: TransferGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.transfer_group_owner(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.newOwnerUserID
|
||||
);
|
||||
}),
|
||||
|
||||
dismissGroup: (groupID: string, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.dismiss_group(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
groupID
|
||||
);
|
||||
}),
|
||||
|
||||
quitGroup: (groupID: string, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.quit_group(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
groupID
|
||||
);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export interface GroupModuleApi {
|
||||
createGroup: (
|
||||
params: CreateGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupItem>>;
|
||||
joinGroup: (
|
||||
params: JoinGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
inviteUserToGroup: (
|
||||
params: OpreateGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
getJoinedGroupList: (opid?: string) => Promise<BaseResponse<GroupItem[]>>;
|
||||
searchGroups: (
|
||||
params: SearchGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupItem[]>>;
|
||||
getSpecifiedGroupsInfo: (
|
||||
groupIDList: string[],
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupItem[]>>;
|
||||
setGroupInfo: (
|
||||
params: SetGroupinfoParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
getGroupApplicationListAsRecipient: (
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupApplicationItem[]>>;
|
||||
getGroupApplicationListAsApplicant: (
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupApplicationItem[]>>;
|
||||
acceptGroupApplication: (
|
||||
params: AccessGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
refuseGroupApplication: (
|
||||
params: AccessGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
getGroupMemberList: (
|
||||
params: GetGroupMemberParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupMemberItem[]>>;
|
||||
getSpecifiedGroupMembersInfo: (
|
||||
params: getGroupMembersInfoParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupMemberItem[]>>;
|
||||
searchGroupMembers: (
|
||||
params: SearchGroupMemberParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupMemberItem[]>>;
|
||||
setGroupMemberInfo: (
|
||||
params: UpdateMemberInfoParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
getGroupMemberOwnerAndAdmin: (
|
||||
groupID: string,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupMemberItem[]>>;
|
||||
getGroupMemberListByJoinTimeFilter: (
|
||||
params: GetGroupMemberByTimeParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupMemberItem[]>>;
|
||||
kickGroupMember: (
|
||||
params: OpreateGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
changeGroupMemberMute: (
|
||||
params: ChangeGroupMemberMuteParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
changeGroupMute: (
|
||||
params: ChangeGroupMuteParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
transferGroupOwner: (
|
||||
params: TransferGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
dismissGroup: (groupID: string, opid?: string) => Promise<BaseResponse<void>>;
|
||||
quitGroup: (groupID: string, opid?: string) => Promise<BaseResponse<void>>;
|
||||
}
|
||||
500
src/core/modules/message.ts
Normal file
500
src/core/modules/message.ts
Normal file
@@ -0,0 +1,500 @@
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import OpenIMSDK from '..';
|
||||
import {
|
||||
AdvancedGetMessageResult,
|
||||
BaseResponse,
|
||||
CardElem,
|
||||
MessageItem,
|
||||
} from '@/types/entity';
|
||||
import {
|
||||
AtMsgParams,
|
||||
CustomMsgParams,
|
||||
FaceMessageParams,
|
||||
FileMsgByPathParams,
|
||||
FileMsgByUrlParams,
|
||||
GetAdvancedHistoryMsgParams,
|
||||
ImageMsgByUrlParams,
|
||||
LocationMsgParams,
|
||||
MergerMsgParams,
|
||||
QuoteMsgParams,
|
||||
SendMsgParams,
|
||||
SoundMsgByPathParams,
|
||||
SoundMsgByUrlParams,
|
||||
VideoMsgByPathParams,
|
||||
VideoMsgByUrlParams,
|
||||
} from '@/types/params';
|
||||
|
||||
export function setupMessageModule(openIMSDK: OpenIMSDK) {
|
||||
return {
|
||||
createTextMessage: (content: string, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_text_message(opid, content)
|
||||
),
|
||||
|
||||
createTextAtMessage: (params: AtMsgParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_text_at_message(
|
||||
opid,
|
||||
params.text,
|
||||
JSON.stringify(params.atUserIDList),
|
||||
JSON.stringify(params.atUsersInfo),
|
||||
JSON.stringify(params.message)
|
||||
)
|
||||
),
|
||||
|
||||
createLocationMessage: (params: LocationMsgParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_location_message(
|
||||
opid,
|
||||
params.description,
|
||||
params.longitude,
|
||||
params.latitude
|
||||
)
|
||||
),
|
||||
|
||||
createCustomMessage: (params: CustomMsgParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_custom_message(
|
||||
opid,
|
||||
params.data,
|
||||
params.extension,
|
||||
params.description
|
||||
)
|
||||
),
|
||||
|
||||
createQuoteMessage: (params: QuoteMsgParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_quote_message(
|
||||
opid,
|
||||
params.text,
|
||||
params.message
|
||||
)
|
||||
),
|
||||
|
||||
createCardMessage: (params: CardElem, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_card_message(opid, JSON.stringify(params))
|
||||
),
|
||||
|
||||
createMergerMessage: (params: MergerMsgParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_merger_message(
|
||||
opid,
|
||||
JSON.stringify(params.messageList),
|
||||
params.title,
|
||||
JSON.stringify(params.summaryList)
|
||||
)
|
||||
),
|
||||
|
||||
createFaceMessage: (params: FaceMessageParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_face_message(
|
||||
opid,
|
||||
params.index,
|
||||
params.data
|
||||
)
|
||||
),
|
||||
|
||||
createForwardMessage: (message: MessageItem, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_forward_message(
|
||||
opid,
|
||||
JSON.stringify(message)
|
||||
)
|
||||
),
|
||||
|
||||
createImageMessage: (imagePath: string, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_image_message(opid, imagePath)
|
||||
),
|
||||
|
||||
createImageMessageFromFullPath: (imagePath: string, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_image_message_from_full_path(
|
||||
opid,
|
||||
imagePath
|
||||
)
|
||||
),
|
||||
|
||||
createImageMessageByUrl: (params: ImageMsgByUrlParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_image_message_by_url(
|
||||
opid,
|
||||
JSON.stringify(params.sourcePicture),
|
||||
JSON.stringify(params.bigPicture),
|
||||
JSON.stringify(params.snapshotPicture)
|
||||
)
|
||||
),
|
||||
|
||||
createVideoMessage: (params: VideoMsgByPathParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_video_message(
|
||||
opid,
|
||||
params.videoPath,
|
||||
params.videoType,
|
||||
params.duration,
|
||||
params.snapshotPath
|
||||
)
|
||||
),
|
||||
|
||||
createVideoMessageFromFullPath: (
|
||||
params: VideoMsgByPathParams,
|
||||
opid = uuidV4()
|
||||
) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_video_message_from_full_path(
|
||||
opid,
|
||||
params.videoPath,
|
||||
params.videoType,
|
||||
params.duration,
|
||||
params.snapshotPath
|
||||
)
|
||||
),
|
||||
|
||||
createVideoMessageByUrl: (params: VideoMsgByUrlParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_video_message_by_url(
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
)
|
||||
),
|
||||
|
||||
createSoundMessage: (params: SoundMsgByPathParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_sound_message(
|
||||
opid,
|
||||
params.soundPath,
|
||||
params.duration
|
||||
)
|
||||
),
|
||||
|
||||
createSoundMessageFromFullPath: (
|
||||
params: SoundMsgByPathParams,
|
||||
opid = uuidV4()
|
||||
) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_sound_message_from_full_path(
|
||||
opid,
|
||||
params.soundPath,
|
||||
params.duration
|
||||
)
|
||||
),
|
||||
|
||||
createSoundMessageByUrl: (params: SoundMsgByUrlParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_sound_message_by_url(
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
)
|
||||
),
|
||||
|
||||
createFileMessage: (params: FileMsgByPathParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_file_message(
|
||||
opid,
|
||||
params.filePath,
|
||||
params.fileName
|
||||
)
|
||||
),
|
||||
|
||||
createFileMessageFromFullPath: (
|
||||
params: FileMsgByPathParams,
|
||||
opid = uuidV4()
|
||||
) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_file_message_from_full_path(
|
||||
opid,
|
||||
params.filePath,
|
||||
params.fileName
|
||||
)
|
||||
),
|
||||
|
||||
createFileMessageByUrl: (params: FileMsgByUrlParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_file_message_by_url(
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
)
|
||||
),
|
||||
|
||||
sendMessage: (params: SendMsgParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<MessageItem>>((resolve, reject) => {
|
||||
const offlinePushInfo = params.offlinePushInfo ?? {
|
||||
title: 'You has a new message.',
|
||||
desc: 'You has a new message.',
|
||||
ex: '',
|
||||
iOSPushSound: '+1',
|
||||
iOSBadgeCount: true,
|
||||
};
|
||||
openIMSDK.libOpenIMSDK.send_message(
|
||||
openIMSDK.baseCallbackWrap<MessageItem>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params.message),
|
||||
params.recvID,
|
||||
params.groupID,
|
||||
JSON.stringify(offlinePushInfo)
|
||||
);
|
||||
}),
|
||||
|
||||
// sendMessageNotOss: (params: SendMsgParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<MessageItem>>((resolve, reject) => {
|
||||
// const offlinePushInfo = params.offlinePushInfo ?? {
|
||||
// title: 'You has a new message.',
|
||||
// desc: 'You has a new message.',
|
||||
// ex: '',
|
||||
// iOSPushSound: '+1',
|
||||
// iOSBadgeCount: true,
|
||||
// };
|
||||
// openIMSDK.libOpenIMSDK.send_message_not_oss(
|
||||
// openIMSDK.baseCallbackWrap<MessageItem>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(params.message),
|
||||
// params.recvID,
|
||||
// params.groupID,
|
||||
// JSON.stringify(offlinePushInfo)
|
||||
// );
|
||||
// }),
|
||||
|
||||
// typingStatusUpdate: (params: TypingUpdateParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.typing_status_update(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.recvID,
|
||||
// params.msgTip
|
||||
// );
|
||||
// }),
|
||||
|
||||
// revokeMessage: (params: OpreateMessageParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.revoke_message(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.clientMsgID
|
||||
// );
|
||||
// }),
|
||||
|
||||
// deleteMessage: (params: OpreateMessageParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.delete_message(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.clientMsgID
|
||||
// );
|
||||
// }),
|
||||
|
||||
// deleteMessageFromLocalStorage: (params: OpreateMessageParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.delete_message_from_local_storage(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.clientMsgID
|
||||
// );
|
||||
// }),
|
||||
|
||||
// deleteAllMsgFromLocal: (opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.delete_all_msg_from_local(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// );
|
||||
// }),
|
||||
|
||||
// deleteAllMsgFromLocalAndSvr: (opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.delete_all_msg_from_local_and_svr(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// );
|
||||
// }),
|
||||
|
||||
// searchLocalMessages: (params: SearchLocalParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<MessageItem[]>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.search_local_messages(
|
||||
// openIMSDK.baseCallbackWrap<MessageItem[]>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(params)
|
||||
// );
|
||||
// }),
|
||||
|
||||
getAdvancedHistoryMessageList: (
|
||||
params: GetAdvancedHistoryMsgParams,
|
||||
opid = uuidV4()
|
||||
) =>
|
||||
new Promise<BaseResponse<AdvancedGetMessageResult>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_advanced_history_message_list(
|
||||
openIMSDK.baseCallbackWrap<AdvancedGetMessageResult>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
// getAdvancedHistoryMessageListReverse: (
|
||||
// params: GetAdvancedHistoryMsgParams, opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<AdvancedGetMessageResult>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_advanced_history_message_list_reverse(
|
||||
// openIMSDK.baseCallbackWrap<AdvancedGetMessageResult>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(params)
|
||||
// );
|
||||
// }),
|
||||
// findMessageList: (params: FindMessageParams[], opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<MessageItem[]>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.find_message_list(
|
||||
// openIMSDK.baseCallbackWrap<MessageItem[]>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(params)
|
||||
// );
|
||||
// }),
|
||||
// insertGroupMessageToLocalStorage: (params: InsertGroupMsgParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.insert_group_message_to_local_storage(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(params.message),
|
||||
// params.groupID,
|
||||
// params.sendID
|
||||
// );
|
||||
// }),
|
||||
// insertSingleMessageToLocalStorage: (params: InsertSingleMsgParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.insert_single_message_to_local_storage(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(params.message),
|
||||
// params.recvID,
|
||||
// params.sendID
|
||||
// );
|
||||
// }),
|
||||
// setMessageLocalEx: (params: SetMessageLocalExParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.set_message_local_ex(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.clientMsgID,
|
||||
// params.localEx
|
||||
// );
|
||||
// }),
|
||||
};
|
||||
}
|
||||
|
||||
export interface MessageModuleApi {
|
||||
createTextMessage: (
|
||||
content: string,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createTextAtMessage: (
|
||||
params: AtMsgParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createLocationMessage: (
|
||||
params: LocationMsgParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createCustomMessage: (
|
||||
params: CustomMsgParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createQuoteMessage: (
|
||||
params: QuoteMsgParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createCardMessage: (
|
||||
params: CardElem,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createMergerMessage: (
|
||||
params: MergerMsgParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createFaceMessage: (
|
||||
params: FaceMessageParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createForwardMessage: (
|
||||
message: MessageItem,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createImageMessage: (
|
||||
imagePath: string,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createImageMessageFromFullPath: (
|
||||
imagePath: string,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createImageMessageByUrl: (
|
||||
params: ImageMsgByUrlParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createVideoMessage: (
|
||||
params: VideoMsgByPathParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createVideoMessageFromFullPath: (
|
||||
params: VideoMsgByPathParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createVideoMessageByUrl: (
|
||||
params: VideoMsgByUrlParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createSoundMessage: (
|
||||
params: SoundMsgByPathParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createSoundMessageFromFullPath: (
|
||||
params: SoundMsgByPathParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createSoundMessageByUrl: (
|
||||
params: SoundMsgByUrlParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createFileMessage: (
|
||||
params: FileMsgByPathParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createFileMessageFromFullPath: (
|
||||
params: FileMsgByPathParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createFileMessageByUrl: (
|
||||
params: FileMsgByUrlParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
getAdvancedHistoryMessageList: (
|
||||
params: GetAdvancedHistoryMsgParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<AdvancedGetMessageResult>>;
|
||||
sendMessage: (
|
||||
params: SendMsgParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
}
|
||||
86
src/core/modules/user.ts
Normal file
86
src/core/modules/user.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import { BaseResponse, SelfUserInfo } from '@/types/entity';
|
||||
import OpenIMSDK from '..';
|
||||
import { SetSelfInfoParams } from '@/types/params';
|
||||
|
||||
export function setupUserModule(openIMSDK: OpenIMSDK) {
|
||||
return {
|
||||
getSelfUserInfo: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<SelfUserInfo>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_self_user_info(
|
||||
openIMSDK.baseCallbackWrap<SelfUserInfo>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
setSelfInfo: (params: SetSelfInfoParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.set_self_info(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
// getUsersInfoWithCache: (
|
||||
// params: GetUserInfoWithCacheParams,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<FullUserItemWithCache[]>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_users_info_with_cache(
|
||||
// openIMSDK.baseCallbackWrap<FullUserItemWithCache[]>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(params.userIDList),
|
||||
// params.groupID ?? ''
|
||||
// );
|
||||
// }),
|
||||
|
||||
// subscribeUsersStatus: (userIDList: string[], opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<UserOnlineState>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.subscribe_users_status(
|
||||
// openIMSDK.baseCallbackWrap<UserOnlineState>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(userIDList)
|
||||
// );
|
||||
// }),
|
||||
|
||||
// unsubscribeUsersStatus: (userIDList: string[], opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.unsubscribe_users_status(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(userIDList)
|
||||
// );
|
||||
// }),
|
||||
|
||||
// getSubscribeUsersStatus: (opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<UserOnlineState[]>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_subscribe_users_status(
|
||||
// openIMSDK.baseCallbackWrap<UserOnlineState[]>(resolve, reject),
|
||||
// opid
|
||||
// );
|
||||
// }),
|
||||
|
||||
// setAppBackgroundStatus: (isInBackground: boolean, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.set_app_background_status(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// isInBackground
|
||||
// );
|
||||
// }),
|
||||
|
||||
// setGlobalRecvMessageOpt: (msgReceiveOptType: MessageReceiveOptType, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.set_global_recv_message_opt(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// msgReceiveOptType
|
||||
// );
|
||||
// }),
|
||||
};
|
||||
}
|
||||
|
||||
export interface UserModuleApi {
|
||||
getSelfUserInfo: (opid?: string) => Promise<BaseResponse<SelfUserInfo>>;
|
||||
}
|
||||
3
src/index.ts
Normal file
3
src/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import OpenIMSDK from './core';
|
||||
|
||||
export default OpenIMSDK;
|
||||
456
src/types/entity.ts
Normal file
456
src/types/entity.ts
Normal file
@@ -0,0 +1,456 @@
|
||||
import {
|
||||
GroupType,
|
||||
ApplicationHandleResult,
|
||||
GroupJoinSource,
|
||||
GroupStatus,
|
||||
MessageReceiveOptType,
|
||||
Relationship,
|
||||
GroupVerificationType,
|
||||
AllowType,
|
||||
GroupMemberRole,
|
||||
SessionType,
|
||||
GroupAtType,
|
||||
MessageType,
|
||||
Platform,
|
||||
MessageStatus,
|
||||
OnlineState,
|
||||
} from './enum';
|
||||
|
||||
export type BaseCallbackWrap = <T>(
|
||||
resolve: (response: BaseResponse<T>) => void,
|
||||
reject: (response: BaseResponse<T>) => void
|
||||
) => Buffer;
|
||||
|
||||
export type AsyncRetunWrap = <T>(
|
||||
operationID: string,
|
||||
data: unknown
|
||||
) => Promise<BaseResponse<T>>;
|
||||
|
||||
export interface BaseResponse<T = unknown> {
|
||||
errCode: number;
|
||||
errMsg: string;
|
||||
data: T;
|
||||
operationID: string;
|
||||
}
|
||||
|
||||
export type MessageEntity = {
|
||||
type: string;
|
||||
offset: number;
|
||||
length: number;
|
||||
url?: string;
|
||||
info?: string;
|
||||
};
|
||||
export type PicBaseInfo = {
|
||||
uuid: string;
|
||||
type: string;
|
||||
size: number;
|
||||
width: number;
|
||||
height: number;
|
||||
url: string;
|
||||
};
|
||||
export type AtUsersInfoItem = {
|
||||
atUserID: string;
|
||||
groupNickname: string;
|
||||
};
|
||||
export type GroupApplicationItem = {
|
||||
createTime: number;
|
||||
creatorUserID: string;
|
||||
ex: string;
|
||||
groupFaceURL: string;
|
||||
groupID: string;
|
||||
groupName: string;
|
||||
groupType: GroupType;
|
||||
handleResult: ApplicationHandleResult;
|
||||
handleUserID: string;
|
||||
handledMsg: string;
|
||||
handledTime: number;
|
||||
introduction: string;
|
||||
memberCount: number;
|
||||
nickname: string;
|
||||
notification: string;
|
||||
ownerUserID: string;
|
||||
reqMsg: string;
|
||||
reqTime: number;
|
||||
joinSource: GroupJoinSource;
|
||||
status: GroupStatus;
|
||||
userFaceURL: string;
|
||||
userID: string;
|
||||
};
|
||||
export type FriendApplicationItem = {
|
||||
createTime: number;
|
||||
ex: string;
|
||||
fromFaceURL: string;
|
||||
fromNickname: string;
|
||||
fromUserID: string;
|
||||
handleMsg: string;
|
||||
handleResult: ApplicationHandleResult;
|
||||
handleTime: number;
|
||||
handlerUserID: string;
|
||||
reqMsg: string;
|
||||
toFaceURL: string;
|
||||
toNickname: string;
|
||||
toUserID: string;
|
||||
};
|
||||
export type FullUserItem = {
|
||||
blackInfo: BlackUserItem | null;
|
||||
friendInfo: FriendUserItem | null;
|
||||
publicInfo: PublicUserItem | null;
|
||||
};
|
||||
export type FullUserItemWithCache = {
|
||||
blackInfo: BlackUserItem | null;
|
||||
friendInfo: FriendUserItem | null;
|
||||
publicInfo: PublicUserItem | null;
|
||||
groupMemberInfo: GroupMemberItem | null;
|
||||
};
|
||||
export type PublicUserItem = {
|
||||
nickname: string;
|
||||
userID: string;
|
||||
faceURL: string;
|
||||
ex: string;
|
||||
};
|
||||
export type SelfUserInfo = {
|
||||
createTime: number;
|
||||
ex: string;
|
||||
faceURL: string;
|
||||
nickname: string;
|
||||
userID: string;
|
||||
globalRecvMsgOpt: MessageReceiveOptType;
|
||||
};
|
||||
export type PartialUserInfo = {
|
||||
userID: string;
|
||||
} & Partial<Omit<SelfUserInfo, 'userID'>>;
|
||||
export type FriendUserItem = {
|
||||
addSource: number;
|
||||
createTime: number;
|
||||
ex: string;
|
||||
faceURL: string;
|
||||
userID: string;
|
||||
nickname: string;
|
||||
operatorUserID: string;
|
||||
ownerUserID: string;
|
||||
remark: string;
|
||||
attachedInfo: string;
|
||||
};
|
||||
export type SearchedFriendsInfo = FriendUserItem & {
|
||||
relationship: Relationship;
|
||||
};
|
||||
export type FriendshipInfo = {
|
||||
result: number;
|
||||
userID: string;
|
||||
};
|
||||
export type BlackUserItem = {
|
||||
addSource: number;
|
||||
userID: string;
|
||||
createTime: number;
|
||||
ex: string;
|
||||
faceURL: string;
|
||||
nickname: string;
|
||||
operatorUserID: string;
|
||||
ownerUserID: string;
|
||||
};
|
||||
export type GroupItem = {
|
||||
groupID: string;
|
||||
groupName: string;
|
||||
notification: string;
|
||||
notificationUserID: string;
|
||||
notificationUpdateTime: number;
|
||||
introduction: string;
|
||||
faceURL: string;
|
||||
ownerUserID: string;
|
||||
createTime: number;
|
||||
memberCount: number;
|
||||
status: GroupStatus;
|
||||
creatorUserID: string;
|
||||
groupType: GroupType;
|
||||
needVerification: GroupVerificationType;
|
||||
ex: string;
|
||||
applyMemberFriend: AllowType;
|
||||
lookMemberInfo: AllowType;
|
||||
};
|
||||
export type GroupMemberItem = {
|
||||
groupID: string;
|
||||
userID: string;
|
||||
nickname: string;
|
||||
faceURL: string;
|
||||
roleLevel: GroupMemberRole;
|
||||
muteEndTime: number;
|
||||
joinTime: number;
|
||||
joinSource: GroupJoinSource;
|
||||
inviterUserID: string;
|
||||
operatorUserID: string;
|
||||
ex: string;
|
||||
};
|
||||
export type ConversationItem = {
|
||||
conversationID: string;
|
||||
conversationType: SessionType;
|
||||
userID: string;
|
||||
groupID: string;
|
||||
showName: string;
|
||||
faceURL: string;
|
||||
recvMsgOpt: MessageReceiveOptType;
|
||||
unreadCount: number;
|
||||
groupAtType: GroupAtType;
|
||||
latestMsg: string;
|
||||
latestMsgSendTime: number;
|
||||
draftText: string;
|
||||
draftTextTime: number;
|
||||
burnDuration: number;
|
||||
msgDestructTime: number;
|
||||
isPinned: boolean;
|
||||
isNotInGroup: boolean;
|
||||
isPrivateChat: boolean;
|
||||
isMsgDestruct: boolean;
|
||||
attachedInfo: string;
|
||||
ex: string;
|
||||
};
|
||||
export type MessageItem = {
|
||||
clientMsgID: string;
|
||||
serverMsgID: string;
|
||||
createTime: number;
|
||||
sendTime: number;
|
||||
sessionType: SessionType;
|
||||
sendID: string;
|
||||
recvID: string;
|
||||
msgFrom: number;
|
||||
contentType: MessageType;
|
||||
senderPlatformID: Platform;
|
||||
senderNickname: string;
|
||||
senderFaceUrl: string;
|
||||
groupID: string;
|
||||
content: string;
|
||||
seq: number;
|
||||
isRead: boolean;
|
||||
status: MessageStatus;
|
||||
isReact: boolean;
|
||||
isExternalExtensions: boolean;
|
||||
offlinePush: OfflinePush;
|
||||
attachedInfo: string;
|
||||
ex: string;
|
||||
localEx: string;
|
||||
textElem: TextElem;
|
||||
cardElem: CardElem;
|
||||
pictureElem: PictureElem;
|
||||
soundElem: SoundElem;
|
||||
videoElem: VideoElem;
|
||||
fileElem: FileElem;
|
||||
mergeElem: MergeElem;
|
||||
atTextElem: AtTextElem;
|
||||
faceElem: FaceElem;
|
||||
locationElem: LocationElem;
|
||||
customElem: CustomElem;
|
||||
quoteElem: QuoteElem;
|
||||
notificationElem: NotificationElem;
|
||||
advancedTextElem: AdvancedTextElem;
|
||||
typingElem: TypingElem;
|
||||
attachedInfoElem: AttachedInfoElem;
|
||||
};
|
||||
export type TextElem = {
|
||||
content: string;
|
||||
};
|
||||
export type CardElem = {
|
||||
userID: string;
|
||||
nickname: string;
|
||||
faceURL: string;
|
||||
ex: string;
|
||||
};
|
||||
export type AtTextElem = {
|
||||
text: string;
|
||||
atUserList: string[];
|
||||
atUsersInfo?: AtUsersInfoItem[];
|
||||
quoteMessage?: MessageItem;
|
||||
isAtSelf?: boolean;
|
||||
};
|
||||
export type NotificationElem = {
|
||||
detail: string;
|
||||
};
|
||||
export type AdvancedTextElem = {
|
||||
text: string;
|
||||
messageEntityList: MessageEntity[];
|
||||
};
|
||||
export type TypingElem = {
|
||||
msgTips: string;
|
||||
};
|
||||
export type CustomElem = {
|
||||
data: string;
|
||||
description: string;
|
||||
extension: string;
|
||||
};
|
||||
export type FileElem = {
|
||||
filePath: string;
|
||||
uuid: string;
|
||||
sourceUrl: string;
|
||||
fileName: string;
|
||||
fileSize: number;
|
||||
};
|
||||
export type FaceElem = {
|
||||
index: number;
|
||||
data: string;
|
||||
};
|
||||
export type LocationElem = {
|
||||
description: string;
|
||||
longitude: number;
|
||||
latitude: number;
|
||||
};
|
||||
export type MergeElem = {
|
||||
title: string;
|
||||
abstractList: string[];
|
||||
multiMessage: MessageItem[];
|
||||
messageEntityList: MessageEntity[];
|
||||
};
|
||||
export type OfflinePush = {
|
||||
title: string;
|
||||
desc: string;
|
||||
ex: string;
|
||||
iOSPushSound: string;
|
||||
iOSBadgeCount: boolean;
|
||||
};
|
||||
export type PictureElem = {
|
||||
sourcePath: string;
|
||||
sourcePicture: Picture;
|
||||
bigPicture: Picture;
|
||||
snapshotPicture: Picture;
|
||||
};
|
||||
export type AttachedInfoElem = {
|
||||
groupHasReadInfo: GroupHasReadInfo;
|
||||
isPrivateChat: boolean;
|
||||
isEncryption: boolean;
|
||||
inEncryptStatus: boolean;
|
||||
burnDuration: number;
|
||||
hasReadTime: number;
|
||||
notSenderNotificationPush: boolean;
|
||||
messageEntityList: MessageEntity[];
|
||||
uploadProgress: UploadProgress;
|
||||
};
|
||||
export type UploadProgress = {
|
||||
total: number;
|
||||
save: number;
|
||||
current: number;
|
||||
};
|
||||
export type GroupHasReadInfo = {
|
||||
hasReadCount: number;
|
||||
unreadCount: number;
|
||||
hasReadUserIDList: string[];
|
||||
groupMemberCount: number;
|
||||
};
|
||||
export type Picture = {
|
||||
uuid: string;
|
||||
type: string;
|
||||
size: number;
|
||||
width: number;
|
||||
height: number;
|
||||
url: string;
|
||||
};
|
||||
export type QuoteElem = {
|
||||
text: string;
|
||||
quoteMessage: MessageItem;
|
||||
};
|
||||
export type SoundElem = {
|
||||
uuid: string;
|
||||
soundPath: string;
|
||||
sourceUrl: string;
|
||||
dataSize: number;
|
||||
duration: number;
|
||||
};
|
||||
export type VideoElem = {
|
||||
videoPath: string;
|
||||
videoUUID: string;
|
||||
videoUrl: string;
|
||||
videoType: string;
|
||||
videoSize: number;
|
||||
duration: number;
|
||||
snapshotPath: string;
|
||||
snapshotUUID: string;
|
||||
snapshotSize: number;
|
||||
snapshotUrl: string;
|
||||
snapshotWidth: number;
|
||||
snapshotHeight: number;
|
||||
};
|
||||
export type AdvancedRevokeContent = {
|
||||
clientMsgID: string;
|
||||
revokeTime: number;
|
||||
revokerID: string;
|
||||
revokerNickname: string;
|
||||
revokerRole: number;
|
||||
seq: number;
|
||||
sessionType: SessionType;
|
||||
sourceMessageSendID: string;
|
||||
sourceMessageSendTime: number;
|
||||
sourceMessageSenderNickname: string;
|
||||
};
|
||||
|
||||
export type RevokedInfo = {
|
||||
revokerID: string;
|
||||
revokerRole: number;
|
||||
clientMsgID: string;
|
||||
revokerNickname: string;
|
||||
revokeTime: number;
|
||||
sourceMessageSendTime: number;
|
||||
sourceMessageSendID: string;
|
||||
sourceMessageSenderNickname: string;
|
||||
sessionType: number;
|
||||
seq: number;
|
||||
ex: string;
|
||||
};
|
||||
|
||||
export type ReceiptInfo = {
|
||||
userID: string;
|
||||
groupID: string;
|
||||
msgIDList: string[];
|
||||
readTime: number;
|
||||
msgFrom: number;
|
||||
contentType: MessageType;
|
||||
sessionType: SessionType;
|
||||
};
|
||||
|
||||
export type SearchMessageResult = {
|
||||
totalCount: number;
|
||||
searchResultItems: SearchMessageResultItem[];
|
||||
};
|
||||
|
||||
export type SearchMessageResultItem = {
|
||||
conversationID: string;
|
||||
messageCount: number;
|
||||
conversationType: SessionType;
|
||||
showName: string;
|
||||
faceURL: string;
|
||||
messageList: MessageItem[];
|
||||
};
|
||||
|
||||
export type AdvancedGetMessageResult = {
|
||||
isEnd: boolean;
|
||||
lastMinSeq: number;
|
||||
errCode: number;
|
||||
errMsg: string;
|
||||
messageList: MessageItem[];
|
||||
};
|
||||
|
||||
export type RtcInvite = {
|
||||
inviterUserID: string;
|
||||
inviteeUserIDList: string[];
|
||||
customData?: string;
|
||||
groupID: string;
|
||||
roomID: string;
|
||||
timeout: number;
|
||||
mediaType: string;
|
||||
sessionType: number;
|
||||
platformID: number;
|
||||
initiateTime?: number;
|
||||
busyLineUserIDList?: string[];
|
||||
};
|
||||
|
||||
export type UserOnlineState = {
|
||||
platformIDs?: Platform[];
|
||||
status: OnlineState;
|
||||
userID: string;
|
||||
};
|
||||
|
||||
export type GroupMessageReceiptInfo = {
|
||||
conversationID: string;
|
||||
groupMessageReadInfo: GroupMessageReadInfo[];
|
||||
};
|
||||
export type GroupMessageReadInfo = {
|
||||
clientMsgID: string;
|
||||
hasReadCount: number;
|
||||
unreadCount: number;
|
||||
readMembers: GroupMemberItem[];
|
||||
};
|
||||
135
src/types/enum.ts
Normal file
135
src/types/enum.ts
Normal file
@@ -0,0 +1,135 @@
|
||||
export enum MessageReceiveOptType {
|
||||
Nomal = 0,
|
||||
NotReceive = 1,
|
||||
NotNotify = 2,
|
||||
}
|
||||
export enum AllowType {
|
||||
Allowed = 0,
|
||||
NotAllowed = 1,
|
||||
}
|
||||
export enum GroupType {
|
||||
Group = 2,
|
||||
WorkingGroup = 2,
|
||||
}
|
||||
export enum GroupJoinSource {
|
||||
Invitation = 2,
|
||||
Search = 3,
|
||||
QrCode = 4,
|
||||
}
|
||||
export enum GroupMemberRole {
|
||||
Nomal = 20,
|
||||
Admin = 60,
|
||||
Owner = 100,
|
||||
}
|
||||
export enum GroupVerificationType {
|
||||
ApplyNeedInviteNot = 0,
|
||||
AllNeed = 1,
|
||||
AllNot = 2,
|
||||
}
|
||||
export enum MessageStatus {
|
||||
Sending = 1,
|
||||
Succeed = 2,
|
||||
Failed = 3,
|
||||
}
|
||||
export enum Platform {
|
||||
iOS = 1,
|
||||
Android = 2,
|
||||
Windows = 3,
|
||||
MacOSX = 4,
|
||||
Web = 5,
|
||||
Linux = 7,
|
||||
AndroidPad = 8,
|
||||
iPad = 9,
|
||||
}
|
||||
export enum LogLevel {
|
||||
Debug = 5,
|
||||
Info = 4,
|
||||
Warn = 3,
|
||||
Error = 2,
|
||||
Fatal = 1,
|
||||
Panic = 0,
|
||||
}
|
||||
export enum ApplicationHandleResult {
|
||||
Unprocessed = 0,
|
||||
Agree = 1,
|
||||
Reject = -1,
|
||||
}
|
||||
export enum MessageType {
|
||||
TextMessage = 101,
|
||||
PictureMessage = 102,
|
||||
VoiceMessage = 103,
|
||||
VideoMessage = 104,
|
||||
FileMessage = 105,
|
||||
AtTextMessage = 106,
|
||||
MergeMessage = 107,
|
||||
CardMessage = 108,
|
||||
LocationMessage = 109,
|
||||
CustomMessage = 110,
|
||||
TypingMessage = 113,
|
||||
QuoteMessage = 114,
|
||||
FaceMessage = 115,
|
||||
FriendAdded = 1201,
|
||||
OANotification = 1400,
|
||||
|
||||
GroupCreated = 1501,
|
||||
MemberQuit = 1504,
|
||||
GroupOwnerTransferred = 1507,
|
||||
MemberKicked = 1508,
|
||||
MemberInvited = 1509,
|
||||
MemberEnter = 1510,
|
||||
GroupDismissed = 1511,
|
||||
GroupMemberMuted = 1512,
|
||||
GroupMemberCancelMuted = 1513,
|
||||
GroupMuted = 1514,
|
||||
GroupCancelMuted = 1515,
|
||||
GroupAnnouncementUpdated = 1519,
|
||||
GroupNameUpdated = 1520,
|
||||
BurnMessageChange = 1701,
|
||||
|
||||
// notification
|
||||
RevokeMessage = 2101,
|
||||
}
|
||||
export enum SessionType {
|
||||
Single = 1,
|
||||
Group = 3,
|
||||
WorkingGroup = 3,
|
||||
Notification = 4,
|
||||
}
|
||||
export enum GroupStatus {
|
||||
Nomal = 0,
|
||||
Baned = 1,
|
||||
Dismissed = 2,
|
||||
Muted = 3,
|
||||
}
|
||||
export enum GroupAtType {
|
||||
AtNormal = 0,
|
||||
AtMe = 1,
|
||||
AtAll = 2,
|
||||
AtAllAtMe = 3,
|
||||
AtGroupNotice = 4,
|
||||
}
|
||||
export enum GroupMemberFilter {
|
||||
All = 0,
|
||||
Owner = 1,
|
||||
Admin = 2,
|
||||
Nomal = 3,
|
||||
AdminAndNomal = 4,
|
||||
AdminAndOwner = 5,
|
||||
}
|
||||
export enum Relationship {
|
||||
isBlack = 0,
|
||||
isFriend = 1,
|
||||
}
|
||||
export enum LoginStatus {
|
||||
Logout = 1,
|
||||
Logging = 2,
|
||||
Logged = 3,
|
||||
}
|
||||
export enum OnlineState {
|
||||
Online = 1,
|
||||
Offline = 0,
|
||||
}
|
||||
export enum GroupMessageReaderFilter {
|
||||
Readed = 0,
|
||||
UnRead = 1,
|
||||
}
|
||||
441
src/types/libOpenIMSDK.d.ts
vendored
Normal file
441
src/types/libOpenIMSDK.d.ts
vendored
Normal file
@@ -0,0 +1,441 @@
|
||||
// libOpenIMSDK.d.ts
|
||||
declare module 'libOpenIMSDK' {
|
||||
export type CB_S = Buffer | ((data: string) => void);
|
||||
export type CB_I_S = Buffer | ((event: number, data: string) => void);
|
||||
export type CB_S_I_S_S =
|
||||
| Buffer
|
||||
| ((
|
||||
operationID: string,
|
||||
errCode: number,
|
||||
errMsg: string,
|
||||
data: string
|
||||
) => void);
|
||||
export type CB_S_I_S_S_I =
|
||||
| Buffer
|
||||
| ((
|
||||
operationID: string,
|
||||
errCode: number,
|
||||
errMsg: string,
|
||||
data: string,
|
||||
progress: number
|
||||
) => void);
|
||||
|
||||
export interface LibOpenIMSDK {
|
||||
set_group_listener(cCallback: CB_I_S): void;
|
||||
set_conversation_listener(cCallback: CB_I_S): void;
|
||||
set_advanced_msg_listener(cCallback: CB_I_S): void;
|
||||
set_batch_msg_listener(cCallback: CB_I_S): void;
|
||||
set_user_listener(cCallback: CB_I_S): void;
|
||||
set_friend_listener(cCallback: CB_I_S): void;
|
||||
set_custom_business_listener(cCallback: CB_I_S): void;
|
||||
init_sdk(cCallback: CB_I_S, operationID: string, config: string): number;
|
||||
un_init_sdk(operationID: string): void;
|
||||
login(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
userID: string,
|
||||
token: string
|
||||
): void;
|
||||
logout(cCallback: CB_S_I_S_S, operationID: string): void;
|
||||
network_status_changed(cCallback: CB_S_I_S_S, operationID: string): void;
|
||||
get_login_status(operationID: string): number;
|
||||
get_login_user(): string;
|
||||
|
||||
// message related functions
|
||||
create_text_message(operationID: string, text: string): string;
|
||||
create_advanced_text_message(
|
||||
operationID: string,
|
||||
text: string,
|
||||
messageEntityList: string
|
||||
): string;
|
||||
create_text_at_message(
|
||||
operationID: string,
|
||||
text: string,
|
||||
atUserList: string,
|
||||
atUsersInfo: string,
|
||||
message: string
|
||||
): string;
|
||||
create_location_message(
|
||||
operationID: string,
|
||||
description: string,
|
||||
longitude: number,
|
||||
latitude: number
|
||||
): string;
|
||||
create_custom_message(
|
||||
operationID: string,
|
||||
data: string,
|
||||
extension: string,
|
||||
description: string
|
||||
): string;
|
||||
create_quote_message(
|
||||
operationID: string,
|
||||
text: string,
|
||||
message: string
|
||||
): string;
|
||||
create_advanced_quote_message(
|
||||
operationID: string,
|
||||
text: string,
|
||||
message: string,
|
||||
messageEntityList: string
|
||||
): string;
|
||||
create_card_message(operationID: string, cardInfo: string): string;
|
||||
create_video_message_from_full_path(
|
||||
operationID: string,
|
||||
videoFullPath: string,
|
||||
videoType: string,
|
||||
duration: number,
|
||||
snapshotFullPath: string
|
||||
): string;
|
||||
create_image_message_from_full_path(
|
||||
operationID: string,
|
||||
imageFullPath: string
|
||||
): string;
|
||||
create_sound_message_from_full_path(
|
||||
operationID: string,
|
||||
soundPath: string,
|
||||
duration: number
|
||||
): string;
|
||||
create_file_message_from_full_path(
|
||||
operationID: string,
|
||||
fileFullPath: string,
|
||||
fileName: string
|
||||
): string;
|
||||
create_image_message(operationID: string, imagePath: string): string;
|
||||
create_image_message_by_url(
|
||||
operationID: string,
|
||||
sourcePicture: string,
|
||||
bigPicture: string,
|
||||
snapshotPicture: string
|
||||
): string;
|
||||
create_sound_message_by_url(
|
||||
operationID: string,
|
||||
soundBaseInfo: string
|
||||
): string;
|
||||
create_sound_message(
|
||||
operationID: string,
|
||||
soundPath: string,
|
||||
duration: number
|
||||
): string;
|
||||
create_video_message_by_url(
|
||||
operationID: string,
|
||||
videoBaseInfo: string
|
||||
): string;
|
||||
create_video_message(
|
||||
operationID: string,
|
||||
videoPath: string,
|
||||
videoType: string,
|
||||
duration: number,
|
||||
snapshotPath: string
|
||||
): string;
|
||||
create_file_message_by_url(
|
||||
operationID: string,
|
||||
fileBaseInfo: string
|
||||
): string;
|
||||
create_file_message(
|
||||
operationID: string,
|
||||
filePath: string,
|
||||
fileName: string
|
||||
): string;
|
||||
create_merger_message(
|
||||
operationID: string,
|
||||
messageList: string,
|
||||
title: string,
|
||||
summaryList: string
|
||||
): string;
|
||||
create_face_message(
|
||||
operationID: string,
|
||||
index: number,
|
||||
data: string
|
||||
): string;
|
||||
create_forward_message(operationID: string, m: string): string;
|
||||
get_advanced_history_message_list(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
getMessageOptions: string
|
||||
): void;
|
||||
send_message(
|
||||
cCallback: CB_S_I_S_S_I,
|
||||
operationID: string,
|
||||
message: string,
|
||||
recvID: string,
|
||||
groupID: string,
|
||||
offlinePushInfo: string
|
||||
): void;
|
||||
|
||||
// Conversation related functions
|
||||
get_all_conversation_list(cCallback: CB_S_I_S_S, operationID: string): void;
|
||||
|
||||
// User related functions
|
||||
get_users_info(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
userIDList: string
|
||||
): void;
|
||||
set_self_info(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
userInfo: string
|
||||
): void;
|
||||
get_self_user_info(cCallback: CB_S_I_S_S, operationID: string): void;
|
||||
subscribe_users_status(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
userIDList: string
|
||||
): void;
|
||||
unsubscribe_users_status(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
userIDList: string
|
||||
): void;
|
||||
get_subscribe_users_status(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string
|
||||
): void;
|
||||
get_user_status(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
userIDList: string
|
||||
): void;
|
||||
|
||||
// Friend related functions
|
||||
get_specified_friends_info(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
userIDList: string
|
||||
): void;
|
||||
get_friend_list(cCallback: CB_S_I_S_S, operationID: string): void;
|
||||
get_friend_list_page(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
offset: number,
|
||||
count: number
|
||||
): void;
|
||||
search_friends(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
searchParam: string
|
||||
): void;
|
||||
check_friend(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
userIDList: string
|
||||
): void;
|
||||
add_friend(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
userIDReqMsg: string
|
||||
): void;
|
||||
set_friend_remark(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
userIDRemark: string
|
||||
): void;
|
||||
delete_friend(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
friendUserID: string
|
||||
): void;
|
||||
get_friend_application_list_as_recipient(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string
|
||||
): void;
|
||||
get_friend_application_list_as_applicant(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string
|
||||
): void;
|
||||
accept_friend_application(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
userIDHandleMsg: string
|
||||
): void;
|
||||
refuse_friend_application(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
userIDHandleMsg: string
|
||||
): void;
|
||||
add_black(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
blackUserID: string
|
||||
): void;
|
||||
get_black_list(cCallback: CB_S_I_S_S, operationID: string): void;
|
||||
remove_black(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
removeUserID: string
|
||||
): void;
|
||||
|
||||
// Group related functions
|
||||
create_group(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupReqInfo: string
|
||||
): void;
|
||||
join_group(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cReqMsg: string,
|
||||
cJoinSource: number
|
||||
): void;
|
||||
quit_group(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string
|
||||
): void;
|
||||
dismiss_group(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string
|
||||
): void;
|
||||
change_group_mute(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cIsMute: number
|
||||
): void;
|
||||
change_group_member_mute(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cUserID: string,
|
||||
cMutedSeconds: number
|
||||
): void;
|
||||
set_group_member_role_level(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cUserID: string,
|
||||
cRoleLevel: number
|
||||
): void;
|
||||
set_group_member_info(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupMemberInfo: string
|
||||
): void;
|
||||
get_joined_group_list(cCallback: CB_S_I_S_S, operationID: string): void;
|
||||
get_specified_groups_info(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupIDList: string
|
||||
): void;
|
||||
search_groups(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cSearchParam: string
|
||||
): void;
|
||||
set_group_info(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupInfo: string
|
||||
): void;
|
||||
set_group_verification(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cVerification: number
|
||||
): void;
|
||||
set_group_look_member_info(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cRule: number
|
||||
): void;
|
||||
set_group_apply_member_friend(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cRule: number
|
||||
): void;
|
||||
get_group_member_list(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cFilter: number,
|
||||
cOffset: number,
|
||||
cCount: number
|
||||
): void;
|
||||
get_group_member_owner_and_admin(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string
|
||||
): void;
|
||||
get_group_member_list_by_join_time_filter(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cOffset: number,
|
||||
cCount: number,
|
||||
cJoinTimeBegin: number,
|
||||
cJoinTimeEnd: number,
|
||||
cFilterUserIDList: string
|
||||
): void;
|
||||
get_specified_group_members_info(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cUserIDList: string
|
||||
): void;
|
||||
kick_group_member(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cReason: string,
|
||||
cUserIDList: string
|
||||
): void;
|
||||
transfer_group_owner(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cNewOwnerUserID: string
|
||||
): void;
|
||||
invite_user_to_group(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cReason: string,
|
||||
cUserIDList: string
|
||||
): void;
|
||||
get_group_application_list_as_recipient(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string
|
||||
): void;
|
||||
get_group_application_list_as_applicant(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string
|
||||
): void;
|
||||
accept_group_application(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cFromUserID: string,
|
||||
cHandleMsg: string
|
||||
): void;
|
||||
refuse_group_application(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cFromUserID: string,
|
||||
cHandleMsg: string
|
||||
): void;
|
||||
set_group_member_nickname(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string,
|
||||
cUserID: string,
|
||||
cGroupMemberNickname: string
|
||||
): void;
|
||||
search_group_members(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cSearchParam: string
|
||||
): void;
|
||||
is_join_group(
|
||||
cCallback: CB_S_I_S_S,
|
||||
operationID: string,
|
||||
cGroupID: string
|
||||
): void;
|
||||
}
|
||||
const lib: LibOpenIMSDK;
|
||||
export default lib;
|
||||
}
|
||||
330
src/types/params.ts
Normal file
330
src/types/params.ts
Normal file
@@ -0,0 +1,330 @@
|
||||
import {
|
||||
AtUsersInfoItem,
|
||||
GroupItem,
|
||||
MessageItem,
|
||||
OfflinePush,
|
||||
PicBaseInfo,
|
||||
SelfUserInfo,
|
||||
} from './entity';
|
||||
import {
|
||||
MessageReceiveOptType,
|
||||
GroupJoinSource,
|
||||
GroupMemberFilter,
|
||||
GroupMemberRole,
|
||||
MessageType,
|
||||
LogLevel,
|
||||
} from './enum';
|
||||
|
||||
export interface InitConfig {
|
||||
apiAddr: string;
|
||||
wsAddr: string;
|
||||
logLevel?: LogLevel;
|
||||
platformID: number;
|
||||
isLogStandardOutput?: boolean;
|
||||
isExternalExtensions?: boolean;
|
||||
}
|
||||
|
||||
export interface LoginParams {
|
||||
userID: string;
|
||||
token: string;
|
||||
}
|
||||
|
||||
export type SetSelfInfoParams = Partial<SelfUserInfo>;
|
||||
|
||||
export type GetUserInfoWithCacheParams = {
|
||||
userIDList: string[];
|
||||
groupID?: string;
|
||||
};
|
||||
|
||||
export type SplitConversationParams = {
|
||||
offset: number;
|
||||
count: number;
|
||||
};
|
||||
|
||||
export type GetOneConversationParams = {
|
||||
sourceID: string;
|
||||
sessionType: number;
|
||||
};
|
||||
|
||||
export type SetConversationDraftParams = {
|
||||
conversationID: string;
|
||||
draftText: string;
|
||||
};
|
||||
|
||||
export type PinConversationParams = {
|
||||
conversationID: string;
|
||||
isPinned: boolean;
|
||||
};
|
||||
|
||||
export type SetConversationRecvOptParams = {
|
||||
conversationID: string;
|
||||
opt: MessageReceiveOptType;
|
||||
};
|
||||
|
||||
export type SetConversationPrivateParams = {
|
||||
conversationID: string;
|
||||
isPrivate: boolean;
|
||||
};
|
||||
|
||||
export type SetBurnDurationParams = {
|
||||
conversationID: string;
|
||||
burnDuration: number;
|
||||
};
|
||||
|
||||
export type AccessFriendParams = {
|
||||
toUserID: string;
|
||||
handleMsg: string;
|
||||
};
|
||||
|
||||
export type SearchFriendParams = {
|
||||
keywordList: string[];
|
||||
isSearchUserID: boolean;
|
||||
isSearchNickname: boolean;
|
||||
isSearchRemark: boolean;
|
||||
};
|
||||
|
||||
export type RemarkFriendParams = {
|
||||
toUserID: string;
|
||||
remark: string;
|
||||
};
|
||||
|
||||
export type CreateGroupParams = {
|
||||
memberUserIDs: string[];
|
||||
groupInfo: Partial<GroupItem>;
|
||||
adminUserIDs?: string[];
|
||||
ownerUserID?: string;
|
||||
};
|
||||
|
||||
export type JoinGroupParams = {
|
||||
groupID: string;
|
||||
reqMsg: string;
|
||||
joinSource: GroupJoinSource;
|
||||
};
|
||||
|
||||
export type OpreateGroupParams = {
|
||||
groupID: string;
|
||||
reason: string;
|
||||
userIDList: string[];
|
||||
};
|
||||
|
||||
export type SearchGroupParams = {
|
||||
keywordList: string[];
|
||||
isSearchGroupID: boolean;
|
||||
isSearchGroupName: boolean;
|
||||
};
|
||||
|
||||
export type SetGroupinfoParams = Partial<GroupItem> & { groupID: string };
|
||||
|
||||
export type AccessGroupParams = {
|
||||
groupID: string;
|
||||
fromUserID: string;
|
||||
handleMsg: string;
|
||||
};
|
||||
|
||||
export declare type GetGroupMemberParams = {
|
||||
groupID: string;
|
||||
filter: GroupMemberFilter;
|
||||
offset: number;
|
||||
count: number;
|
||||
};
|
||||
|
||||
export type getGroupMembersInfoParams = {
|
||||
groupID: string;
|
||||
userIDList: string[];
|
||||
};
|
||||
|
||||
export type SearchGroupMemberParams = {
|
||||
groupID: string;
|
||||
keywordList: string[];
|
||||
isSearchUserID: boolean;
|
||||
isSearchMemberNickname: boolean;
|
||||
offset: number;
|
||||
count: number;
|
||||
};
|
||||
|
||||
export type UpdateMemberInfoParams = {
|
||||
groupID: string;
|
||||
userID: string;
|
||||
nickname?: string;
|
||||
faceURL?: string;
|
||||
roleLevel?: GroupMemberRole;
|
||||
ex?: string;
|
||||
};
|
||||
|
||||
export type GetGroupMemberByTimeParams = {
|
||||
groupID: string;
|
||||
filterUserIDList: string[];
|
||||
offset: number;
|
||||
count: number;
|
||||
joinTimeBegin: number;
|
||||
joinTimeEnd: number;
|
||||
};
|
||||
|
||||
export type ChangeGroupMemberMuteParams = {
|
||||
groupID: string;
|
||||
userID: string;
|
||||
mutedSeconds: number;
|
||||
};
|
||||
|
||||
export type ChangeGroupMuteParams = {
|
||||
groupID: string;
|
||||
isMute: boolean;
|
||||
};
|
||||
|
||||
export type TransferGroupParams = {
|
||||
groupID: string;
|
||||
newOwnerUserID: string;
|
||||
};
|
||||
|
||||
export type AtMsgParams = {
|
||||
text: string;
|
||||
atUserIDList: string[];
|
||||
atUsersInfo?: AtUsersInfoItem[];
|
||||
message?: MessageItem;
|
||||
};
|
||||
|
||||
export type ImageMsgByUrlParams = {
|
||||
sourcePicture: PicBaseInfo;
|
||||
bigPicture: PicBaseInfo;
|
||||
snapshotPicture: PicBaseInfo;
|
||||
sourcePath: string;
|
||||
};
|
||||
|
||||
export type SoundMsgByUrlParams = {
|
||||
uuid: string;
|
||||
soundPath: string;
|
||||
sourceUrl: string;
|
||||
dataSize: number;
|
||||
duration: number;
|
||||
soundType?: string;
|
||||
};
|
||||
export type SoundMsgByPathParams = {
|
||||
soundPath: string;
|
||||
duration: number;
|
||||
};
|
||||
|
||||
export type VideoMsgByUrlParams = {
|
||||
videoPath: string;
|
||||
duration: number;
|
||||
videoType: string;
|
||||
snapshotPath: string;
|
||||
videoUUID: string;
|
||||
videoUrl: string;
|
||||
videoSize: number;
|
||||
snapshotUUID: string;
|
||||
snapshotSize: number;
|
||||
snapshotUrl: string;
|
||||
snapshotWidth: number;
|
||||
snapshotHeight: number;
|
||||
snapShotType?: string;
|
||||
};
|
||||
|
||||
export type VideoMsgByPathParams = {
|
||||
videoPath: string;
|
||||
videoType: string;
|
||||
duration: number;
|
||||
snapshotPath: string;
|
||||
};
|
||||
|
||||
export type FileMsgByPathParams = {
|
||||
filePath: string;
|
||||
fileName: string;
|
||||
};
|
||||
|
||||
export type FileMsgByUrlParams = {
|
||||
filePath: string;
|
||||
fileName: string;
|
||||
uuid: string;
|
||||
sourceUrl: string;
|
||||
fileSize: number;
|
||||
fileType?: string;
|
||||
};
|
||||
|
||||
export type MergerMsgParams = {
|
||||
messageList: MessageItem[];
|
||||
title: string;
|
||||
summaryList: string[];
|
||||
};
|
||||
|
||||
export type LocationMsgParams = {
|
||||
description: string;
|
||||
longitude: number;
|
||||
latitude: number;
|
||||
};
|
||||
|
||||
export type QuoteMsgParams = {
|
||||
text: string;
|
||||
message: string;
|
||||
};
|
||||
|
||||
export type CustomMsgParams = {
|
||||
data: string;
|
||||
extension: string;
|
||||
description: string;
|
||||
};
|
||||
|
||||
export type FaceMessageParams = {
|
||||
index: number;
|
||||
data: string;
|
||||
};
|
||||
|
||||
export type SendMsgParams = {
|
||||
recvID: string;
|
||||
groupID: string;
|
||||
offlinePushInfo?: OfflinePush;
|
||||
message: MessageItem;
|
||||
};
|
||||
|
||||
export type TypingUpdateParams = {
|
||||
recvID: string;
|
||||
msgTip: string;
|
||||
};
|
||||
|
||||
export type OpreateMessageParams = {
|
||||
conversationID: string;
|
||||
clientMsgID: string;
|
||||
};
|
||||
|
||||
export type SearchLocalParams = {
|
||||
conversationID: string;
|
||||
keywordList: string[];
|
||||
keywordListMatchType?: number;
|
||||
senderUserIDList?: string[];
|
||||
messageTypeList?: MessageType[];
|
||||
searchTimePosition?: number;
|
||||
searchTimePeriod?: number;
|
||||
pageIndex?: number;
|
||||
count?: number;
|
||||
};
|
||||
|
||||
export type GetAdvancedHistoryMsgParams = {
|
||||
userID?: string;
|
||||
groupID?: string;
|
||||
lastMinSeq: number;
|
||||
count: number;
|
||||
startClientMsgID: string;
|
||||
conversationID: string;
|
||||
};
|
||||
|
||||
export type FindMessageParams = {
|
||||
conversationID: string;
|
||||
clientMsgIDList: string[];
|
||||
};
|
||||
|
||||
export type InsertGroupMsgParams = {
|
||||
message: MessageItem;
|
||||
groupID: string;
|
||||
sendID: string;
|
||||
};
|
||||
|
||||
export type InsertSingleMsgParams = {
|
||||
message: MessageItem;
|
||||
recvID: string;
|
||||
sendID: string;
|
||||
};
|
||||
|
||||
export type SetMessageLocalExParams = {
|
||||
conversationID: string;
|
||||
clientMsgID: string;
|
||||
localEx: string;
|
||||
};
|
||||
54
src/utils/emitter.ts
Normal file
54
src/utils/emitter.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { CbEvents } from '@/constant/callback';
|
||||
|
||||
interface Events {
|
||||
[key: string]: Cbfn[];
|
||||
}
|
||||
|
||||
type Cbfn = (data: unknown) => void;
|
||||
|
||||
class Emitter {
|
||||
private events: Events;
|
||||
|
||||
constructor() {
|
||||
this.events = {};
|
||||
}
|
||||
|
||||
emit(event: CbEvents, data: unknown) {
|
||||
if (this.events[event]) {
|
||||
this.events[event].forEach(fn => {
|
||||
return fn(data);
|
||||
});
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
on(event: CbEvents, fn: Cbfn) {
|
||||
if (this.events[event]) {
|
||||
this.events[event].push(fn);
|
||||
} else {
|
||||
this.events[event] = [fn];
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
off(event: CbEvents, fn: Cbfn) {
|
||||
if (event && typeof fn === 'function' && this.events[event]) {
|
||||
const listeners = this.events[event];
|
||||
if (!listeners || listeners.length === 0) {
|
||||
return;
|
||||
}
|
||||
const index = listeners.findIndex(_fn => {
|
||||
return _fn === fn;
|
||||
});
|
||||
if (index !== -1) {
|
||||
listeners.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
export default Emitter;
|
||||
7
tsconfig.build.json
Normal file
7
tsconfig.build.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"declaration": false
|
||||
},
|
||||
"exclude": ["test/**/*.spec.ts"]
|
||||
}
|
||||
17
tsconfig.json
Normal file
17
tsconfig.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2017",
|
||||
"module": "esnext",
|
||||
"lib": ["esnext", "dom"],
|
||||
"declaration": true,
|
||||
"outDir": "./lib",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"moduleResolution": "node",
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"@/*": ["src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user