Skip to main content

🚀Using Demo

We strongly recommend that you first run the framework-related example DEMO we prepared for you. This will not only give you an intuitive experience of OpenIMSDK's capabilities, but will also help you quickly locate and solve problems during the actual integration process.

tip

The project has just started and is still being updated, those in urgent need of functionality will need to add it themselves.

2. Import Package

  import OpenIMSDKRN from "open-im-sdk-rn";

3. Initialization

    const Init = async () => {
await RNFS.mkdir(RNFS.DocumentDirectoryPath + '/tmp');
const config = {
platformID: platform,
apiAddr: API_URL,
wsAddr: WS_URL,

dataDir: RNFS.DocumentDirectoryPath + '/tmp',
logLevel: 6,
isLogStandardOutput: true,
};
try {
const opid = "123456";
const result = await OpenIMSDKRN.initSDK(config, opid);

} catch (error) {
console.error('Error initializing SDK:', error); // Log the error
}
};
const checkLogin = async () => {
const status = (await GetLoginStatus()).status;
if (status == 3){
setIsLoggedIn(true)
initStore()
}

}

4. Setting Listeners

    const setIMListener = () => {

// account
OpenIMEmitter.addListener('onSelfInfoUpdated', (v) => { selfUpdateHandler });
OpenIMEmitter.addListener('onConnecting', connectingHandler);
OpenIMEmitter.addListener('onConnectFailed', connectFailedHandler);
OpenIMEmitter.addListener('onConnectSuccess', connectSuccessHandler);
OpenIMEmitter.addListener('onKickedOffline', (v) => { kickHandler });
OpenIMEmitter.addListener('onUserTokenExpired', (v) => { expiredHandler });
// sync
OpenIMEmitter.addListener('onSyncServerStart', syncStartHandler );
OpenIMEmitter.addListener('onSyncServerFinish', syncFinishHandler );
OpenIMEmitter.addListener('onSyncServerFailed', syncFailedHandler );
// message
OpenIMEmitter.addListener('onRecvNewMessage', newMessageHandler );
OpenIMEmitter.addListener('onRecvNewMessages', newMessageHandler );
OpenIMEmitter.addListener('onNewRecvMessageRevoked',revokedMessageHandler );
// // conversation
OpenIMEmitter.addListener('onConversationChanged', (v) => { conversationChnageHandler });
OpenIMEmitter.addListener('onNewConversation', (v) => { newConversationHandler });
OpenIMEmitter.addListener('onTotalUnreadMessageCountChanged', (v) => { totalUnreadChangeHandler });
// // friend
OpenIMEmitter.addListener('onFriendInfoChanged', friendInfoChangeHandler );
OpenIMEmitter.addListener('onFriendAdded', friendAddedHandler );
OpenIMEmitter.addListener('onFriendDeleted', (v) => { friendDeletedHandler });
// // blacklist
OpenIMEmitter.addListener('onBlackAdded', (v) => { blackAddedHandler });
OpenIMEmitter.addListener('onBlackDeleted', (v) => { blackDeletedHandler });
// // group
OpenIMEmitter.addListener('onJoinedGroupAdded', (v) => { joinedGroupAddedHandler });
OpenIMEmitter.addListener('onJoinedGroupDeleted', (v) => { joinedGroupDeletedHandler });
OpenIMEmitter.addListener('onGroupInfoChanged', (v) => { groupInfoChangedHandler });
OpenIMEmitter.addListener('onGroupMemberAdded', (v) => { groupMemberAddedHandler });
OpenIMEmitter.addListener('onGroupMemberDeleted', (v) => { groupMemberDeletedHandler });
OpenIMEmitter.addListener('onGroupMemberInfoChanged', (v) => { groupMemberInfoChangedHandler });
// // application
OpenIMEmitter.addListener('onFriendApplicationAdded', friendApplicationProcessedHandler );
OpenIMEmitter.addListener('onFriendApplicationAccepted', friendApplicationProcessedHandler );
OpenIMEmitter.addListener('onFriendApplicationRejected', friendApplicationProcessedHandler );
OpenIMEmitter.addListener('onGroupApplicationAdded', (v) => { groupApplicationProcessedHandler });
OpenIMEmitter.addListener('onGroupApplicationAccepted', (v) => { groupApplicationProcessedHandler });
OpenIMEmitter.addListener('onGroupApplicationRejected', (v) => { groupApplicationProcessedHandler });
};