Skip to content

Commit f7552ac

Browse files
docs: update README and rename IOS-EXAMPLE-WARN file (#81)
1 parent 418a7df commit f7552ac

File tree

2 files changed

+67
-14
lines changed

2 files changed

+67
-14
lines changed

README.md

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
# React Native Client SDK for OpenIM 👨‍💻💬
22

3-
> **📢 Important Notice:** Starting from version 3.8.3-patch.10, the package name has been changed from `open-im-sdk-rn` to `@openim/rn-client-sdk`. Please update your dependency installation and import statements.
4-
53
Use this SDK to add instant messaging capabilities to your application. By connecting to a self-hosted [OpenIM](https://www.openim.io) server, you can quickly integrate instant messaging capabilities into your app with just a few lines of code.
64

75
The iOS SDK core is implemented in [OpenIM SDK Core](https://github.com/openimsdk/openim-sdk-core). Using [gomobile](https://github.com/golang/mobile), it can be compiled into an XCFramework for iOS integration. iOS 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, iOS utilizes the SQLite layer provided internally by the [OpenIM SDK Core](https://github.com/openimsdk/openim-sdk-core).
86

97
The android SDK core is implemented in [OpenIM SDK Core](https://github.com/openimsdk/openim-sdk-core). Using [gomobile](https://github.com/golang/mobile), it can be compiled into an AAR file for Android integration. Android 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, Android utilizes the SQLite layer provided internally by the [OpenIM SDK Core](https://github.com/openimsdk/openim-sdk-core).
108

11-
The React Native Client SDK use [NativeModule](https://reactnative.dev/docs/native-modules-intro) system exposes instances of Java/Objective-C classes to JavaScript (JS) as JS objects, thereby allowing you to execute arbitrary native code from within JS.
9+
The React Native Client SDK uses the [NativeModule](https://reactnative.dev/docs/native-modules-intro) system to expose instances of Java/Objective-C classes to JavaScript (JS) as JS objects, thereby allowing you to execute arbitrary native code from within JS.
1210

1311
## Tips 🔔
1412

15-
1. The [email protected] has contains ***significant disruptive updates***. If you need to upgrade, please check the incoming data and the returned data. **Note: Package name has been changed to `@openim/rn-client-sdk` starting from version 3.8.3-patch.10.**
13+
1. Starting from `v3.8.3-patch.10`, the package name has been changed from `open-im-sdk-rn` to `@openim/rn-client-sdk`.
14+
15+
2. **operationID Parameter:** This parameter is used for backend log querying. Starting from `v3.8.3-patch.10.2`, the `operationID` parameter is optional for all APIs (the SDK will auto-generate one if not provided). For earlier versions, this parameter is required and must be passed explicitly.
16+
17+
3. **Event Binding API:** Starting from `v3.8.3-patch.10.2`, you can use `OpenIMSDK.on()` to listen for events with better TypeScript type hints. Earlier versions must use the `OpenIMEmitter` object. Both approaches remain compatible with the latest version.
1618

17-
2. Unlike other SDKS, React Native SDK operationID is not optional, but required.
19+
4. The `v3.5.1` contains ***significant disruptive updates***. If you need to upgrade, please check the incoming data and the returned data.
1820

1921
## Documentation 📚
2022

21-
Visit [https://doc.rentsoft.cn](https://doc.rentsoft.cn) for detailed documentation and guides.
23+
Visit [https://docs.openim.io](https://docs.openim.io) for detailed documentation and guides.
2224

23-
For the SDK reference, see [https://doc.rentsoft.cn/sdks/quickstart/reactnative](https://doc.rentsoft.cn/sdks/quickstart/reactnative).
25+
For the SDK reference, see [https://docs.openim.io/sdks/quickstart/reactNative](https://docs.openim.io/sdks/quickstart/reactNative).
2426

2527
## Installation 💻
2628

@@ -37,23 +39,47 @@ The following examples demonstrate how to use the SDK. TypeScript is used, provi
3739
### Importing the SDK and init
3840

3941
```typescript
40-
import OpenIMSDKRN from '@openim/rn-client-sdk';
42+
import OpenIMSDK from '@openim/rn-client-sdk';
4143
import RNFS from 'react-native-fs';
4244

4345
RNFS.mkdir(RNFS.DocumentDirectoryPath + '/tmp');
4446

45-
OpenIMSDKRN.initSDK({
47+
OpenIMSDK.initSDK({
4648
platformID: 2, // 1: ios, 2: android
4749
apiAddr: 'http://your-server-ip:10002',
4850
wsAddr: 'ws://your-server-ip:10001',
4951
dataDir: RNFS.DocumentDirectoryPath + '/tmp',
52+
logFilePath: RNFS.DocumentDirectoryPath + '/tmp',
5053
logLevel: 5,
5154
isLogStandardOutput: true,
52-
}, 'opid');
55+
});
5356
```
5457

5558
### Logging In and Listening for Connection Status
5659

60+
```typescript
61+
import OpenIMSDK from '@openim/rn-client-sdk';
62+
63+
OpenIMSDK.login({
64+
userID: 'IM user ID',
65+
token: 'IM user token',
66+
});
67+
68+
OpenIMSDK.on('onConnecting', () => {
69+
console.log('onConnecting');
70+
});
71+
72+
OpenIMSDK.on('onConnectSuccess', () => {
73+
console.log('onConnectSuccess');
74+
});
75+
76+
OpenIMSDK.on('onConnectFailed', ({ errCode, errMsg }) => {
77+
console.log('onConnectFailed', errCode, errMsg);
78+
});
79+
```
80+
81+
**For versions prior to v3.8.3-patch.10.2:**
82+
5783
```typescript
5884
import OpenIMSDKRN, { OpenIMEmitter } from '@openim/rn-client-sdk';
5985

@@ -75,18 +101,43 @@ OpenIMEmitter.addListener('onConnectFailed', ({ errCode, errMsg }) => {
75101
});
76102
```
77103

78-
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.
104+
To log into the IM server, you need to create an account and obtain a user ID and token. Refer to the [access token documentation](https://docs.openim.io/restapi/apis/usermanagement/userregister) for details.
79105

80106
### Receiving and Sending Messages 💬
81107

82108
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.
83109

84110
```typescript
85-
import OpenIMSDKRN, { OpenIMEmitter } from '@openim/rn-client-sdk';
111+
import OpenIMSDK from '@openim/rn-client-sdk';
86112
import type { MessageItem } from '@openim/rn-client-sdk';
87113

88-
OpenIMEmitter.addListener('onRecvNewMessages', (data: MessageItem[]) => {
89-
console.log('onRecvNewMessages', data);
114+
OpenIMSDK.on('onRecvNewMessages', (messages: MessageItem[]) => {
115+
console.log('onRecvNewMessages', messages);
116+
});
117+
118+
const message = await OpenIMSDK.createTextMessage('hello openim');
119+
120+
OpenIMSDK.sendMessage({
121+
recvID: 'recipient user ID',
122+
groupID: '',
123+
message,
124+
})
125+
.then(() => {
126+
// Message sent successfully ✉️
127+
})
128+
.catch(err => {
129+
// Failed to send message ❌
130+
console.log(err);
131+
});
132+
```
133+
134+
**For versions prior to v3.8.3-patch.10.2:**
135+
136+
```typescript
137+
import OpenIMSDKRN, { OpenIMEmitter } from '@openim/rn-client-sdk';
138+
139+
OpenIMEmitter.addListener('onRecvNewMessages', (messages) => {
140+
console.log('onRecvNewMessages', messages);
90141
});
91142

92143
const message = await OpenIMSDKRN.createTextMessage('hello openim', 'opid');
@@ -121,6 +172,8 @@ yarn example android
121172
yarn example ios
122173
```
123174

175+
> **Note for iOS:** When running the iOS example project, you may encounter dependency installation errors or build failures. Please refer to [iOS Example Project Running Notes](./docs/IOS-EXAMPLE-WARN.md) for detailed solutions.
176+
124177
## Community :busts_in_silhouette:
125178

126179
- 📚 [OpenIM Community](https://github.com/OpenIMSDK/community)
File renamed without changes.

0 commit comments

Comments
 (0)