npm install @tencentcloud/chat --save// The Tencent Cloud Chat upload plugin is required to send messages such as images and files.npm install tim-upload-plugin --save
import TencentCloudChat from '@tencentcloud/chat';import TIMUploadPlugin from 'tim-upload-plugin';let options = {SDKAppID: 0 // Replace 0 with the SDKAppID of your Chat application when connecting.};// Create an SDK instance.// The `TencentCloudChat.create()` method returns the same instance for the same `SDKAppID`.// The SDK instance is usually represented by chat.let chat = TencentCloudChat.create(options);// Set the SDK log level.// 0: Common level. You are advised to use this level during access as it covers more logs.// 1: Release level. You are advised to use this level for key information in a production environment.chat.setLogLevel(0);// chat.setLogLevel(1);// Register the Tencent Cloud Chat upload plugin.chat.registerPlugin({'tim-upload-plugin': TIMUploadPlugin});
chat.setLogLevel(level);
Name | Type | Description |
level | Number | Log levels:
0 - Normal level, with a larger amount of logs. It is recommended for use during integration.
1 - Release level, the SDK outputs key information. It is recommended for use in production environments.
2 - Warning level, the SDK only outputs warning and error level logs.
3 - Error level, the SDK only outputs error level logs.
4 - No log level, the SDK will not print any logs. |
chat.setLogLevel(0);
tim-upload-plugin
to upload files to Tencent Cloud Object Storage. tim-upload-plugin
in a React Native project, you need to upgrade tim-upload-plugin
to version v1.3.1 or above. Also, to improve the user experience in poor network conditions or during network switching, you need to register the network status listening plugin @react-native-community/netinfo
.AndroidManifest.xml
in the Android project:<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.RECORD_AUDIO" />
<key>NSCameraUsageDescription</key><string>We need access to your camera to take photos</string><key>NSPhotoLibraryUsageDescription</key><string>We need access to your photo library to select photos</string><key>NSMicrophoneUsageDescription</key><string>We need access to your microphone to record audio</string>
chat.registerPlugin(options);
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
key | String | Plugin name. |
value | Class | Plugin class. |
chat.registerPlugin({'tim-upload-plugin': TIMUploadPlugin});
// Register the network status listening plugin in a React Native project.npm install @react-native-community/netinfo --saveimport NetInfo from "@react-native-community/netinfo";chat.registerPlugin({'chat-network-monitor': NetInfo});
Was this page helpful?